From 4a17c5a49ce0bd1af5e2d2602e70207305c769b1 Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Thu, 12 Jul 2018 21:16:24 -0400 Subject: [PATCH] limit fortifying to the amount of hck thread you needed to drain the server --- src/NetscriptFunctions.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/NetscriptFunctions.js b/src/NetscriptFunctions.js index 39de69c76..8f909be67 100644 --- a/src/NetscriptFunctions.js +++ b/src/NetscriptFunctions.js @@ -239,8 +239,9 @@ function NetscriptFunctions(workerScript) { var expGainedOnSuccess = scriptCalculateExpGain(server) * threads; var expGainedOnFailure = (expGainedOnSuccess / 4); if (rand < hackChance) { //Success! - var moneyGained = scriptCalculatePercentMoneyHacked(server); - moneyGained = Math.floor(server.moneyAvailable * moneyGained) * threads; + const percentHacked = scriptCalculatePercentMoneyHacked(server); + const maxThreadNeeded = Math.ceil(1/percentHacked*(server.moneyAvailable/server.moneyMax)) + let moneyGained = Math.floor(server.moneyAvailable * percentHacked) * threads; //Over-the-top safety checks if (moneyGained <= 0) { @@ -260,7 +261,7 @@ function NetscriptFunctions(workerScript) { if (workerScript.disableLogs.ALL == null && workerScript.disableLogs.hack == null) { workerScript.scriptRef.log("Script SUCCESSFULLY hacked " + server.hostname + " for $" + formatNumber(moneyGained, 2) + " and " + formatNumber(expGainedOnSuccess, 4) + " exp (t=" + threads + ")"); } - server.fortify(CONSTANTS.ServerFortifyAmount * threads); + server.fortify(CONSTANTS.ServerFortifyAmount * Math.min(threads, maxThreadNeeded)); return Promise.resolve(moneyGained); } else { //Player only gains 25% exp for failure?