bitburner-official / bitburner-src

Bitburner source code.
Other
688 stars 232 forks source link

The function `ns.singularity.getFactionWorkTypes()` is missing? #1420

Closed otac0n closed 1 week ago

otac0n commented 2 weeks ago

As of the most recent version of the game, there is no API for determining faction work types, aside from attempting to join them. This can cause problems if it interrupts some long running work activity (like a slow crime or something else).

For example, you can do something like this:

let factionWorkTypes = {};
export function nsGetFactionWorkTypes(ns: NS, faction: string) {
  if (factionWorkTypes.hasOwnProperty(faction)) {
    return factionWorkTypes[faction];
  }
  if (!ns.getPlayer().factions.includes(faction)) return null;
  return factionWorkTypes[faction] = workTypes.map(w => ns.singularity.workForFaction(faction, w, false));
}

This will cache the result, but it will interrupt existing jobs (with potentially large downsides).

otac0n commented 2 weeks ago

Aiming to get this info without clobbering game state: image