From 209055423865d7829b72862489e083c9f83e61dc Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Thu, 5 Jul 2018 23:15:01 -0400 Subject: [PATCH] fixed ramUsed wrong calculation --- src/NetscriptWorker.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/NetscriptWorker.js b/src/NetscriptWorker.js index e93f8b717..45f51d06e 100644 --- a/src/NetscriptWorker.js +++ b/src/NetscriptWorker.js @@ -164,8 +164,17 @@ function runScriptsLoop() { var ip = workerScripts[i].serverIp; var name = workerScripts[i].name; - //Free RAM - AllServers[ip].ramUsed -= workerScripts[i].ramUsage; + //recalculate ram used + AllServers[ip].ramUsed = 0; + for(let j = 0; j < workerScripts.length; j++) { + if(workerScripts[j].serverIp !== ip) { + continue + } + if(j === i) { // not this one + continue + } + AllServers[ip].ramUsed += workerScripts[j].ramUsage; + } //Delete script from Active Scripts deleteActiveScriptsItem(workerScripts[i]);