From ad6f74a16d79c0c583ccf2cafe9786ce6bd26e55 Mon Sep 17 00:00:00 2001 From: Daniel Xie Date: Mon, 29 May 2017 21:02:41 -0500 Subject: [PATCH] Lowered cost for NeuroFlux governor. Fixed tab completion for scp command. Fixed bugs with Netscript scp command --- src/Constants.js | 3 ++- src/NetscriptEvaluator.js | 12 ++++++------ src/Player.js | 2 +- src/Script.js | 2 ++ src/Terminal.js | 36 +++++++++++++++++++++++++++++------- 5 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/Constants.js b/src/Constants.js index c9eb92ae5..6c788c83b 100644 --- a/src/Constants.js +++ b/src/Constants.js @@ -30,7 +30,7 @@ CONSTANTS = { /* Augmentation */ //NeuroFlux Governor cost multiplier as you level up - NeuroFluxGovernorLevelMult: 1.18, + NeuroFluxGovernorLevelMult: 1.14, /* Script related things */ //Time (ms) it takes to run one operation in Netscript. @@ -49,6 +49,7 @@ CONSTANTS = { ScriptHttpwormRamCost: 0.05, ScriptSqlinjectRamCost: 0.05, ScriptRunRamCost: 0.8, + ScriptScpRamCost: 0.5, ScriptHasRootAccessRamCost: 0.05, ScriptGetHostnameRamCost: 0.1, ScriptGetHackingLevelRamCost: 0.1, diff --git a/src/NetscriptEvaluator.js b/src/NetscriptEvaluator.js index 50a6a48a1..4ddc07895 100644 --- a/src/NetscriptEvaluator.js +++ b/src/NetscriptEvaluator.js @@ -708,7 +708,7 @@ function evaluate(exp, workerScript) { reject(e); }); } else if (exp.func.value == "scp") { - if (exp.args.length != 1) { + if (exp.args.length != 2) { reject(makeRuntimeRejectMsg(workerScript, "scp() call has incorrect number of arguments. Takes 2 arguments")); return; } @@ -725,7 +725,7 @@ function evaluate(exp, workerScript) { //Check that a script with this filename does not already exist for (var i = 0; i < destServer.scripts.length; ++i) { if (scriptname == destServer.scripts[i].filename) { - workerScript.scriptRef.log(destServ.hostname + " already contains a script named " + scriptname); + workerScript.scriptRef.log(destServer.hostname + " already contains a script named " + scriptname); resolve(false); return; } @@ -742,9 +742,9 @@ function evaluate(exp, workerScript) { newScript.filename = scriptname; newScript.code = currServ.scripts[i].code; newScript.ramUsage = currServ.scripts[i].ramUsage; - newScript.server = ip; - server.scripts.push(newScript); - workerScript.scriptRef.log(scriptname + " copied over to " + server.hostname); + newScript.server = destServer.ip; + destServer.scripts.push(newScript); + workerScript.scriptRef.log(scriptname + " copied over to " + destServer.hostname); resolve(true); return; } @@ -1259,7 +1259,7 @@ function scriptCalculateExpGain(server) { function scriptCalculatePercentMoneyHacked(server) { var difficultyMult = (100 - server.hackDifficulty) / 100; var skillMult = (Player.hacking_skill - (server.requiredHackingSkill - 1)) / Player.hacking_skill; - var percentMoneyHacked = difficultyMult * skillMult * Player.hacking_money_mult / 825; + var percentMoneyHacked = difficultyMult * skillMult * Player.hacking_money_mult / 725; if (percentMoneyHacked < 0) {return 0;} if (percentMoneyHacked > 1) {return 1;} return percentMoneyHacked; diff --git a/src/Player.js b/src/Player.js index cb9757fa4..19eda9588 100644 --- a/src/Player.js +++ b/src/Player.js @@ -243,7 +243,7 @@ PlayerObject.prototype.calculateHackingTime = function() { PlayerObject.prototype.calculatePercentMoneyHacked = function() { var difficultyMult = (100 - this.getCurrentServer().hackDifficulty) / 100; var skillMult = (this.hacking_skill - (this.getCurrentServer().requiredHackingSkill - 1)) / this.hacking_skill; - var percentMoneyHacked = difficultyMult * skillMult * this.hacking_money_mult / 825; + var percentMoneyHacked = difficultyMult * skillMult * this.hacking_money_mult / 725; console.log("Percent money hacked calculated to be: " + percentMoneyHacked); if (percentMoneyHacked < 0) {return 0;} if (percentMoneyHacked > 1) {return 1;} diff --git a/src/Script.js b/src/Script.js index 147bae1e8..14f793d87 100644 --- a/src/Script.js +++ b/src/Script.js @@ -182,6 +182,7 @@ Script.prototype.updateRamUsage = function() { var httpwormCount = numOccurrences(codeCopy, "httpworm("); var sqlinjectCount = numOccurrences(codeCopy, "sqlinject("); var runCount = numOccurrences(codeCopy, "run("); + var scpCount = numOccurrences(codeCopy, "scp("); var hasRootAccessCount = numOccurrences(codeCopy, "hasRootAccess("); var getHostnameCount = numOccurrences(codeCopy, "getHostname("); var getHackingLevelCount = numOccurrences(codeCopy, "getHackingLevel("); @@ -206,6 +207,7 @@ Script.prototype.updateRamUsage = function() { (httpwormCount * CONSTANTS.ScriptHttpwormRamCost) + (sqlinjectCount * CONSTANTS.ScriptSqlinjectRamCost) + (runCount * CONSTANTS.ScriptRunRamCost) + + (scpCount * CONSTANTS.ScriptScpRamCost) + (hasRootAccessCount * CONSTANTS.ScriptHasRootAccessRamCost) + (getHostnameCount * CONSTANTS.ScriptGetHostnameRamCost) + (getHackingLevelCount * CONSTANTS.ScriptGetHackingLevelRamCost) + diff --git a/src/Terminal.js b/src/Terminal.js index 144baa912..b96a39363 100644 --- a/src/Terminal.js +++ b/src/Terminal.js @@ -102,18 +102,28 @@ $(document).keydown(function(event) { input = input.trim(); input = input.replace(/\s\s+/g, ' '); - var allPos = determineAllPossibilitiesForTabCompletion(input); + var commandArray = input.split(" "); + var index = commandArray.length - 2; + if (index < 0) {index = 0;} + var allPos = determineAllPossibilitiesForTabCompletion(input, index); if (allPos.length == 0) {return;} - var commandArray = input.split(" "); + var arg = ""; + var command = ""; if (commandArray.length == 0) {return;} - else if (commandArray.length > 1) { + else if (commandArray.length == 2) { + command = commandArray[0]; arg = commandArray[1]; + } else if (commandArray.length == 3) { + command = commandArray[0] + " " + commandArray[1]; + arg = commandArray[2]; + } else { + command = commandArray[0]; } - tabCompletion(commandArray[0], arg, allPos); + tabCompletion(command, arg, allPos); } } }); @@ -155,7 +165,8 @@ $(document).keyup(function(e) { // a series of possible options for // allPossibilities - Array of strings containing all possibilities that the // string can complete to -function tabCompletion(command, arg, allPossibilities) { +// index - index of argument that is being "tab completed". By default is 0, the first argument +function tabCompletion(command, arg, allPossibilities, index=0) { if (!(allPossibilities.constructor === Array)) {return;} if (!containsAllStrings(allPossibilities)) {return;} @@ -191,9 +202,19 @@ function tabCompletion(command, arg, allPossibilities) { } } -function determineAllPossibilitiesForTabCompletion(input) { +function determineAllPossibilitiesForTabCompletion(input, index=0) { var allPos = []; var currServ = Player.getCurrentServer(); + + if (input.startsWith("scp ") && index == 1) { + for (var iphostname in AllServers) { + if (AllServers.hasOwnProperty(iphostname)) { + allPos.push(AllServers[iphostname].ip); + allPos.push(AllServers[iphostname].hostname); + } + } + } + if (input.startsWith("connect ") || input.startsWith("telnet ")) { //All network connections for (var i = 0; i < currServ.serversOnNetwork.length; ++i) { @@ -207,7 +228,8 @@ function determineAllPossibilitiesForTabCompletion(input) { if (input.startsWith("kill ") || input.startsWith("nano ") || input.startsWith("tail ") || input.startsWith("rm ") || - input.startsWith("mem ")) { + input.startsWith("mem ") || + (input.startsWith("scp ") && index == 0)) { //All Scripts for (var i = 0; i < currServ.scripts.length; ++i) { allPos.push(currServ.scripts[i].filename);