From 1007ce5e68d86efb4562b6a659b4d2cc18d63cf4 Mon Sep 17 00:00:00 2001 From: missymae#2783 <141260118+myCatsName@users.noreply.github.com> Date: Tue, 17 Oct 2023 00:18:54 -0600 Subject: [PATCH] API: Add ns.bladeburner.getNextBlackOp() (#815) --- .../bitburner.bladeburner.getnextblackop.md | 25 +++++++++++++++++ markdown/bitburner.bladeburner.md | 1 + src/Bladeburner/Bladeburner.tsx | 28 ++++++++++++++++++- src/Netscript/RamCostGenerator.ts | 1 + src/NetscriptFunctions/Bladeburner.ts | 4 +++ src/ScriptEditor/NetscriptDefinitions.d.ts | 12 ++++++++ 6 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 markdown/bitburner.bladeburner.getnextblackop.md diff --git a/markdown/bitburner.bladeburner.getnextblackop.md b/markdown/bitburner.bladeburner.getnextblackop.md new file mode 100644 index 000000000..f64673b86 --- /dev/null +++ b/markdown/bitburner.bladeburner.getnextblackop.md @@ -0,0 +1,25 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [Bladeburner](./bitburner.bladeburner.md) > [getNextBlackOp](./bitburner.bladeburner.getnextblackop.md) + +## Bladeburner.getNextBlackOp() method + +Get an object with the name and rank requirement of the next BlackOp that can be completed. + +**Signature:** + +```typescript +getNextBlackOp(): { name: string; rank: number } | null; +``` +**Returns:** + +{ name: string; rank: number } \| null + +An object with the `.name` and `.rank` properties of the available BlackOp, or `null`. + +## Remarks + +RAM cost: 2 GB + +Returns the name and rank requirement for the available BlackOp. Returns `null` if no BlackOps remain in the BitNode. + diff --git a/markdown/bitburner.bladeburner.md b/markdown/bitburner.bladeburner.md index 1d41da85b..066bbd5bc 100644 --- a/markdown/bitburner.bladeburner.md +++ b/markdown/bitburner.bladeburner.md @@ -39,6 +39,7 @@ You have to be employed in the Bladeburner division and be in BitNode-7 or have | [getContractNames()](./bitburner.bladeburner.getcontractnames.md) | List all contracts. | | [getCurrentAction()](./bitburner.bladeburner.getcurrentaction.md) | Get current action. | | [getGeneralActionNames()](./bitburner.bladeburner.getgeneralactionnames.md) | List all general actions. | +| [getNextBlackOp()](./bitburner.bladeburner.getnextblackop.md) | Get an object with the name and rank requirement of the next BlackOp that can be completed. | | [getOperationNames()](./bitburner.bladeburner.getoperationnames.md) | List all operations. | | [getRank()](./bitburner.bladeburner.getrank.md) | Get player bladeburner rank. | | [getSkillLevel(skillName)](./bitburner.bladeburner.getskilllevel.md) | Get skill level. | diff --git a/src/Bladeburner/Bladeburner.tsx b/src/Bladeburner/Bladeburner.tsx index 72bbf3628..2a05a89a2 100644 --- a/src/Bladeburner/Bladeburner.tsx +++ b/src/Bladeburner/Bladeburner.tsx @@ -116,6 +116,33 @@ export class Bladeburner { return Math.min(1, this.stamina / (0.5 * this.maxStamina)); } + // Todo, deduplicate this functionality + getNextBlackOp(): { name: string; rank: number } | null { + let blackops: BlackOperation[] = []; + for (const blackopName of Object.keys(BlackOperations)) { + if (Object.hasOwn(BlackOperations, blackopName)) { + blackops.push(BlackOperations[blackopName]); + } + } + blackops.sort(function (a, b) { + return a.reqdRank - b.reqdRank; + }); + + blackops = blackops.filter( + (blackop: BlackOperation, i: number) => + !(this.blackops[blackops[i].name] == null && i !== 0 && this.blackops[blackops[i - 1].name] == null), + ); + + blackops = blackops.reverse(); + const actionID = this.getActionIdFromTypeAndName("Black Op", "Operation Daedalus"); + + return blackops[0].name === "Operation Daedalus" && + actionID !== null && + !this.canAttemptBlackOp(actionID).isAvailable + ? null + : { name: blackops[0].name, rank: blackops[0].reqdRank }; + } + canAttemptBlackOp(actionId: ActionIdentifier): BlackOpsAttempt { // Safety measure - don't repeat BlackOps that are already done if (this.blackops[actionId.name] != null) { @@ -301,7 +328,6 @@ export class Bladeburner { this.storedCycles += numCycles; } - // working on getActionIdFromTypeAndName(type = "", name = ""): ActionIdentifier | null { if (type === "" || name === "") { return null; diff --git a/src/Netscript/RamCostGenerator.ts b/src/Netscript/RamCostGenerator.ts index e1fde599c..bc68d374c 100644 --- a/src/Netscript/RamCostGenerator.ts +++ b/src/Netscript/RamCostGenerator.ts @@ -243,6 +243,7 @@ const bladeburner = { getContractNames: RamCostConstants.BladeburnerApiBase / 10, getOperationNames: RamCostConstants.BladeburnerApiBase / 10, getBlackOpNames: RamCostConstants.BladeburnerApiBase / 10, + getNextBlackOp: RamCostConstants.BladeburnerApiBase / 2, getBlackOpRank: RamCostConstants.BladeburnerApiBase / 2, getGeneralActionNames: RamCostConstants.BladeburnerApiBase / 10, getSkillNames: RamCostConstants.BladeburnerApiBase / 10, diff --git a/src/NetscriptFunctions/Bladeburner.ts b/src/NetscriptFunctions/Bladeburner.ts index 7e198e82c..2e798ccac 100644 --- a/src/NetscriptFunctions/Bladeburner.ts +++ b/src/NetscriptFunctions/Bladeburner.ts @@ -54,6 +54,10 @@ export function NetscriptBladeburner(): InternalAPI { const bladeburner = getBladeburner(ctx); return bladeburner.getBlackOpNamesNetscriptFn(); }, + getNextBlackOp: (ctx) => () => { + const bladeburner = getBladeburner(ctx); + return bladeburner.getNextBlackOp(); + }, getBlackOpRank: (ctx) => (_blackOpName) => { const blackOpName = helpers.string(ctx, "blackOpName", _blackOpName); checkBladeburnerAccess(ctx); diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index a9c7197a3..de481fbf3 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -2809,6 +2809,18 @@ export interface Bladeburner { */ getBlackOpNames(): string[]; + /** + * Get an object with the name and rank requirement of the next BlackOp that can be completed. + * @remarks + * RAM cost: 2 GB + * + * Returns the name and rank requirement for the available BlackOp. + * Returns `null` if no BlackOps remain in the BitNode. + * + * @returns An object with the `.name` and `.rank` properties of the available BlackOp, or `null`. + */ + getNextBlackOp(): { name: string; rank: number } | null; + /** * List all general actions. * @remarks