SLEEVE: Editorial followup on #1314 (#1347)

This commit is contained in:
Snarling 2024-06-04 09:49:23 -04:00 committed by GitHub
parent cb92643c7e
commit 3afafe4454
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -3,7 +3,7 @@ import type { Sleeve as NetscriptSleeve } from "@nsdefs";
import type { ActionIdentifier } from "../Bladeburner/Types"; import type { ActionIdentifier } from "../Bladeburner/Types";
import { Player } from "@player"; import { Player } from "@player";
import { BladeActionType } from "@enums"; import { BladeActionType, type BladeContractName } from "@enums";
import { Augmentations } from "../Augmentation/Augmentations"; import { Augmentations } from "../Augmentation/Augmentations";
import { findCrime } from "../Crime/CrimeHelpers"; import { findCrime } from "../Crime/CrimeHelpers";
import { getEnumHelper } from "../utils/EnumHelper"; import { getEnumHelper } from "../utils/EnumHelper";
@ -238,24 +238,23 @@ export function NetscriptSleeve(): InternalAPI<NetscriptSleeve> {
const action = helpers.string(ctx, "action", _action); const action = helpers.string(ctx, "action", _action);
checkSleeveAPIAccess(ctx); checkSleeveAPIAccess(ctx);
checkSleeveNumber(ctx, sleeveNumber); checkSleeveNumber(ctx, sleeveNumber);
let contractName = undefined; let contract: BladeContractName | undefined = undefined;
if (action === "Take on contracts") { if (action === "Take on contracts") {
const contractEnum = getEnumHelper("BladeContractName").nsGetMember(ctx, _contract); contract = getEnumHelper("BladeContractName").nsGetMember(ctx, _contract);
contractName = helpers.string(ctx, "contract", _contract);
for (let i = 0; i < Player.sleeves.length; ++i) { for (let i = 0; i < Player.sleeves.length; ++i) {
if (i === sleeveNumber) continue; if (i === sleeveNumber) continue;
const otherWork = Player.sleeves[i].currentWork; const otherWork = Player.sleeves[i].currentWork;
if (otherWork?.type === SleeveWorkType.BLADEBURNER && otherWork.actionId.name === contractEnum) { if (otherWork?.type === SleeveWorkType.BLADEBURNER && otherWork.actionId.name === contract) {
throw helpers.errorMessage( throw helpers.errorMessage(
ctx, ctx,
`Sleeve ${sleeveNumber} cannot take on contracts because Sleeve ${i} is already performing that action.`, `Sleeve ${sleeveNumber} cannot take on contracts because Sleeve ${i} is already performing that action.`,
); );
} }
} }
const actionId: ActionIdentifier = { type: BladeActionType.contract, name: contractEnum }; const actionId: ActionIdentifier = { type: BladeActionType.contract, name: contract };
Player.sleeves[sleeveNumber].startWork(new SleeveBladeburnerWork({ actionId })); Player.sleeves[sleeveNumber].startWork(new SleeveBladeburnerWork({ actionId }));
} }
return Player.sleeves[sleeveNumber].bladeburner(action, contractName); return Player.sleeves[sleeveNumber].bladeburner(action, contract);
}, },
}; };