mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-19 04:35:46 +01:00
Added several configurable game settings. Added donate button. Added Hacknet Node API functions for getting cost of upgrades
This commit is contained in:
parent
be48875ff3
commit
2afb313a53
@ -127,7 +127,7 @@
|
||||
}
|
||||
|
||||
/* Infiltration-box */
|
||||
#infiltration-box-sell,
|
||||
#infiltration-box-sell,
|
||||
#infiltration-box-faction {
|
||||
display: block;
|
||||
padding: 8px;
|
||||
@ -141,17 +141,23 @@
|
||||
|
||||
#game-options-content {
|
||||
background-color: var(--my-background-color);
|
||||
margin: 15% auto; /* 15% from the top and centered */
|
||||
margin: 15% auto;
|
||||
padding: 10px;
|
||||
border: 5px solid var(--my-highlight-color);
|
||||
width: 50%; /* Could be more or less, depending on screen size */
|
||||
width: 60%;
|
||||
color: var(--my-font-color);
|
||||
}
|
||||
|
||||
#game-options-left-panel,
|
||||
#game-options-right-panel {
|
||||
display: inline-block;
|
||||
width: 49%;
|
||||
}
|
||||
|
||||
#game-options-close-button {
|
||||
color: #aaa;
|
||||
float: right;
|
||||
margin: 4px;
|
||||
margin: 4px;
|
||||
padding: 4px;
|
||||
font-size: 20px;
|
||||
font-weight: bold;
|
||||
@ -170,7 +176,11 @@
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#game-options-left-panel fieldset {
|
||||
padding:2px;
|
||||
margin:2px;
|
||||
}
|
||||
|
||||
#import-game-file-selector {
|
||||
display:none;
|
||||
}
|
||||
|
||||
|
114
index.html
114
index.html
@ -66,6 +66,7 @@
|
||||
<script src="src/StockMarket.js"></script>
|
||||
<script src="src/RedPill.js"></script>
|
||||
<script src="src/BitNode.js"></script>
|
||||
<script src="src/Settings.js"></script>
|
||||
|
||||
<script src="src/engine.js"></script>
|
||||
|
||||
@ -898,36 +899,93 @@
|
||||
<span id="game-options-close-button">×</span>
|
||||
<h1> Game Options </h1>
|
||||
<br>
|
||||
<a class="a-link-button" style="display:block;" href="https://bitburner.wikia.com/wiki/Changelog" target="_blank"> Changelog </a>
|
||||
<a class="a-link-button" style="display:block;" href="https://bitburner.wikia.com" target="_blank">Wiki</a>
|
||||
<a class="a-link-button" style="display:block;", href="https://www.reddit.com/r/bitburner" target="_blank">Subreddit</a>
|
||||
<div id="game-options-left-panel">
|
||||
<!-- Netscript execution time -->
|
||||
<fieldset>
|
||||
<label for="settingsNSExecTimeRangeVal" class="tooltip">Netscript exec time:
|
||||
<span class="tooltiptext">
|
||||
The minimum number of milliseconds it takes to execute an operation in Netscript.
|
||||
Setting this too low can result in poor performance if you have many scripts running.
|
||||
The default value is 100ms.
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
|
||||
<input type="hidden" name="cmd" value="_s-xclick">
|
||||
<input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----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-----END PKCS7-----
|
||||
">
|
||||
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
|
||||
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
|
||||
</form>
|
||||
<input type ="range" max="200" min="25"
|
||||
oninput="document.getElementById('settingsNSExecTimeRangeValLabel').innerHTML = this.value + 'ms';
|
||||
Settings.CodeInstructionRunTime=this.value;"
|
||||
step="1" name="settingsNSExecTimeRangeVal" id="settingsNSExecTimeRangeVal" value="100">
|
||||
</input>
|
||||
<em id="settingsNSExecTimeRangeValLabel" style="font-style: normal;"></em>
|
||||
</fieldset>
|
||||
|
||||
<a id="save-game-link" class="a-link-button" style="display:inline-block;width:46%;"> Save Game </a>
|
||||
<a id="delete-game-link" class="a-link-button" style="display:inline-block;width:46%;"> Delete Game </a>
|
||||
<a id="export-game-link" class="a-link-button" style="display:inline-block;width:46%;"> Export Game </a>
|
||||
<input type="file" id="import-game-file-selector" name="file"/>
|
||||
<a id="import-game-link" class="a-link-button" style="display:inline-block;width:46%;" onclick="saveObject.importGame();"> Import Game </a>
|
||||
<a id="debug-delete-scripts-link" class="a-link-button tooltip" style="display:block;">
|
||||
(DEBUG) Delete Active Scripts
|
||||
<span class="tooltiptext">
|
||||
Debug option used to forcefully kill all active running scripts, in case there is a bug or some unexpected issue with the game. After
|
||||
using this, save the game and then reload the page.
|
||||
</span>
|
||||
</a>
|
||||
<a id="debug-soft-reset" class="a-link-button tooltip" style="display:block;">
|
||||
(DEBUG) Soft Reset
|
||||
<span class="tooltiptext">
|
||||
Perform a soft reset. Resets everything as if you had just purchased an Augmentation
|
||||
</span>
|
||||
</a>
|
||||
<!-- Log capacity -->
|
||||
<fieldset>
|
||||
<label for="settingsNSLogRangeVal" class="tooltip">Netscript log size:
|
||||
<span class="tooltiptext">
|
||||
The maximum number of lines a script's logs can hold. Setting this too high
|
||||
can cause the game to use a lot of memory if you have many scripts running.
|
||||
The default value is 50.
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<input type ="range" max="100" min="20"
|
||||
oninput="document.getElementById('settingsNSLogRangeValLabel').innerHTML = this.value;
|
||||
Settings.MaxLogCapacity=this.value;"
|
||||
step="1" name="settingsNSLogRangeVal" id="settingsNSLogRangeVal" value="50">
|
||||
</input>
|
||||
<em id="settingsNSLogRangeValLabel" style="font-style: normal;"></em>
|
||||
</fieldset>
|
||||
|
||||
<!-- Port capacity -->
|
||||
<fieldset>
|
||||
<label for="settingsNSPortRangeVal" class="tooltip">Netscript port size:
|
||||
<span class="tooltiptext">
|
||||
The maximum number of entries that can be written to a port using Netscript's
|
||||
write() function. Setting this too high can cause the game to use a lot of memory.
|
||||
The default value is 50.
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<input type ="range" max="100" min="20"
|
||||
oninput="document.getElementById('settingsNSPortRangeValLabel').innerHTML = this.value;
|
||||
Settings.MaxPortCapacity=this.value;"
|
||||
step="1" name="settingsNSPortRangeVal" id="settingsNSPortRangeVal" value="50">
|
||||
</input>
|
||||
<em id="settingsNSPortRangeValLabel" style="font-style: normal;"></em>
|
||||
</fieldset>
|
||||
|
||||
<!-- Donate button -->
|
||||
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
|
||||
<input type="hidden" name="cmd" value="_s-xclick">
|
||||
<input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----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-----END PKCS7-----
|
||||
">
|
||||
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
|
||||
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
|
||||
</form>
|
||||
</div>
|
||||
<div id="game-options-right-panel">
|
||||
<a class="a-link-button" style="display:block;" href="https://bitburner.wikia.com/wiki/Changelog" target="_blank"> Changelog </a>
|
||||
<a class="a-link-button" style="display:block;" href="https://bitburner.wikia.com" target="_blank">Wiki</a>
|
||||
<a class="a-link-button" style="display:block;", href="https://www.reddit.com/r/bitburner" target="_blank">Subreddit</a>
|
||||
<a id="save-game-link" class="a-link-button" style="display:inline-block;width:46%;"> Save Game </a>
|
||||
<a id="delete-game-link" class="a-link-button" style="display:inline-block;width:46%;"> Delete Game </a>
|
||||
<a id="export-game-link" class="a-link-button" style="display:inline-block;width:46%;"> Export Game </a>
|
||||
<input type="file" id="import-game-file-selector" name="file"/>
|
||||
<a id="import-game-link" class="a-link-button" style="display:inline-block;width:46%;" onclick="saveObject.importGame();"> Import Game </a>
|
||||
<a id="debug-delete-scripts-link" class="a-link-button tooltip" style="display:block;width:46%;">
|
||||
(DEBUG) Delete Active Scripts
|
||||
<span class="tooltiptext">
|
||||
Debug option used to forcefully kill all active running scripts, in case there is a bug or some unexpected issue with the game. After
|
||||
using this, save the game and then reload the page.
|
||||
</span>
|
||||
</a>
|
||||
<a id="debug-soft-reset" class="a-link-button tooltip" style="display:block;width:46%;">
|
||||
(DEBUG) Soft Reset
|
||||
<span class="tooltiptext">
|
||||
Perform a soft reset. Resets everything as if you had just purchased an Augmentation
|
||||
</span>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,5 +1,5 @@
|
||||
CONSTANTS = {
|
||||
Version: "0.26.0",
|
||||
Version: "0.26.1",
|
||||
|
||||
//Max level for any skill, assuming no multipliers. Determined by max numerical value in javascript for experience
|
||||
//and the skill level formula in Player.js. Note that all this means it that when experience hits MAX_INT, then
|
||||
@ -680,8 +680,9 @@ CONSTANTS = {
|
||||
LatestUpdate:
|
||||
"V0.26.1<br>" +
|
||||
"-Added autocompletion for aliases<br>" +
|
||||
"Added getServerRam() Netscript function()<br>" +
|
||||
"Added getLevelUpgradeCost(n), getRamUpgradeCost(), getCoreUpgradeCost() functions for Netscript Hacknet Node API<br>" +
|
||||
"-Added getServerRam() Netscript function()<br>" +
|
||||
"-Added getLevelUpgradeCost(n), getRamUpgradeCost(), getCoreUpgradeCost() functions for Netscript Hacknet Node API<br>" +
|
||||
"-Added some configurable settings (See Game Options menu)<br><br>" +
|
||||
"v0.26.0<br>" +
|
||||
"-Game now has a real ending, although it's not very interesting/satisfying right now. It sets up the framework for the secondary prestige system " +
|
||||
"in the future<br>" +
|
||||
|
@ -205,8 +205,8 @@ function evaluate(exp, workerScript) {
|
||||
reject(makeRuntimeRejectMsg(workerScript, "Unrecognized token: " + exp.type + ". This is a bug please report to game developer"));
|
||||
break;
|
||||
} //End switch
|
||||
}, CONSTANTS.CodeInstructionRunTime); //End setTimeout, the Netscript operation run time
|
||||
|
||||
}, Settings.CodeInstructionRunTime); //End setTimeout, the Netscript operation run time
|
||||
|
||||
}); // End Promise
|
||||
}
|
||||
|
||||
@ -356,7 +356,7 @@ function evalAssignment(exp, workerScript) {
|
||||
if (exp.operator !== "=" && !(exp.left.name in env.vars)){
|
||||
return reject(makeRuntimeRejectMsg(workerScript, "variable " + exp.left.name + " not definied"));
|
||||
}
|
||||
|
||||
|
||||
var expRightPromise = evaluate(exp.right, workerScript);
|
||||
expRightPromise.then(function(expRight) {
|
||||
if (exp.left.type == "MemberExpression") {
|
||||
@ -452,7 +452,7 @@ function evaluateFor(exp, workerScript) {
|
||||
var env = workerScript.env;
|
||||
return new Promise(function(resolve, reject) {
|
||||
if (env.stopFlag) {reject(workerScript); return;}
|
||||
|
||||
|
||||
var pCond = evaluate(exp.test, workerScript);
|
||||
pCond.then(function(resCond) {
|
||||
if (resCond) {
|
||||
@ -485,21 +485,21 @@ function evaluateFor(exp, workerScript) {
|
||||
|
||||
function evaluateWhile(exp, workerScript) {
|
||||
var env = workerScript.env;
|
||||
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
if (env.stopFlag) {reject(workerScript); return;}
|
||||
|
||||
|
||||
var pCond = new Promise(function(resolve, reject) {
|
||||
setTimeout(function() {
|
||||
var evaluatePromise = evaluate(exp.test, workerScript);
|
||||
evaluatePromise.then(function(resCond) {
|
||||
resolve(resCond);
|
||||
}, function(e) {
|
||||
reject(e);
|
||||
reject(e);
|
||||
});
|
||||
}, CONSTANTS.CodeInstructionRunTime);
|
||||
});
|
||||
|
||||
|
||||
pCond.then(function(resCond) {
|
||||
if (resCond) {
|
||||
//Run the while loop code
|
||||
@ -513,7 +513,7 @@ function evaluateWhile(exp, workerScript) {
|
||||
});
|
||||
}, CONSTANTS.CodeInstructionRunTime);
|
||||
});
|
||||
|
||||
|
||||
//After the code executes make a recursive call
|
||||
pCode.then(function(resCode) {
|
||||
var recursiveCall = evaluateWhile(exp, workerScript);
|
||||
@ -545,13 +545,13 @@ function evaluateHacknetNode(exp, workerScript) {
|
||||
(exp.op.type == "var" && exp.op.value == "length")) {
|
||||
resolve(Player.hacknetNodes.length);
|
||||
workerScript.scriptRef.log("hacknetnodes.length returned " + Player.hacknetNodes.length);
|
||||
return;
|
||||
return;
|
||||
} else {
|
||||
workerScript.scriptRef.log("Invalid/null index for hacknetnodes");
|
||||
reject(makeRuntimeRejectMsg(workerScript, "Invalid/null index. hacknetnodes array must be accessed with an index"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
var indexPromise = evaluate(exp.index.value, workerScript);
|
||||
indexPromise.then(function(index) {
|
||||
@ -576,11 +576,11 @@ function evaluateHacknetNode(exp, workerScript) {
|
||||
case "cores":
|
||||
resolve(nodeObj.numCores);
|
||||
break;
|
||||
default:
|
||||
default:
|
||||
reject(makeRuntimeRejectMsg(workerScript, "Unrecognized property for Hacknet Node. Valid properties: ram, cores, level"));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
} else if (exp.op.type == "call") {
|
||||
switch(exp.op.func.value) {
|
||||
case "upgradeLevel":
|
||||
@ -633,7 +633,7 @@ function evaluateHacknetNode(exp, workerScript) {
|
||||
}, function(e) {
|
||||
reject(e);
|
||||
});
|
||||
|
||||
|
||||
}, CONSTANTS.CodeInstructionRunTime);
|
||||
}, function(e) {
|
||||
reject(e);
|
||||
@ -643,10 +643,10 @@ function evaluateHacknetNode(exp, workerScript) {
|
||||
|
||||
function evaluateProg(exp, workerScript, index) {
|
||||
var env = workerScript.env;
|
||||
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
if (env.stopFlag) {reject(workerScript); return;}
|
||||
|
||||
|
||||
if (index >= exp.body.length) {
|
||||
resolve("progFinished");
|
||||
} else {
|
||||
@ -661,7 +661,7 @@ function evaluateProg(exp, workerScript, index) {
|
||||
});
|
||||
}, CONSTANTS.CodeInstructionRunTime);
|
||||
});
|
||||
|
||||
|
||||
//After the code finishes evaluating, evaluate the next line recursively
|
||||
code.then(function(codeRes) {
|
||||
var nextLine = evaluateProg(exp, workerScript, index + 1);
|
||||
@ -678,7 +678,7 @@ function evaluateProg(exp, workerScript, index) {
|
||||
}
|
||||
|
||||
function netscriptDelay(time) {
|
||||
return new Promise(function(resolve) {
|
||||
return new Promise(function(resolve) {
|
||||
setTimeout(resolve, time);
|
||||
});
|
||||
}
|
||||
@ -786,7 +786,7 @@ function scriptCalculateHackingTime(server) {
|
||||
return hackingTime;
|
||||
}
|
||||
|
||||
//The same as Player's calculateExpGain() function but takes in the server as an argument
|
||||
//The same as Player's calculateExpGain() function but takes in the server as an argument
|
||||
function scriptCalculateExpGain(server) {
|
||||
if (server.baseDifficulty == null) {
|
||||
server.baseDifficulty = server.hackDifficulty;
|
||||
@ -818,4 +818,4 @@ function scriptCalculateWeakenTime(server) {
|
||||
var skillFactor = (2.5 * difficultyMult + 500) / (Player.hacking_skill + 50);
|
||||
var weakenTime = 20 * skillFactor / Player.hacking_speed_mult; //This is in seconds
|
||||
return weakenTime * 1000;
|
||||
}
|
||||
}
|
||||
|
@ -693,7 +693,7 @@ function NetscriptFunctions(workerScript) {
|
||||
throw makeRuntimeRejectMsg(workerScript, "Could not find port: " + port + ". This is a bug contact the game developer");
|
||||
}
|
||||
port.push(data);
|
||||
if (port.length > CONSTANTS.MaxPortCapacity) {
|
||||
if (port.length > Settings.MaxPortCapacity) {
|
||||
port.shift();
|
||||
return true;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* SaveObject.js
|
||||
* Defines the object used to save/load games
|
||||
/* SaveObject.js
|
||||
* Defines the object used to save/load games
|
||||
*/
|
||||
var saveObject = new BitburnerSaveObject();
|
||||
|
||||
@ -13,13 +13,14 @@ function BitburnerSaveObject() {
|
||||
this.GlobalAliasesSave = "";
|
||||
this.MessagesSave = "";
|
||||
this.StockMarketSave = "";
|
||||
this.SettingsSave = "";
|
||||
this.VersionSave = "";
|
||||
}
|
||||
|
||||
BitburnerSaveObject.prototype.saveGame = function() {
|
||||
this.PlayerSave = JSON.stringify(Player);
|
||||
|
||||
//Delete all logs from all running scripts
|
||||
|
||||
//Delete all logs from all running scripts
|
||||
var TempAllServers = JSON.parse(JSON.stringify(AllServers), Reviver);
|
||||
//var TempAllServers = jQuery.extend(true, {}, AllServers); //Deep copy
|
||||
for (var ip in TempAllServers) {
|
||||
@ -31,7 +32,7 @@ BitburnerSaveObject.prototype.saveGame = function() {
|
||||
runningScriptObj.logs = [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.AllServersSave = JSON.stringify(TempAllServers);
|
||||
this.CompaniesSave = JSON.stringify(Companies);
|
||||
this.FactionsSave = JSON.stringify(Factions);
|
||||
@ -40,10 +41,11 @@ BitburnerSaveObject.prototype.saveGame = function() {
|
||||
this.GlobalAliasesSave = JSON.stringify(GlobalAliases);
|
||||
this.MessagesSave = JSON.stringify(Messages);
|
||||
this.StockMarketSave = JSON.stringify(StockMarket);
|
||||
this.SettingsSave = JSON.stringify(Settings);
|
||||
this.VersionSave = JSON.stringify(CONSTANTS.Version);
|
||||
var saveString = btoa(unescape(encodeURIComponent(JSON.stringify(this))));
|
||||
window.localStorage.setItem("bitburnerSave", saveString);
|
||||
|
||||
|
||||
console.log("Game saved!");
|
||||
Engine.createStatusText("Game saved!");
|
||||
}
|
||||
@ -55,13 +57,13 @@ loadGame = function(saveObj) {
|
||||
}
|
||||
var saveString = decodeURIComponent(escape(atob(window.localStorage.getItem("bitburnerSave"))));
|
||||
saveObj = JSON.parse(saveString, Reviver);
|
||||
|
||||
|
||||
Player = JSON.parse(saveObj.PlayerSave, Reviver);
|
||||
AllServers = JSON.parse(saveObj.AllServersSave, Reviver);
|
||||
Companies = JSON.parse(saveObj.CompaniesSave, Reviver);
|
||||
Factions = JSON.parse(saveObj.FactionsSave, Reviver);
|
||||
SpecialServerIps = JSON.parse(saveObj.SpecialServerIpsSave, Reviver);
|
||||
|
||||
|
||||
if (saveObj.hasOwnProperty("AliasesSave")) {
|
||||
try {
|
||||
Aliases = JSON.parse(saveObj.AliasesSave, Reviver);
|
||||
@ -98,6 +100,15 @@ loadGame = function(saveObj) {
|
||||
} else {
|
||||
StockMarket = {};
|
||||
}
|
||||
if (saveObj.hasOwnProperty("SettingsSave")) {
|
||||
try {
|
||||
Settings = JSON.parse(saveObj.SettingsSave, Reviver);
|
||||
} catch(e) {
|
||||
initSettings();
|
||||
}
|
||||
} else {
|
||||
initSettings();
|
||||
}
|
||||
if (saveObj.hasOwnProperty("VersionSave")) {
|
||||
try {
|
||||
var ver = JSON.parse(saveObj.VersionSave, Reviver);
|
||||
@ -105,8 +116,8 @@ loadGame = function(saveObj) {
|
||||
if (CONSTANTS.Version == "0.21.0" || CONSTANTS.Version == "0.22.0" ||
|
||||
CONSTANTS.Version == "0.22.1") {
|
||||
dialogBoxCreate("All scripts automatically killed for the sake of compatibility " +
|
||||
"with new version. If the game is still broken, try the following: " +
|
||||
"Options -> Soft Reset -> Save Game -> Reload page. If that STILL " +
|
||||
"with new version. If the game is still broken, try the following: " +
|
||||
"Options -> Soft Reset -> Save Game -> Reload page. If that STILL " +
|
||||
"doesn't work contact the dev");
|
||||
//This is the big update that might break games. Kill all running scripts
|
||||
for (var ip in AllServers) {
|
||||
@ -127,7 +138,7 @@ loadGame = function(saveObj) {
|
||||
} else {
|
||||
createNewUpdateText();
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -147,7 +158,7 @@ loadImportedGame = function(saveObj, saveString) {
|
||||
saveString = decodeURIComponent(escape(atob(saveString)));
|
||||
tempSaveObj = new BitburnerSaveObject();
|
||||
tempSaveObj = JSON.parse(saveString, Reviver);
|
||||
|
||||
|
||||
tempPlayer = JSON.parse(tempSaveObj.PlayerSave, Reviver);
|
||||
tempAllServers = JSON.parse(tempSaveObj.AllServersSave, Reviver);
|
||||
tempCompanies = JSON.parse(tempSaveObj.CompaniesSave, Reviver);
|
||||
@ -196,14 +207,14 @@ loadImportedGame = function(saveObj, saveString) {
|
||||
if (ver != CONSTANTS.Version) {
|
||||
createNewUpdateText();
|
||||
}
|
||||
|
||||
|
||||
if (ver != CONSTANTS.Version) {
|
||||
if (CONSTANTS.Version == "0.21.0" || CONSTANTS.Version == "0.22.0" ||
|
||||
CONSTANTS.Version == "0.22.1") {
|
||||
console.log("here");
|
||||
//This is the big update that might break games. Kill all running scripts
|
||||
for (var ip in tempAllServers) {
|
||||
if (tempAllServers.hasOwnProperty(ip)) {
|
||||
if (tempAllServers.hasOwnProperty(ip)) {
|
||||
tempAllServers[ip].runningScripts = [];
|
||||
tempAllServers[ip].runningScripts.length = 0;
|
||||
}
|
||||
@ -224,7 +235,7 @@ loadImportedGame = function(saveObj, saveString) {
|
||||
dialogBoxCreate("Error importing game");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
saveObj = tempSaveObj;
|
||||
Player = tempPlayer;
|
||||
AllServers = tempAllServers;
|
||||
@ -235,22 +246,22 @@ loadImportedGame = function(saveObj, saveString) {
|
||||
if (tempAliases) {
|
||||
Aliases = tempAliases;
|
||||
}
|
||||
|
||||
|
||||
if (tempGlobalAliases) {
|
||||
GlobalAliases = tempGlobalAliases;
|
||||
}
|
||||
|
||||
|
||||
if (tempMessages) {
|
||||
Messages = tempMessages;
|
||||
}
|
||||
|
||||
|
||||
if (tempStockMarket) {
|
||||
StockMarket = tempStockMarket;
|
||||
}
|
||||
|
||||
|
||||
dialogBoxCreate("Imported game");
|
||||
gameOptionsBoxClose();
|
||||
|
||||
|
||||
//Re-start game
|
||||
console.log("Importing game");
|
||||
Engine.setDisplayElements(); //Sets variables for important DOM elements
|
||||
@ -261,7 +272,7 @@ loadImportedGame = function(saveObj, saveString) {
|
||||
Engine._lastUpdate = new Date().getTime();
|
||||
var lastUpdate = Player.lastUpdate;
|
||||
var numCyclesOffline = Math.floor((Engine._lastUpdate - lastUpdate) / Engine._idleSpeed);
|
||||
|
||||
|
||||
/* Process offline progress */
|
||||
var offlineProductionFromScripts = loadAllRunningScripts(); //This also takes care of offline production for those scripts
|
||||
if (Player.isWorking) {
|
||||
@ -280,30 +291,30 @@ loadImportedGame = function(saveObj, saveString) {
|
||||
Player.work(numCyclesOffline);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Hacknet Nodes offline progress
|
||||
var offlineProductionFromHacknetNodes = processAllHacknetNodeEarnings(numCyclesOffline);
|
||||
|
||||
|
||||
//Passive faction rep gain offline
|
||||
processPassiveFactionRepGain(numCyclesOffline);
|
||||
|
||||
|
||||
//Update total playtime
|
||||
var time = numCyclesOffline * Engine._idleSpeed;
|
||||
if (Player.totalPlaytime == null) {Player.totalPlaytime = 0;}
|
||||
if (Player.playtimeSinceLastAug == null) {Player.playtimeSinceLastAug = 0;}
|
||||
Player.totalPlaytime += time;
|
||||
Player.playtimeSinceLastAug += time;
|
||||
|
||||
|
||||
//Re-apply augmentations
|
||||
Player.reapplyAllAugmentations();
|
||||
|
||||
|
||||
//Clear terminal
|
||||
$("#terminal tr:not(:last)").remove();
|
||||
|
||||
|
||||
Player.lastUpdate = Engine._lastUpdate;
|
||||
Engine.start(); //Run main game loop and Scripts loop
|
||||
dialogBoxCreate("While you were offline, your scripts generated $" +
|
||||
formatNumber(offlineProductionFromScripts, 2) + " and your Hacknet Nodes generated $" +
|
||||
dialogBoxCreate("While you were offline, your scripts generated $" +
|
||||
formatNumber(offlineProductionFromScripts, 2) + " and your Hacknet Nodes generated $" +
|
||||
formatNumber(offlineProductionFromHacknetNodes, 2));
|
||||
return true;
|
||||
}
|
||||
@ -319,12 +330,12 @@ BitburnerSaveObject.prototype.exportGame = function() {
|
||||
this.GlobalAliasesSave = JSON.stringify(GlobalAliases);
|
||||
this.MessagesSave = JSON.stringify(Messages);
|
||||
this.VersionSave = JSON.stringify(CONSTANTS.Version);
|
||||
|
||||
|
||||
var saveString = btoa(unescape(encodeURIComponent(JSON.stringify(this))));
|
||||
|
||||
|
||||
var file = new Blob([saveString], {type: 'text/plain'});
|
||||
if (window.navigator.msSaveOrOpenBlob) {// IE10+
|
||||
window.navigator.msSaveOrOpenBlob(file, filename);
|
||||
window.navigator.msSaveOrOpenBlob(file, filename);
|
||||
} else { // Others
|
||||
var a = document.createElement("a"),
|
||||
url = URL.createObjectURL(file);
|
||||
@ -334,8 +345,8 @@ BitburnerSaveObject.prototype.exportGame = function() {
|
||||
a.click();
|
||||
setTimeout(function() {
|
||||
document.body.removeChild(a);
|
||||
window.URL.revokeObjectURL(url);
|
||||
}, 0);
|
||||
window.URL.revokeObjectURL(url);
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -347,7 +358,7 @@ BitburnerSaveObject.prototype.importGame = function() {
|
||||
} else {
|
||||
dialogBoxCreate("ERR: Your browser does not support HTML5 File API. Cannot import.");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
BitburnerSaveObject.prototype.deleteGame = function() {
|
||||
@ -358,9 +369,9 @@ BitburnerSaveObject.prototype.deleteGame = function() {
|
||||
}
|
||||
|
||||
createNewUpdateText = function() {
|
||||
dialogBoxCreate("New update!<br>" +
|
||||
"Please report any bugs/issues through the github repository " +
|
||||
"or the Bitburner subreddit (reddit.com/r/bitburner).<br><br>" +
|
||||
dialogBoxCreate("New update!<br>" +
|
||||
"Please report any bugs/issues through the github repository " +
|
||||
"or the Bitburner subreddit (reddit.com/r/bitburner).<br><br>" +
|
||||
CONSTANTS.LatestUpdate);
|
||||
}
|
||||
|
||||
@ -375,7 +386,7 @@ BitburnerSaveObject.fromJSON = function(value) {
|
||||
|
||||
Reviver.constructors.BitburnerSaveObject = BitburnerSaveObject;
|
||||
|
||||
//Import game
|
||||
//Import game
|
||||
|
||||
function openImportFileHandler(evt) {
|
||||
var file = evt.target.files[0];
|
||||
@ -383,11 +394,11 @@ function openImportFileHandler(evt) {
|
||||
dialogBoxCreate("Invalid file selected");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(e) {
|
||||
var contents = e.target.result;
|
||||
loadImportedGame(saveObject, contents);
|
||||
};
|
||||
reader.readAsText(file);
|
||||
}
|
||||
}
|
||||
|
144
src/Script.js
144
src/Script.js
@ -5,12 +5,12 @@
|
||||
function scriptEditorInit() {
|
||||
//Initialize save and close button
|
||||
var closeButton = document.getElementById("script-editor-save-and-close-button");
|
||||
|
||||
|
||||
closeButton.addEventListener("click", function() {
|
||||
saveAndCloseScriptEditor();
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
//Allow tabs (four spaces) in all textareas
|
||||
var textareas = document.getElementsByTagName('textarea');
|
||||
var count = textareas.length;
|
||||
@ -37,11 +37,11 @@ document.addEventListener("DOMContentLoaded", scriptEditorInit, false);
|
||||
function upgradeScriptEditorContent() {
|
||||
var txt = $("#script-editor-text")[0];
|
||||
var lineNum = txt.value.substr(0, txt.selectionStart).split("\n").length;
|
||||
|
||||
|
||||
var code = document.getElementById("script-editor-text").value;
|
||||
var codeCopy = code.repeat(1);
|
||||
var ramUsage = calculateRamUsage(codeCopy);
|
||||
document.getElementById("script-editor-status-text").innerText =
|
||||
document.getElementById("script-editor-status-text").innerText =
|
||||
"Line Number: " + lineNum + ", RAM: " + formatNumber(ramUsage, 2).toString() + "GB";
|
||||
}
|
||||
|
||||
@ -69,21 +69,21 @@ function saveAndCloseScriptEditor() {
|
||||
dialogBoxCreate("Please copy and paste the code from the tutorial!");
|
||||
return;
|
||||
}
|
||||
iTutorialNextStep();
|
||||
iTutorialNextStep();
|
||||
}
|
||||
|
||||
|
||||
if (filename == "") {
|
||||
dialogBoxCreate("You must specify a filename!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (checkValidFilename(filename) == false) {
|
||||
dialogBoxCreate("Script filename can contain only alphanumerics, hyphens, and underscores");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
filename += ".script";
|
||||
|
||||
|
||||
//If the current script already exists on the server, overwrite it
|
||||
for (var i = 0; i < Player.getCurrentServer().scripts.length; i++) {
|
||||
if (filename == Player.getCurrentServer().scripts[i].filename) {
|
||||
@ -92,7 +92,7 @@ function saveAndCloseScriptEditor() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//If the current script does NOT exist, create a new one
|
||||
var script = new Script();
|
||||
script.saveScript();
|
||||
@ -104,14 +104,14 @@ function saveAndCloseScriptEditor() {
|
||||
// underscores and hyphens
|
||||
function checkValidFilename(filename) {
|
||||
var regex = /^[a-zA-Z0-9_-]+$/;
|
||||
|
||||
|
||||
if (filename.match(regex)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function Script() {
|
||||
function Script() {
|
||||
this.filename = "";
|
||||
this.code = "";
|
||||
this.ramUsage = 0;
|
||||
@ -124,14 +124,14 @@ Script.prototype.saveScript = function() {
|
||||
//Update code and filename
|
||||
var code = document.getElementById("script-editor-text").value;
|
||||
this.code = code.replace(/^\s+|\s+$/g, '');
|
||||
|
||||
|
||||
var filename = document.getElementById("script-editor-filename").value + ".script";
|
||||
this.filename = filename;
|
||||
|
||||
|
||||
//Server
|
||||
this.server = Player.currentServer;
|
||||
|
||||
//Calculate/update ram usage, execution time, etc.
|
||||
|
||||
//Calculate/update ram usage, execution time, etc.
|
||||
this.updateRamUsage();
|
||||
}
|
||||
}
|
||||
@ -181,53 +181,53 @@ function calculateRamUsage(codeCopy) {
|
||||
var hnUpgLevelCount = numOccurrences(codeCopy, ".upgradeLevel(");
|
||||
var hnUpgRamCount = numOccurrences(codeCopy, ".upgradeRam()");
|
||||
var hnUpgCoreCount = numOccurrences(codeCopy, ".upgradeCore()");
|
||||
var scriptGetStockCount = numOccurrences(codeCopy, "getStockPrice(") +
|
||||
var scriptGetStockCount = numOccurrences(codeCopy, "getStockPrice(") +
|
||||
numOccurrences(codeCopy, "getStockPosition(");
|
||||
var scriptBuySellStockCount = numOccurrences(codeCopy, "buyStock(") +
|
||||
var scriptBuySellStockCount = numOccurrences(codeCopy, "buyStock(") +
|
||||
numOccurrences(codeCopy, "sellStock(");
|
||||
var scriptPurchaseServerCount = numOccurrences(codeCopy, "purchaseServer(");
|
||||
var scriptRoundCount = numOccurrences(codeCopy, "round(");
|
||||
var scriptWriteCount = numOccurrences(codeCopy, "write(");
|
||||
var scriptReadCount = numOccurrences(codeCopy, "read(");
|
||||
|
||||
return baseRam +
|
||||
((whileCount * CONSTANTS.ScriptWhileRamCost) +
|
||||
(forCount * CONSTANTS.ScriptForRamCost) +
|
||||
(ifCount * CONSTANTS.ScriptIfRamCost) +
|
||||
(hackCount * CONSTANTS.ScriptHackRamCost) +
|
||||
(growCount * CONSTANTS.ScriptGrowRamCost) +
|
||||
(weakenCount * CONSTANTS.ScriptWeakenRamCost) +
|
||||
(scanCount * CONSTANTS.ScriptScanRamCost) +
|
||||
(nukeCount * CONSTANTS.ScriptNukeRamCost) +
|
||||
(brutesshCount * CONSTANTS.ScriptBrutesshRamCost) +
|
||||
(ftpcrackCount * CONSTANTS.ScriptFtpcrackRamCost) +
|
||||
(relaysmtpCount * CONSTANTS.ScriptRelaysmtpRamCost) +
|
||||
(httpwormCount * CONSTANTS.ScriptHttpwormRamCost) +
|
||||
(sqlinjectCount * CONSTANTS.ScriptSqlinjectRamCost) +
|
||||
(runCount * CONSTANTS.ScriptRunRamCost) +
|
||||
(execCount * CONSTANTS.ScriptExecRamCost) +
|
||||
(scpCount * CONSTANTS.ScriptScpRamCost) +
|
||||
(hasRootAccessCount * CONSTANTS.ScriptHasRootAccessRamCost) +
|
||||
|
||||
return baseRam +
|
||||
((whileCount * CONSTANTS.ScriptWhileRamCost) +
|
||||
(forCount * CONSTANTS.ScriptForRamCost) +
|
||||
(ifCount * CONSTANTS.ScriptIfRamCost) +
|
||||
(hackCount * CONSTANTS.ScriptHackRamCost) +
|
||||
(growCount * CONSTANTS.ScriptGrowRamCost) +
|
||||
(weakenCount * CONSTANTS.ScriptWeakenRamCost) +
|
||||
(scanCount * CONSTANTS.ScriptScanRamCost) +
|
||||
(nukeCount * CONSTANTS.ScriptNukeRamCost) +
|
||||
(brutesshCount * CONSTANTS.ScriptBrutesshRamCost) +
|
||||
(ftpcrackCount * CONSTANTS.ScriptFtpcrackRamCost) +
|
||||
(relaysmtpCount * CONSTANTS.ScriptRelaysmtpRamCost) +
|
||||
(httpwormCount * CONSTANTS.ScriptHttpwormRamCost) +
|
||||
(sqlinjectCount * CONSTANTS.ScriptSqlinjectRamCost) +
|
||||
(runCount * CONSTANTS.ScriptRunRamCost) +
|
||||
(execCount * CONSTANTS.ScriptExecRamCost) +
|
||||
(scpCount * CONSTANTS.ScriptScpRamCost) +
|
||||
(hasRootAccessCount * CONSTANTS.ScriptHasRootAccessRamCost) +
|
||||
(getHostnameCount * CONSTANTS.ScriptGetHostnameRamCost) +
|
||||
(getHackingLevelCount * CONSTANTS.ScriptGetHackingLevelRamCost) +
|
||||
(getServerMoneyAvailableCount * CONSTANTS.ScriptGetServerMoneyRamCost) +
|
||||
(getServerMaxMoneyCount * CONSTANTS.ScriptGetServerMoneyRamCost) +
|
||||
(getHackingLevelCount * CONSTANTS.ScriptGetHackingLevelRamCost) +
|
||||
(getServerMoneyAvailableCount * CONSTANTS.ScriptGetServerMoneyRamCost) +
|
||||
(getServerMaxMoneyCount * CONSTANTS.ScriptGetServerMoneyRamCost) +
|
||||
(getServerSecurityCount * CONSTANTS.ScriptGetServerSecurityRamCost) +
|
||||
(getServerBaseSecurityCount * CONSTANTS.ScriptGetServerSecurityRamCost) +
|
||||
(getServerReqdHackingCount * CONSTANTS.ScriptGetServerReqdHackRamCost) +
|
||||
(fileExistsCount * CONSTANTS.ScriptFileExistsRamCost) +
|
||||
(getServerReqdHackingCount * CONSTANTS.ScriptGetServerReqdHackRamCost) +
|
||||
(fileExistsCount * CONSTANTS.ScriptFileExistsRamCost) +
|
||||
(isRunningCount * CONSTANTS.ScriptIsRunningRamCost) +
|
||||
(numOperators * CONSTANTS.ScriptOperatorRamCost) +
|
||||
(purchaseHacknetCount * CONSTANTS.ScriptPurchaseHacknetRamCost) +
|
||||
(purchaseHacknetCount * CONSTANTS.ScriptPurchaseHacknetRamCost) +
|
||||
(hacknetnodesArrayCount * CONSTANTS.ScriptHacknetNodesRamCost) +
|
||||
(hnUpgLevelCount * CONSTANTS.ScriptHNUpgLevelRamCost) +
|
||||
(hnUpgLevelCount * CONSTANTS.ScriptHNUpgLevelRamCost) +
|
||||
(hnUpgRamCount * CONSTANTS.ScriptHNUpgRamRamCost) +
|
||||
(hnUpgCoreCount * CONSTANTS.ScriptHNUpgCoreRamCost) +
|
||||
(scriptGetStockCount * CONSTANTS.ScriptGetStockRamCost) +
|
||||
(scriptBuySellStockCount * CONSTANTS.ScriptBuySellStockRamCost) +
|
||||
(scriptPurchaseServerCount * CONSTANTS.ScriptPurchaseServerRamCost) +
|
||||
(scriptRoundCount * CONSTANTS.ScriptRoundRamCost) +
|
||||
(scriptWriteCount * CONSTANTS.ScriptReadWriteRamCost) +
|
||||
(hnUpgCoreCount * CONSTANTS.ScriptHNUpgCoreRamCost) +
|
||||
(scriptGetStockCount * CONSTANTS.ScriptGetStockRamCost) +
|
||||
(scriptBuySellStockCount * CONSTANTS.ScriptBuySellStockRamCost) +
|
||||
(scriptPurchaseServerCount * CONSTANTS.ScriptPurchaseServerRamCost) +
|
||||
(scriptRoundCount * CONSTANTS.ScriptRoundRamCost) +
|
||||
(scriptWriteCount * CONSTANTS.ScriptReadWriteRamCost) +
|
||||
(scriptReadCount * CONSTANTS.ScriptReadWriteRamCost));
|
||||
}
|
||||
|
||||
@ -250,14 +250,14 @@ loadAllRunningScripts = function() {
|
||||
for (var property in AllServers) {
|
||||
if (AllServers.hasOwnProperty(property)) {
|
||||
var server = AllServers[property];
|
||||
|
||||
|
||||
//Reset each server's RAM usage to 0
|
||||
server.ramUsed = 0;
|
||||
|
||||
|
||||
for (var j = 0; j < server.runningScripts.length; ++j) {
|
||||
count++;
|
||||
addWorkerScript(server.runningScripts[j], server);
|
||||
|
||||
|
||||
//Offline production
|
||||
total += scriptCalculateOfflineProduction(server.runningScripts[j]);
|
||||
}
|
||||
@ -273,15 +273,15 @@ scriptCalculateOfflineProduction = function(runningScriptObj) {
|
||||
var lastUpdate = Player.lastUpdate;
|
||||
var timePassed = (thisUpdate - lastUpdate) / 1000; //Seconds
|
||||
console.log("Offline for " + timePassed + " seconds");
|
||||
|
||||
|
||||
//Calculate the "confidence" rating of the script's true production. This is based
|
||||
//entirely off of time. We will arbitrarily say that if a script has been running for
|
||||
//4 hours (14400 sec) then we are completely confident in its ability
|
||||
var confidence = (runningScriptObj.onlineRunningTime) / 14400;
|
||||
if (confidence >= 1) {confidence = 1;}
|
||||
|
||||
|
||||
//Data map: [MoneyStolen, NumTimesHacked, NumTimesGrown, NumTimesWeaken]
|
||||
|
||||
|
||||
//Grow
|
||||
for (var ip in runningScriptObj.dataMap) {
|
||||
if (runningScriptObj.dataMap.hasOwnProperty(ip)) {
|
||||
@ -295,7 +295,7 @@ scriptCalculateOfflineProduction = function(runningScriptObj) {
|
||||
runningScriptObj.log(serv.hostname + " grown by " + formatNumber(growth * 100 - 100, 6) + "% from grow() calls made while offline");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var totalOfflineProduction = 0;
|
||||
for (var ip in runningScriptObj.dataMap) {
|
||||
if (runningScriptObj.dataMap.hasOwnProperty(ip)) {
|
||||
@ -308,7 +308,7 @@ scriptCalculateOfflineProduction = function(runningScriptObj) {
|
||||
production = serv.moneyAvailable;
|
||||
}
|
||||
totalOfflineProduction += production;
|
||||
Player.gainMoney(production);
|
||||
Player.gainMoney(production);
|
||||
console.log(runningScriptObj.filename + " generated $" + production + " while offline by hacking " + serv.hostname);
|
||||
runningScriptObj.log(runningScriptObj.filename + " generated $" + production + " while offline by hacking " + serv.hostname);
|
||||
serv.moneyAvailable -= production;
|
||||
@ -318,17 +318,17 @@ scriptCalculateOfflineProduction = function(runningScriptObj) {
|
||||
}
|
||||
|
||||
//Offline EXP gain
|
||||
//A script's offline production will always be at most half of its online production.
|
||||
//A script's offline production will always be at most half of its online production.
|
||||
var expGain = 0.5 * (runningScriptObj.onlineExpGained / runningScriptObj.onlineRunningTime) * timePassed;
|
||||
expGain *= confidence;
|
||||
|
||||
|
||||
Player.gainHackingExp(expGain);
|
||||
|
||||
|
||||
//Update script stats
|
||||
runningScriptObj.offlineMoneyMade += totalOfflineProduction;
|
||||
runningScriptObj.offlineRunningTime += timePassed;
|
||||
runningScriptObj.offlineExpGained += expGain;
|
||||
|
||||
|
||||
//Fortify a server's security based on how many times it was hacked
|
||||
for (var ip in runningScriptObj.dataMap) {
|
||||
if (runningScriptObj.dataMap.hasOwnProperty(ip)) {
|
||||
@ -341,7 +341,7 @@ scriptCalculateOfflineProduction = function(runningScriptObj) {
|
||||
serv.fortify(CONSTANTS.ServerFortifyAmount * timesHacked);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//Weaken
|
||||
for (var ip in runningScriptObj.dataMap) {
|
||||
if (runningScriptObj.dataMap.hasOwnProperty(ip)) {
|
||||
@ -354,7 +354,7 @@ scriptCalculateOfflineProduction = function(runningScriptObj) {
|
||||
serv.weaken(CONSTANTS.ServerWeakenAmount * timesWeakened);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return totalOfflineProduction;
|
||||
}
|
||||
|
||||
@ -376,9 +376,9 @@ function RunningScript(script, args) {
|
||||
this.args = args;
|
||||
this.scriptRef = script;
|
||||
this.server = script.server; //IP Address only
|
||||
|
||||
|
||||
this.logs = []; //Script logging. Array of strings, with each element being a log entry
|
||||
|
||||
|
||||
//Stats to display on the Scripts menu, and used to determine offline progress
|
||||
this.offlineRunningTime = 0.01; //Seconds
|
||||
this.offlineMoneyMade = 0;
|
||||
@ -386,16 +386,16 @@ function RunningScript(script, args) {
|
||||
this.onlineRunningTime = 0.01; //Seconds
|
||||
this.onlineMoneyMade = 0;
|
||||
this.onlineExpGained = 0;
|
||||
|
||||
|
||||
this.threads = 1;
|
||||
|
||||
|
||||
//[MoneyStolen, NumTimesHacked, NumTimesGrown, NumTimesWeaken]
|
||||
this.dataMap = new AllServersMap([0, 0, 0, 0]);
|
||||
}
|
||||
|
||||
RunningScript.prototype.reset = function() {
|
||||
this.scriptRef.updateRamUsage();
|
||||
|
||||
|
||||
this.offlineRunningTime = 0.01; //Seconds
|
||||
this.offlineMoneyMade = 0;
|
||||
this.offlineExpGained = 0;
|
||||
@ -406,7 +406,7 @@ RunningScript.prototype.reset = function() {
|
||||
}
|
||||
|
||||
RunningScript.prototype.log = function(txt) {
|
||||
if (this.logs.length > CONSTANTS.MaxLogCapacity) {
|
||||
if (this.logs.length > Settings.MaxLogCapacity) {
|
||||
//Delete first element and add new log entry to the end.
|
||||
//TODO Eventually it might be better to replace this with circular array
|
||||
//to improve performance
|
||||
@ -424,7 +424,7 @@ RunningScript.prototype.displayLog = function() {
|
||||
RunningScript.prototype.clearLog = function() {
|
||||
this.logs.length = 0;
|
||||
}
|
||||
|
||||
|
||||
//Update the moneyStolen and numTimesHack maps when hacking
|
||||
RunningScript.prototype.recordHack = function(serverIp, moneyGained, n=1) {
|
||||
if (this.dataMap == null) {
|
||||
@ -505,4 +505,4 @@ AllServersMap.fromJSON = function(value) {
|
||||
return Generic_fromJSON(AllServersMap, value.data);
|
||||
}
|
||||
|
||||
Reviver.constructors.AllServersMap = AllServersMap;
|
||||
Reviver.constructors.AllServersMap = AllServersMap;
|
||||
|
@ -4,4 +4,20 @@ Settings = {
|
||||
suppressMessages: false,
|
||||
MaxLogCapacity: 50,
|
||||
MaxPortCapacity: 50,
|
||||
}
|
||||
}
|
||||
|
||||
function initSettings() {
|
||||
Settings.CodeInstructionRunTime = 100;
|
||||
Settings.suppressMessages = false;
|
||||
Settings.MaxLogCapacity = 50;
|
||||
Settings.MaxPortCapacity = 50;
|
||||
}
|
||||
|
||||
function setSettingsLabels() {
|
||||
document.getElementById("settingsNSExecTimeRangeValLabel").innerHTML
|
||||
= Settings.CodeInstructionRunTime + "ms";
|
||||
document.getElementById("settingsNSLogRangeValLabel").innerHTML
|
||||
= Settings.MaxLogCapacity;
|
||||
document.getElementById("settingsNSPortRangeValLabel").innerHTML
|
||||
= Settings.MaxPortCapacity;
|
||||
}
|
||||
|
@ -1031,7 +1031,8 @@ var Engine = {
|
||||
iTutorialStart();
|
||||
Engine.removeLoadingScreen();
|
||||
}
|
||||
|
||||
//Initialize labels on game settings
|
||||
setSettingsLabels();
|
||||
},
|
||||
|
||||
setDisplayElements: function() {
|
||||
|
Loading…
Reference in New Issue
Block a user