Fix #1863: Add getHashUpgrades hacknet function

Adds a new functions ofr hacknet servers that returns the list of
available hash upgrades.
This commit is contained in:
Martin Fournier
2021-12-17 05:35:17 -05:00
parent 6c5842d2e7
commit 217b94d0a0
5 changed files with 87 additions and 0 deletions
+8
View File
@@ -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) {
+16
View File
@@ -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