diff --git a/doc/source/netscriptfunctions.rst b/doc/source/netscriptfunctions.rst index 6515412b4..ce42f59c6 100644 --- a/doc/source/netscriptfunctions.rst +++ b/doc/source/netscriptfunctions.rst @@ -422,7 +422,7 @@ getHackingMultipliers .. js:function:: getHackingMultipliers() Returns an object containing the Player's hacking related multipliers. These multipliers are - returned in integer forms, not percentages (e.g. 1.5 instead of 150%). The object has the following structure:: + returned in fractional forms, not percentages (e.g. 1.5 instead of 150%). The object has the following structure:: { chance: Player's hacking chance multiplier, @@ -437,6 +437,30 @@ getHackingMultipliers print(mults.chance); print(mults.growth); +getHacknetMultipliers +^^^^^^^^^^^^^^^^^^^^^ + +.. js:function:: getHacknetMultipliers() + + Returns an object containing the Player's hacknet related multipliers. These multipliers are + returned in fractional forms, not percentages (e.g. 1.5 instead of 150%). The object has the following structure:: + + { + production: Player's hacknet production multiplier, + purchaseCost: Player's hacknet purchase cost multiplier, + ramCost: Player's hacknet ram cost multiplier, + coreCost: Player's hacknet core cost multiplier, + levelCost: Player's hacknet level cost multiplier + } + + Example of how this can be used:: + + mults = getHacknetMultipliers(); + print(mults.production); + print(mults.purchaseCost); + + + getServerMoneyAvailable ^^^^^^^^^^^^^^^^^^^^^^^ @@ -789,10 +813,10 @@ getScriptName getScriptRam ^^^^^^^^^^^^ -.. js:function:: getScriptRam(scriptname, hostname/ip) +.. js:function:: getScriptRam(scriptname[, hostname/ip]) :param string scriptname: Filename of script. This is case-sensitive. - :param string hostname/ip: Hostname or IP of target server + :param string hostname/ip: Hostname or IP of target server the script is located on. This is optional, If it is not specified then the function will se the current server as the target server. Returns the amount of RAM required to run the specified script on the target server diff --git a/doc/source/netscripthacknetnodeapi.rst b/doc/source/netscripthacknetnodeapi.rst index 74b4c93f0..34ac33cf8 100644 --- a/doc/source/netscripthacknetnodeapi.rst +++ b/doc/source/netscripthacknetnodeapi.rst @@ -111,6 +111,29 @@ array itself. Returns the cost of upgrading the number of cores of the specified Hacknet Node. Upgrading a Node's number of cores adds one additional core. +Utils +^^^^^ + +.. js:function:: getHacknetMultipliers() + + Returns an object containing the Player's hacknet related multipliers. These multipliers are + returned in integer forms, not percentages (e.g. 1.5 instead of 150%). The object has the following structure:: + + { + production: Player's hacknet production multiplier, + purchaseCost: Player's hacknet purchase cost multiplier, + ramCost: Player's hacknet ram cost multiplier, + coreCost: Player's hacknet core cost multiplier, + levelCost: Player's hacknet level cost multiplier + } + + Example of how this can be used:: + + mults = getHacknetMultipliers(); + print(mults.production); + print(mults.purchaseCost); + + Example(s) ^^^^^^^^^^ diff --git a/src/NetscriptFunctions.js b/src/NetscriptFunctions.js index 69d73f72f..67f686bac 100644 --- a/src/NetscriptFunctions.js +++ b/src/NetscriptFunctions.js @@ -1036,6 +1036,23 @@ function NetscriptFunctions(workerScript) { growth: Player.hacking_grow_mult, }; }, + getHacknetMultipliers : function() { + if (workerScript.checkingRam) { + if (workerScript.loadedFns.getHacknetMultipliers) { + return 0; + } else { + workerScript.loadedFns.getHacknetMultipliers = true; + return CONSTANTS.ScriptGetMultipliersRamCost; + } + } + return { + production: Player.hacknet_node_money_mult, + purchaseCost: Player.hacknet_node_purchase_cost_mult, + ramCost: Player.hacknet_node_ram_cost_mult, + coreCost: Player.hacknet_node_core_cost_mult, + levelCost: Player.hacknet_node_level_cost_mult, + }; + }, getBitNodeMultipliers: function() { if (workerScript.checkingRam) { if (workerScript.loadedFns.getBitNodeMultipliers) { @@ -2006,7 +2023,7 @@ function NetscriptFunctions(workerScript) { if (workerScript.checkingRam) {return 0;} return workerScript.name; }, - getScriptRam : function (scriptname, ip) { + getScriptRam : function (scriptname, ip=workerScript.serverIp) if (workerScript.checkingRam) { if (workerScript.loadedFns.getScriptRam) { return 0; diff --git a/src/NetscriptWorker.js b/src/NetscriptWorker.js index e024d729c..0fc043d26 100644 --- a/src/NetscriptWorker.js +++ b/src/NetscriptWorker.js @@ -73,6 +73,15 @@ function startJsScript(workerScript) { // This function unfortunately cannot be an async function, because we don't // know if the original one was, and there's no way to tell. return function (...args) { + // Wrap every netscript function with a check for the stop flag. + // This prevents cases where we never stop because we are only calling + // netscript functions that don't check this. + // This is not a problem for legacy Netscript because it also checks the + // stop flag in the evaluator. + if (workerScript.env.stopFlag) {throw workerScript;} + + if (propName === "sleep") return f(...args); // OK for multiple simultaneous calls to sleep. + const msg = "Concurrent calls to Netscript functions not allowed! " + "Did you forget to await hack(), grow(), or some other " + "promise-returning function? (Currently running: %s tried to run: %s)" @@ -92,9 +101,9 @@ function startJsScript(workerScript) { } } }; + for (let prop in workerScript.env.vars) { if (typeof workerScript.env.vars[prop] !== "function") continue; - if (prop === "sleep") continue; // OK for multiple simultaneous calls to sleep. workerScript.env.vars[prop] = wrap(prop, workerScript.env.vars[prop]); } diff --git a/src/Player.js b/src/Player.js index 2fa3aa1b7..23d227ed7 100644 --- a/src/Player.js +++ b/src/Player.js @@ -1283,7 +1283,7 @@ PlayerObject.prototype.finishCreateProgramWork = function(cancelled, sing=false) this.getHomeComputer().programs.push(programName); } else { - var perc = Math.floor(this.timeWorkedCreateProgram / this.timeNeededToCompleteWork * 100).toString(); + var perc = (Math.floor(this.timeWorkedCreateProgram / this.timeNeededToCompleteWork * 10000)/100).toString(); var incompleteName = programName + "-" + perc + "%-INC"; this.getHomeComputer().programs.push(incompleteName); }