From 217b94d0a07949ae991139677fc2ae032708bc15 Mon Sep 17 00:00:00 2001 From: Martin Fournier Date: Fri, 17 Dec 2021 05:35:17 -0500 Subject: [PATCH] Fix #1863: Add getHashUpgrades hacknet function Adds a new functions ofr hacknet servers that returns the list of available hash upgrades. --- input/bitburner.api.json | 28 +++++++++++++++ markdown/bitburner.hacknet.gethashupgrades.md | 34 +++++++++++++++++++ markdown/bitburner.hacknet.md | 1 + src/NetscriptFunctions/Hacknet.ts | 8 +++++ src/ScriptEditor/NetscriptDefinitions.d.ts | 16 +++++++++ 5 files changed, 87 insertions(+) create mode 100644 markdown/bitburner.hacknet.gethashupgrades.md diff --git a/input/bitburner.api.json b/input/bitburner.api.json index 4148c530c..b6823c8e8 100644 --- a/input/bitburner.api.json +++ b/input/bitburner.api.json @@ -12012,6 +12012,34 @@ ], "name": "getHashUpgradeLevel" }, + { + "kind": "MethodSignature", + "canonicalReference": "bitburner!Hacknet#getHashUpgrades:member(1)", + "docComment": "/**\n * Get the list of hash upgrades\n *\n * @remarks\n *\n * RAM cost: 0 GB\n *\n * This function is only applicable for Hacknet Servers (the upgraded version of a Hacknet Node).\n *\n * Returns the list of all available hash upgrades that can be used in the spendHashes function.\n *\n * @returns An array containing the available upgrades\n *\n * @example\n * ```ts\n * const upgrades = hacknet.getHashUpgrades(); // [\"Sell for Money\",\"Sell for Corporation Funds\",...]\n * ```\n *\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "getHashUpgrades(): " + }, + { + "kind": "Content", + "text": "string[]" + }, + { + "kind": "Content", + "text": ";" + } + ], + "isOptional": false, + "returnTypeTokenRange": { + "startIndex": 1, + "endIndex": 2 + }, + "releaseTag": "Public", + "overloadIndex": 1, + "parameters": [], + "name": "getHashUpgrades" + }, { "kind": "MethodSignature", "canonicalReference": "bitburner!Hacknet#getLevelUpgradeCost:member(1)", diff --git a/markdown/bitburner.hacknet.gethashupgrades.md b/markdown/bitburner.hacknet.gethashupgrades.md new file mode 100644 index 000000000..4ae3ffef2 --- /dev/null +++ b/markdown/bitburner.hacknet.gethashupgrades.md @@ -0,0 +1,34 @@ + + +[Home](./index.md) > [bitburner](./bitburner.md) > [Hacknet](./bitburner.hacknet.md) > [getHashUpgrades](./bitburner.hacknet.gethashupgrades.md) + +## Hacknet.getHashUpgrades() method + +Get the list of hash upgrades + +Signature: + +```typescript +getHashUpgrades(): string[]; +``` +Returns: + +string\[\] + +An array containing the available upgrades + +## Remarks + +RAM cost: 0 GB + +This function is only applicable for Hacknet Servers (the upgraded version of a Hacknet Node). + +Returns the list of all available hash upgrades that can be used in the spendHashes function. + +## Example + + +```ts +const upgrades = hacknet.getHashUpgrades(); // ["Sell for Money","Sell for Corporation Funds",...] +``` + diff --git a/markdown/bitburner.hacknet.md b/markdown/bitburner.hacknet.md index 6f931bd93..68e36c9e7 100644 --- a/markdown/bitburner.hacknet.md +++ b/markdown/bitburner.hacknet.md @@ -23,6 +23,7 @@ Not all these functions are immediately available. | [getCacheUpgradeCost(index, n)](./bitburner.hacknet.getcacheupgradecost.md) | Calculate the cost of upgrading hacknet node cache. | | [getCoreUpgradeCost(index, n)](./bitburner.hacknet.getcoreupgradecost.md) | Calculate the cost of upgrading hacknet node cores. | | [getHashUpgradeLevel(upgName)](./bitburner.hacknet.gethashupgradelevel.md) | Get the level of a hash upgrade. | +| [getHashUpgrades()](./bitburner.hacknet.gethashupgrades.md) | Get the list of hash upgrades | | [getLevelUpgradeCost(index, n)](./bitburner.hacknet.getlevelupgradecost.md) | Calculate the cost of upgrading hacknet node levels. | | [getNodeStats(index)](./bitburner.hacknet.getnodestats.md) | Get the stats of a hacknet node. | | [getPurchaseNodeCost()](./bitburner.hacknet.getpurchasenodecost.md) | Get the price of the next hacknet node. | diff --git a/src/NetscriptFunctions/Hacknet.ts b/src/NetscriptFunctions/Hacknet.ts index 4626a50c5..4f0564f14 100644 --- a/src/NetscriptFunctions/Hacknet.ts +++ b/src/NetscriptFunctions/Hacknet.ts @@ -16,6 +16,8 @@ import { } from "../Hacknet/HacknetHelpers"; import { HacknetServer } from "../Hacknet/HacknetServer"; import { HacknetNode } from "../Hacknet/HacknetNode"; +import { HashUpgrades } from "../Hacknet/HashUpgrades"; +import { HashUpgrade } from "../Hacknet/HashUpgrade"; import { GetServer } from "../Server/AllServers"; import { Hacknet as IHacknet, NodeStats } from "../ScriptEditor/NetscriptDefinitions"; @@ -166,6 +168,12 @@ export function NetscriptHacknet(player: IPlayer, workerScript: WorkerScript, he } return purchaseHashUpgrade(player, upgName, upgTarget); }, + getHashUpgrades: function(): string[] { + if (!hasHacknetServers(player)) { + return []; + } + return Object.values(HashUpgrades).map((upgrade: HashUpgrade) => upgrade.name); + }, getHashUpgradeLevel: function (upgName: any): number { const level = player.hashManager.upgrades[upgName]; if (level === undefined) { diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index d463d68a7..8172e733a 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -2290,6 +2290,22 @@ export interface Hacknet { */ spendHashes(upgName: string, upgTarget?: string): boolean; + /** + * Get the list of hash upgrades + * @remarks + * RAM cost: 0 GB + * + * This function is only applicable for Hacknet Servers (the upgraded version of a Hacknet Node). + * + * Returns the list of all available hash upgrades that can be used in the spendHashes function. + * @example + * ```ts + * const upgrades = hacknet.getHashUpgrades(); // ["Sell for Money","Sell for Corporation Funds",...] + * ``` + * @returns An array containing the available upgrades + */ + getHashUpgrades(): string[]; + /** * Get the level of a hash upgrade. * @remarks