mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2025-03-08 11:29:19 +01:00
Adjusted RAM costs for Singularity functions and document/window. Fixed bug with calling print() in NetscriptJS
This commit is contained in:
@ -48,7 +48,7 @@ let CONSTANTS = {
|
||||
/* Netscript Constants */
|
||||
//RAM Costs for different commands
|
||||
ScriptBaseRamCost: 1.6,
|
||||
ScriptDomRamCost: 100,
|
||||
ScriptDomRamCost: 25,
|
||||
ScriptWhileRamCost: 0,
|
||||
ScriptForRamCost: 0,
|
||||
ScriptIfRamCost: 0,
|
||||
@ -91,6 +91,8 @@ let CONSTANTS = {
|
||||
ScriptSingularityFn2RamCost: 2,
|
||||
ScriptSingularityFn3RamCost: 3,
|
||||
|
||||
ScriptSingularityFnRamMult: 2, // Multiplier for RAM cost outside of BN-4
|
||||
|
||||
ScriptBladeburnerApiBaseRamCost: 4,
|
||||
|
||||
NumNetscriptPorts: 20,
|
||||
@ -507,8 +509,12 @@ let CONSTANTS = {
|
||||
LatestUpdate:
|
||||
`
|
||||
v0.41.0
|
||||
* WARNING: In NetscriptJS, defining a function called print() is no longer possible
|
||||
* RAM Cost of accessing the global document object lowered from 100 GB to 25 GB
|
||||
* RAM Cost to use Singularity Functions outside of BitNode-4 lowered by 75%. They now only cost twice as much as they do in BitNode-4
|
||||
* b1t_flum3.exe now takes significantly less time to create
|
||||
* Improved number formatting for Player 'work' actions (including crimes, etc.). These numbers should also adhere to locale settings now (by Kline-)
|
||||
* Bug Fix: Calling print() in NetscriptJS no longer brings up the print dialog
|
||||
* Bug Fix: Fixed a bug that sometimes caused a blank black screen when destroying/resetting/switching BitNodes
|
||||
* Bug Fix: Netscript calls that throw errors will now no longer cause the 'concurrent calls' error if they are caught in the script. i.e. try/catch should now work properly in scripts
|
||||
* Bug Fix: Fixed a bug where sometimes the NeuroFlux Governor Augmentation level would be incorrectly calculated when the game was loaded
|
||||
|
@ -2313,7 +2313,7 @@ function NetscriptFunctions(workerScript) {
|
||||
/* Singularity Functions */
|
||||
universityCourse : function(universityName, className) {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn1RamCost;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("universityCourse", ramCost);
|
||||
}
|
||||
@ -2402,7 +2402,7 @@ function NetscriptFunctions(workerScript) {
|
||||
|
||||
gymWorkout : function(gymName, stat) {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn1RamCost;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("gymWorkout", ramCost);
|
||||
}
|
||||
@ -2504,7 +2504,7 @@ function NetscriptFunctions(workerScript) {
|
||||
|
||||
travelToCity(cityname) {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn1RamCost;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("travelToCity", ramCost);
|
||||
}
|
||||
@ -2541,7 +2541,7 @@ function NetscriptFunctions(workerScript) {
|
||||
|
||||
purchaseTor() {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn1RamCost;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("purchaseTor", ramCost);
|
||||
}
|
||||
@ -2585,7 +2585,7 @@ function NetscriptFunctions(workerScript) {
|
||||
},
|
||||
purchaseProgram(programName) {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn1RamCost;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("purchaseProgram", ramCost);
|
||||
}
|
||||
@ -2637,7 +2637,7 @@ function NetscriptFunctions(workerScript) {
|
||||
},
|
||||
getStats : function() {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn1RamCost / 4;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("getStats", ramCost);
|
||||
}
|
||||
@ -2661,7 +2661,7 @@ function NetscriptFunctions(workerScript) {
|
||||
},
|
||||
getCharacterInformation : function() {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn1RamCost / 4;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("getCharacterInformation", ramCost);
|
||||
}
|
||||
@ -2697,7 +2697,7 @@ function NetscriptFunctions(workerScript) {
|
||||
},
|
||||
isBusy : function() {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn1RamCost / 4;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("isBusy", ramCost);
|
||||
}
|
||||
@ -2712,7 +2712,7 @@ function NetscriptFunctions(workerScript) {
|
||||
},
|
||||
stopAction : function() {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn1RamCost / 2;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("stopAction", ramCost);
|
||||
}
|
||||
@ -2734,7 +2734,7 @@ function NetscriptFunctions(workerScript) {
|
||||
},
|
||||
upgradeHomeRam : function() {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn2RamCost;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("upgradeHomeRam", ramCost);
|
||||
}
|
||||
@ -2766,7 +2766,7 @@ function NetscriptFunctions(workerScript) {
|
||||
},
|
||||
getUpgradeHomeRamCost : function() {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn2RamCost / 2;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("getUpgradeHomeRamCost", ramCost);
|
||||
}
|
||||
@ -2782,7 +2782,7 @@ function NetscriptFunctions(workerScript) {
|
||||
},
|
||||
workForCompany : function() {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn2RamCost;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("workForCompany", ramCost);
|
||||
}
|
||||
@ -2823,7 +2823,7 @@ function NetscriptFunctions(workerScript) {
|
||||
},
|
||||
applyToCompany : function(companyName, field) {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn2RamCost;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("applyToCompany", ramCost);
|
||||
}
|
||||
@ -2904,7 +2904,7 @@ function NetscriptFunctions(workerScript) {
|
||||
},
|
||||
getCompanyRep : function(companyName) {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn2RamCost / 2;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("getCompanyRep", ramCost);
|
||||
}
|
||||
@ -2925,7 +2925,7 @@ function NetscriptFunctions(workerScript) {
|
||||
},
|
||||
getCompanyFavor : function(companyName) {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn2RamCost / 4;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("getCompanyFavor", ramCost);
|
||||
}
|
||||
@ -2946,7 +2946,7 @@ function NetscriptFunctions(workerScript) {
|
||||
},
|
||||
getCompanyFavorGain : function(companyName) {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn2RamCost / 4;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("getCompanyFavorGain", ramCost);
|
||||
}
|
||||
@ -2967,7 +2967,7 @@ function NetscriptFunctions(workerScript) {
|
||||
},
|
||||
checkFactionInvitations : function() {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn2RamCost;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("checkFactionInvitations", ramCost);
|
||||
}
|
||||
@ -2983,7 +2983,7 @@ function NetscriptFunctions(workerScript) {
|
||||
},
|
||||
joinFaction : function(name) {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn2RamCost;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("joinFaction", ramCost);
|
||||
}
|
||||
@ -3022,7 +3022,7 @@ function NetscriptFunctions(workerScript) {
|
||||
},
|
||||
workForFaction : function(name, type) {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn2RamCost;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("workForFaction", ramCost);
|
||||
}
|
||||
@ -3122,7 +3122,7 @@ function NetscriptFunctions(workerScript) {
|
||||
},
|
||||
getFactionRep : function(name) {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn2RamCost / 4;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("getFactionRep", ramCost);
|
||||
}
|
||||
@ -3143,7 +3143,7 @@ function NetscriptFunctions(workerScript) {
|
||||
},
|
||||
getFactionFavor : function(name) {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn2RamCost;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("getFactionFavor", ramCost);
|
||||
}
|
||||
@ -3164,7 +3164,7 @@ function NetscriptFunctions(workerScript) {
|
||||
},
|
||||
getFactionFavorGain: function(name) {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn2RamCost;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("getFactionFavorGain", ramCost);
|
||||
}
|
||||
@ -3185,7 +3185,7 @@ function NetscriptFunctions(workerScript) {
|
||||
},
|
||||
donateToFaction : function(name, amt) {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn3RamCost;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("donateToFaction", ramCost);
|
||||
}
|
||||
@ -3224,7 +3224,7 @@ function NetscriptFunctions(workerScript) {
|
||||
},
|
||||
createProgram : function(name) {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn3RamCost;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("createProgram", ramCost);
|
||||
}
|
||||
@ -3278,7 +3278,7 @@ function NetscriptFunctions(workerScript) {
|
||||
},
|
||||
commitCrime : function(crimeRoughName) {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn3RamCost;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("commitCrime", ramCost);
|
||||
}
|
||||
@ -3335,7 +3335,7 @@ function NetscriptFunctions(workerScript) {
|
||||
},
|
||||
getCrimeChance : function(crimeRoughName) {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn3RamCost;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("getCrimeChance", ramCost);
|
||||
}
|
||||
@ -3356,7 +3356,7 @@ function NetscriptFunctions(workerScript) {
|
||||
},
|
||||
getOwnedAugmentations : function(purchased=false) {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn3RamCost;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("getOwnedAugmentations", ramCost);
|
||||
}
|
||||
@ -3380,7 +3380,7 @@ function NetscriptFunctions(workerScript) {
|
||||
},
|
||||
getOwnedSourceFiles : function() {
|
||||
let ramCost = CONSTANTS.ScriptSingularityFn3RamCost;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("getOwnedSourceFiles", ramCost);
|
||||
}
|
||||
@ -3399,7 +3399,7 @@ function NetscriptFunctions(workerScript) {
|
||||
},
|
||||
getAugmentationsFromFaction : function(facname) {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn3RamCost;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("getAugmentationsFromFaction", ramCost);
|
||||
}
|
||||
@ -3425,7 +3425,7 @@ function NetscriptFunctions(workerScript) {
|
||||
},
|
||||
getAugmentationCost : function(name) {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn3RamCost;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("getAugmentationCost", ramCost);
|
||||
}
|
||||
@ -3447,7 +3447,7 @@ function NetscriptFunctions(workerScript) {
|
||||
},
|
||||
purchaseAugmentation : function(faction, name) {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn3RamCost;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("purchaseAugmentation", ramCost);
|
||||
}
|
||||
@ -3512,7 +3512,7 @@ function NetscriptFunctions(workerScript) {
|
||||
},
|
||||
installAugmentations : function(cbScript) {
|
||||
var ramCost = CONSTANTS.ScriptSingularityFn3RamCost;
|
||||
if (Player.bitNodeN !== 4) {ramCost *= 8;}
|
||||
if (Player.bitNodeN !== 4) {ramCost *= CONSTANTS.ScriptSingularityFnRamMult;}
|
||||
if (workerScript.checkingRam) {
|
||||
return updateStaticRam("installAugmentations", ramCost);
|
||||
}
|
||||
|
@ -31,8 +31,6 @@ export async function executeJSScript(scripts = [], workerScript) {
|
||||
loadedModule = script.module;
|
||||
|
||||
let ns = workerScript.env.vars;
|
||||
//ns.threads = workerScript.threads;
|
||||
//ns.args = workerScript.args;
|
||||
|
||||
try {
|
||||
// TODO: putting await in a non-async function yields unhelpful
|
||||
@ -75,7 +73,7 @@ export function _getScriptUrls(script, scripts, seen) {
|
||||
// import {foo} from "blob://<uuid>"
|
||||
//
|
||||
// Where the blob URL contains the script content.
|
||||
const transformedCode = script.code.replace(/((?:from|import)\s+(?:'|"))([^'"]+)('|";)/g,
|
||||
let transformedCode = script.code.replace(/((?:from|import)\s+(?:'|"))([^'"]+)('|";)/g,
|
||||
(unmodified, prefix, filename, suffix) => {
|
||||
const isAllowedImport = scripts.some(s => s.filename == filename);
|
||||
if (!isAllowedImport) return unmodified;
|
||||
@ -92,6 +90,9 @@ export function _getScriptUrls(script, scripts, seen) {
|
||||
}
|
||||
);
|
||||
|
||||
// We automatically define a print function() in the NetscriptJS module so that
|
||||
// accidental calls to window.print() do not bring up the "print screen" dialog
|
||||
transformedCode += `\n\nfunction print() {throw new Error("Invalid call to window.print(). Did you mean to use Netscript's print()?");}`
|
||||
|
||||
// If we successfully transformed the code, create a blob url for it and
|
||||
// push that URL onto the top of the stack.
|
||||
|
@ -14,7 +14,6 @@ import {NetscriptPort} from "./NetscriptPort";
|
||||
import {AllServers} from "./Server";
|
||||
import {Settings} from "./Settings";
|
||||
|
||||
//TODO Maybe escodegen might be better?
|
||||
import {generate} from 'escodegen';
|
||||
|
||||
import {parse, Node} from "../utils/acorn";
|
||||
|
Reference in New Issue
Block a user