From f18b8d58faa6508a5b99ba5240e61d6176ebefa5 Mon Sep 17 00:00:00 2001 From: Daniel Xie Date: Thu, 29 Jun 2017 09:16:32 -0500 Subject: [PATCH] scan() now takes in 1 argument representing the server to scan --- src/Constants.js | 7 ++++++- src/NetscriptEvaluator.js | 33 ++++++++++++++++++++------------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/Constants.js b/src/Constants.js index 43024237d..31e70c4f4 100644 --- a/src/Constants.js +++ b/src/Constants.js @@ -1,5 +1,5 @@ CONSTANTS = { - Version: "0.23.0", + Version: "0.23.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 @@ -94,6 +94,9 @@ CONSTANTS = { //Infiltration constants InfiltrationBribeBaseAmount: 100000, //Amount per clearance level + + HospitalCostPerHp: 25000, + MillisecondsPer20Hours: 72000000, GameCyclesPer20Hours: 72000000 / 200, @@ -857,6 +860,8 @@ CONSTANTS = { "-You can now see what an Augmentation does and its price even while its locked

", LatestUpdate: + "v0.23.1
" + + "-scan() Netscript function now takes a single argument representing the server from which to scan.

" + "v0.23.0
" + "-You can now purchase multiple Augmentations in a run. When you purchase an Augmentation you will lose money equal to the price " + "and then the cost of purchasing another Augmentation during this run will be increased by 75%. You do not gain the benefits " + diff --git a/src/NetscriptEvaluator.js b/src/NetscriptEvaluator.js index a939af495..c72917736 100644 --- a/src/NetscriptEvaluator.js +++ b/src/NetscriptEvaluator.js @@ -204,20 +204,27 @@ function evaluate(exp, workerScript) { }); } else if (exp.func.value == "scan") { - if (exp.args.length != 0) { - return reject(makeRuntimeRejectMsg(workerScript, "scan() call has incorrect number of arguments. Takes 0 arguments")); + if (exp.args.length != 1) { + return reject(makeRuntimeRejectMsg(workerScript, "scan() call has incorrect number of arguments. Takes 1 argument")); } - var currServ = getServer(workerScript.serverIp); - if (currServ == null) { - return reject(makeRuntimeRejectMsg(workerScript, "Could not find server ip for this script. This is a bug please contact game developer")); - } - var res = []; - for (var i = 0; i < currServ.serversOnNetwork.length; ++i) { - var thisServ = getServer(currServ.serversOnNetwork[i]); - if (thisServ == null) {continue;} - res.push({type:"str", value: thisServ.hostname}); - } - resolve(res); + + var ipPromise = evaluate(exp.args[0], workerScript); + ipPromise.then(function(ip) { + var server = getServer(ip); + if (server == null) { + workerScript.scriptRef.log("scan() failed. Invalid IP or hostname passed in: " + ip); + return reject(makeRuntimeRejectMsg(workerScript, "Invalid IP or hostname passed into scan() command"));; + } + var res = []; + for (var i = 0; i < server.serversOnNetwork.length; ++i) { + var thisServ = getServer(server.serversOnNetwork[i]); + if (thisServ == null) {continue;} + res.push({type:"str", value: thisServ.hostname}); + } + resolve(res); + }, function(e) { + reject(e); + }); } else if (exp.func.value == "nuke") { var p = netscriptRunProgram(exp, workerScript, Programs.NukeProgram); p.then(function(res) {