Fixed bug with loading game when working on creating program

This commit is contained in:
Daniel Xie 2017-05-15 10:28:59 -05:00
parent 5039a03732
commit 51c8e7a6c6
4 changed files with 16 additions and 2 deletions

@ -45,7 +45,7 @@ CONSTANTS = {
ScriptRelaysmtpRamCost: 0.05, ScriptRelaysmtpRamCost: 0.05,
ScriptHttpwormRamCost: 0.05, ScriptHttpwormRamCost: 0.05,
ScriptSqlinjectRamCost: 0.05, ScriptSqlinjectRamCost: 0.05,
ScriptRunRamCost: 0.5, ScriptRunRamCost: 0.75,
ScriptGetHackingLevelRamCost: 0.1, ScriptGetHackingLevelRamCost: 0.1,
ScriptGetServerMoneyRamCost: 0.1, ScriptGetServerMoneyRamCost: 0.1,

@ -225,6 +225,7 @@ function evaluate(exp, workerScript) {
if (exp.func.value == "hack") { if (exp.func.value == "hack") {
if (exp.args.length != 1) { if (exp.args.length != 1) {
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|Hack() call has incorrect number of arguments. Takes 1 argument"); reject("|" + workerScript.serverIp + "|" + workerScript.name + "|Hack() call has incorrect number of arguments. Takes 1 argument");
return;
} }
var ipPromise = evaluate(exp.args[0], workerScript); var ipPromise = evaluate(exp.args[0], workerScript);
@ -306,6 +307,7 @@ function evaluate(exp, workerScript) {
} else if (exp.func.value == "sleep") { } else if (exp.func.value == "sleep") {
if (exp.args.length != 1) { if (exp.args.length != 1) {
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|sleep() call has incorrect number of arguments. Takes 1 argument."); reject("|" + workerScript.serverIp + "|" + workerScript.name + "|sleep() call has incorrect number of arguments. Takes 1 argument.");
return;
} }
var sleepTimePromise = evaluate(exp.args[0], workerScript); var sleepTimePromise = evaluate(exp.args[0], workerScript);
sleepTimePromise.then(function(sleepTime) { sleepTimePromise.then(function(sleepTime) {
@ -327,6 +329,7 @@ function evaluate(exp, workerScript) {
} else if (exp.func.value == "print") { } else if (exp.func.value == "print") {
if (exp.args.length != 1) { if (exp.args.length != 1) {
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|print() call has incorrect number of arguments. Takes 1 argument"); reject("|" + workerScript.serverIp + "|" + workerScript.name + "|print() call has incorrect number of arguments. Takes 1 argument");
return;
} }
var p = new Promise(function(resolve, reject) { var p = new Promise(function(resolve, reject) {
@ -349,6 +352,7 @@ function evaluate(exp, workerScript) {
} else if (exp.func.value == "grow") { } else if (exp.func.value == "grow") {
if (exp.args.length != 1) { if (exp.args.length != 1) {
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|grow() call has incorrect number of arguments. Takes 1 argument"); reject("|" + workerScript.serverIp + "|" + workerScript.name + "|grow() call has incorrect number of arguments. Takes 1 argument");
return;
} }
var ipPromise = evaluate(exp.args[0], workerScript); var ipPromise = evaluate(exp.args[0], workerScript);
ipPromise.then(function(ip) { ipPromise.then(function(ip) {
@ -390,6 +394,7 @@ function evaluate(exp, workerScript) {
} else if (exp.func.value == "nuke") { } else if (exp.func.value == "nuke") {
if (exp.args.length != 1) { if (exp.args.length != 1) {
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|nuke() call has incorrect number of arguments. Takes 1 argument"); reject("|" + workerScript.serverIp + "|" + workerScript.name + "|nuke() call has incorrect number of arguments. Takes 1 argument");
return;
} }
var ipPromise = evaluate(exp.args[0], workerScript); var ipPromise = evaluate(exp.args[0], workerScript);
ipPromise.then(function(ip) { ipPromise.then(function(ip) {
@ -436,6 +441,7 @@ function evaluate(exp, workerScript) {
} else if (exp.func.value == "brutessh") { } else if (exp.func.value == "brutessh") {
if (exp.args.length != 1) { if (exp.args.length != 1) {
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|brutessh() call has incorrect number of arguments. Takes 1 argument"); reject("|" + workerScript.serverIp + "|" + workerScript.name + "|brutessh() call has incorrect number of arguments. Takes 1 argument");
return;
} }
var ipPromise = evaluate(exp.args[0], workerScript); var ipPromise = evaluate(exp.args[0], workerScript);
ipPromise.then(function(ip) { ipPromise.then(function(ip) {
@ -478,6 +484,7 @@ function evaluate(exp, workerScript) {
} else if (exp.func.value == "ftpcrack") { } else if (exp.func.value == "ftpcrack") {
if (exp.args.length != 1) { if (exp.args.length != 1) {
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|ftpcrack() call has incorrect number of arguments. Takes 1 argument"); reject("|" + workerScript.serverIp + "|" + workerScript.name + "|ftpcrack() call has incorrect number of arguments. Takes 1 argument");
return;
} }
var ipPromise = evaluate(exp.args[0], workerScript); var ipPromise = evaluate(exp.args[0], workerScript);
ipPromise.then(function(ip) { ipPromise.then(function(ip) {
@ -520,6 +527,7 @@ function evaluate(exp, workerScript) {
} else if (exp.func.value == "relaysmtp") { } else if (exp.func.value == "relaysmtp") {
if (exp.args.length != 1) { if (exp.args.length != 1) {
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|relaysmtp() call has incorrect number of arguments. Takes 1 argument"); reject("|" + workerScript.serverIp + "|" + workerScript.name + "|relaysmtp() call has incorrect number of arguments. Takes 1 argument");
return;
} }
var ipPromise = evaluate(exp.args[0], workerScript); var ipPromise = evaluate(exp.args[0], workerScript);
ipPromise.then(function(ip) { ipPromise.then(function(ip) {
@ -562,6 +570,7 @@ function evaluate(exp, workerScript) {
} else if (exp.func.value == "httpworm") { } else if (exp.func.value == "httpworm") {
if (exp.args.length != 1) { if (exp.args.length != 1) {
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|httpworm() call has incorrect number of arguments. Takes 1 argument"); reject("|" + workerScript.serverIp + "|" + workerScript.name + "|httpworm() call has incorrect number of arguments. Takes 1 argument");
return;
} }
var ipPromise = evaluate(exp.args[0], workerScript); var ipPromise = evaluate(exp.args[0], workerScript);
ipPromise.then(function(ip) { ipPromise.then(function(ip) {
@ -604,6 +613,7 @@ function evaluate(exp, workerScript) {
} else if (exp.func.value == "sqlinject") { } else if (exp.func.value == "sqlinject") {
if (exp.args.length != 1) { if (exp.args.length != 1) {
reject("|" + workerScript.serverIp + "|" + workerScript.name + "|sqlinject() call has incorrect number of arguments. Takes 1 argument"); reject("|" + workerScript.serverIp + "|" + workerScript.name + "|sqlinject() call has incorrect number of arguments. Takes 1 argument");
return;
} }
var ipPromise = evaluate(exp.args[0], workerScript); var ipPromise = evaluate(exp.args[0], workerScript);
ipPromise.then(function(ip) { ipPromise.then(function(ip) {
@ -646,6 +656,7 @@ function evaluate(exp, workerScript) {
} else if (exp.func.value == "run") { } else if (exp.func.value == "run") {
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");
return;
} }
var scriptNamePromise = evaluate(exp.args[0], workerScript); var scriptNamePromise = evaluate(exp.args[0], workerScript);
scriptNamePromise.then(function(scriptname) { scriptNamePromise.then(function(scriptname) {
@ -653,6 +664,7 @@ function evaluate(exp, workerScript) {
var scriptServer = AllServers[serverIp]; var scriptServer = AllServers[serverIp];
if (scriptServer == null) { if (scriptServer == null) {
reject("|"+workerScript.serverIp+"|"+workerScript.name+"|Could not find server. This is a bug in the game. Report to game dev"); reject("|"+workerScript.serverIp+"|"+workerScript.name+"|Could not find server. This is a bug in the game. Report to game dev");
return;
} }
var runScriptPromise = runScriptFromScript(scriptServer, scriptname, workerScript); var runScriptPromise = runScriptFromScript(scriptServer, scriptname, workerScript);
@ -668,6 +680,7 @@ function evaluate(exp, workerScript) {
} else if (exp.func.value == "getHackingLevel") { } else if (exp.func.value == "getHackingLevel") {
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");
return;
} }
setTimeout(function() { setTimeout(function() {
Player.updateSkillLevels(); Player.updateSkillLevels();

@ -164,6 +164,7 @@ Script.prototype.updateRamUsage = function() {
var runCount = numOccurrences(codeCopy, "run("); var runCount = numOccurrences(codeCopy, "run(");
var getHackingLevelCount = numOccurrences(codeCopy, "getHackingLevel("); var getHackingLevelCount = numOccurrences(codeCopy, "getHackingLevel(");
var getServerMoneyAvailableCount = numOccurrences(codeCopy, "getServerMoneyAvailable("); var getServerMoneyAvailableCount = numOccurrences(codeCopy, "getServerMoneyAvailable(");
var numOperators = numNetscriptOperators(codeCopy);
this.ramUsage = baseRam + this.ramUsage = baseRam +
((whileCount * CONSTANTS.ScriptWhileRamCost) + ((whileCount * CONSTANTS.ScriptWhileRamCost) +

@ -993,7 +993,7 @@ var Engine = {
if (Player.workType == CONSTANTS.WorkTypeFaction) { if (Player.workType == CONSTANTS.WorkTypeFaction) {
var fac = Factions[Player.currentWorkFactionName]; var fac = Factions[Player.currentWorkFactionName];
Player.finishFactionWork(true, fac); Player.finishFactionWork(true, fac);
} else if (Player.WorkType == CONSTANTS.WorkTypeCreateProgram) { } else if (Player.workType == CONSTANTS.WorkTypeCreateProgram) {
Player.finishCreateProgramWork(true, Player.createProgramName); Player.finishCreateProgramWork(true, Player.createProgramName);
} else if (Player.workType == CONSTANTS.WorkTypeStudyClass) { } else if (Player.workType == CONSTANTS.WorkTypeStudyClass) {
Player.finishClass(); Player.finishClass();