BUGFIX: Grow log shows invalid values in edge cases (#1872)

This commit is contained in:
catloversg
2025-01-09 09:48:45 +07:00
committed by GitHub
parent 5b6380a5c3
commit 8c19165323
4 changed files with 25 additions and 14 deletions
+4 -5
View File
@@ -294,16 +294,15 @@ export const ns: InternalAPI<NSFull> = {
if (host === null) {
throw helpers.errorMessage(ctx, `Cannot find host of WorkerScript. Hostname: ${ctx.workerScript.hostname}.`);
}
const moneyBefore = server.moneyAvailable <= 0 ? 1 : server.moneyAvailable;
processSingleServerGrowth(server, threads, host.cpuCores);
const moneyBefore = server.moneyAvailable;
const growth = processSingleServerGrowth(server, threads, host.cpuCores);
const moneyAfter = server.moneyAvailable;
ctx.workerScript.scriptRef.recordGrow(server.hostname, threads);
const expGain = calculateHackingExpGain(server, Player) * threads;
const logGrowPercent = moneyAfter / moneyBefore - 1;
helpers.log(
ctx,
() =>
`Available money on '${server.hostname}' grown by ${formatPercent(logGrowPercent, 6)}. Gained ${formatExp(
`Available money on '${server.hostname}' grown by ${formatPercent(growth - 1, 6)}. Gained ${formatExp(
expGain,
)} hacking exp (t=${formatThreads(threads)}).`,
);
@@ -312,7 +311,7 @@ export const ns: InternalAPI<NSFull> = {
if (stock) {
influenceStockThroughServerGrow(server, moneyAfter - moneyBefore);
}
return Promise.resolve(moneyAfter / moneyBefore);
return Promise.resolve(server.moneyMax === 0 ? 0 : growth);
});
},
growthAnalyze: