Bug fixes for new Netscript commands. Added total Playtime statistics. Minor UI improvements

This commit is contained in:
Daniel Xie 2017-05-15 09:15:59 -05:00
parent f32ec4f9a7
commit 3919d3e97a
11 changed files with 57 additions and 36 deletions

@ -57,9 +57,7 @@ Private beta feedback
Also not really a big deal, but I'm at 110% zoom on chrome and the tutorial window Also not really a big deal, but I'm at 110% zoom on chrome and the tutorial window
covers some of the text covers some of the text
For the last thing of the tutorial, I would just have a button like "Finish Tutorial" rather than "Next"
I'd put a little popup or something when you click save, so you know I'd put a little popup or something when you click save, so you know
Netscript commands: Netscript commands:

@ -112,6 +112,10 @@
<li class="delete-game-tab"> <li class="delete-game-tab">
<a href="#" id="delete-game-link"> Delete Game </a> <a href="#" id="delete-game-link"> Delete Game </a>
</li> </li>
<li class="debug-delete-scripts-tab">
<a href="#" id="debug-delete-scripts-link"> Delete Active Scripts </a>
</li>
</ul> </ul>
</div> </div>

@ -760,7 +760,7 @@ initAugmentations = function() {
AddToAugmentations(HacknetNodeNICUpload); AddToAugmentations(HacknetNodeNICUpload);
var HacknetNodeKernelDNI = new Augmentation(AugmentationNames.HacknetNodeKernelDNI); var HacknetNodeKernelDNI = new Augmentation(AugmentationNames.HacknetNodeKernelDNI);
HacknetNodeKernelDNI.setRequirements(4000, 90000000); HacknetNodeKernelDNI.setRequirements(4000, 12000000);
HacknetNodeKernelDNI.setInfo("Installs a Direct-Neural Interface jack into the arm that is capable of connecting to a " + HacknetNodeKernelDNI.setInfo("Installs a Direct-Neural Interface jack into the arm that is capable of connecting to a " +
"Hacknet Node. This lets the user access and manipulate the Node's kernel using the mind's " + "Hacknet Node. This lets the user access and manipulate the Node's kernel using the mind's " +
"electrochemical signals.<br><br>" + "electrochemical signals.<br><br>" +

@ -34,17 +34,20 @@ CONSTANTS = {
CodeInstructionRunTime: 1500, CodeInstructionRunTime: 1500,
//RAM Costs for differenc commands //RAM Costs for differenc commands
ScriptWhileRamCost: 0.4, ScriptWhileRamCost: 0.4,
ScriptForRamCost: 0.4, ScriptForRamCost: 0.4,
ScriptIfRamCost: 0.1, ScriptIfRamCost: 0.1,
ScriptHackRamCost: 0.25, ScriptHackRamCost: 0.25,
ScriptGrowRamCost: 0.25, ScriptGrowRamCost: 0.25,
ScriptNukeRamCost: 0.05, ScriptNukeRamCost: 0.05,
ScriptBrutesshRamCost: 0.05, ScriptBrutesshRamCost: 0.05,
ScriptFtpcrackRamCost: 0.05, ScriptFtpcrackRamCost: 0.05,
ScriptRelaysmtpRamCost: 0.05, ScriptRelaysmtpRamCost: 0.05,
ScriptHttpwormRamCost: 0.05, ScriptHttpwormRamCost: 0.05,
ScriptSqlinjectRamCost: 0.05, ScriptSqlinjectRamCost: 0.05,
ScriptRunRamCost: 0.5,
ScriptGetHackingLevelRamCost: 0.1,
ScriptGetServerMoneyRamCost: 0.1,
//Server growth rate //Server growth rate
ServerGrowthRate: 1.00075, ServerGrowthRate: 1.00075,

@ -638,6 +638,7 @@ function evaluate(exp, workerScript) {
reject(e); reject(e);
}); });
} else if (exp.func.value == "run") { } else if (exp.func.value == "run") {
console.log("run() called");
if (exp.args.length != 1) { if (exp.args.length != 1) {
reject("|"+workerScript.serverIp+"|"+workerScript.name+"|run() call has incorrect number of arguments. Takes 1 argument"); reject("|"+workerScript.serverIp+"|"+workerScript.name+"|run() call has incorrect number of arguments. Takes 1 argument");
} }
@ -660,10 +661,12 @@ function evaluate(exp, workerScript) {
reject(e); reject(e);
}); });
} else if (exp.func.value == "getHackingLevel") { } else if (exp.func.value == "getHackingLevel") {
console.log("getHackingLevel called");
if (exp.args.length != 0) { if (exp.args.length != 0) {
reject("|"+workerScript.serverIp+"|"+workerScript.name+"|getHackingLevel() call has incorrect number of arguments. Takes 0 arguments"); reject("|"+workerScript.serverIp+"|"+workerScript.name+"|getHackingLevel() call has incorrect number of arguments. Takes 0 arguments");
} }
setTimeout(function() { setTimeout(function() {
console.log("About to resolve getHackingLevel");
resolve(Player.hacking_skill); resolve(Player.hacking_skill);
}, CONSTANTS.CodeInstructionRunTime); }, CONSTANTS.CodeInstructionRunTime);
} else if (exp.func.value == "getServerMoneyAvailable") { } else if (exp.func.value == "getServerMoneyAvailable") {
@ -687,6 +690,7 @@ function evaluate(exp, workerScript) {
} }
}, CONSTANTS.CodeInstructionRunTime); }, CONSTANTS.CodeInstructionRunTime);
}); });
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|Unrecognized function call");
break; break;
default: default:

