From 0ba337f091798ee8a455b88aced687d69fb0341d Mon Sep 17 00:00:00 2001 From: Caldwell <115591472+Caldwell-74@users.noreply.github.com> Date: Thu, 15 Feb 2024 13:48:04 +0100 Subject: [PATCH] BUGFIX: few bandaids for Bladeburner (#1093) bandaids for 3 bugs in bladeburner this really needs proper fixes and a alot of refactoring! the manual action start didnt start tasks the right way, modifying an existing action object instead of creating a new one therefore the current action wasnt shown on the stats overview the api start action didnt check for the BladesSimulacrum Aug and didnt stop current Player tasks so the next time Bladeburner proccessed it stopped the bladeburner tasks again when the player was doing something else like crimes sometimes blops had an action.count of 0 even when they wherent done in that bladeburner instance yet this happends because the BlackOps class instances are only initialized on game load and then later on BlackOps completion manipulated this change doesnt reset on a bitnode change or when bladeburner is deleted through the dev Menu as a quick fix i added a new resetBlackOps function that always runs when Bladeburner processes this isnt the best solution but any proper fix i came up with requires a refactor that i couldnt do at this moment credits to @TheAimMan for finding the clue that the count is the problem not the rank! edit,; added a 4th bandaid to avoid NaN Stamina Penalty when stamina is infinite --- src/Bladeburner/Bladeburner.tsx | 14 ++++++++++++++ src/Bladeburner/ui/StartButton.tsx | 7 ++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Bladeburner/Bladeburner.tsx b/src/Bladeburner/Bladeburner.tsx index 38276949a..355d3b2d5 100644 --- a/src/Bladeburner/Bladeburner.tsx +++ b/src/Bladeburner/Bladeburner.tsx @@ -109,12 +109,23 @@ export class Bladeburner { this.stamina = this.maxStamina; this.create(); } + /* + just a quick fix for the broken implementation + BlackOperations are only initialized on game load with a count of 1 + and are not reset on BitNode change or dev menu reset of bladeburner + */ + resetBlackOps(): void { + for (const [blackopName, blackop] of Object.entries(BlackOperations)) { + blackop.count = Number(!this.blackops[blackopName]); + } + } getCurrentCity(): City { return this.cities[this.city]; } calculateStaminaPenalty(): number { + if (this.stamina === this.maxStamina) return 1; return Math.min(1, this.stamina / (0.5 * this.maxStamina)); } @@ -1998,6 +2009,8 @@ export class Bladeburner { process(): void { // Edge race condition when the engine checks the processing counters and attempts to route before the router is initialized. if (!Router.isInitialized) return; + //safety measure this needs to be removed in a bigger refactor + this.resetBlackOps(); // If the Player starts doing some other actions, set action to idle and alert if (!Player.hasAugmentation(AugmentationName.BladesSimulacrum, true) && Player.currentWork) { @@ -2166,6 +2179,7 @@ export class Bladeburner { try { this.startAction(actionId); + if (!Player.hasAugmentation(AugmentationName.BladesSimulacrum, true)) Player.finishWork(true); workerScript.log( "bladeburner.startAction", () => `Starting bladeburner action with type '${type}' and name '${name}'`, diff --git a/src/Bladeburner/ui/StartButton.tsx b/src/Bladeburner/ui/StartButton.tsx index 39327277f..b472af4d2 100644 --- a/src/Bladeburner/ui/StartButton.tsx +++ b/src/Bladeburner/ui/StartButton.tsx @@ -31,10 +31,11 @@ export function StartButton(props: IProps): React.ReactElement { } function onStart(): void { if (disabled) return; - props.bladeburner.action.type = props.type; - props.bladeburner.action.name = props.name; + const action = new ActionIdentifier(); + action.type = props.type; + action.name = props.name; if (!Player.hasAugmentation(AugmentationName.BladesSimulacrum, true)) Player.finishWork(true); - props.bladeburner.startAction(props.bladeburner.action); + props.bladeburner.startAction(action); props.rerender(); }