From c59a267437fe47bb5ed0ac1391d10edf035d8d66 Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Tue, 4 Jan 2022 19:09:34 -0500 Subject: [PATCH] change sf4 --- doc/source/advancedgameplay.rst | 1 + doc/source/advancedgameplay/sourcefiles.rst | 2 +- src/BitNode/BitNode.tsx | 2 +- src/Electron.tsx | 14 +- src/Netscript/RamCostGenerator.ts | 115 +++++++------ src/NetscriptFunctions.ts | 158 +++++++++--------- src/NetscriptFunctions/Bladeburner.ts | 71 ++++---- src/NetscriptFunctions/CodingContract.ts | 10 +- src/NetscriptFunctions/Gang.ts | 42 ++--- src/NetscriptFunctions/Singularity.ts | 155 ++++++----------- src/NetscriptFunctions/Sleeve.ts | 30 ++-- src/NetscriptFunctions/Stanek.ts | 16 +- src/NetscriptFunctions/StockMarket.ts | 38 ++--- src/NetscriptFunctions/UserInterface.ts | 7 +- src/NetscriptJSEvaluator.ts | 13 +- src/NetscriptWorker.ts | 30 +++- src/Prestige.ts | 4 +- src/Script/RamCalculations.ts | 7 +- src/Script/Script.ts | 18 +- src/ScriptEditor/ui/ScriptEditorRoot.tsx | 20 ++- src/Server/BaseServer.ts | 6 +- src/Server/ServerHelpers.ts | 4 +- src/SourceFile/SourceFiles.tsx | 2 +- src/Terminal/commands/cp.ts | 2 +- src/Terminal/commands/runScript.ts | 2 +- src/Terminal/commands/scp.ts | 2 +- src/Terminal/commands/wget.ts | 2 +- ...termineAllPossibilitiesForTabCompletion.ts | 2 +- src/engine.tsx | 2 +- src/ui/React/LogBoxManager.tsx | 17 +- src/utils/v1APIBreak.ts | 2 +- ...neAllPossibilitiesForTabCompletion.test.ts | 90 ++++------ 32 files changed, 431 insertions(+), 455 deletions(-) diff --git a/doc/source/advancedgameplay.rst b/doc/source/advancedgameplay.rst index d33d3107b..8687c8c89 100644 --- a/doc/source/advancedgameplay.rst +++ b/doc/source/advancedgameplay.rst @@ -12,3 +12,4 @@ must be unlocked. Source-Files Intelligence Sleeves + Hacking algorithms diff --git a/doc/source/advancedgameplay/sourcefiles.rst b/doc/source/advancedgameplay/sourcefiles.rst index f6eb482ca..7a9976411 100644 --- a/doc/source/advancedgameplay/sourcefiles.rst +++ b/doc/source/advancedgameplay/sourcefiles.rst @@ -28,7 +28,7 @@ List of all Source-Files || || * Increases the player's charisma and company salary multipliers by 8%/12%/14%. | +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ || BitNode-4: The Singularity || * Let the player access and use Netscript Singularity Functions in other BitNodes. | -|| || * Each level of this Source-File opens up more of the Singularity Functions to use. | +|| || * Each level of this Source-File reduces the RAM cost of singularity functions. | +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ || BitNode-5: Artificial Intelligence || * Unlocks :ref:`gameplay_intelligence`. | || || * Unlocks :js:func:`getBitNodeMultipliers` and start with Formulas.exe. | diff --git a/src/BitNode/BitNode.tsx b/src/BitNode/BitNode.tsx index c59a339de..947a2ee65 100644 --- a/src/BitNode/BitNode.tsx +++ b/src/BitNode/BitNode.tsx @@ -165,7 +165,7 @@ BitNodes["BitNode4"] = new BitNode(
Destroying this BitNode will give you Source-File 4, or if you already have this Source-File it will upgrade its level up to a maximum of 3. This Source-File lets you access and use the Singularity Functions in other BitNodes. - Each level of this Source-File will open up more Singularity Functions that you can use. + Each level of this Source-File reduces the RAM cost of singularity functions. ), ); diff --git a/src/Electron.tsx b/src/Electron.tsx index 0e9d35f26..37aa66d2d 100644 --- a/src/Electron.tsx +++ b/src/Electron.tsx @@ -22,7 +22,7 @@ import { Server } from "./Server/Server"; import { Router } from "./ui/GameRoot"; import { Page } from "./ui/Router"; import { removeLeadingSlash } from "./Terminal/DirectoryHelpers"; -import { Terminal } from './Terminal'; +import { Terminal } from "./Terminal"; import { SnackbarEvents } from "./ui/React/Snackbar"; import { IMap } from "./types"; @@ -418,7 +418,7 @@ function calculateAchievements(): void { export function initElectron(): void { const userAgent = navigator.userAgent.toLowerCase(); - if (userAgent.indexOf(' electron/') > -1) { + if (userAgent.indexOf(" electron/") > -1) { // Electron-specific code setAchievements([]); initWebserver(); @@ -439,14 +439,14 @@ function initWebserver(): void { //If the current script already exists on the server, overwrite it for (let i = 0; i < home.scripts.length; i++) { if (filename == home.scripts[i].filename) { - home.scripts[i].saveScript(filename, code, "home", home.scripts); + home.scripts[i].saveScript(Player, filename, code, "home", home.scripts); return "written"; } } //If the current script does NOT exist, create a new one const script = new Script(); - script.saveScript(filename, code, "home", home.scripts); + script.saveScript(Player, filename, code, "home", home.scripts); home.scripts.push(script); return "written"; } @@ -463,16 +463,16 @@ function initAppNotifier(): void { info: Terminal.info, warn: Terminal.warn, error: Terminal.error, - success: Terminal.success + success: Terminal.success, }; let fn; if (type) fn = typesFn[type]; if (!fn) fn = Terminal.print; fn.bind(Terminal)(message); }, - toast: (message: string, type: "info" | "success" | "warning" | "error" , duration = 2000) => + toast: (message: string, type: "info" | "success" | "warning" | "error", duration = 2000) => SnackbarEvents.emit(message, type, duration), - } + }; // Will be consumud by the electron wrapper. // @ts-ignore diff --git a/src/Netscript/RamCostGenerator.ts b/src/Netscript/RamCostGenerator.ts index e1b8f3291..2f72db211 100644 --- a/src/Netscript/RamCostGenerator.ts +++ b/src/Netscript/RamCostGenerator.ts @@ -1,3 +1,4 @@ +import { IPlayer } from "src/PersonObjects/IPlayer"; import { IMap } from "../types"; // TODO remember to update RamCalculations.js and WorkerScript.js @@ -67,6 +68,16 @@ export const RamCostConstants: IMap = { ScriptStanekDeleteAt: 0.15, }; +function SF4Cost(cost: number): (player: IPlayer) => number { + return (player: IPlayer): number => { + if (player.bitNodeN === 4) return cost; + const sf4 = player.sourceFileLvl(4); + if (sf4 <= 1) return cost * 64; + if (sf4 === 2) return cost * 8; + return cost; + }; +} + export const RamCosts: IMap = { hacknet: { numNodes: 0, @@ -196,55 +207,55 @@ export const RamCosts: IMap = { getFavorToDonate: RamCostConstants.ScriptGetFavorToDonate, // Singularity Functions - universityCourse: RamCostConstants.ScriptSingularityFn1RamCost, - gymWorkout: RamCostConstants.ScriptSingularityFn1RamCost, - travelToCity: RamCostConstants.ScriptSingularityFn1RamCost, - goToLocation: RamCostConstants.ScriptSingularityFn1RamCost, - purchaseTor: RamCostConstants.ScriptSingularityFn1RamCost, - purchaseProgram: RamCostConstants.ScriptSingularityFn1RamCost, - getCurrentServer: RamCostConstants.ScriptSingularityFn1RamCost, - connect: RamCostConstants.ScriptSingularityFn1RamCost, - manualHack: RamCostConstants.ScriptSingularityFn1RamCost, - installBackdoor: RamCostConstants.ScriptSingularityFn1RamCost, - getStats: RamCostConstants.ScriptSingularityFn1RamCost / 4, - getCharacterInformation: RamCostConstants.ScriptSingularityFn1RamCost / 4, - getPlayer: RamCostConstants.ScriptSingularityFn1RamCost / 4, - hospitalize: RamCostConstants.ScriptSingularityFn1RamCost / 4, - isBusy: RamCostConstants.ScriptSingularityFn1RamCost / 4, - stopAction: RamCostConstants.ScriptSingularityFn1RamCost / 2, - upgradeHomeRam: RamCostConstants.ScriptSingularityFn2RamCost, - upgradeHomeCores: RamCostConstants.ScriptSingularityFn2RamCost, - getUpgradeHomeRamCost: RamCostConstants.ScriptSingularityFn2RamCost / 2, - getUpgradeHomeCoresCost: RamCostConstants.ScriptSingularityFn2RamCost / 2, - workForCompany: RamCostConstants.ScriptSingularityFn2RamCost, - applyToCompany: RamCostConstants.ScriptSingularityFn2RamCost, - getCompanyRep: RamCostConstants.ScriptSingularityFn2RamCost / 3, - getCompanyFavor: RamCostConstants.ScriptSingularityFn2RamCost / 3, - getCompanyFavorGain: RamCostConstants.ScriptSingularityFn2RamCost / 4, - checkFactionInvitations: RamCostConstants.ScriptSingularityFn2RamCost, - joinFaction: RamCostConstants.ScriptSingularityFn2RamCost, - workForFaction: RamCostConstants.ScriptSingularityFn2RamCost, - getFactionRep: RamCostConstants.ScriptSingularityFn2RamCost / 3, - getFactionFavor: RamCostConstants.ScriptSingularityFn2RamCost / 3, - getFactionFavorGain: RamCostConstants.ScriptSingularityFn2RamCost / 4, - donateToFaction: RamCostConstants.ScriptSingularityFn3RamCost, - createProgram: RamCostConstants.ScriptSingularityFn3RamCost, - commitCrime: RamCostConstants.ScriptSingularityFn3RamCost, - getCrimeChance: RamCostConstants.ScriptSingularityFn3RamCost, - getCrimeStats: RamCostConstants.ScriptSingularityFn3RamCost, - getOwnedAugmentations: RamCostConstants.ScriptSingularityFn3RamCost, - getOwnedSourceFiles: RamCostConstants.ScriptSingularityFn3RamCost, - getAugmentationsFromFaction: RamCostConstants.ScriptSingularityFn3RamCost, - getAugmentationCost: RamCostConstants.ScriptSingularityFn3RamCost, - getAugmentationPrereq: RamCostConstants.ScriptSingularityFn3RamCost, - getAugmentationPrice: RamCostConstants.ScriptSingularityFn3RamCost / 2, - getAugmentationRepReq: RamCostConstants.ScriptSingularityFn3RamCost / 2, - getAugmentationStats: RamCostConstants.ScriptSingularityFn3RamCost, - purchaseAugmentation: RamCostConstants.ScriptSingularityFn3RamCost, - softReset: RamCostConstants.ScriptSingularityFn3RamCost, - installAugmentations: RamCostConstants.ScriptSingularityFn3RamCost, - isFocused: 0.1, - setFocus: 0.1, + universityCourse: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost), + gymWorkout: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost), + travelToCity: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost), + goToLocation: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost), + purchaseTor: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost), + purchaseProgram: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost), + getCurrentServer: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost), + connect: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost), + manualHack: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost), + installBackdoor: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost), + getStats: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost / 4), + getCharacterInformation: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost / 4), + getPlayer: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost / 4), + hospitalize: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost / 4), + isBusy: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost / 4), + stopAction: SF4Cost(RamCostConstants.ScriptSingularityFn1RamCost / 2), + upgradeHomeRam: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost), + upgradeHomeCores: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost), + getUpgradeHomeRamCost: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost / 2), + getUpgradeHomeCoresCost: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost / 2), + workForCompany: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost), + applyToCompany: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost), + getCompanyRep: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost / 3), + getCompanyFavor: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost / 3), + getCompanyFavorGain: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost / 4), + checkFactionInvitations: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost), + joinFaction: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost), + workForFaction: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost), + getFactionRep: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost / 3), + getFactionFavor: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost / 3), + getFactionFavorGain: SF4Cost(RamCostConstants.ScriptSingularityFn2RamCost / 4), + donateToFaction: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost), + createProgram: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost), + commitCrime: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost), + getCrimeChance: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost), + getCrimeStats: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost), + getOwnedAugmentations: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost), + getOwnedSourceFiles: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost), + getAugmentationsFromFaction: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost), + getAugmentationCost: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost), + getAugmentationPrereq: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost), + getAugmentationPrice: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost / 2), + getAugmentationRepReq: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost / 2), + getAugmentationStats: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost), + purchaseAugmentation: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost), + softReset: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost), + installAugmentations: SF4Cost(RamCostConstants.ScriptSingularityFn3RamCost), + isFocused: SF4Cost(0.1), + setFocus: SF4Cost(0.1), // Gang API gang: { @@ -358,7 +369,7 @@ export const RamCosts: IMap = { }, }; -export function getRamCost(...args: string[]): number { +export function getRamCost(player: IPlayer, ...args: string[]): number { if (args.length === 0) { console.warn(`No arguments passed to getRamCost()`); return 0; @@ -383,6 +394,10 @@ export function getRamCost(...args: string[]): number { return curr; } + if (typeof curr === "function") { + return curr(player); + } + console.warn(`Unexpected type (${curr}) for value [${args}]`); return 0; } diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index d9608de53..892b3f54b 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -443,7 +443,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { getServer: safeGetServer, checkSingularityAccess: checkSingularityAccess, hack: hack, - getValidPort: (funcName:string, port: any): IPort => { + getValidPort: (funcName: string, port: any): IPort => { if (isNaN(port)) { throw makeRuntimeErrorMsg( funcName, @@ -462,7 +462,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { throw makeRuntimeErrorMsg(funcName, `Could not find port: ${port}. This is a bug. Report to dev.`); } return iport; - } + }, }; const gang = NetscriptGang(Player, workerScript, helper); @@ -495,7 +495,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { sprintf: sprintf, vsprintf: vsprintf, scan: function (hostname: any = workerScript.hostname): any { - updateDynamicRam("scan", getRamCost("scan")); + updateDynamicRam("scan", getRamCost(Player, "scan")); const server = safeGetServer(hostname, "scan"); const out = []; for (let i = 0; i < server.serversOnNetwork.length; i++) { @@ -509,11 +509,11 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return out; }, hack: function (hostname: any, { threads: requestedThreads, stock }: any = {}): any { - updateDynamicRam("hack", getRamCost("hack")); + updateDynamicRam("hack", getRamCost(Player, "hack")); return hack(hostname, false, { threads: requestedThreads, stock: stock }); }, hackAnalyzeThreads: function (hostname: any, hackAmount: any): any { - updateDynamicRam("hackAnalyzeThreads", getRamCost("hackAnalyzeThreads")); + updateDynamicRam("hackAnalyzeThreads", getRamCost(Player, "hackAnalyzeThreads")); // Check argument validity const server = safeGetServer(hostname, "hackAnalyzeThreads"); @@ -539,7 +539,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return hackAmount / Math.floor(server.moneyAvailable * percentHacked); }, hackAnalyze: function (hostname: any): any { - updateDynamicRam("hackAnalyze", getRamCost("hackAnalyze")); + updateDynamicRam("hackAnalyze", getRamCost(Player, "hackAnalyze")); const server = safeGetServer(hostname, "hackAnalyze"); if (!(server instanceof Server)) { @@ -553,7 +553,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return CONSTANTS.ServerFortifyAmount * threads; }, hackAnalyzeChance: function (hostname: any): any { - updateDynamicRam("hackAnalyzeChance", getRamCost("hackAnalyzeChance")); + updateDynamicRam("hackAnalyzeChance", getRamCost(Player, "hackAnalyzeChance")); const server = safeGetServer(hostname, "hackAnalyzeChance"); if (!(server instanceof Server)) { @@ -582,7 +582,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { }); }, grow: function (hostname: any, { threads: requestedThreads, stock }: any = {}): any { - updateDynamicRam("grow", getRamCost("grow")); + updateDynamicRam("grow", getRamCost(Player, "grow")); const threads = resolveNetscriptRequestedThreads(workerScript, "grow", requestedThreads); if (hostname === undefined) { throw makeRuntimeErrorMsg("grow", "Takes 1 argument."); @@ -640,7 +640,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { }); }, growthAnalyze: function (hostname: any, growth: any, cores: any = 1): any { - updateDynamicRam("growthAnalyze", getRamCost("growthAnalyze")); + updateDynamicRam("growthAnalyze", getRamCost(Player, "growthAnalyze")); // Check argument validity const server = safeGetServer(hostname, "growthAnalyze"); @@ -658,7 +658,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return 2 * CONSTANTS.ServerFortifyAmount * threads; }, weaken: function (hostname: any, { threads: requestedThreads }: any = {}): any { - updateDynamicRam("weaken", getRamCost("weaken")); + updateDynamicRam("weaken", getRamCost(Player, "weaken")); const threads = resolveNetscriptRequestedThreads(workerScript, "weaken", requestedThreads); if (hostname === undefined) { throw makeRuntimeErrorMsg("weaken", "Takes 1 argument."); @@ -824,7 +824,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { LogBoxEvents.emit(runningScriptObj); }, nuke: function (hostname: any): boolean { - updateDynamicRam("nuke", getRamCost("nuke")); + updateDynamicRam("nuke", getRamCost(Player, "nuke")); if (hostname === undefined) { throw makeRuntimeErrorMsg("nuke", "Takes 1 argument."); } @@ -848,7 +848,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return true; }, brutessh: function (hostname: any): boolean { - updateDynamicRam("brutessh", getRamCost("brutessh")); + updateDynamicRam("brutessh", getRamCost(Player, "brutessh")); if (hostname === undefined) { throw makeRuntimeErrorMsg("brutessh", "Takes 1 argument."); } @@ -870,7 +870,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return true; }, ftpcrack: function (hostname: any): boolean { - updateDynamicRam("ftpcrack", getRamCost("ftpcrack")); + updateDynamicRam("ftpcrack", getRamCost(Player, "ftpcrack")); if (hostname === undefined) { throw makeRuntimeErrorMsg("ftpcrack", "Takes 1 argument."); } @@ -892,7 +892,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return true; }, relaysmtp: function (hostname: any): boolean { - updateDynamicRam("relaysmtp", getRamCost("relaysmtp")); + updateDynamicRam("relaysmtp", getRamCost(Player, "relaysmtp")); if (hostname === undefined) { throw makeRuntimeErrorMsg("relaysmtp", "Takes 1 argument."); } @@ -914,7 +914,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return true; }, httpworm: function (hostname: any): boolean { - updateDynamicRam("httpworm", getRamCost("httpworm")); + updateDynamicRam("httpworm", getRamCost(Player, "httpworm")); if (hostname === undefined) { throw makeRuntimeErrorMsg("httpworm", "Takes 1 argument"); } @@ -936,7 +936,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return true; }, sqlinject: function (hostname: any): boolean { - updateDynamicRam("sqlinject", getRamCost("sqlinject")); + updateDynamicRam("sqlinject", getRamCost(Player, "sqlinject")); if (hostname === undefined) { throw makeRuntimeErrorMsg("sqlinject", "Takes 1 argument."); } @@ -958,7 +958,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return true; }, run: function (scriptname: any, threads: any = 1, ...args: any[]): any { - updateDynamicRam("run", getRamCost("run")); + updateDynamicRam("run", getRamCost(Player, "run")); if (scriptname === undefined) { throw makeRuntimeErrorMsg("run", "Usage: run(scriptname, [numThreads], [arg1], [arg2]...)"); } @@ -970,10 +970,10 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { throw makeRuntimeErrorMsg("run", "Could not find server. This is a bug. Report to dev."); } - return runScriptFromScript("run", scriptServer, scriptname, args, workerScript, threads); + return runScriptFromScript(Player, "run", scriptServer, scriptname, args, workerScript, threads); }, exec: function (scriptname: any, hostname: any, threads: any = 1, ...args: any[]): any { - updateDynamicRam("exec", getRamCost("exec")); + updateDynamicRam("exec", getRamCost(Player, "exec")); if (scriptname === undefined || hostname === undefined) { throw makeRuntimeErrorMsg("exec", "Usage: exec(scriptname, server, [numThreads], [arg1], [arg2]...)"); } @@ -981,10 +981,10 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { throw makeRuntimeErrorMsg("exec", `Invalid thread count. Must be numeric and > 0, is ${threads}`); } const server = safeGetServer(hostname, "exec"); - return runScriptFromScript("exec", server, scriptname, args, workerScript, threads); + return runScriptFromScript(Player, "exec", server, scriptname, args, workerScript, threads); }, spawn: function (scriptname: any, threads: any = 1, ...args: any[]): any { - updateDynamicRam("spawn", getRamCost("spawn")); + updateDynamicRam("spawn", getRamCost(Player, "spawn")); if (!scriptname || !threads) { throw makeRuntimeErrorMsg("spawn", "Usage: spawn(scriptname, threads)"); } @@ -999,7 +999,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { throw makeRuntimeErrorMsg("spawn", "Could not find server. This is a bug. Report to dev"); } - return runScriptFromScript("spawn", scriptServer, scriptname, args, workerScript, threads); + return runScriptFromScript(Player, "spawn", scriptServer, scriptname, args, workerScript, threads); }, spawnDelay * 1e3); workerScript.log("spawn", () => `Will execute '${scriptname}' in ${spawnDelay} seconds`); @@ -1010,7 +1010,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { } }, kill: function (filename: any, hostname?: any, ...scriptArgs: any): any { - updateDynamicRam("kill", getRamCost("kill")); + updateDynamicRam("kill", getRamCost(Player, "kill")); let res; const killByPid = typeof filename === "number"; @@ -1056,7 +1056,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { } }, killall: function (hostname: any = workerScript.hostname): any { - updateDynamicRam("killall", getRamCost("killall")); + updateDynamicRam("killall", getRamCost(Player, "killall")); if (hostname === undefined) { throw makeRuntimeErrorMsg("killall", "Takes 1 argument"); } @@ -1082,7 +1082,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { } }, scp: async function (scriptname: any, hostname1: any, hostname2: any): Promise { - updateDynamicRam("scp", getRamCost("scp")); + updateDynamicRam("scp", getRamCost(Player, "scp")); if (arguments.length !== 2 && arguments.length !== 3) { throw makeRuntimeErrorMsg("scp", "Takes 2 or 3 arguments"); } @@ -1235,11 +1235,11 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { resolve(false); return; } - newScript.updateRamUsage(destServer.scripts).then(() => resolve(true)); + newScript.updateRamUsage(Player, destServer.scripts).then(() => resolve(true)); }); }, ls: function (hostname: any, grep: any): any { - updateDynamicRam("ls", getRamCost("ls")); + updateDynamicRam("ls", getRamCost(Player, "ls")); if (hostname === undefined) { throw makeRuntimeErrorMsg("ls", "Usage: ls(hostname/ip, [grep filter])"); } @@ -1306,7 +1306,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return allFiles; }, ps: function (hostname: any = workerScript.hostname): any { - updateDynamicRam("ps", getRamCost("ps")); + updateDynamicRam("ps", getRamCost(Player, "ps")); const server = safeGetServer(hostname, "ps"); const processes = []; for (const i in server.runningScripts) { @@ -1321,7 +1321,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return processes; }, hasRootAccess: function (hostname: any): any { - updateDynamicRam("hasRootAccess", getRamCost("hasRootAccess")); + updateDynamicRam("hasRootAccess", getRamCost(Player, "hasRootAccess")); if (hostname === undefined) { throw makeRuntimeErrorMsg("hasRootAccess", "Takes 1 argument"); } @@ -1329,7 +1329,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return server.hasAdminRights; }, getHostname: function (): any { - updateDynamicRam("getHostname", getRamCost("getHostname")); + updateDynamicRam("getHostname", getRamCost(Player, "getHostname")); const scriptServer = GetServer(workerScript.hostname); if (scriptServer == null) { throw makeRuntimeErrorMsg("getHostname", "Could not find server. This is a bug. Report to dev."); @@ -1337,13 +1337,13 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return scriptServer.hostname; }, getHackingLevel: function (): any { - updateDynamicRam("getHackingLevel", getRamCost("getHackingLevel")); + updateDynamicRam("getHackingLevel", getRamCost(Player, "getHackingLevel")); Player.updateSkillLevels(); workerScript.log("getHackingLevel", () => `returned ${Player.hacking}`); return Player.hacking; }, getHackingMultipliers: function (): any { - updateDynamicRam("getHackingMultipliers", getRamCost("getHackingMultipliers")); + updateDynamicRam("getHackingMultipliers", getRamCost(Player, "getHackingMultipliers")); return { chance: Player.hacking_chance_mult, speed: Player.hacking_speed_mult, @@ -1352,7 +1352,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { }; }, getHacknetMultipliers: function (): any { - updateDynamicRam("getHacknetMultipliers", getRamCost("getHacknetMultipliers")); + updateDynamicRam("getHacknetMultipliers", getRamCost(Player, "getHacknetMultipliers")); return { production: Player.hacknet_node_money_mult, purchaseCost: Player.hacknet_node_purchase_cost_mult, @@ -1362,7 +1362,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { }; }, getBitNodeMultipliers: function (): any { - updateDynamicRam("getBitNodeMultipliers", getRamCost("getBitNodeMultipliers")); + updateDynamicRam("getBitNodeMultipliers", getRamCost(Player, "getBitNodeMultipliers")); if (SourceFileFlags[5] <= 0 && Player.bitNodeN !== 5) { throw makeRuntimeErrorMsg("getBitNodeMultipliers", "Requires Source-File 5 to run."); } @@ -1370,7 +1370,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return copy; }, getServer: function (hostname: any = workerScript.hostname): any { - updateDynamicRam("getServer", getRamCost("getServer")); + updateDynamicRam("getServer", getRamCost(Player, "getServer")); const server = safeGetServer(hostname, "getServer"); const copy = Object.assign({}, server) as any; // These fields should be hidden. @@ -1393,7 +1393,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return copy; }, getServerMoneyAvailable: function (hostname: any): any { - updateDynamicRam("getServerMoneyAvailable", getRamCost("getServerMoneyAvailable")); + updateDynamicRam("getServerMoneyAvailable", getRamCost(Player, "getServerMoneyAvailable")); const server = safeGetServer(hostname, "getServerMoneyAvailable"); if (!(server instanceof Server)) { workerScript.log("getServerMoneyAvailable", () => "Cannot be executed on this server."); @@ -1417,7 +1417,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return server.moneyAvailable; }, getServerSecurityLevel: function (hostname: any): any { - updateDynamicRam("getServerSecurityLevel", getRamCost("getServerSecurityLevel")); + updateDynamicRam("getServerSecurityLevel", getRamCost(Player, "getServerSecurityLevel")); const server = safeGetServer(hostname, "getServerSecurityLevel"); if (!(server instanceof Server)) { workerScript.log("getServerSecurityLevel", () => "Cannot be executed on this server."); @@ -1433,7 +1433,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return server.hackDifficulty; }, getServerBaseSecurityLevel: function (hostname: any): any { - updateDynamicRam("getServerBaseSecurityLevel", getRamCost("getServerBaseSecurityLevel")); + updateDynamicRam("getServerBaseSecurityLevel", getRamCost(Player, "getServerBaseSecurityLevel")); workerScript.log( "getServerBaseSecurityLevel", () => `getServerBaseSecurityLevel is deprecated because it's not useful.`, @@ -1453,7 +1453,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return server.baseDifficulty; }, getServerMinSecurityLevel: function (hostname: any): any { - updateDynamicRam("getServerMinSecurityLevel", getRamCost("getServerMinSecurityLevel")); + updateDynamicRam("getServerMinSecurityLevel", getRamCost(Player, "getServerMinSecurityLevel")); const server = safeGetServer(hostname, "getServerMinSecurityLevel"); if (!(server instanceof Server)) { workerScript.log("getServerMinSecurityLevel", () => "Cannot be executed on this server."); @@ -1469,7 +1469,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return server.minDifficulty; }, getServerRequiredHackingLevel: function (hostname: any): any { - updateDynamicRam("getServerRequiredHackingLevel", getRamCost("getServerRequiredHackingLevel")); + updateDynamicRam("getServerRequiredHackingLevel", getRamCost(Player, "getServerRequiredHackingLevel")); const server = safeGetServer(hostname, "getServerRequiredHackingLevel"); if (!(server instanceof Server)) { workerScript.log("getServerRequiredHackingLevel", () => "Cannot be executed on this server."); @@ -1485,7 +1485,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return server.requiredHackingSkill; }, getServerMaxMoney: function (hostname: any): any { - updateDynamicRam("getServerMaxMoney", getRamCost("getServerMaxMoney")); + updateDynamicRam("getServerMaxMoney", getRamCost(Player, "getServerMaxMoney")); const server = safeGetServer(hostname, "getServerMaxMoney"); if (!(server instanceof Server)) { workerScript.log("getServerMaxMoney", () => "Cannot be executed on this server."); @@ -1501,7 +1501,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return server.moneyMax; }, getServerGrowth: function (hostname: any): any { - updateDynamicRam("getServerGrowth", getRamCost("getServerGrowth")); + updateDynamicRam("getServerGrowth", getRamCost(Player, "getServerGrowth")); const server = safeGetServer(hostname, "getServerGrowth"); if (!(server instanceof Server)) { workerScript.log("getServerGrowth", () => "Cannot be executed on this server."); @@ -1514,7 +1514,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return server.serverGrowth; }, getServerNumPortsRequired: function (hostname: any): any { - updateDynamicRam("getServerNumPortsRequired", getRamCost("getServerNumPortsRequired")); + updateDynamicRam("getServerNumPortsRequired", getRamCost(Player, "getServerNumPortsRequired")); const server = safeGetServer(hostname, "getServerNumPortsRequired"); if (!(server instanceof Server)) { workerScript.log("getServerNumPortsRequired", () => "Cannot be executed on this server."); @@ -1530,7 +1530,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return server.numOpenPortsRequired; }, getServerRam: function (hostname: any): any { - updateDynamicRam("getServerRam", getRamCost("getServerRam")); + updateDynamicRam("getServerRam", getRamCost(Player, "getServerRam")); workerScript.log( "getServerRam", () => `getServerRam is deprecated in favor of getServerMaxRam / getServerUsedRam`, @@ -1543,23 +1543,23 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return [server.maxRam, server.ramUsed]; }, getServerMaxRam: function (hostname: any): any { - updateDynamicRam("getServerMaxRam", getRamCost("getServerMaxRam")); + updateDynamicRam("getServerMaxRam", getRamCost(Player, "getServerMaxRam")); const server = safeGetServer(hostname, "getServerMaxRam"); workerScript.log("getServerMaxRam", () => `returned ${numeralWrapper.formatRAM(server.maxRam)}`); return server.maxRam; }, getServerUsedRam: function (hostname: any): any { - updateDynamicRam("getServerUsedRam", getRamCost("getServerUsedRam")); + updateDynamicRam("getServerUsedRam", getRamCost(Player, "getServerUsedRam")); const server = safeGetServer(hostname, "getServerUsedRam"); workerScript.log("getServerUsedRam", () => `returned ${numeralWrapper.formatRAM(server.ramUsed)}`); return server.ramUsed; }, serverExists: function (hostname: any): any { - updateDynamicRam("serverExists", getRamCost("serverExists")); + updateDynamicRam("serverExists", getRamCost(Player, "serverExists")); return GetServer(hostname) !== null; }, fileExists: function (filename: any, hostname: any = workerScript.hostname): any { - updateDynamicRam("fileExists", getRamCost("fileExists")); + updateDynamicRam("fileExists", getRamCost(Player, "fileExists")); if (filename === undefined) { throw makeRuntimeErrorMsg("fileExists", "Usage: fileExists(scriptname, [server])"); } @@ -1586,7 +1586,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return false; }, isRunning: function (fn: any, hostname: any = workerScript.hostname, ...scriptArgs: any): any { - updateDynamicRam("isRunning", getRamCost("isRunning")); + updateDynamicRam("isRunning", getRamCost(Player, "isRunning")); if (fn === undefined || hostname === undefined) { throw makeRuntimeErrorMsg("isRunning", "Usage: isRunning(scriptname, server, [arg1], [arg2]...)"); } @@ -1597,17 +1597,17 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { } }, getPurchasedServerLimit: function (): any { - updateDynamicRam("getPurchasedServerLimit", getRamCost("getPurchasedServerLimit")); + updateDynamicRam("getPurchasedServerLimit", getRamCost(Player, "getPurchasedServerLimit")); return getPurchaseServerLimit(); }, getPurchasedServerMaxRam: function (): any { - updateDynamicRam("getPurchasedServerMaxRam", getRamCost("getPurchasedServerMaxRam")); + updateDynamicRam("getPurchasedServerMaxRam", getRamCost(Player, "getPurchasedServerMaxRam")); return getPurchaseServerMaxRam(); }, getPurchasedServerCost: function (ram: any): any { - updateDynamicRam("getPurchasedServerCost", getRamCost("getPurchasedServerCost")); + updateDynamicRam("getPurchasedServerCost", getRamCost(Player, "getPurchasedServerCost")); const cost = getPurchaseServerCost(ram); if (cost === Infinity) { @@ -1620,7 +1620,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { purchaseServer: function (aname: any, aram: any): any { const name = helper.string("purchaseServer", "name", aname); const ram = helper.number("purchaseServer", "ram", aram); - updateDynamicRam("purchaseServer", getRamCost("purchaseServer")); + updateDynamicRam("purchaseServer", getRamCost(Player, "purchaseServer")); let hostnameStr = String(name); hostnameStr = hostnameStr.replace(/\s+/g, ""); if (hostnameStr == "") { @@ -1673,7 +1673,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return newServ.hostname; }, deleteServer: function (name: any): any { - updateDynamicRam("deleteServer", getRamCost("deleteServer")); + updateDynamicRam("deleteServer", getRamCost(Player, "deleteServer")); let hostnameStr = String(name); hostnameStr = hostnameStr.replace(/\s\s+/g, ""); const server = GetServer(hostnameStr); @@ -1749,7 +1749,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return false; }, getPurchasedServers: function (): any { - updateDynamicRam("getPurchasedServers", getRamCost("getPurchasedServers")); + updateDynamicRam("getPurchasedServers", getRamCost(Player, "getPurchasedServers")); const res: string[] = []; Player.purchasedServers.forEach(function (hostname) { res.push(hostname); @@ -1767,7 +1767,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return Promise.resolve(iport.write(data)); }, write: function (port: any, data: any = "", mode: any = "a"): any { - updateDynamicRam("write", getRamCost("write")); + updateDynamicRam("write", getRamCost(Player, "write")); if (isString(port)) { // Write to script or text file let fn = port; @@ -1795,12 +1795,12 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { let script = workerScript.getScriptOnServer(fn, server); if (script == null) { // Create a new script - script = new Script(fn, data, server.hostname, server.scripts); + script = new Script(Player, fn, data, server.hostname, server.scripts); server.scripts.push(script); - return script.updateRamUsage(server.scripts); + return script.updateRamUsage(Player, server.scripts); } mode === "w" ? (script.code = data) : (script.code += data); - return script.updateRamUsage(server.scripts); + return script.updateRamUsage(Player, server.scripts); } else { // Write to text file const txtFile = getTextFile(fn, server); @@ -1820,7 +1820,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { } }, tryWritePort: function (port: any, data: any = ""): any { - updateDynamicRam("tryWritePort", getRamCost("tryWritePort")); + updateDynamicRam("tryWritePort", getRamCost(Player, "tryWritePort")); if (!isNaN(port)) { port = Math.round(port); if (port < 1 || port > CONSTANTS.NumNetscriptPorts) { @@ -1845,7 +1845,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return x; }, read: function (port: any): any { - updateDynamicRam("read", getRamCost("read")); + updateDynamicRam("read", getRamCost(Player, "read")); if (isString(port)) { // Read from script or text file const fn = port; @@ -1874,13 +1874,13 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { } }, peek: function (port: any): any { - updateDynamicRam("peek", getRamCost("peek")); + updateDynamicRam("peek", getRamCost(Player, "peek")); const iport = helper.getValidPort("peek", port); const x = iport.peek(); return x; }, clear: function (file: any): any { - updateDynamicRam("clear", getRamCost("clear")); + updateDynamicRam("clear", getRamCost(Player, "clear")); if (isString(file)) { // Clear text file const fn = file; @@ -1903,12 +1903,12 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return iport.clear(); }, getPortHandle: function (port: any): any { - updateDynamicRam("getPortHandle", getRamCost("getPortHandle")); + updateDynamicRam("getPortHandle", getRamCost(Player, "getPortHandle")); const iport = helper.getValidPort("getPortHandle", port); return iport; }, rm: function (fn: any, hostname: any): any { - updateDynamicRam("rm", getRamCost("rm")); + updateDynamicRam("rm", getRamCost(Player, "rm")); if (hostname == null || hostname === "") { hostname = workerScript.hostname; @@ -1923,7 +1923,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return status.res; }, scriptRunning: function (scriptname: any, hostname: any): any { - updateDynamicRam("scriptRunning", getRamCost("scriptRunning")); + updateDynamicRam("scriptRunning", getRamCost(Player, "scriptRunning")); const server = safeGetServer(hostname, "scriptRunning"); for (let i = 0; i < server.runningScripts.length; ++i) { if (server.runningScripts[i].filename == scriptname) { @@ -1933,7 +1933,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return false; }, scriptKill: function (scriptname: any, hostname: any): any { - updateDynamicRam("scriptKill", getRamCost("scriptKill")); + updateDynamicRam("scriptKill", getRamCost(Player, "scriptKill")); const server = safeGetServer(hostname, "scriptKill"); let suc = false; for (let i = 0; i < server.runningScripts.length; i++) { @@ -1949,7 +1949,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return workerScript.name; }, getScriptRam: function (scriptname: any, hostname: any = workerScript.hostname): any { - updateDynamicRam("getScriptRam", getRamCost("getScriptRam")); + updateDynamicRam("getScriptRam", getRamCost(Player, "getScriptRam")); const server = safeGetServer(hostname, "getScriptRam"); for (let i = 0; i < server.scripts.length; ++i) { if (server.scripts[i].filename == scriptname) { @@ -1959,7 +1959,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return 0; }, getRunningScript: function (fn: any, hostname: any, ...args: any[]): any { - updateDynamicRam("getRunningScript", getRamCost("getRunningScript")); + updateDynamicRam("getRunningScript", getRamCost(Player, "getRunningScript")); let runningScript; if (fn === undefined && hostname === undefined && args.length === 0) { @@ -1987,7 +1987,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { }; }, getHackTime: function (hostname: any): any { - updateDynamicRam("getHackTime", getRamCost("getHackTime")); + updateDynamicRam("getHackTime", getRamCost(Player, "getHackTime")); const server = safeGetServer(hostname, "getHackTime"); if (!(server instanceof Server)) { workerScript.log("getHackTime", () => "invalid for this kind of server"); @@ -2000,7 +2000,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return calculateHackingTime(server, Player) * 1000; }, getGrowTime: function (hostname: any): any { - updateDynamicRam("getGrowTime", getRamCost("getGrowTime")); + updateDynamicRam("getGrowTime", getRamCost(Player, "getGrowTime")); const server = safeGetServer(hostname, "getGrowTime"); if (!(server instanceof Server)) { workerScript.log("getGrowTime", () => "invalid for this kind of server"); @@ -2013,7 +2013,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return calculateGrowTime(server, Player) * 1000; }, getWeakenTime: function (hostname: any): any { - updateDynamicRam("getWeakenTime", getRamCost("getWeakenTime")); + updateDynamicRam("getWeakenTime", getRamCost(Player, "getWeakenTime")); const server = safeGetServer(hostname, "getWeakenTime"); if (!(server instanceof Server)) { workerScript.log("getWeakenTime", () => "invalid for this kind of server"); @@ -2026,7 +2026,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return calculateWeakenTime(server, Player) * 1000; }, getScriptIncome: function (scriptname?: any, hostname?: any, ...args: any[]): any { - updateDynamicRam("getScriptIncome", getRamCost("getScriptIncome")); + updateDynamicRam("getScriptIncome", getRamCost(Player, "getScriptIncome")); if (arguments.length === 0) { const res = []; @@ -2055,7 +2055,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { } }, getScriptExpGain: function (scriptname?: any, hostname?: any, ...args: any[]): any { - updateDynamicRam("getScriptExpGain", getRamCost("getScriptExpGain")); + updateDynamicRam("getScriptExpGain", getRamCost(Player, "getScriptExpGain")); if (arguments.length === 0) { let total = 0; for (const ws of workerScripts.values()) { @@ -2087,7 +2087,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return convertTimeMsToTimeElapsedString(milliseconds, milliPrecision); }, getTimeSinceLastAug: function (): any { - updateDynamicRam("getTimeSinceLastAug", getRamCost("getTimeSinceLastAug")); + updateDynamicRam("getTimeSinceLastAug", getRamCost(Player, "getTimeSinceLastAug")); return Player.playtimeSinceLastAug; }, alert: function (message: any): void { @@ -2125,7 +2125,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { function (data) { let res; if (isScriptFilename(target)) { - res = s.writeToScriptFile(target, data); + res = s.writeToScriptFile(Player, target, data); } else { res = s.writeToTextFile(target, data); } @@ -2151,11 +2151,11 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { }); }, getFavorToDonate: function (): any { - updateDynamicRam("getFavorToDonate", getRamCost("getFavorToDonate")); + updateDynamicRam("getFavorToDonate", getRamCost(Player, "getFavorToDonate")); return Math.floor(CONSTANTS.BaseFavorToDonate * BitNodeMultipliers.RepToDonateToFaction); }, getOwnedSourceFiles: function (): SourceFileLvl[] { - helper.updateDynamicRam("getOwnedSourceFiles", getRamCost("getOwnedSourceFiles")); + helper.updateDynamicRam("getOwnedSourceFiles", getRamCost(Player, "getOwnedSourceFiles")); const res: SourceFileLvl[] = []; for (let i = 0; i < Player.sourceFiles.length; ++i) { res.push({ @@ -2166,7 +2166,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { return res; }, getPlayer: function (): INetscriptPlayer { - helper.updateDynamicRam("getPlayer", getRamCost("getPlayer")); + helper.updateDynamicRam("getPlayer", getRamCost(Player, "getPlayer")); const data = { hacking: Player.hacking, diff --git a/src/NetscriptFunctions/Bladeburner.ts b/src/NetscriptFunctions/Bladeburner.ts index 68e10b1c2..d0d1590e3 100644 --- a/src/NetscriptFunctions/Bladeburner.ts +++ b/src/NetscriptFunctions/Bladeburner.ts @@ -57,48 +57,48 @@ export function NetscriptBladeburner( return { getContractNames: function (): string[] { - helper.updateDynamicRam("getContractNames", getRamCost("bladeburner", "getContractNames")); + helper.updateDynamicRam("getContractNames", getRamCost(player, "bladeburner", "getContractNames")); checkBladeburnerAccess("getContractNames"); const bladeburner = player.bladeburner; if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); return bladeburner.getContractNamesNetscriptFn(); }, getOperationNames: function (): string[] { - helper.updateDynamicRam("getOperationNames", getRamCost("bladeburner", "getOperationNames")); + helper.updateDynamicRam("getOperationNames", getRamCost(player, "bladeburner", "getOperationNames")); checkBladeburnerAccess("getOperationNames"); const bladeburner = player.bladeburner; if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); return bladeburner.getOperationNamesNetscriptFn(); }, getBlackOpNames: function (): string[] { - helper.updateDynamicRam("getBlackOpNames", getRamCost("bladeburner", "getBlackOpNames")); + helper.updateDynamicRam("getBlackOpNames", getRamCost(player, "bladeburner", "getBlackOpNames")); checkBladeburnerAccess("getBlackOpNames"); const bladeburner = player.bladeburner; if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); return bladeburner.getBlackOpNamesNetscriptFn(); }, getBlackOpRank: function (name: any = ""): number { - helper.updateDynamicRam("getBlackOpRank", getRamCost("bladeburner", "getBlackOpRank")); + helper.updateDynamicRam("getBlackOpRank", getRamCost(player, "bladeburner", "getBlackOpRank")); checkBladeburnerAccess("getBlackOpRank"); const action: any = getBladeburnerActionObject("getBlackOpRank", "blackops", name); return action.reqdRank; }, getGeneralActionNames: function (): string[] { - helper.updateDynamicRam("getGeneralActionNames", getRamCost("bladeburner", "getGeneralActionNames")); + helper.updateDynamicRam("getGeneralActionNames", getRamCost(player, "bladeburner", "getGeneralActionNames")); checkBladeburnerAccess("getGeneralActionNames"); const bladeburner = player.bladeburner; if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); return bladeburner.getGeneralActionNamesNetscriptFn(); }, getSkillNames: function (): string[] { - helper.updateDynamicRam("getSkillNames", getRamCost("bladeburner", "getSkillNames")); + helper.updateDynamicRam("getSkillNames", getRamCost(player, "bladeburner", "getSkillNames")); checkBladeburnerAccess("getSkillNames"); const bladeburner = player.bladeburner; if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); return bladeburner.getSkillNamesNetscriptFn(); }, startAction: function (type: any = "", name: any = ""): boolean { - helper.updateDynamicRam("startAction", getRamCost("bladeburner", "startAction")); + helper.updateDynamicRam("startAction", getRamCost(player, "bladeburner", "startAction")); checkBladeburnerAccess("startAction"); const bladeburner = player.bladeburner; if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); @@ -109,21 +109,21 @@ export function NetscriptBladeburner( } }, stopBladeburnerAction: function (): void { - helper.updateDynamicRam("stopBladeburnerAction", getRamCost("bladeburner", "stopBladeburnerAction")); + helper.updateDynamicRam("stopBladeburnerAction", getRamCost(player, "bladeburner", "stopBladeburnerAction")); checkBladeburnerAccess("stopBladeburnerAction"); const bladeburner = player.bladeburner; if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); return bladeburner.resetAction(); }, getCurrentAction: function (): BladeburnerCurAction { - helper.updateDynamicRam("getCurrentAction", getRamCost("bladeburner", "getCurrentAction")); + helper.updateDynamicRam("getCurrentAction", getRamCost(player, "bladeburner", "getCurrentAction")); checkBladeburnerAccess("getCurrentAction"); const bladeburner = player.bladeburner; if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); return bladeburner.getTypeAndNameFromActionId(bladeburner.action); }, getActionTime: function (type: any = "", name: any = ""): number { - helper.updateDynamicRam("getActionTime", getRamCost("bladeburner", "getActionTime")); + helper.updateDynamicRam("getActionTime", getRamCost(player, "bladeburner", "getActionTime")); checkBladeburnerAccess("getActionTime"); const bladeburner = player.bladeburner; if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); @@ -136,7 +136,7 @@ export function NetscriptBladeburner( getActionEstimatedSuccessChance: function (type: any = "", name: any = ""): [number, number] { helper.updateDynamicRam( "getActionEstimatedSuccessChance", - getRamCost("bladeburner", "getActionEstimatedSuccessChance"), + getRamCost(player, "bladeburner", "getActionEstimatedSuccessChance"), ); checkBladeburnerAccess("getActionEstimatedSuccessChance"); const bladeburner = player.bladeburner; @@ -148,7 +148,7 @@ export function NetscriptBladeburner( } }, getActionRepGain: function (type: any = "", name: any = "", level: any): number { - helper.updateDynamicRam("getActionRepGain", getRamCost("bladeburner", "getActionRepGain")); + helper.updateDynamicRam("getActionRepGain", getRamCost(player, "bladeburner", "getActionRepGain")); checkBladeburnerAccess("getActionRepGain"); const action = getBladeburnerActionObject("getActionRepGain", type, name); let rewardMultiplier; @@ -161,7 +161,7 @@ export function NetscriptBladeburner( return action.rankGain * rewardMultiplier * BitNodeMultipliers.BladeburnerRank; }, getActionCountRemaining: function (type: any = "", name: any = ""): number { - helper.updateDynamicRam("getActionCountRemaining", getRamCost("bladeburner", "getActionCountRemaining")); + helper.updateDynamicRam("getActionCountRemaining", getRamCost(player, "bladeburner", "getActionCountRemaining")); checkBladeburnerAccess("getActionCountRemaining"); const bladeburner = player.bladeburner; if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); @@ -172,31 +172,31 @@ export function NetscriptBladeburner( } }, getActionMaxLevel: function (type: any = "", name: any = ""): number { - helper.updateDynamicRam("getActionMaxLevel", getRamCost("bladeburner", "getActionMaxLevel")); + helper.updateDynamicRam("getActionMaxLevel", getRamCost(player, "bladeburner", "getActionMaxLevel")); checkBladeburnerAccess("getActionMaxLevel"); const action = getBladeburnerActionObject("getActionMaxLevel", type, name); return action.maxLevel; }, getActionCurrentLevel: function (type: any = "", name: any = ""): number { - helper.updateDynamicRam("getActionCurrentLevel", getRamCost("bladeburner", "getActionCurrentLevel")); + helper.updateDynamicRam("getActionCurrentLevel", getRamCost(player, "bladeburner", "getActionCurrentLevel")); checkBladeburnerAccess("getActionCurrentLevel"); const action = getBladeburnerActionObject("getActionCurrentLevel", type, name); return action.level; }, getActionAutolevel: function (type: any = "", name: any = ""): boolean { - helper.updateDynamicRam("getActionAutolevel", getRamCost("bladeburner", "getActionAutolevel")); + helper.updateDynamicRam("getActionAutolevel", getRamCost(player, "bladeburner", "getActionAutolevel")); checkBladeburnerAccess("getActionAutolevel"); const action = getBladeburnerActionObject("getActionCurrentLevel", type, name); return action.autoLevel; }, setActionAutolevel: function (type: any = "", name: any = "", autoLevel: any = true): void { - helper.updateDynamicRam("setActionAutolevel", getRamCost("bladeburner", "setActionAutolevel")); + helper.updateDynamicRam("setActionAutolevel", getRamCost(player, "bladeburner", "setActionAutolevel")); checkBladeburnerAccess("setActionAutolevel"); const action = getBladeburnerActionObject("setActionAutolevel", type, name); action.autoLevel = autoLevel; }, setActionLevel: function (type: any = "", name: any = "", level: any = 1): void { - helper.updateDynamicRam("setActionLevel", getRamCost("bladeburner", "setActionLevel")); + helper.updateDynamicRam("setActionLevel", getRamCost(player, "bladeburner", "setActionLevel")); checkBladeburnerAccess("setActionLevel"); const action = getBladeburnerActionObject("setActionLevel", type, name); if (level < 1 || level > action.maxLevel) { @@ -208,21 +208,21 @@ export function NetscriptBladeburner( action.level = level; }, getRank: function (): number { - helper.updateDynamicRam("getRank", getRamCost("bladeburner", "getRank")); + helper.updateDynamicRam("getRank", getRamCost(player, "bladeburner", "getRank")); checkBladeburnerAccess("getRank"); const bladeburner = player.bladeburner; if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); return bladeburner.rank; }, getSkillPoints: function (): number { - helper.updateDynamicRam("getSkillPoints", getRamCost("bladeburner", "getSkillPoints")); + helper.updateDynamicRam("getSkillPoints", getRamCost(player, "bladeburner", "getSkillPoints")); checkBladeburnerAccess("getSkillPoints"); const bladeburner = player.bladeburner; if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); return bladeburner.skillPoints; }, getSkillLevel: function (skillName: any = ""): number { - helper.updateDynamicRam("getSkillLevel", getRamCost("bladeburner", "getSkillLevel")); + helper.updateDynamicRam("getSkillLevel", getRamCost(player, "bladeburner", "getSkillLevel")); checkBladeburnerAccess("getSkillLevel"); const bladeburner = player.bladeburner; if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); @@ -233,7 +233,7 @@ export function NetscriptBladeburner( } }, getSkillUpgradeCost: function (skillName: any = ""): number { - helper.updateDynamicRam("getSkillUpgradeCost", getRamCost("bladeburner", "getSkillUpgradeCost")); + helper.updateDynamicRam("getSkillUpgradeCost", getRamCost(player, "bladeburner", "getSkillUpgradeCost")); checkBladeburnerAccess("getSkillUpgradeCost"); const bladeburner = player.bladeburner; if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); @@ -244,7 +244,7 @@ export function NetscriptBladeburner( } }, upgradeSkill: function (skillName: any): boolean { - helper.updateDynamicRam("upgradeSkill", getRamCost("bladeburner", "upgradeSkill")); + helper.updateDynamicRam("upgradeSkill", getRamCost(player, "bladeburner", "upgradeSkill")); checkBladeburnerAccess("upgradeSkill"); const bladeburner = player.bladeburner; if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); @@ -255,7 +255,7 @@ export function NetscriptBladeburner( } }, getTeamSize: function (type: any = "", name: any = ""): number { - helper.updateDynamicRam("getTeamSize", getRamCost("bladeburner", "getTeamSize")); + helper.updateDynamicRam("getTeamSize", getRamCost(player, "bladeburner", "getTeamSize")); checkBladeburnerAccess("getTeamSize"); const bladeburner = player.bladeburner; if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); @@ -266,7 +266,7 @@ export function NetscriptBladeburner( } }, setTeamSize: function (type: any = "", name: any = "", size: any): number { - helper.updateDynamicRam("setTeamSize", getRamCost("bladeburner", "setTeamSize")); + helper.updateDynamicRam("setTeamSize", getRamCost(player, "bladeburner", "setTeamSize")); checkBladeburnerAccess("setTeamSize"); const bladeburner = player.bladeburner; if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); @@ -277,7 +277,10 @@ export function NetscriptBladeburner( } }, getCityEstimatedPopulation: function (cityName: any): number { - helper.updateDynamicRam("getCityEstimatedPopulation", getRamCost("bladeburner", "getCityEstimatedPopulation")); + helper.updateDynamicRam( + "getCityEstimatedPopulation", + getRamCost(player, "bladeburner", "getCityEstimatedPopulation"), + ); checkBladeburnerAccess("getCityEstimatedPopulation"); checkBladeburnerCity("getCityEstimatedPopulation", cityName); const bladeburner = player.bladeburner; @@ -285,7 +288,7 @@ export function NetscriptBladeburner( return bladeburner.cities[cityName].popEst; }, getCityCommunities: function (cityName: any): number { - helper.updateDynamicRam("getCityCommunities", getRamCost("bladeburner", "getCityCommunities")); + helper.updateDynamicRam("getCityCommunities", getRamCost(player, "bladeburner", "getCityCommunities")); checkBladeburnerAccess("getCityCommunities"); checkBladeburnerCity("getCityCommunities", cityName); const bladeburner = player.bladeburner; @@ -293,7 +296,7 @@ export function NetscriptBladeburner( return bladeburner.cities[cityName].comms; }, getCityChaos: function (cityName: any): number { - helper.updateDynamicRam("getCityChaos", getRamCost("bladeburner", "getCityChaos")); + helper.updateDynamicRam("getCityChaos", getRamCost(player, "bladeburner", "getCityChaos")); checkBladeburnerAccess("getCityChaos"); checkBladeburnerCity("getCityChaos", cityName); const bladeburner = player.bladeburner; @@ -301,14 +304,14 @@ export function NetscriptBladeburner( return bladeburner.cities[cityName].chaos; }, getCity: function (): string { - helper.updateDynamicRam("getCity", getRamCost("bladeburner", "getCity")); + helper.updateDynamicRam("getCity", getRamCost(player, "bladeburner", "getCity")); checkBladeburnerAccess("getCityChaos"); const bladeburner = player.bladeburner; if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); return bladeburner.city; }, switchCity: function (cityName: any): boolean { - helper.updateDynamicRam("switchCity", getRamCost("bladeburner", "switchCity")); + helper.updateDynamicRam("switchCity", getRamCost(player, "bladeburner", "switchCity")); checkBladeburnerAccess("switchCity"); checkBladeburnerCity("switchCity", cityName); const bladeburner = player.bladeburner; @@ -316,21 +319,21 @@ export function NetscriptBladeburner( return (bladeburner.city = cityName); }, getStamina: function (): [number, number] { - helper.updateDynamicRam("getStamina", getRamCost("bladeburner", "getStamina")); + helper.updateDynamicRam("getStamina", getRamCost(player, "bladeburner", "getStamina")); checkBladeburnerAccess("getStamina"); const bladeburner = player.bladeburner; if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); return [bladeburner.stamina, bladeburner.maxStamina]; }, joinBladeburnerFaction: function (): boolean { - helper.updateDynamicRam("joinBladeburnerFaction", getRamCost("bladeburner", "joinBladeburnerFaction")); + helper.updateDynamicRam("joinBladeburnerFaction", getRamCost(player, "bladeburner", "joinBladeburnerFaction")); checkBladeburnerAccess("joinBladeburnerFaction", true); const bladeburner = player.bladeburner; if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); return bladeburner.joinBladeburnerFactionNetscriptFn(workerScript); }, joinBladeburnerDivision: function (): boolean { - helper.updateDynamicRam("joinBladeburnerDivision", getRamCost("bladeburner", "joinBladeburnerDivision")); + helper.updateDynamicRam("joinBladeburnerDivision", getRamCost(player, "bladeburner", "joinBladeburnerDivision")); if (player.bitNodeN === 7 || player.sourceFileLvl(7) > 0) { if (player.bitNodeN === 8) { return false; @@ -358,7 +361,7 @@ export function NetscriptBladeburner( return false; }, getBonusTime: function (): number { - helper.updateDynamicRam("getBonusTime", getRamCost("bladeburner", "getBonusTime")); + helper.updateDynamicRam("getBonusTime", getRamCost(player, "bladeburner", "getBonusTime")); checkBladeburnerAccess("getBonusTime"); const bladeburner = player.bladeburner; if (bladeburner === null) throw new Error("Should not be called without Bladeburner"); diff --git a/src/NetscriptFunctions/CodingContract.ts b/src/NetscriptFunctions/CodingContract.ts index 9f36aa9f9..71fb95062 100644 --- a/src/NetscriptFunctions/CodingContract.ts +++ b/src/NetscriptFunctions/CodingContract.ts @@ -31,7 +31,7 @@ export function NetscriptCodingContract( hostname: any = workerScript.hostname, { returnReward }: any = {}, ): boolean | string { - helper.updateDynamicRam("attempt", getRamCost("codingcontract", "attempt")); + helper.updateDynamicRam("attempt", getRamCost(player, "codingcontract", "attempt")); const contract = getCodingContract("attempt", hostname, filename); // Convert answer to string. If the answer is a 2D array, then we have to @@ -78,12 +78,12 @@ export function NetscriptCodingContract( } }, getContractType: function (filename: any, hostname: any = workerScript.hostname): string { - helper.updateDynamicRam("getContractType", getRamCost("codingcontract", "getContractType")); + helper.updateDynamicRam("getContractType", getRamCost(player, "codingcontract", "getContractType")); const contract = getCodingContract("getContractType", hostname, filename); return contract.getType(); }, getData: function (filename: any, hostname: any = workerScript.hostname): any { - helper.updateDynamicRam("getData", getRamCost("codingcontract", "getData")); + helper.updateDynamicRam("getData", getRamCost(player, "codingcontract", "getData")); const contract = getCodingContract("getData", hostname, filename); const data = contract.getData(); if (data.constructor === Array) { @@ -103,12 +103,12 @@ export function NetscriptCodingContract( } }, getDescription: function (filename: any, hostname: any = workerScript.hostname): string { - helper.updateDynamicRam("getDescription", getRamCost("codingcontract", "getDescription")); + helper.updateDynamicRam("getDescription", getRamCost(player, "codingcontract", "getDescription")); const contract = getCodingContract("getDescription", hostname, filename); return contract.getDescription(); }, getNumTriesRemaining: function (filename: any, hostname: any = workerScript.hostname): number { - helper.updateDynamicRam("getNumTriesRemaining", getRamCost("codingcontract", "getNumTriesRemaining")); + helper.updateDynamicRam("getNumTriesRemaining", getRamCost(player, "codingcontract", "getNumTriesRemaining")); const contract = getCodingContract("getNumTriesRemaining", hostname, filename); return contract.getMaxNumTries() - contract.tries; }, diff --git a/src/NetscriptFunctions/Gang.ts b/src/NetscriptFunctions/Gang.ts index 5ef3c8e11..c484947be 100644 --- a/src/NetscriptFunctions/Gang.ts +++ b/src/NetscriptFunctions/Gang.ts @@ -47,7 +47,7 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe return { createGang: function (faction: string): boolean { - helper.updateDynamicRam("createGang", getRamCost("gang", "createGang")); + helper.updateDynamicRam("createGang", getRamCost(player, "gang", "createGang")); // this list is copied from Faction/ui/Root.tsx const GangNames = [ "Slum Snakes", @@ -67,18 +67,18 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe return true; }, inGang: function (): boolean { - helper.updateDynamicRam("inGang", getRamCost("gang", "inGang")); + helper.updateDynamicRam("inGang", getRamCost(player, "gang", "inGang")); return player.inGang(); }, getMemberNames: function (): string[] { - helper.updateDynamicRam("getMemberNames", getRamCost("gang", "getMemberNames")); + helper.updateDynamicRam("getMemberNames", getRamCost(player, "gang", "getMemberNames")); checkGangApiAccess("getMemberNames"); const gang = player.gang; if (gang === null) throw new Error("Should not be called without Gang"); return gang.members.map((member) => member.name); }, getGangInformation: function (): GangGenInfo { - helper.updateDynamicRam("getGangInformation", getRamCost("gang", "getGangInformation")); + helper.updateDynamicRam("getGangInformation", getRamCost(player, "gang", "getGangInformation")); checkGangApiAccess("getGangInformation"); const gang = player.gang; if (gang === null) throw new Error("Should not be called without Gang"); @@ -98,7 +98,7 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe }; }, getOtherGangInformation: function (): GangOtherInfo { - helper.updateDynamicRam("getOtherGangInformation", getRamCost("gang", "getOtherGangInformation")); + helper.updateDynamicRam("getOtherGangInformation", getRamCost(player, "gang", "getOtherGangInformation")); checkGangApiAccess("getOtherGangInformation"); const cpy: any = {}; for (const gang in AllGangs) { @@ -108,7 +108,7 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe return cpy; }, getMemberInformation: function (name: any): GangMemberInfo { - helper.updateDynamicRam("getMemberInformation", getRamCost("gang", "getMemberInformation")); + helper.updateDynamicRam("getMemberInformation", getRamCost(player, "gang", "getMemberInformation")); checkGangApiAccess("getMemberInformation"); const gang = player.gang; if (gang === null) throw new Error("Should not be called without Gang"); @@ -161,14 +161,14 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe }; }, canRecruitMember: function (): boolean { - helper.updateDynamicRam("canRecruitMember", getRamCost("gang", "canRecruitMember")); + helper.updateDynamicRam("canRecruitMember", getRamCost(player, "gang", "canRecruitMember")); checkGangApiAccess("canRecruitMember"); const gang = player.gang; if (gang === null) throw new Error("Should not be called without Gang"); return gang.canRecruitMember(); }, recruitMember: function (name: any): boolean { - helper.updateDynamicRam("recruitMember", getRamCost("gang", "recruitMember")); + helper.updateDynamicRam("recruitMember", getRamCost(player, "gang", "recruitMember")); checkGangApiAccess("recruitMember"); const gang = player.gang; if (gang === null) throw new Error("Should not be called without Gang"); @@ -182,7 +182,7 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe return recruited; }, getTaskNames: function (): string[] { - helper.updateDynamicRam("getTaskNames", getRamCost("gang", "getTaskNames")); + helper.updateDynamicRam("getTaskNames", getRamCost(player, "gang", "getTaskNames")); checkGangApiAccess("getTaskNames"); const gang = player.gang; if (gang === null) throw new Error("Should not be called without Gang"); @@ -191,7 +191,7 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe return tasks; }, setMemberTask: function (memberName: any, taskName: any): boolean { - helper.updateDynamicRam("setMemberTask", getRamCost("gang", "setMemberTask")); + helper.updateDynamicRam("setMemberTask", getRamCost(player, "gang", "setMemberTask")); checkGangApiAccess("setMemberTask"); const member = getGangMember("setMemberTask", memberName); const success = member.assignToTask(taskName); @@ -210,7 +210,7 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe return success; }, getTaskStats: function (taskName: any): GangTaskStats { - helper.updateDynamicRam("getTaskStats", getRamCost("gang", "getTaskStats")); + helper.updateDynamicRam("getTaskStats", getRamCost(player, "gang", "getTaskStats")); checkGangApiAccess("getTaskStats"); const task = getGangTask("getTaskStats", taskName); const copy = Object.assign({}, task); @@ -218,12 +218,12 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe return copy; }, getEquipmentNames: function (): string[] { - helper.updateDynamicRam("getEquipmentNames", getRamCost("gang", "getEquipmentNames")); + helper.updateDynamicRam("getEquipmentNames", getRamCost(player, "gang", "getEquipmentNames")); checkGangApiAccess("getEquipmentNames"); return Object.keys(GangMemberUpgrades); }, getEquipmentCost: function (equipName: any): number { - helper.updateDynamicRam("getEquipmentCost", getRamCost("gang", "getEquipmentCost")); + helper.updateDynamicRam("getEquipmentCost", getRamCost(player, "gang", "getEquipmentCost")); checkGangApiAccess("getEquipmentCost"); const gang = player.gang; if (gang === null) throw new Error("Should not be called without Gang"); @@ -232,14 +232,14 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe return gang.getUpgradeCost(upg); }, getEquipmentType: function (equipName: any): string { - helper.updateDynamicRam("getEquipmentType", getRamCost("gang", "getEquipmentType")); + helper.updateDynamicRam("getEquipmentType", getRamCost(player, "gang", "getEquipmentType")); checkGangApiAccess("getEquipmentType"); const upg = GangMemberUpgrades[equipName]; if (upg == null) return ""; return upg.getType(); }, getEquipmentStats: function (equipName: any): EquipmentStats { - helper.updateDynamicRam("getEquipmentStats", getRamCost("gang", "getEquipmentStats")); + helper.updateDynamicRam("getEquipmentStats", getRamCost(player, "gang", "getEquipmentStats")); checkGangApiAccess("getEquipmentStats"); const equipment = GangMemberUpgrades[equipName]; if (!equipment) { @@ -249,7 +249,7 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe return Object.assign({}, typecheck) as any; }, purchaseEquipment: function (memberName: any, equipName: any): boolean { - helper.updateDynamicRam("purchaseEquipment", getRamCost("gang", "purchaseEquipment")); + helper.updateDynamicRam("purchaseEquipment", getRamCost(player, "gang", "purchaseEquipment")); checkGangApiAccess("purchaseEquipment"); const gang = player.gang; if (gang === null) throw new Error("Should not be called without Gang"); @@ -269,7 +269,7 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe return res; }, ascendMember: function (name: any): GangMemberAscension | undefined { - helper.updateDynamicRam("ascendMember", getRamCost("gang", "ascendMember")); + helper.updateDynamicRam("ascendMember", getRamCost(player, "gang", "ascendMember")); checkGangApiAccess("ascendMember"); const gang = player.gang; if (gang === null) throw new Error("Should not be called without Gang"); @@ -278,7 +278,7 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe return gang.ascendMember(member, workerScript); }, getAscensionResult: function (name: any): GangMemberAscension | undefined { - helper.updateDynamicRam("getAscensionResult", getRamCost("gang", "getAscensionResult")); + helper.updateDynamicRam("getAscensionResult", getRamCost(player, "gang", "getAscensionResult")); checkGangApiAccess("getAscensionResult"); const gang = player.gang; if (gang === null) throw new Error("Should not be called without Gang"); @@ -290,7 +290,7 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe }; }, setTerritoryWarfare: function (engage: any): void { - helper.updateDynamicRam("setTerritoryWarfare", getRamCost("gang", "setTerritoryWarfare")); + helper.updateDynamicRam("setTerritoryWarfare", getRamCost(player, "gang", "setTerritoryWarfare")); checkGangApiAccess("setTerritoryWarfare"); const gang = player.gang; if (gang === null) throw new Error("Should not be called without Gang"); @@ -303,7 +303,7 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe } }, getChanceToWinClash: function (otherGang: any): number { - helper.updateDynamicRam("getChanceToWinClash", getRamCost("gang", "getChanceToWinClash")); + helper.updateDynamicRam("getChanceToWinClash", getRamCost(player, "gang", "getChanceToWinClash")); checkGangApiAccess("getChanceToWinClash"); const gang = player.gang; if (gang === null) throw new Error("Should not be called without Gang"); @@ -317,7 +317,7 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe return playerPower / (otherPower + playerPower); }, getBonusTime: function (): number { - helper.updateDynamicRam("getBonusTime", getRamCost("gang", "getBonusTime")); + helper.updateDynamicRam("getBonusTime", getRamCost(player, "gang", "getBonusTime")); checkGangApiAccess("getBonusTime"); const gang = player.gang; if (gang === null) throw new Error("Should not be called without Gang"); diff --git a/src/NetscriptFunctions/Singularity.ts b/src/NetscriptFunctions/Singularity.ts index 99b960856..2e9b5900d 100644 --- a/src/NetscriptFunctions/Singularity.ts +++ b/src/NetscriptFunctions/Singularity.ts @@ -85,15 +85,14 @@ export function NetscriptSingularity( } const runningScriptObj = new RunningScript(script, []); // No args runningScriptObj.threads = 1; // Only 1 thread - startWorkerScript(runningScriptObj, home); + startWorkerScript(player, runningScriptObj, home); } } } }; return { getOwnedAugmentations: function (purchased: any = false): any { - helper.updateDynamicRam("getOwnedAugmentations", getRamCost("getOwnedAugmentations")); - helper.checkSingularityAccess("getOwnedAugmentations", 3); + helper.updateDynamicRam("getOwnedAugmentations", getRamCost(player, "getOwnedAugmentations")); const res = []; for (let i = 0; i < player.augmentations.length; ++i) { res.push(player.augmentations[i].name); @@ -106,8 +105,7 @@ export function NetscriptSingularity( return res; }, getAugmentationsFromFaction: function (facname: any): any { - helper.updateDynamicRam("getAugmentationsFromFaction", getRamCost("getAugmentationsFromFaction")); - helper.checkSingularityAccess("getAugmentationsFromFaction", 3); + helper.updateDynamicRam("getAugmentationsFromFaction", getRamCost(player, "getAugmentationsFromFaction")); const faction = getFaction("getAugmentationsFromFaction", facname); // If player has a gang with this faction, return all augmentations. @@ -128,38 +126,32 @@ export function NetscriptSingularity( return faction.augmentations.slice(); }, getAugmentationCost: function (name: any): any { - helper.updateDynamicRam("getAugmentationCost", getRamCost("getAugmentationCost")); - helper.checkSingularityAccess("getAugmentationCost", 3); + helper.updateDynamicRam("getAugmentationCost", getRamCost(player, "getAugmentationCost")); const aug = getAugmentation("getAugmentationCost", name); return [aug.baseRepRequirement, aug.baseCost]; }, getAugmentationPrereq: function (name: any): any { - helper.updateDynamicRam("getAugmentationPrereq", getRamCost("getAugmentationPrereq")); - helper.checkSingularityAccess("getAugmentationPrereq", 3); + helper.updateDynamicRam("getAugmentationPrereq", getRamCost(player, "getAugmentationPrereq")); const aug = getAugmentation("getAugmentationPrereq", name); return aug.prereqs.slice(); }, getAugmentationPrice: function (name: any): any { - helper.updateDynamicRam("getAugmentationPrice", getRamCost("getAugmentationPrice")); - helper.checkSingularityAccess("getAugmentationPrice", 3); + helper.updateDynamicRam("getAugmentationPrice", getRamCost(player, "getAugmentationPrice")); const aug = getAugmentation("getAugmentationPrice", name); return aug.baseCost; }, getAugmentationRepReq: function (name: any): any { - helper.updateDynamicRam("getAugmentationRepReq", getRamCost("getAugmentationRepReq")); - helper.checkSingularityAccess("getAugmentationRepReq", 3); + helper.updateDynamicRam("getAugmentationRepReq", getRamCost(player, "getAugmentationRepReq")); const aug = getAugmentation("getAugmentationRepReq", name); return aug.baseRepRequirement; }, getAugmentationStats: function (name: any): any { - helper.updateDynamicRam("getAugmentationStats", getRamCost("getAugmentationStats")); - helper.checkSingularityAccess("getAugmentationStats", 3); + helper.updateDynamicRam("getAugmentationStats", getRamCost(player, "getAugmentationStats")); const aug = getAugmentation("getAugmentationStats", name); return Object.assign({}, aug.mults); }, purchaseAugmentation: function (faction: any, name: any): any { - helper.updateDynamicRam("purchaseAugmentation", getRamCost("purchaseAugmentation")); - helper.checkSingularityAccess("purchaseAugmentation", 3); + helper.updateDynamicRam("purchaseAugmentation", getRamCost(player, "purchaseAugmentation")); const fac = getFaction("purchaseAugmentation", faction); const aug = getAugmentation("purchaseAugmentation", name); @@ -214,8 +206,7 @@ export function NetscriptSingularity( } }, softReset: function (cbScript: any): any { - helper.updateDynamicRam("softReset", getRamCost("softReset")); - helper.checkSingularityAccess("softReset", 3); + helper.updateDynamicRam("softReset", getRamCost(player, "softReset")); workerScript.log("softReset", () => "Soft resetting. This will cause this script to be killed"); setTimeout(() => { @@ -228,8 +219,7 @@ export function NetscriptSingularity( killWorkerScript(workerScript); }, installAugmentations: function (cbScript: any): any { - helper.updateDynamicRam("installAugmentations", getRamCost("installAugmentations")); - helper.checkSingularityAccess("installAugmentations", 3); + helper.updateDynamicRam("installAugmentations", getRamCost(player, "installAugmentations")); if (player.queuedAugmentations.length === 0) { workerScript.log("installAugmentations", () => "You do not have any Augmentations to be installed."); @@ -250,8 +240,7 @@ export function NetscriptSingularity( }, goToLocation: function (locationName: any): boolean { - helper.updateDynamicRam("goToLocation", getRamCost("goToLocation")); - helper.checkSingularityAccess("goToLocation", 1); + helper.updateDynamicRam("goToLocation", getRamCost(player, "goToLocation")); const location = Object.values(Locations).find((l) => l.name === locationName); if (!location) { workerScript.log("goToLocation", () => `No location named ${locationName}`); @@ -266,8 +255,7 @@ export function NetscriptSingularity( return true; }, universityCourse: function (universityName: any, className: any): any { - helper.updateDynamicRam("universityCourse", getRamCost("universityCourse")); - helper.checkSingularityAccess("universityCourse", 1); + helper.updateDynamicRam("universityCourse", getRamCost(player, "universityCourse")); if (player.isWorking) { const txt = player.singularityStopWork(); workerScript.log("universityCourse", () => txt); @@ -346,8 +334,7 @@ export function NetscriptSingularity( }, gymWorkout: function (gymName: any, stat: any): any { - helper.updateDynamicRam("gymWorkout", getRamCost("gymWorkout")); - helper.checkSingularityAccess("gymWorkout", 1); + helper.updateDynamicRam("gymWorkout", getRamCost(player, "gymWorkout")); if (player.isWorking) { const txt = player.singularityStopWork(); workerScript.log("gymWorkout", () => txt); @@ -445,8 +432,7 @@ export function NetscriptSingularity( }, travelToCity: function (cityname: any): any { - helper.updateDynamicRam("travelToCity", getRamCost("travelToCity")); - helper.checkSingularityAccess("travelToCity", 1); + helper.updateDynamicRam("travelToCity", getRamCost(player, "travelToCity")); switch (cityname) { case CityName.Aevum: @@ -470,8 +456,7 @@ export function NetscriptSingularity( }, purchaseTor: function (): any { - helper.updateDynamicRam("purchaseTor", getRamCost("purchaseTor")); - helper.checkSingularityAccess("purchaseTor", 1); + helper.updateDynamicRam("purchaseTor", getRamCost(player, "purchaseTor")); if (player.hasTorRouter()) { workerScript.log("purchaseTor", () => "You already have a TOR router!"); @@ -502,8 +487,7 @@ export function NetscriptSingularity( return true; }, purchaseProgram: function (programName: any): any { - helper.updateDynamicRam("purchaseProgram", getRamCost("purchaseProgram")); - helper.checkSingularityAccess("purchaseProgram", 1); + helper.updateDynamicRam("purchaseProgram", getRamCost(player, "purchaseProgram")); if (!player.hasTorRouter()) { workerScript.log("purchaseProgram", () => "You do not have the TOR router."); @@ -541,13 +525,11 @@ export function NetscriptSingularity( return true; }, getCurrentServer: function (): any { - helper.updateDynamicRam("getCurrentServer", getRamCost("getCurrentServer")); - helper.checkSingularityAccess("getCurrentServer", 1); + helper.updateDynamicRam("getCurrentServer", getRamCost(player, "getCurrentServer")); return player.getCurrentServer().hostname; }, connect: function (hostname: any): any { - helper.updateDynamicRam("connect", getRamCost("connect")); - helper.checkSingularityAccess("connect", 1); + helper.updateDynamicRam("connect", getRamCost(player, "connect")); if (!hostname) { throw helper.makeRuntimeErrorMsg("connect", `Invalid hostname: '${hostname}'`); } @@ -581,14 +563,12 @@ export function NetscriptSingularity( return false; }, manualHack: function (): any { - helper.updateDynamicRam("manualHack", getRamCost("manualHack")); - helper.checkSingularityAccess("manualHack", 1); + helper.updateDynamicRam("manualHack", getRamCost(player, "manualHack")); const server = player.getCurrentServer(); return helper.hack(server.hostname, true); }, installBackdoor: function (): any { - helper.updateDynamicRam("installBackdoor", getRamCost("installBackdoor")); - helper.checkSingularityAccess("installBackdoor", 1); + helper.updateDynamicRam("installBackdoor", getRamCost(player, "installBackdoor")); const baseserver = player.getCurrentServer(); if (!(baseserver instanceof Server)) { workerScript.log("installBackdoor", () => "cannot backdoor this kind of server"); @@ -623,14 +603,12 @@ export function NetscriptSingularity( }); }, isFocused: function (): boolean { - helper.updateDynamicRam("isFocused", getRamCost("isFocused")); - helper.checkSingularityAccess("isFocused", 2); + helper.updateDynamicRam("isFocused", getRamCost(player, "isFocused")); return player.focus; }, setFocus: function (afocus: any): boolean { const focus = helper.boolean(afocus); - helper.updateDynamicRam("setFocus", getRamCost("setFocus")); - helper.checkSingularityAccess("setFocus", 2); + helper.updateDynamicRam("setFocus", getRamCost(player, "setFocus")); if (!player.isWorking) { throw helper.makeRuntimeErrorMsg("setFocus", "Not currently working"); } @@ -655,8 +633,7 @@ export function NetscriptSingularity( return false; }, getStats: function (): any { - helper.updateDynamicRam("getStats", getRamCost("getStats")); - helper.checkSingularityAccess("getStats", 1); + helper.updateDynamicRam("getStats", getRamCost(player, "getStats")); workerScript.log("getStats", () => `getStats is deprecated, please use getplayer`); return { @@ -670,8 +647,7 @@ export function NetscriptSingularity( }; }, getCharacterInformation: function (): any { - helper.updateDynamicRam("getCharacterInformation", getRamCost("getCharacterInformation")); - helper.checkSingularityAccess("getCharacterInformation", 1); + helper.updateDynamicRam("getCharacterInformation", getRamCost(player, "getCharacterInformation")); workerScript.log("getCharacterInformation", () => `getCharacterInformation is deprecated, please use getplayer`); return { @@ -718,8 +694,7 @@ export function NetscriptSingularity( }; }, hospitalize: function (): any { - helper.updateDynamicRam("hospitalize", getRamCost("hospitalize")); - helper.checkSingularityAccess("hospitalize", 1); + helper.updateDynamicRam("hospitalize", getRamCost(player, "hospitalize")); if (player.isWorking || Router.page() === Page.Infiltration || Router.page() === Page.BitVerse) { workerScript.log("hospitalize", () => "Cannot go to the hospital because the player is busy."); return; @@ -727,13 +702,11 @@ export function NetscriptSingularity( return player.hospitalize(); }, isBusy: function (): any { - helper.updateDynamicRam("isBusy", getRamCost("isBusy")); - helper.checkSingularityAccess("isBusy", 1); + helper.updateDynamicRam("isBusy", getRamCost(player, "isBusy")); return player.isWorking || Router.page() === Page.Infiltration || Router.page() === Page.BitVerse; }, stopAction: function (): any { - helper.updateDynamicRam("stopAction", getRamCost("stopAction")); - helper.checkSingularityAccess("stopAction", 1); + helper.updateDynamicRam("stopAction", getRamCost(player, "stopAction")); if (player.isWorking) { if (player.focus) { Router.toTerminal(); @@ -745,8 +718,7 @@ export function NetscriptSingularity( return false; }, upgradeHomeCores: function (): any { - helper.updateDynamicRam("upgradeHomeCores", getRamCost("upgradeHomeCores")); - helper.checkSingularityAccess("upgradeHomeCores", 2); + helper.updateDynamicRam("upgradeHomeCores", getRamCost(player, "upgradeHomeCores")); // Check if we're at max cores const homeComputer = player.getHomeComputer(); @@ -775,14 +747,12 @@ export function NetscriptSingularity( return true; }, getUpgradeHomeCoresCost: function (): any { - helper.updateDynamicRam("getUpgradeHomeCoresCost", getRamCost("getUpgradeHomeCoresCost")); - helper.checkSingularityAccess("getUpgradeHomeCoresCost", 2); + helper.updateDynamicRam("getUpgradeHomeCoresCost", getRamCost(player, "getUpgradeHomeCoresCost")); return player.getUpgradeHomeCoresCost(); }, upgradeHomeRam: function (): any { - helper.updateDynamicRam("upgradeHomeRam", getRamCost("upgradeHomeRam")); - helper.checkSingularityAccess("upgradeHomeRam", 2); + helper.updateDynamicRam("upgradeHomeRam", getRamCost(player, "upgradeHomeRam")); // Check if we're at max RAM const homeComputer = player.getHomeComputer(); @@ -814,14 +784,12 @@ export function NetscriptSingularity( return true; }, getUpgradeHomeRamCost: function (): any { - helper.updateDynamicRam("getUpgradeHomeRamCost", getRamCost("getUpgradeHomeRamCost")); - helper.checkSingularityAccess("getUpgradeHomeRamCost", 2); + helper.updateDynamicRam("getUpgradeHomeRamCost", getRamCost(player, "getUpgradeHomeRamCost")); return player.getUpgradeHomeRamCost(); }, workForCompany: function (companyName: any, focus = true): any { - helper.updateDynamicRam("workForCompany", getRamCost("workForCompany")); - helper.checkSingularityAccess("workForCompany", 2); + helper.updateDynamicRam("workForCompany", getRamCost(player, "workForCompany")); // Sanitize input if (companyName == null) { @@ -863,8 +831,7 @@ export function NetscriptSingularity( if (focus) { player.startFocusing(); Router.toWork(); - } - else if (wasFocused) { + } else if (wasFocused) { player.stopFocusing(); Router.toTerminal(); } @@ -875,8 +842,7 @@ export function NetscriptSingularity( return true; }, applyToCompany: function (companyName: any, field: any): any { - helper.updateDynamicRam("applyToCompany", getRamCost("applyToCompany")); - helper.checkSingularityAccess("applyToCompany", 2); + helper.updateDynamicRam("applyToCompany", getRamCost(player, "applyToCompany")); getCompany("applyToCompany", companyName); player.location = companyName; @@ -945,32 +911,27 @@ export function NetscriptSingularity( return res; }, getCompanyRep: function (companyName: any): any { - helper.updateDynamicRam("getCompanyRep", getRamCost("getCompanyRep")); - helper.checkSingularityAccess("getCompanyRep", 2); + helper.updateDynamicRam("getCompanyRep", getRamCost(player, "getCompanyRep")); const company = getCompany("getCompanyRep", companyName); return company.playerReputation; }, getCompanyFavor: function (companyName: any): any { - helper.updateDynamicRam("getCompanyFavor", getRamCost("getCompanyFavor")); - helper.checkSingularityAccess("getCompanyFavor", 2); + helper.updateDynamicRam("getCompanyFavor", getRamCost(player, "getCompanyFavor")); const company = getCompany("getCompanyFavor", companyName); return company.favor; }, getCompanyFavorGain: function (companyName: any): any { - helper.updateDynamicRam("getCompanyFavorGain", getRamCost("getCompanyFavorGain")); - helper.checkSingularityAccess("getCompanyFavorGain", 2); + helper.updateDynamicRam("getCompanyFavorGain", getRamCost(player, "getCompanyFavorGain")); const company = getCompany("getCompanyFavorGain", companyName); return company.getFavorGain(); }, checkFactionInvitations: function (): any { - helper.updateDynamicRam("checkFactionInvitations", getRamCost("checkFactionInvitations")); - helper.checkSingularityAccess("checkFactionInvitations", 2); + helper.updateDynamicRam("checkFactionInvitations", getRamCost(player, "checkFactionInvitations")); // Make a copy of player.factionInvitations return player.factionInvitations.slice(); }, joinFaction: function (name: any): any { - helper.updateDynamicRam("joinFaction", getRamCost("joinFaction")); - helper.checkSingularityAccess("joinFaction", 2); + helper.updateDynamicRam("joinFaction", getRamCost(player, "joinFaction")); getFaction("joinFaction", name); if (!player.factionInvitations.includes(name)) { @@ -992,8 +953,7 @@ export function NetscriptSingularity( return true; }, workForFaction: function (name: any, type: any, focus = true): any { - helper.updateDynamicRam("workForFaction", getRamCost("workForFaction")); - helper.checkSingularityAccess("workForFaction", 2); + helper.updateDynamicRam("workForFaction", getRamCost(player, "workForFaction")); getFaction("workForFaction", name); // if the player is in a gang and the target faction is any of the gang faction, fail @@ -1106,8 +1066,7 @@ export function NetscriptSingularity( return false; } player.startFactionHackWork(fac); - if (focus) - { + if (focus) { player.startFocusing(); Router.toWork(); } else if (wasFocusing) { @@ -1124,8 +1083,7 @@ export function NetscriptSingularity( return false; } player.startFactionFieldWork(fac); - if (focus) - { + if (focus) { player.startFocusing(); Router.toWork(); } else if (wasFocusing) { @@ -1142,8 +1100,7 @@ export function NetscriptSingularity( return false; } player.startFactionSecurityWork(fac); - if (focus) - { + if (focus) { player.startFocusing(); Router.toWork(); } else if (wasFocusing) { @@ -1158,26 +1115,22 @@ export function NetscriptSingularity( return true; }, getFactionRep: function (name: any): any { - helper.updateDynamicRam("getFactionRep", getRamCost("getFactionRep")); - helper.checkSingularityAccess("getFactionRep", 2); + helper.updateDynamicRam("getFactionRep", getRamCost(player, "getFactionRep")); const faction = getFaction("getFactionRep", name); return faction.playerReputation; }, getFactionFavor: function (name: any): any { - helper.updateDynamicRam("getFactionFavor", getRamCost("getFactionFavor")); - helper.checkSingularityAccess("getFactionFavor", 2); + helper.updateDynamicRam("getFactionFavor", getRamCost(player, "getFactionFavor")); const faction = getFaction("getFactionFavor", name); return faction.favor; }, getFactionFavorGain: function (name: any): any { - helper.updateDynamicRam("getFactionFavorGain", getRamCost("getFactionFavorGain")); - helper.checkSingularityAccess("getFactionFavorGain", 2); + helper.updateDynamicRam("getFactionFavorGain", getRamCost(player, "getFactionFavorGain")); const faction = getFaction("getFactionFavorGain", name); return faction.getFavorGain(); }, donateToFaction: function (name: any, amt: any): any { - helper.updateDynamicRam("donateToFaction", getRamCost("donateToFaction")); - helper.checkSingularityAccess("donateToFaction", 3); + helper.updateDynamicRam("donateToFaction", getRamCost(player, "donateToFaction")); const faction = getFaction("donateToFaction", name); if (typeof amt !== "number" || amt <= 0) { @@ -1213,8 +1166,7 @@ export function NetscriptSingularity( return true; }, createProgram: function (name: any): any { - helper.updateDynamicRam("createProgram", getRamCost("createProgram")); - helper.checkSingularityAccess("createProgram", 3); + helper.updateDynamicRam("createProgram", getRamCost(player, "createProgram")); if (player.isWorking) { const txt = player.singularityStopWork(); @@ -1254,8 +1206,7 @@ export function NetscriptSingularity( return true; }, commitCrime: function (crimeRoughName: any): any { - helper.updateDynamicRam("commitCrime", getRamCost("commitCrime")); - helper.checkSingularityAccess("commitCrime", 3); + helper.updateDynamicRam("commitCrime", getRamCost(player, "commitCrime")); if (player.isWorking) { const txt = player.singularityStopWork(); @@ -1274,8 +1225,7 @@ export function NetscriptSingularity( return crime.commit(Router, player, 1, workerScript); }, getCrimeChance: function (crimeRoughName: any): any { - helper.updateDynamicRam("getCrimeChance", getRamCost("getCrimeChance")); - helper.checkSingularityAccess("getCrimeChance", 3); + helper.updateDynamicRam("getCrimeChance", getRamCost(player, "getCrimeChance")); const crime = findCrime(crimeRoughName.toLowerCase()); if (crime == null) { @@ -1285,8 +1235,7 @@ export function NetscriptSingularity( return crime.successRate(player); }, getCrimeStats: function (crimeRoughName: any): any { - helper.updateDynamicRam("getCrimeStats", getRamCost("getCrimeStats")); - helper.checkSingularityAccess("getCrimeStats", 3); + helper.updateDynamicRam("getCrimeStats", getRamCost(player, "getCrimeStats")); const crime = findCrime(crimeRoughName.toLowerCase()); if (crime == null) { diff --git a/src/NetscriptFunctions/Sleeve.ts b/src/NetscriptFunctions/Sleeve.ts index c4d1baea3..5e340c6cd 100644 --- a/src/NetscriptFunctions/Sleeve.ts +++ b/src/NetscriptFunctions/Sleeve.ts @@ -32,20 +32,20 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel return { getNumSleeves: function (): number { - helper.updateDynamicRam("getNumSleeves", getRamCost("sleeve", "getNumSleeves")); + helper.updateDynamicRam("getNumSleeves", getRamCost(player, "sleeve", "getNumSleeves")); checkSleeveAPIAccess("getNumSleeves"); return player.sleeves.length; }, setToShockRecovery: function (asleeveNumber: any = 0): boolean { const sleeveNumber = helper.number("setToShockRecovery", "sleeveNumber", asleeveNumber); - helper.updateDynamicRam("setToShockRecovery", getRamCost("sleeve", "setToShockRecovery")); + helper.updateDynamicRam("setToShockRecovery", getRamCost(player, "sleeve", "setToShockRecovery")); checkSleeveAPIAccess("setToShockRecovery"); checkSleeveNumber("setToShockRecovery", sleeveNumber); return player.sleeves[sleeveNumber].shockRecovery(player); }, setToSynchronize: function (asleeveNumber: any = 0): boolean { const sleeveNumber = helper.number("setToSynchronize", "sleeveNumber", asleeveNumber); - helper.updateDynamicRam("setToSynchronize", getRamCost("sleeve", "setToSynchronize")); + helper.updateDynamicRam("setToSynchronize", getRamCost(player, "sleeve", "setToSynchronize")); checkSleeveAPIAccess("setToSynchronize"); checkSleeveNumber("setToSynchronize", sleeveNumber); return player.sleeves[sleeveNumber].synchronize(player); @@ -53,7 +53,7 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel setToCommitCrime: function (asleeveNumber: any = 0, aCrimeRoughName: any = ""): boolean { const sleeveNumber = helper.number("setToCommitCrime", "sleeveNumber", asleeveNumber); const crimeRoughName = helper.string("setToCommitCrime", "crimeName", aCrimeRoughName); - helper.updateDynamicRam("setToCommitCrime", getRamCost("sleeve", "setToCommitCrime")); + helper.updateDynamicRam("setToCommitCrime", getRamCost(player, "sleeve", "setToCommitCrime")); checkSleeveAPIAccess("setToCommitCrime"); checkSleeveNumber("setToCommitCrime", sleeveNumber); const crime = findCrime(crimeRoughName); @@ -66,7 +66,7 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel const sleeveNumber = helper.number("setToUniversityCourse", "sleeveNumber", asleeveNumber); const universityName = helper.string("setToUniversityCourse", "universityName", auniversityName); const className = helper.string("setToUniversityCourse", "className", aclassName); - helper.updateDynamicRam("setToUniversityCourse", getRamCost("sleeve", "setToUniversityCourse")); + helper.updateDynamicRam("setToUniversityCourse", getRamCost(player, "sleeve", "setToUniversityCourse")); checkSleeveAPIAccess("setToUniversityCourse"); checkSleeveNumber("setToUniversityCourse", sleeveNumber); return player.sleeves[sleeveNumber].takeUniversityCourse(player, universityName, className); @@ -74,7 +74,7 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel travel: function (asleeveNumber: any = 0, acityName: any = ""): boolean { const sleeveNumber = helper.number("travel", "sleeveNumber", asleeveNumber); const cityName = helper.string("setToUniversityCourse", "cityName", acityName); - helper.updateDynamicRam("travel", getRamCost("sleeve", "travel")); + helper.updateDynamicRam("travel", getRamCost(player, "sleeve", "travel")); checkSleeveAPIAccess("travel"); checkSleeveNumber("travel", sleeveNumber); return player.sleeves[sleeveNumber].travel(player, cityName as CityName); @@ -82,7 +82,7 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel setToCompanyWork: function (asleeveNumber: any = 0, acompanyName: any = ""): boolean { const sleeveNumber = helper.number("setToCompanyWork", "sleeveNumber", asleeveNumber); const companyName = helper.string("setToUniversityCourse", "companyName", acompanyName); - helper.updateDynamicRam("setToCompanyWork", getRamCost("sleeve", "setToCompanyWork")); + helper.updateDynamicRam("setToCompanyWork", getRamCost(player, "sleeve", "setToCompanyWork")); checkSleeveAPIAccess("setToCompanyWork"); checkSleeveNumber("setToCompanyWork", sleeveNumber); @@ -106,7 +106,7 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel const sleeveNumber = helper.number("setToFactionWork", "sleeveNumber", asleeveNumber); const factionName = helper.string("setToUniversityCourse", "factionName", afactionName); const workType = helper.string("setToUniversityCourse", "workType", aworkType); - helper.updateDynamicRam("setToFactionWork", getRamCost("sleeve", "setToFactionWork")); + helper.updateDynamicRam("setToFactionWork", getRamCost(player, "sleeve", "setToFactionWork")); checkSleeveAPIAccess("setToFactionWork"); checkSleeveNumber("setToFactionWork", sleeveNumber); @@ -130,7 +130,7 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel const sleeveNumber = helper.number("setToGymWorkout", "sleeveNumber", asleeveNumber); const gymName = helper.string("setToUniversityCourse", "gymName", agymName); const stat = helper.string("setToUniversityCourse", "stat", astat); - helper.updateDynamicRam("setToGymWorkout", getRamCost("sleeve", "setToGymWorkout")); + helper.updateDynamicRam("setToGymWorkout", getRamCost(player, "sleeve", "setToGymWorkout")); checkSleeveAPIAccess("setToGymWorkout"); checkSleeveNumber("setToGymWorkout", sleeveNumber); @@ -147,7 +147,7 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel charisma: number; } { const sleeveNumber = helper.number("getSleeveStats", "sleeveNumber", asleeveNumber); - helper.updateDynamicRam("getSleeveStats", getRamCost("sleeve", "getSleeveStats")); + helper.updateDynamicRam("getSleeveStats", getRamCost(player, "sleeve", "getSleeveStats")); checkSleeveAPIAccess("getSleeveStats"); checkSleeveNumber("getSleeveStats", sleeveNumber); @@ -171,7 +171,7 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel factionWorkType: string; } { const sleeveNumber = helper.number("getTask", "sleeveNumber", asleeveNumber); - helper.updateDynamicRam("getTask", getRamCost("sleeve", "getTask")); + helper.updateDynamicRam("getTask", getRamCost(player, "sleeve", "getTask")); checkSleeveAPIAccess("getTask"); checkSleeveNumber("getTask", sleeveNumber); @@ -186,7 +186,7 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel }, getInformation: function (asleeveNumber: any = 0): any { const sleeveNumber = helper.number("getInformation", "sleeveNumber", asleeveNumber); - helper.updateDynamicRam("getInformation", getRamCost("sleeve", "getInformation")); + helper.updateDynamicRam("getInformation", getRamCost(player, "sleeve", "getInformation")); checkSleeveAPIAccess("getInformation"); checkSleeveNumber("getInformation", sleeveNumber); @@ -251,7 +251,7 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel }, getSleeveAugmentations: function (asleeveNumber: any = 0): string[] { const sleeveNumber = helper.number("getSleeveAugmentations", "sleeveNumber", asleeveNumber); - helper.updateDynamicRam("getSleeveAugmentations", getRamCost("sleeve", "getSleeveAugmentations")); + helper.updateDynamicRam("getSleeveAugmentations", getRamCost(player, "sleeve", "getSleeveAugmentations")); checkSleeveAPIAccess("getSleeveAugmentations"); checkSleeveNumber("getSleeveAugmentations", sleeveNumber); @@ -266,7 +266,7 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel cost: number; }[] { const sleeveNumber = helper.number("getSleevePurchasableAugs", "sleeveNumber", asleeveNumber); - helper.updateDynamicRam("getSleevePurchasableAugs", getRamCost("sleeve", "getSleevePurchasableAugs")); + helper.updateDynamicRam("getSleevePurchasableAugs", getRamCost(player, "sleeve", "getSleevePurchasableAugs")); checkSleeveAPIAccess("getSleevePurchasableAugs"); checkSleeveNumber("getSleevePurchasableAugs", sleeveNumber); @@ -285,7 +285,7 @@ export function NetscriptSleeve(player: IPlayer, workerScript: WorkerScript, hel purchaseSleeveAug: function (asleeveNumber: any = 0, aaugName: any = ""): boolean { const sleeveNumber = helper.number("purchaseSleeveAug", "sleeveNumber", asleeveNumber); const augName = helper.string("setToUniversityCourse", "augName", aaugName); - helper.updateDynamicRam("purchaseSleeveAug", getRamCost("sleeve", "purchaseSleeveAug")); + helper.updateDynamicRam("purchaseSleeveAug", getRamCost(player, "sleeve", "purchaseSleeveAug")); checkSleeveAPIAccess("purchaseSleeveAug"); checkSleeveNumber("purchaseSleeveAug", sleeveNumber); diff --git a/src/NetscriptFunctions/Stanek.ts b/src/NetscriptFunctions/Stanek.ts index 8c345853a..94dd6d24b 100644 --- a/src/NetscriptFunctions/Stanek.ts +++ b/src/NetscriptFunctions/Stanek.ts @@ -32,7 +32,7 @@ export function NetscriptStanek(player: IPlayer, workerScript: WorkerScript, hel const rootX = helper.number("stanek.charge", "rootX", arootX); const rootY = helper.number("stanek.charge", "rootY", arootY); - helper.updateDynamicRam("charge", getRamCost("stanek", "charge")); + helper.updateDynamicRam("charge", getRamCost(player, "stanek", "charge")); checkStanekAPIAccess("charge"); const fragment = staneksGift.findFragment(rootX, rootY); if (!fragment) throw helper.makeRuntimeErrorMsg("stanek.charge", `No fragment with root (${rootX}, ${rootY}).`); @@ -47,13 +47,13 @@ export function NetscriptStanek(player: IPlayer, workerScript: WorkerScript, hel }); }, fragmentDefinitions: function (): IFragment[] { - helper.updateDynamicRam("fragmentDefinitions", getRamCost("stanek", "fragmentDefinitions")); + helper.updateDynamicRam("fragmentDefinitions", getRamCost(player, "stanek", "fragmentDefinitions")); checkStanekAPIAccess("fragmentDefinitions"); workerScript.log("stanek.fragmentDefinitions", () => `Returned ${Fragments.length} fragments`); return Fragments.map((f) => f.copy()); }, activeFragments: function (): IActiveFragment[] { - helper.updateDynamicRam("activeFragments", getRamCost("stanek", "activeFragments")); + helper.updateDynamicRam("activeFragments", getRamCost(player, "stanek", "activeFragments")); checkStanekAPIAccess("activeFragments"); workerScript.log("stanek.activeFragments", () => `Returned ${staneksGift.fragments.length} fragments`); return staneksGift.fragments.map((af) => { @@ -61,7 +61,7 @@ export function NetscriptStanek(player: IPlayer, workerScript: WorkerScript, hel }); }, clear: function (): void { - helper.updateDynamicRam("clear", getRamCost("stanek", "clear")); + helper.updateDynamicRam("clear", getRamCost(player, "stanek", "clear")); checkStanekAPIAccess("clear"); workerScript.log("stanek.clear", () => `Cleared Stanek's Gift.`); staneksGift.clear(); @@ -71,7 +71,7 @@ export function NetscriptStanek(player: IPlayer, workerScript: WorkerScript, hel const rootY = helper.number("stanek.canPlace", "rootY", arootY); const rotation = helper.number("stanek.canPlace", "rotation", arotation); const fragmentId = helper.number("stanek.canPlace", "fragmentId", afragmentId); - helper.updateDynamicRam("canPlace", getRamCost("stanek", "canPlace")); + helper.updateDynamicRam("canPlace", getRamCost(player, "stanek", "canPlace")); checkStanekAPIAccess("canPlace"); const fragment = FragmentById(fragmentId); if (!fragment) throw helper.makeRuntimeErrorMsg("stanek.canPlace", `Invalid fragment id: ${fragmentId}`); @@ -83,7 +83,7 @@ export function NetscriptStanek(player: IPlayer, workerScript: WorkerScript, hel const rootY = helper.number("stanek.place", "rootY", arootY); const rotation = helper.number("stanek.place", "rotation", arotation); const fragmentId = helper.number("stanek.place", "fragmentId", afragmentId); - helper.updateDynamicRam("place", getRamCost("stanek", "place")); + helper.updateDynamicRam("place", getRamCost(player, "stanek", "place")); checkStanekAPIAccess("place"); const fragment = FragmentById(fragmentId); if (!fragment) throw helper.makeRuntimeErrorMsg("stanek.place", `Invalid fragment id: ${fragmentId}`); @@ -92,7 +92,7 @@ export function NetscriptStanek(player: IPlayer, workerScript: WorkerScript, hel get: function (arootX: any, arootY: any): IActiveFragment | undefined { const rootX = helper.number("stanek.get", "rootX", arootX); const rootY = helper.number("stanek.get", "rootY", arootY); - helper.updateDynamicRam("get", getRamCost("stanek", "get")); + helper.updateDynamicRam("get", getRamCost(player, "stanek", "get")); checkStanekAPIAccess("get"); const fragment = staneksGift.findFragment(rootX, rootY); if (fragment !== undefined) return fragment.copy(); @@ -101,7 +101,7 @@ export function NetscriptStanek(player: IPlayer, workerScript: WorkerScript, hel remove: function (arootX: any, arootY: any): boolean { const rootX = helper.number("stanek.remove", "rootX", arootX); const rootY = helper.number("stanek.remove", "rootY", arootY); - helper.updateDynamicRam("remove", getRamCost("stanek", "remove")); + helper.updateDynamicRam("remove", getRamCost(player, "stanek", "remove")); checkStanekAPIAccess("remove"); return staneksGift.delete(rootX, rootY); }, diff --git a/src/NetscriptFunctions/StockMarket.ts b/src/NetscriptFunctions/StockMarket.ts index 030afe661..a347d09d5 100644 --- a/src/NetscriptFunctions/StockMarket.ts +++ b/src/NetscriptFunctions/StockMarket.ts @@ -35,33 +35,33 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript }; return { getSymbols: function (): any { - helper.updateDynamicRam("getSymbols", getRamCost("stock", "getSymbols")); + helper.updateDynamicRam("getSymbols", getRamCost(player, "stock", "getSymbols")); checkTixApiAccess("getSymbols"); return Object.values(StockSymbols); }, getPrice: function (symbol: any): any { - helper.updateDynamicRam("getPrice", getRamCost("stock", "getPrice")); + helper.updateDynamicRam("getPrice", getRamCost(player, "stock", "getPrice")); checkTixApiAccess("getPrice"); const stock = getStockFromSymbol(symbol, "getPrice"); return stock.price; }, getAskPrice: function (symbol: any): any { - helper.updateDynamicRam("getAskPrice", getRamCost("stock", "getAskPrice")); + helper.updateDynamicRam("getAskPrice", getRamCost(player, "stock", "getAskPrice")); checkTixApiAccess("getAskPrice"); const stock = getStockFromSymbol(symbol, "getAskPrice"); return stock.getAskPrice(); }, getBidPrice: function (symbol: any): any { - helper.updateDynamicRam("getBidPrice", getRamCost("stock", "getBidPrice")); + helper.updateDynamicRam("getBidPrice", getRamCost(player, "stock", "getBidPrice")); checkTixApiAccess("getBidPrice"); const stock = getStockFromSymbol(symbol, "getBidPrice"); return stock.getBidPrice(); }, getPosition: function (symbol: any): any { - helper.updateDynamicRam("getPosition", getRamCost("stock", "getPosition")); + helper.updateDynamicRam("getPosition", getRamCost(player, "stock", "getPosition")); checkTixApiAccess("getPosition"); const stock = SymbolToStockMap[symbol]; if (stock == null) { @@ -70,14 +70,14 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript return [stock.playerShares, stock.playerAvgPx, stock.playerShortShares, stock.playerAvgShortPx]; }, getMaxShares: function (symbol: any): any { - helper.updateDynamicRam("getMaxShares", getRamCost("stock", "getMaxShares")); + helper.updateDynamicRam("getMaxShares", getRamCost(player, "stock", "getMaxShares")); checkTixApiAccess("getMaxShares"); const stock = getStockFromSymbol(symbol, "getMaxShares"); return stock.maxShares; }, getPurchaseCost: function (symbol: any, shares: any, posType: any): any { - helper.updateDynamicRam("getPurchaseCost", getRamCost("stock", "getPurchaseCost")); + helper.updateDynamicRam("getPurchaseCost", getRamCost(player, "stock", "getPurchaseCost")); checkTixApiAccess("getPurchaseCost"); const stock = getStockFromSymbol(symbol, "getPurchaseCost"); shares = Math.round(shares); @@ -100,7 +100,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript return res; }, getSaleGain: function (symbol: any, shares: any, posType: any): any { - helper.updateDynamicRam("getSaleGain", getRamCost("stock", "getSaleGain")); + helper.updateDynamicRam("getSaleGain", getRamCost(player, "stock", "getSaleGain")); checkTixApiAccess("getSaleGain"); const stock = getStockFromSymbol(symbol, "getSaleGain"); shares = Math.round(shares); @@ -123,14 +123,14 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript return res; }, buy: function (symbol: any, shares: any): any { - helper.updateDynamicRam("buy", getRamCost("stock", "buy")); + helper.updateDynamicRam("buy", getRamCost(player, "stock", "buy")); checkTixApiAccess("buy"); const stock = getStockFromSymbol(symbol, "buy"); const res = buyStock(stock, shares, workerScript, {}); return res ? stock.getAskPrice() : 0; }, sell: function (symbol: any, shares: any): any { - helper.updateDynamicRam("sell", getRamCost("stock", "sell")); + helper.updateDynamicRam("sell", getRamCost(player, "stock", "sell")); checkTixApiAccess("sell"); const stock = getStockFromSymbol(symbol, "sell"); const res = sellStock(stock, shares, workerScript, {}); @@ -138,7 +138,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript return res ? stock.getBidPrice() : 0; }, short: function (symbol: any, shares: any): any { - helper.updateDynamicRam("short", getRamCost("stock", "short")); + helper.updateDynamicRam("short", getRamCost(player, "stock", "short")); checkTixApiAccess("short"); if (player.bitNodeN !== 8) { if (player.sourceFileLvl(8) <= 1) { @@ -154,7 +154,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript return res ? stock.getBidPrice() : 0; }, sellShort: function (symbol: any, shares: any): any { - helper.updateDynamicRam("sellShort", getRamCost("stock", "sellShort")); + helper.updateDynamicRam("sellShort", getRamCost(player, "stock", "sellShort")); checkTixApiAccess("sellShort"); if (player.bitNodeN !== 8) { if (player.sourceFileLvl(8) <= 1) { @@ -170,7 +170,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript return res ? stock.getAskPrice() : 0; }, placeOrder: function (symbol: any, shares: any, price: any, type: any, pos: any): any { - helper.updateDynamicRam("placeOrder", getRamCost("stock", "placeOrder")); + helper.updateDynamicRam("placeOrder", getRamCost(player, "stock", "placeOrder")); checkTixApiAccess("placeOrder"); if (player.bitNodeN !== 8) { if (player.sourceFileLvl(8) <= 2) { @@ -209,7 +209,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript return placeOrder(stock, shares, price, orderType, orderPos, workerScript); }, cancelOrder: function (symbol: any, shares: any, price: any, type: any, pos: any): any { - helper.updateDynamicRam("cancelOrder", getRamCost("stock", "cancelOrder")); + helper.updateDynamicRam("cancelOrder", getRamCost(player, "stock", "cancelOrder")); checkTixApiAccess("cancelOrder"); if (player.bitNodeN !== 8) { if (player.sourceFileLvl(8) <= 2) { @@ -259,7 +259,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript return cancelOrder(params, workerScript); }, getOrders: function (): any { - helper.updateDynamicRam("getOrders", getRamCost("stock", "getOrders")); + helper.updateDynamicRam("getOrders", getRamCost(player, "stock", "getOrders")); checkTixApiAccess("getOrders"); if (player.bitNodeN !== 8) { if (player.sourceFileLvl(8) <= 2) { @@ -291,7 +291,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript return orders; }, getVolatility: function (symbol: any): any { - helper.updateDynamicRam("getVolatility", getRamCost("stock", "getVolatility")); + helper.updateDynamicRam("getVolatility", getRamCost(player, "stock", "getVolatility")); if (!player.has4SDataTixApi) { throw helper.makeRuntimeErrorMsg("getVolatility", "You don't have 4S Market Data TIX API Access!"); } @@ -300,7 +300,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript return stock.mv / 100; // Convert from percentage to decimal }, getForecast: function (symbol: any): any { - helper.updateDynamicRam("getForecast", getRamCost("stock", "getForecast")); + helper.updateDynamicRam("getForecast", getRamCost(player, "stock", "getForecast")); if (!player.has4SDataTixApi) { throw helper.makeRuntimeErrorMsg("getForecast", "You don't have 4S Market Data TIX API Access!"); } @@ -311,7 +311,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript return forecast / 100; // Convert from percentage to decimal }, purchase4SMarketData: function () { - helper.updateDynamicRam("purchase4SMarketData", getRamCost("stock", "purchase4SMarketData")); + helper.updateDynamicRam("purchase4SMarketData", getRamCost(player, "stock", "purchase4SMarketData")); checkTixApiAccess("purchase4SMarketData"); if (player.has4SData) { @@ -330,7 +330,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript return true; }, purchase4SMarketDataTixApi: function () { - helper.updateDynamicRam("purchase4SMarketDataTixApi", getRamCost("stock", "purchase4SMarketDataTixApi")); + helper.updateDynamicRam("purchase4SMarketDataTixApi", getRamCost(player, "stock", "purchase4SMarketDataTixApi")); checkTixApiAccess("purchase4SMarketDataTixApi"); if (player.has4SDataTixApi) { diff --git a/src/NetscriptFunctions/UserInterface.ts b/src/NetscriptFunctions/UserInterface.ts index b684623ad..89c3aeaa0 100644 --- a/src/NetscriptFunctions/UserInterface.ts +++ b/src/NetscriptFunctions/UserInterface.ts @@ -12,9 +12,8 @@ export function NetscriptUserInterface( ): IUserInterface { return { getTheme: function (): UserInterfaceTheme { - helper.updateDynamicRam("getTheme", getRamCost("ui", "getTheme")); - return {...Settings.theme}; + helper.updateDynamicRam("getTheme", getRamCost(player, "ui", "getTheme")); + return { ...Settings.theme }; }, - } + }; } - diff --git a/src/NetscriptJSEvaluator.ts b/src/NetscriptJSEvaluator.ts index d4c7b6dbc..268496c98 100644 --- a/src/NetscriptJSEvaluator.ts +++ b/src/NetscriptJSEvaluator.ts @@ -6,13 +6,14 @@ import { computeHash } from "./utils/helpers/computeHash"; import { BlobCache } from "./utils/BlobCache"; import { ImportCache } from "./utils/ImportCache"; import { areImportsEquals } from "./Terminal/DirectoryHelpers"; +import { IPlayer } from "./PersonObjects/IPlayer"; // Makes a blob that contains the code of a given script. function makeScriptBlob(code: string): Blob { return new Blob([code], { type: "text/javascript" }); } -export async function compile(script: Script, scripts: Script[]): Promise { +export async function compile(player: IPlayer, script: Script, scripts: Script[]): Promise { if (!shouldCompile(script, scripts)) return; // The URL at the top is the one we want to import. It will // recursively import all the other modules in the urlStack. @@ -21,7 +22,7 @@ export async function compile(script: Script, scripts: Script[]): Promise // but not really behaves like import. Particularly, it cannot // load fully dynamic content. So we hide the import from webpack // by placing it inside an eval call. - await script.updateRamUsage(scripts); + await script.updateRamUsage(player, scripts); const uurls = _getScriptUrls(script, scripts, []); const url = uurls[uurls.length - 1].url; if (script.url && script.url !== url) { @@ -50,10 +51,14 @@ export async function compile(script: Script, scripts: Script[]): Promise // (i.e. hack, grow, etc.). // When the promise returned by this resolves, we'll have finished // running the main function of the script. -export async function executeJSScript(scripts: Script[] = [], workerScript: WorkerScript): Promise { +export async function executeJSScript( + player: IPlayer, + scripts: Script[] = [], + workerScript: WorkerScript, +): Promise { const script = workerScript.getScript(); if (script === null) throw new Error("script is null"); - await compile(script, scripts); + await compile(player, script, scripts); workerScript.ramUsage = script.ramUsage; const loadedModule = await script.module; diff --git a/src/NetscriptWorker.ts b/src/NetscriptWorker.ts index bb062c995..dfcb1245a 100644 --- a/src/NetscriptWorker.ts +++ b/src/NetscriptWorker.ts @@ -35,6 +35,7 @@ import { simple as walksimple } from "acorn-walk"; import { areFilesEqual } from "./Terminal/DirectoryHelpers"; import { Player } from "./Player"; import { Terminal } from "./Terminal"; +import { IPlayer } from "./PersonObjects/IPlayer"; // Netscript Ports are instantiated here export const NetscriptPorts: IPort[] = []; @@ -55,7 +56,7 @@ export function prestigeWorkerScripts(): void { // JS script promises need a little massaging to have the same guarantees as netscript // promises. This does said massaging and kicks the script off. It returns a promise // that resolves or rejects when the corresponding worker script is done. -function startNetscript2Script(workerScript: WorkerScript): Promise { +function startNetscript2Script(player: IPlayer, workerScript: WorkerScript): Promise { workerScript.running = true; // The name of the currently running netscript function, to prevent concurrent @@ -121,7 +122,7 @@ function startNetscript2Script(workerScript: WorkerScript): Promise((resolve, reject) => { - executeJSScript(workerScript.getServer().scripts, workerScript) + executeJSScript(player, workerScript.getServer().scripts, workerScript) .then(() => { resolve(workerScript); }) @@ -457,8 +458,13 @@ function processNetscript1Imports(code: string, workerScript: WorkerScript): any * @param {Server} server - Server on which the script is to be run * @returns {number} pid of started script */ -export function startWorkerScript(runningScript: RunningScript, server: BaseServer, parent?: WorkerScript): number { - if (createAndAddWorkerScript(runningScript, server, parent)) { +export function startWorkerScript( + player: IPlayer, + runningScript: RunningScript, + server: BaseServer, + parent?: WorkerScript, +): number { + if (createAndAddWorkerScript(player, runningScript, server, parent)) { // Push onto runningScripts. // This has to come after createAndAddWorkerScript() because that fn updates RAM usage server.runScript(runningScript); @@ -478,7 +484,12 @@ export function startWorkerScript(runningScript: RunningScript, server: BaseServ * @param {Server} server - Server on which the script is to be run * returns {boolean} indicating whether or not the workerScript was successfully added */ -function createAndAddWorkerScript(runningScriptObj: RunningScript, server: BaseServer, parent?: WorkerScript): boolean { +function createAndAddWorkerScript( + player: IPlayer, + runningScriptObj: RunningScript, + server: BaseServer, + parent?: WorkerScript, +): boolean { // Update server's ram usage let threads = 1; if (runningScriptObj.threads && !isNaN(runningScriptObj.threads)) { @@ -522,7 +533,7 @@ function createAndAddWorkerScript(runningScriptObj: RunningScript, server: BaseS // Start the script's execution let p: Promise | null = null; // Script's resulting promise if (s.name.endsWith(".js") || s.name.endsWith(".ns")) { - p = startNetscript2Script(s); + p = startNetscript2Script(player, s); } else { p = startNetscript1Script(s); if (!(p instanceof Promise)) { @@ -607,7 +618,7 @@ export function updateOnlineScriptTimes(numCycles = 1): void { * Called when the game is loaded. Loads all running scripts (from all servers) * into worker scripts so that they will start running */ -export function loadAllRunningScripts(): void { +export function loadAllRunningScripts(player: IPlayer): void { const skipScriptLoad = window.location.href.toLowerCase().indexOf("?noscripts") !== -1; if (skipScriptLoad) { Terminal.warn("Skipped loading player scripts during startup"); @@ -627,7 +638,7 @@ export function loadAllRunningScripts(): void { server.runningScripts.length = 0; } else { for (let j = 0; j < server.runningScripts.length; ++j) { - createAndAddWorkerScript(server.runningScripts[j], server); + createAndAddWorkerScript(player, server.runningScripts[j], server); // Offline production scriptCalculateOfflineProduction(server.runningScripts[j]); @@ -640,6 +651,7 @@ export function loadAllRunningScripts(): void { * Run a script from inside another script (run(), exec(), spawn(), etc.) */ export function runScriptFromScript( + player: IPlayer, caller: string, server: BaseServer, scriptname: string, @@ -714,7 +726,7 @@ export function runScriptFromScript( runningScriptObj.threads = threads; runningScriptObj.server = server.hostname; - return startWorkerScript(runningScriptObj, server, workerScript); + return startWorkerScript(player, runningScriptObj, server, workerScript); } break; } diff --git a/src/Prestige.ts b/src/Prestige.ts index ce0e82ab7..6000ac3ec 100755 --- a/src/Prestige.ts +++ b/src/Prestige.ts @@ -52,7 +52,7 @@ export function prestigeAugmentation(): void { // Reset home computer (only the programs) and add to AllServers AddToAllServers(homeComp); - prestigeHomeComputer(homeComp); + prestigeHomeComputer(Player, homeComp); if (augmentationExists(AugmentationNames.Neurolink) && Augmentations[AugmentationNames.Neurolink].owned) { homeComp.programs.push(Programs.FTPCrackProgram.name); @@ -180,7 +180,7 @@ export function prestigeSourceFile(flume: boolean): void { // Reset home computer (only the programs) and add to AllServers AddToAllServers(homeComp); - prestigeHomeComputer(homeComp); + prestigeHomeComputer(Player, homeComp); // Re-create foreign servers initForeignServers(Player.getHomeComputer()); diff --git a/src/Script/RamCalculations.ts b/src/Script/RamCalculations.ts index 05920baf9..bbd67a997 100644 --- a/src/Script/RamCalculations.ts +++ b/src/Script/RamCalculations.ts @@ -14,6 +14,7 @@ import { RamCosts, RamCostConstants } from "../Netscript/RamCostGenerator"; import { Script } from "../Script/Script"; import { WorkerScript } from "../Netscript/WorkerScript"; import { areImportsEquals } from "../Terminal/DirectoryHelpers"; +import { IPlayer } from "../PersonObjects/IPlayer"; // These special strings are used to reference the presence of a given logical // construct within a user script. @@ -33,6 +34,7 @@ const memCheckGlobalKey = ".__GLOBAL__"; * keep track of what functions have/havent been accounted for */ async function parseOnlyRamCalculate( + player: IPlayer, otherScripts: Script[], code: string, workerScript: WorkerScript, @@ -169,6 +171,8 @@ async function parseOnlyRamCalculate( function applyFuncRam(cost: any): number { if (typeof cost === "number") { return cost; + } else if (typeof cost === "function") { + return cost(player); } else { return 0; } @@ -375,6 +379,7 @@ function parseOnlyCalculateDeps(code: string, currentModule: string): any { * Used to account for imported scripts */ export async function calculateRamUsage( + player: IPlayer, codeCopy: string, otherScripts: Script[], ): Promise { @@ -388,7 +393,7 @@ export async function calculateRamUsage( } as WorkerScript; try { - return await parseOnlyRamCalculate(otherScripts, codeCopy, workerScript); + return await parseOnlyRamCalculate(player, otherScripts, codeCopy, workerScript); } catch (e) { console.error(`Failed to parse script for RAM calculations:`); console.error(e); diff --git a/src/Script/Script.ts b/src/Script/Script.ts index ccdfa578e..5f350ef55 100644 --- a/src/Script/Script.ts +++ b/src/Script/Script.ts @@ -10,6 +10,7 @@ import { ScriptUrl } from "./ScriptUrl"; import { Generic_fromJSON, Generic_toJSON, Reviver } from "../utils/JSONReviver"; import { roundToTwo } from "../utils/helpers/roundToTwo"; import { computeHash } from "../utils/helpers/computeHash"; +import { IPlayer } from "../PersonObjects/IPlayer"; let globalModuleSequenceNumber = 0; @@ -44,7 +45,7 @@ export class Script { // sha256 hash of the code in the Script. Do not access directly. _hash = ""; - constructor(fn = "", code = "", server = "", otherScripts: Script[] = []) { + constructor(player: IPlayer | null = null, fn = "", code = "", server = "", otherScripts: Script[] = []) { this.filename = fn; this.code = code; this.ramUsage = 0; @@ -52,8 +53,8 @@ export class Script { this.module = ""; this.moduleSequenceNumber = ++globalModuleSequenceNumber; this._hash = ""; - if (this.code !== "") { - this.updateRamUsage(otherScripts); + if (this.code !== "" && player !== null) { + this.updateRamUsage(player, otherScripts); this.rehash(); } } @@ -105,8 +106,7 @@ export class Script { * @returns the computed hash of the script */ hash(): string { - if (!this._hash) - this.rehash(); + if (!this._hash) this.rehash(); return this._hash; } @@ -115,13 +115,13 @@ export class Script { * @param {string} code - The new contents of the script * @param {Script[]} otherScripts - Other scripts on the server. Used to process imports */ - saveScript(filename: string, code: string, hostname: string, otherScripts: Script[]): void { + saveScript(player: IPlayer, filename: string, code: string, hostname: string, otherScripts: Script[]): void { // Update code and filename this.code = code.replace(/^\s+|\s+$/g, ""); this.filename = filename; this.server = hostname; - this.updateRamUsage(otherScripts); + this.updateRamUsage(player, otherScripts); this.markUpdated(); } @@ -129,8 +129,8 @@ export class Script { * Calculates and updates the script's RAM usage based on its code * @param {Script[]} otherScripts - Other scripts on the server. Used to process imports */ - async updateRamUsage(otherScripts: Script[]): Promise { - const res = await calculateRamUsage(this.code, otherScripts); + async updateRamUsage(player: IPlayer, otherScripts: Script[]): Promise { + const res = await calculateRamUsage(player, this.code, otherScripts); if (res > 0) { this.ramUsage = roundToTwo(res); } diff --git a/src/ScriptEditor/ui/ScriptEditorRoot.tsx b/src/ScriptEditor/ui/ScriptEditorRoot.tsx index 9feaab3f1..e5b7078a6 100644 --- a/src/ScriptEditor/ui/ScriptEditorRoot.tsx +++ b/src/ScriptEditor/ui/ScriptEditorRoot.tsx @@ -226,7 +226,7 @@ export function Root(props: IProps): React.ReactElement { } setUpdatingRam(true); const codeCopy = newCode + ""; - const ramUsage = await calculateRamUsage(codeCopy, props.player.getCurrentServer().scripts); + const ramUsage = await calculateRamUsage(props.player, codeCopy, props.player.getCurrentServer().scripts); if (ramUsage > 0) { debouncedSetRAM("RAM: " + numeralWrapper.formatRAM(ramUsage)); return; @@ -431,6 +431,7 @@ export function Root(props: IProps): React.ReactElement { for (let i = 0; i < server.scripts.length; i++) { if (scriptToSave.fileName == server.scripts[i].filename) { server.scripts[i].saveScript( + props.player, scriptToSave.fileName, scriptToSave.code, props.player.currentServer, @@ -444,7 +445,13 @@ export function Root(props: IProps): React.ReactElement { //If the current script does NOT exist, create a new one const script = new Script(); - script.saveScript(scriptToSave.fileName, scriptToSave.code, props.player.currentServer, server.scripts); + script.saveScript( + props.player, + scriptToSave.fileName, + scriptToSave.code, + props.player.currentServer, + server.scripts, + ); server.scripts.push(script); } else if (scriptToSave.fileName.endsWith(".txt")) { for (let i = 0; i < server.textFiles.length; ++i) { @@ -510,6 +517,7 @@ export function Root(props: IProps): React.ReactElement { for (let i = 0; i < server.scripts.length; i++) { if (currentScript.fileName == server.scripts[i].filename) { server.scripts[i].saveScript( + props.player, currentScript.fileName, currentScript.code, props.player.currentServer, @@ -522,7 +530,13 @@ export function Root(props: IProps): React.ReactElement { //If the current script does NOT exist, create a new one const script = new Script(); - script.saveScript(currentScript.fileName, currentScript.code, props.player.currentServer, server.scripts); + script.saveScript( + props.player, + currentScript.fileName, + currentScript.code, + props.player.currentServer, + server.scripts, + ); server.scripts.push(script); } else if (currentScript.fileName.endsWith(".txt")) { for (let i = 0; i < server.textFiles.length; ++i) { diff --git a/src/Server/BaseServer.ts b/src/Server/BaseServer.ts index 4c28581f4..d497e9091 100644 --- a/src/Server/BaseServer.ts +++ b/src/Server/BaseServer.ts @@ -255,7 +255,7 @@ export class BaseServer { * Write to a script file * Overwrites existing files. Creates new files if the script does not eixst */ - writeToScriptFile(fn: string, code: string): writeResult { + writeToScriptFile(player: IPlayer, fn: string, code: string): writeResult { const ret = { success: false, overwritten: false }; if (!isValidFilePath(fn) || !isScriptFilename(fn)) { return ret; @@ -266,7 +266,7 @@ export class BaseServer { if (fn === this.scripts[i].filename) { const script = this.scripts[i]; script.code = code; - script.updateRamUsage(this.scripts); + script.updateRamUsage(player, this.scripts); script.markUpdated(); ret.overwritten = true; ret.success = true; @@ -275,7 +275,7 @@ export class BaseServer { } // Otherwise, create a new script - const newScript = new Script(fn, code, this.hostname, this.scripts); + const newScript = new Script(player, fn, code, this.hostname, this.scripts); this.scripts.push(newScript); ret.success = true; return ret; diff --git a/src/Server/ServerHelpers.ts b/src/Server/ServerHelpers.ts index affb42a00..7e8459e9d 100644 --- a/src/Server/ServerHelpers.ts +++ b/src/Server/ServerHelpers.ts @@ -98,7 +98,7 @@ export function processSingleServerGrowth(server: Server, threads: number, p: IP return server.moneyAvailable / oldMoneyAvailable; } -export function prestigeHomeComputer(homeComp: Server): void { +export function prestigeHomeComputer(player: IPlayer, homeComp: Server): void { const hasBitflume = homeComp.programs.includes(Programs.BitFlume.name); homeComp.programs.length = 0; //Remove programs @@ -113,7 +113,7 @@ export function prestigeHomeComputer(homeComp: Server): void { //Update RAM usage on all scripts homeComp.scripts.forEach(function (script) { - script.updateRamUsage(homeComp.scripts); + script.updateRamUsage(player, homeComp.scripts); }); homeComp.messages.length = 0; //Remove .lit and .msg files diff --git a/src/SourceFile/SourceFiles.tsx b/src/SourceFile/SourceFiles.tsx index 517206c65..9fb8e94be 100644 --- a/src/SourceFile/SourceFiles.tsx +++ b/src/SourceFile/SourceFiles.tsx @@ -56,7 +56,7 @@ SourceFiles["SourceFile4"] = new SourceFile( ( <> This Source-File lets you access and use the Singularity Functions in every BitNode. Every level of this - Source-File opens up more of the Singularity Functions you can use. + Source-File reduces the RAM cost of Singularity functions. ), ); diff --git a/src/Terminal/commands/cp.ts b/src/Terminal/commands/cp.ts index 021e9c60d..e33f6a9fd 100644 --- a/src/Terminal/commands/cp.ts +++ b/src/Terminal/commands/cp.ts @@ -89,7 +89,7 @@ export function cp( return; } - const sRes = server.writeToScriptFile(dst, sourceScript.code); + const sRes = server.writeToScriptFile(player, dst, sourceScript.code); if (!sRes.success) { terminal.error(`cp failed`); return; diff --git a/src/Terminal/commands/runScript.ts b/src/Terminal/commands/runScript.ts index a6688ed4a..06eaf2245 100644 --- a/src/Terminal/commands/runScript.ts +++ b/src/Terminal/commands/runScript.ts @@ -76,7 +76,7 @@ export function runScript( const runningScript = new RunningScript(script, args); runningScript.threads = numThreads; - const success = startWorkerScript(runningScript, server); + const success = startWorkerScript(player, runningScript, server); if (!success) { terminal.error(`Failed to start script`); return; diff --git a/src/Terminal/commands/scp.ts b/src/Terminal/commands/scp.ts index d5def4d68..89d87e74e 100644 --- a/src/Terminal/commands/scp.ts +++ b/src/Terminal/commands/scp.ts @@ -94,7 +94,7 @@ export function scp( return; } - const sRes = destServer.writeToScriptFile(scriptname, sourceScript.code); + const sRes = destServer.writeToScriptFile(player, scriptname, sourceScript.code); if (!sRes.success) { terminal.error(`scp failed`); return; diff --git a/src/Terminal/commands/wget.ts b/src/Terminal/commands/wget.ts index 46502e2ca..72832c56e 100644 --- a/src/Terminal/commands/wget.ts +++ b/src/Terminal/commands/wget.ts @@ -26,7 +26,7 @@ export function wget( function (data: any) { let res; if (isScriptFilename(target)) { - res = server.writeToScriptFile(target, data); + res = server.writeToScriptFile(player, target, data); } else { res = server.writeToTextFile(target, data); } diff --git a/src/Terminal/determineAllPossibilitiesForTabCompletion.ts b/src/Terminal/determineAllPossibilitiesForTabCompletion.ts index 7e8cb07dd..e765f1757 100644 --- a/src/Terminal/determineAllPossibilitiesForTabCompletion.ts +++ b/src/Terminal/determineAllPossibilitiesForTabCompletion.ts @@ -296,7 +296,7 @@ export async function determineAllPossibilitiesForTabCompletion( const script = currServ.scripts.find((script) => script.filename === filename); if (!script) return; // Doesn't exist. if (!script.module) { - await compile(script, currServ.scripts); + await compile(p, script, currServ.scripts); } const loadedModule = await script.module; if (!loadedModule.autocomplete) return; // Doesn't have an autocomplete function. diff --git a/src/engine.tsx b/src/engine.tsx index 3d2545406..a741d9641 100644 --- a/src/engine.tsx +++ b/src/engine.tsx @@ -277,7 +277,7 @@ const Engine: { const offlineHackingIncome = (Player.moneySourceA.hacking / Player.playtimeSinceLastAug) * timeOffline * 0.75; Player.gainMoney(offlineHackingIncome, "hacking"); // Process offline progress - loadAllRunningScripts(); // This also takes care of offline production for those scripts + loadAllRunningScripts(Player); // This also takes care of offline production for those scripts if (Player.isWorking) { Player.focus = true; if (Player.workType == CONSTANTS.WorkTypeFaction) { diff --git a/src/ui/React/LogBoxManager.tsx b/src/ui/React/LogBoxManager.tsx index 806b5f399..135459a70 100644 --- a/src/ui/React/LogBoxManager.tsx +++ b/src/ui/React/LogBoxManager.tsx @@ -16,6 +16,7 @@ import { startWorkerScript } from "../../NetscriptWorker"; import { GetServer } from "../../Server/AllServers"; import { Theme } from "@mui/material"; import { findRunningScript } from "../../Script/ScriptHelpers"; +import { Player } from "../../Player"; let layerCounter = 0; @@ -79,12 +80,12 @@ const useStyles = makeStyles((theme: Theme) => createStyles({ title: { "&.is-minimized + *": { - border: "none", - margin: 0, - "max-height": 0, - padding: 0, - "pointer-events": "none", - visibility: "hidden" + border: "none", + margin: 0, + "max-height": 0, + padding: 0, + "pointer-events": "none", + visibility: "hidden", }, }, logs: { @@ -137,7 +138,7 @@ function LogWindow(props: IProps): React.ReactElement { if (server === null) return; const s = findRunningScript(script.filename, script.args, server); if (s === null) { - startWorkerScript(script, server); + startWorkerScript(Player, script, server); } else { setScript(s); } @@ -195,7 +196,7 @@ function LogWindow(props: IProps): React.ReactElement { >
'', { +jest.mock(`!!raw-loader!../NetscriptDefinitions.d.ts`, () => "", { virtual: true, }); @@ -56,24 +56,26 @@ describe("determineAllPossibilitiesForTabCompletion", function () { it("completes the buy command", async () => { const options = await determineAllPossibilitiesForTabCompletion(Player, "buy ", 0); - expect(options.sort()).toEqual([ - "BruteSSH.exe", - "FTPCrack.exe", - "relaySMTP.exe", - "HTTPWorm.exe", - "SQLInject.exe", - "DeepscanV1.exe", - "DeepscanV2.exe", - "AutoLink.exe", - "ServerProfiler.exe", - "Formulas.exe", - ].sort()); + expect(options.sort()).toEqual( + [ + "BruteSSH.exe", + "FTPCrack.exe", + "relaySMTP.exe", + "HTTPWorm.exe", + "SQLInject.exe", + "DeepscanV1.exe", + "DeepscanV2.exe", + "AutoLink.exe", + "ServerProfiler.exe", + "Formulas.exe", + ].sort(), + ); }); it("completes the scp command", async () => { Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark"); Player.getHomeComputer().messages.push("af.lit"); - Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark"); + Player.getHomeComputer().writeToScriptFile(Player, "/www/script.js", "oh hai mark"); const options1 = await determineAllPossibilitiesForTabCompletion(Player, "scp ", 0); expect(options1).toEqual(["/www/script.js", "af.lit", "note.txt", "www/"]); @@ -82,7 +84,7 @@ describe("determineAllPossibilitiesForTabCompletion", function () { }); it("completes the kill, tail, mem, and check commands", async () => { - Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark"); + Player.getHomeComputer().writeToScriptFile(Player, "/www/script.js", "oh hai mark"); for (const command of ["kill", "tail", "mem", "check"]) { const options = await determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0); expect(options).toEqual(["/www/script.js", "www/"]); @@ -90,43 +92,27 @@ describe("determineAllPossibilitiesForTabCompletion", function () { }); it("completes the nano commands", async () => { - Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark"); + Player.getHomeComputer().writeToScriptFile(Player, "/www/script.js", "oh hai mark"); Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark"); const options = await determineAllPossibilitiesForTabCompletion(Player, "nano ", 0); - expect(options).toEqual([ - "/www/script.js", - "note.txt", - "www/", - ]); + expect(options).toEqual(["/www/script.js", "note.txt", "www/"]); }); it("completes the rm command", async () => { Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark"); - Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark"); + Player.getHomeComputer().writeToScriptFile(Player, "/www/script.js", "oh hai mark"); Player.getHomeComputer().contracts.push(new CodingContract("linklist.cct")); Player.getHomeComputer().messages.push("asl.msg"); Player.getHomeComputer().messages.push("af.lit"); const options = await determineAllPossibilitiesForTabCompletion(Player, "rm ", 0); - expect(options).toEqual([ - "/www/script.js", - "NUKE.exe", - "af.lit", - "note.txt", - "linklist.cct", - "www/", - ]); + expect(options).toEqual(["/www/script.js", "NUKE.exe", "af.lit", "note.txt", "linklist.cct", "www/"]); }); it("completes the run command", async () => { - Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark"); + Player.getHomeComputer().writeToScriptFile(Player, "/www/script.js", "oh hai mark"); Player.getHomeComputer().contracts.push(new CodingContract("linklist.cct")); const options = await determineAllPossibilitiesForTabCompletion(Player, "run ", 0); - expect(options).toEqual([ - "/www/script.js", - "NUKE.exe", - "linklist.cct", - "www/", - ]); + expect(options).toEqual(["/www/script.js", "NUKE.exe", "linklist.cct", "www/"]); }); it("completes the cat command", async () => { @@ -134,36 +120,26 @@ describe("determineAllPossibilitiesForTabCompletion", function () { Player.getHomeComputer().messages.push("asl.msg"); Player.getHomeComputer().messages.push("af.lit"); const options = await determineAllPossibilitiesForTabCompletion(Player, "cat ", 0); - expect(options).toEqual([ - "asl.msg", - "af.lit", - "/www/note.txt", - "www/", - ]); + expect(options).toEqual(["asl.msg", "af.lit", "/www/note.txt", "www/"]); }); it("completes the download and mv commands", async () => { - Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark"); + Player.getHomeComputer().writeToScriptFile(Player, "/www/script.js", "oh hai mark"); Player.getHomeComputer().writeToTextFile("note.txt", "oh hai mark"); for (const command of ["download", "mv"]) { - const options = await determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0); - expect(options).toEqual([ - "/www/script.js", - "note.txt", - "www/", - ]); + expect(options).toEqual(["/www/script.js", "note.txt", "www/"]); } }); it("completes the cd command", async () => { - Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark"); + Player.getHomeComputer().writeToScriptFile(Player, "/www/script.js", "oh hai mark"); const options = await determineAllPossibilitiesForTabCompletion(Player, "cd ", 0); expect(options).toEqual(["www/"]); }); it("completes the ls and cd commands", async () => { - Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark"); + Player.getHomeComputer().writeToScriptFile(Player, "/www/script.js", "oh hai mark"); for (const command of ["ls", "cd"]) { const options = await determineAllPossibilitiesForTabCompletion(Player, `${command} `, 0); expect(options).toEqual(["www/"]); @@ -171,12 +147,8 @@ describe("determineAllPossibilitiesForTabCompletion", function () { }); it("completes commands starting with ./", async () => { - Player.getHomeComputer().writeToScriptFile("/www/script.js", "oh hai mark"); + Player.getHomeComputer().writeToScriptFile(Player, "/www/script.js", "oh hai mark"); const options = await determineAllPossibilitiesForTabCompletion(Player, "run ./", 0); - expect(options).toEqual([ - ".//www/script.js", - "NUKE.exe", - "./www/", - ]); + expect(options).toEqual([".//www/script.js", "NUKE.exe", "./www/"]); }); });