Correction for ns.hack pro-rated security increase

corrects an issue where hacking with more threads than was needed to hack all remaining money from a server with availMoney < maxMoney would have irregular results on security increase.

fix for issue #2307
discord thread: https://discord.com/channels/415207508303544321/931980343970513026/931980345329479750
This commit is contained in:
zeddrak
2022-01-15 11:33:46 -08:00
committed by GitHub
parent 0a1e1c548b
commit bf48741792

View File

@ -352,7 +352,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
if (rand < hackChance) {
// Success!
const percentHacked = calculatePercentMoneyHacked(server, Player);
let maxThreadNeeded = Math.ceil((1 / percentHacked) * (server.moneyAvailable / server.moneyMax));
let maxThreadNeeded = Math.ceil(1 / percentHacked);
if (isNaN(maxThreadNeeded)) {
// Server has a 'max money' of 0 (probably). We'll set this to an arbitrarily large value
maxThreadNeeded = 1e6;