Fixed bug where hacking special servers w/ no money would result in NaN because of a '0 / 0' in fortify() calculation

This commit is contained in:
danielyxie
2018-07-25 15:58:36 -05:00
parent a27ecca7bf
commit 47134a9640
3 changed files with 9 additions and 2 deletions
+5 -1
View File
@@ -298,7 +298,11 @@ function NetscriptFunctions(workerScript) {
var expGainedOnFailure = (expGainedOnSuccess / 4);
if (rand < hackChance) { //Success!
const percentHacked = scriptCalculatePercentMoneyHacked(server);
const maxThreadNeeded = Math.ceil(1/percentHacked*(server.moneyAvailable/server.moneyMax))
let maxThreadNeeded = Math.ceil(1/percentHacked*(server.moneyAvailable/server.moneyMax));
if (isNaN(maxThreadNeeded)) {
maxThreadNeeded = 1e6; //Server has a 'max money' of 0 (probably)
}
let moneyGained = Math.floor(server.moneyAvailable * percentHacked) * threads;
//Over-the-top safety checks