From 1cc0288cd8adeb275ecc6364e8b3cd7d342460c9 Mon Sep 17 00:00:00 2001 From: catloversg <152669316+catloversg@users.noreply.github.com> Date: Sun, 2 Feb 2025 12:41:07 +0700 Subject: [PATCH] BUGFIX: Sleeve takes on contracts without checking availability (#1946) --- src/Bladeburner/Bladeburner.ts | 5 +++-- src/NetscriptFunctions/Sleeve.ts | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Bladeburner/Bladeburner.ts b/src/Bladeburner/Bladeburner.ts index 0f324f7d5..f213aa32e 100644 --- a/src/Bladeburner/Bladeburner.ts +++ b/src/Bladeburner/Bladeburner.ts @@ -136,9 +136,10 @@ export class Bladeburner implements OperationTeam { this.resetAction(); return { success: true, message: "Stopped current Bladeburner action" }; } - if (!Player.hasAugmentation(AugmentationName.BladesSimulacrum, true)) Player.finishWork(true); + if (!Player.hasAugmentation(AugmentationName.BladesSimulacrum, true)) { + Player.finishWork(true); + } const action = this.getActionObject(actionId); - // This switch statement is just for handling error cases, it does not have to be exhaustive const availability = action.getAvailability(this); if (!availability.available) { return { message: `Could not start action ${action.name}: ${availability.error}` }; diff --git a/src/NetscriptFunctions/Sleeve.ts b/src/NetscriptFunctions/Sleeve.ts index cf91c009a..b3571a3af 100644 --- a/src/NetscriptFunctions/Sleeve.ts +++ b/src/NetscriptFunctions/Sleeve.ts @@ -8,7 +8,6 @@ import { Augmentations } from "../Augmentation/Augmentations"; import { findCrime } from "../Crime/CrimeHelpers"; import { getEnumHelper } from "../utils/EnumHelper"; import { InternalAPI, NetscriptContext, setRemovedFunctions } from "../Netscript/APIWrapper"; -import { SleeveBladeburnerWork } from "../PersonObjects/Sleeve/Work/SleeveBladeburnerWork"; import { isSleeveFactionWork } from "../PersonObjects/Sleeve/Work/SleeveFactionWork"; import { isSleeveCompanyWork } from "../PersonObjects/Sleeve/Work/SleeveCompanyWork"; import { helpers } from "../Netscript/NetscriptHelpers"; @@ -259,11 +258,17 @@ export function NetscriptSleeve(): InternalAPI { const action = helpers.string(ctx, "action", _action); checkSleeveAPIAccess(ctx); checkSleeveNumber(ctx, sleeveNumber); + if (!Player.bladeburner) { + helpers.log(ctx, () => "You must be a member of the Bladeburner division to use this API."); + return false; + } let contract: BladeburnerContractName | undefined = undefined; if (action === "Take on contracts") { contract = getEnumHelper("BladeburnerContractName").nsGetMember(ctx, _contract); for (let i = 0; i < Player.sleeves.length; ++i) { - if (i === sleeveNumber) continue; + if (i === sleeveNumber) { + continue; + } const otherWork = Player.sleeves[i].currentWork; if (otherWork?.type === SleeveWorkType.BLADEBURNER && otherWork.actionId.name === contract) { throw helpers.errorMessage( @@ -273,7 +278,11 @@ export function NetscriptSleeve(): InternalAPI { } } const actionId: ActionIdentifier = { type: BladeburnerActionType.Contract, name: contract }; - Player.sleeves[sleeveNumber].startWork(new SleeveBladeburnerWork({ actionId })); + const availability = Player.bladeburner.getActionObject(actionId).getAvailability(Player.bladeburner); + if (!availability.available) { + helpers.log(ctx, () => `Could not start action ${contract}: ${availability.error}`); + return false; + } } return Player.sleeves[sleeveNumber].bladeburner(action, contract); },