@ -109,16 +109,13 @@ function Parser(input) {
* else: {"type": "var", "value": "foo"} * else: {"type": "var", "value": "foo"}
*/ */
function parse_if() { function parse_if() {
console.log("Parsing if token");
checkKeywordAndSkip("if"); checkKeywordAndSkip("if");
//Conditional //Conditional
var cond = parse_expression(); var cond = parse_expression();
console.log("cond: " + cond);
//Body //Body
var then = parse_expression(); var then = parse_expression();
console.log("then: " + then);
var ret = { var ret = {
type: "if", type: "if",
cond: [], cond: [],

@ -31,6 +31,7 @@ function runScriptsLoop() {
if (workerScripts[i].running == false && workerScripts[i].env.stopFlag == false) { if (workerScripts[i].running == false && workerScripts[i].env.stopFlag == false) {
try { try {
var ast = Parser(Tokenizer(InputStream(workerScripts[i].code))); var ast = Parser(Tokenizer(InputStream(workerScripts[i].code)));
console.log(ast);
} catch (e) { } catch (e) {
dialogBoxCreate("Syntax ERROR in " + workerScripts[i].name + ":", e, "", ""); dialogBoxCreate("Syntax ERROR in " + workerScripts[i].name + ":", e, "", "");
workerScripts[i].env.stopFlag = true; workerScripts[i].env.stopFlag = true;

@ -168,6 +168,7 @@ function PlayerObject() {
//Used to store the last update time. //Used to store the last update time.
this.lastUpdate = new Date().getTime(); this.lastUpdate = new Date().getTime();
this.totalPlaytime = 0;
}; };
PlayerObject.prototype.init = function() { PlayerObject.prototype.init = function() {

@ -96,11 +96,6 @@ function Script() {
this.logs = []; //Script logging. Array of strings, with each element being a log entry this.logs = []; //Script logging. Array of strings, with each element being a log entry
/* Properties to calculate offline progress. Only applies for infinitely looping scripts */ /* Properties to calculate offline progress. Only applies for infinitely looping scripts */
//Number of instructions ("lines") in the code. Any call ending in a ;
//is considered one instruction. Used to calculate ramUsage
this.numInstructions = 0;
//Stats to display on the Scripts menu, and used to determine offline progress //Stats to display on the Scripts menu, and used to determine offline progress
this.offlineRunningTime = 0.01; //Seconds this.offlineRunningTime = 0.01; //Seconds
this.offlineMoneyMade = 0; this.offlineMoneyMade = 0;
@ -125,8 +120,7 @@ Script.prototype.saveScript = function() {
//Server //Server
this.server = Player.currentServer; this.server = Player.currentServer;
//Calculate/update number of instructions, ram usage, execution time, etc. //Calculate/update ram usage, execution time, etc.
this.updateNumInstructions();
this.updateRamUsage(); this.updateRamUsage();
//Clear the stats when the script is updated //Clear the stats when the script is updated
@ -147,12 +141,7 @@ Script.prototype.reset = function() {
this.onlineRunningTime = 0.01; //Seconds this.onlineRunningTime = 0.01; //Seconds
this.onlineMoneyMade = 0; this.onlineMoneyMade = 0;
this.onlineExpGained = 0; this.onlineExpGained = 0;
} this.logs = [];
//Calculates the number of instructions, which is just determined by number of semicolons
Script.prototype.updateNumInstructions = function() {
var numSemicolons = this.code.split(";").length - 1;
this.numInstructions = numSemicolons;
} }
//Updates how much RAM the script uses when it is running. //Updates how much RAM the script uses when it is running.
@ -172,6 +161,9 @@ Script.prototype.updateRamUsage = function() {
var relaysmtpCount = numOccurrences(codeCopy, "relaysmtp("); var relaysmtpCount = numOccurrences(codeCopy, "relaysmtp(");
var httpwormCount = numOccurrences(codeCopy, "httpworm("); var httpwormCount = numOccurrences(codeCopy, "httpworm(");
var sqlinjectCount = numOccurrences(codeCopy, "sqlinject("); var sqlinjectCount = numOccurrences(codeCopy, "sqlinject(");
var runCount = numOccurrences(codeCopy, "run(");
var getHackingLevelCount = numOccurrences(codeCopy, "getHackingLevel(");
var getServerMoneyAvailableCount = numOccurrences(codeCopy, "getServerMoneyAvailable(");
this.ramUsage = baseRam + this.ramUsage = baseRam +
((whileCount * CONSTANTS.ScriptWhileRamCost) + ((whileCount * CONSTANTS.ScriptWhileRamCost) +
@ -184,7 +176,10 @@ Script.prototype.updateRamUsage = function() {
(ftpcrackCount * CONSTANTS.ScriptFtpcrackRamCost) + (ftpcrackCount * CONSTANTS.ScriptFtpcrackRamCost) +
(relaysmtpCount * CONSTANTS.ScriptRelaysmtpRamCost) + (relaysmtpCount * CONSTANTS.ScriptRelaysmtpRamCost) +
(httpwormCount * CONSTANTS.ScriptHttpwormRamCost) + (httpwormCount * CONSTANTS.ScriptHttpwormRamCost) +
(sqlinjectCount * CONSTANTS.ScriptSqlinjectRamCost)); (sqlinjectCount * CONSTANTS.ScriptSqlinjectRamCost) +
(runCount * CONSTANTS.ScriptRunRamCost) +
(getHackingLevelCount * CONSTANTS.ScriptGetHackingLevelRamCost) +
(getServerMoneyAvailableCount * CONSTANTS.ScriptGetServerMoneyRamCost));
console.log("ram usage: " + this.ramUsage); console.log("ram usage: " + this.ramUsage);
} }
@ -304,7 +299,6 @@ function AllServersToMoneyMap() {
} }
AllServersToMoneyMap.prototype.printConsole = function() { AllServersToMoneyMap.prototype.printConsole = function() {
console.log("Printing AllServersToMoneyMap");
for (var ip in this) { for (var ip in this) {
if (this.hasOwnProperty(ip)) { if (this.hasOwnProperty(ip)) {
var serv = AllServers[ip]; var serv = AllServers[ip];
@ -312,7 +306,6 @@ AllServersToMoneyMap.prototype.printConsole = function() {
console.log("Warning null server encountered with ip: " + ip); console.log("Warning null server encountered with ip: " + ip);
continue; continue;
} }
console.log(ip + "(" + serv.hostname + "): " + this[ip]);
} }
} }
} }

@ -273,7 +273,8 @@ var Engine = {
'Crime money multiplier: ' + formatNumber(Player.crime_money_mult * 100, 2) + '%<br><br><br>' + 'Crime money multiplier: ' + formatNumber(Player.crime_money_mult * 100, 2) + '%<br><br><br>' +
'<b>Misc</b><br><br>' + '<b>Misc</b><br><br>' +
'Servers owned: ' + Player.purchasedServers.length + '<br>' + 'Servers owned: ' + Player.purchasedServers.length + '<br>' +
'Hacknet Nodes owned: ' + Player.hacknetNodes.length + '<br><br> ').replace( / /g, "&nbsp;" ); 'Hacknet Nodes owned: ' + Player.hacknetNodes.length + '<br>' +
'Time played: ' + convertTimeMsToTimeElapsedString(Player.totalPlaytime) + '<br><br><br>').replace( / /g, "&nbsp;" );
}, },
@ -524,6 +525,11 @@ var Engine = {
}, },
updateGame: function(numCycles = 1) { updateGame: function(numCycles = 1) {
//Update total playtime
var time = numCycles * Engine._idleSpeed;
if (Player.totalPlaytime == null) {Player.totalPlaytime = 0;}
Player.totalPlaytime += time;
//Start Manual hack //Start Manual hack
if (Player.startAction == true) { if (Player.startAction == true) {
Engine._totalActionTime = Player.actionTime; Engine._totalActionTime = Player.actionTime;
@ -1001,6 +1007,12 @@ var Engine = {
}); });
Engine.loadWorkInProgressContent(); Engine.loadWorkInProgressContent();
} }
//DEBUG
document.getElementById("debug-delete-scripts-link").addEventListener("click", function() {
Player.getHomeComputer().runningScripts = [];
return false;
});
}, },
start: function() { start: function() {

@ -32,6 +32,9 @@ function convertTimeMsToTimeElapsedString(time) {
//Convert ms to seconds, since we only have second-level precision //Convert ms to seconds, since we only have second-level precision
time = Math.floor(time / 1000); time = Math.floor(time / 1000);
var days = Math.floor(time / 86400);
time %= 86400;
var hours = Math.floor(time / 3600); var hours = Math.floor(time / 3600);
time %= 3600; time %= 3600;
@ -40,7 +43,12 @@ function convertTimeMsToTimeElapsedString(time) {
var seconds = time; var seconds = time;
return hours + " hours " + minutes + " minutes " + seconds + " seconds"; var res = "";
if (days) {res += days + " days";}
if (hours) {res += hours + " hours ";}
if (minutes) {res += minutes + " minutes ";}
if (seconds) {res += seconds + " seconds ";}
return res;
} }
//Finds the longest common starting substring in a set of strings //Finds the longest common starting substring in a set of strings