mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-16 06:18:42 +02:00
BUGFIX: Grow log shows invalid values in edge cases (#1872)
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -33,19 +33,23 @@ export function scriptCalculateOfflineProduction(runningScript: RunningScript):
|
||||
if (runningScript.dataMap[hostname][2] == 0 || runningScript.dataMap[hostname][2] == null) {
|
||||
continue;
|
||||
}
|
||||
const serv = GetServer(hostname);
|
||||
if (serv == null) {
|
||||
const server = GetServer(hostname);
|
||||
if (server == null) {
|
||||
continue;
|
||||
}
|
||||
const timesGrown = Math.round(
|
||||
((0.5 * runningScript.dataMap[hostname][2]) / runningScript.onlineRunningTime) * timePassed,
|
||||
);
|
||||
runningScript.log(`Called on ${serv.hostname} ${timesGrown} times while offline`);
|
||||
runningScript.log(`Called on ${server.hostname} ${timesGrown} times while offline`);
|
||||
const host = GetServer(runningScript.server);
|
||||
if (host === null) throw new Error("getServer of null key?");
|
||||
if (!(serv instanceof Server)) throw new Error("trying to grow a non-normal server");
|
||||
const growth = processSingleServerGrowth(serv, timesGrown, host.cpuCores);
|
||||
runningScript.log(`'${serv.hostname}' grown by ${formatPercent(growth - 1, 6)} while offline`);
|
||||
if (host === null) {
|
||||
throw new Error("getServer of null key?");
|
||||
}
|
||||
if (!(server instanceof Server)) {
|
||||
throw new Error("trying to grow a non-normal server");
|
||||
}
|
||||
const growth = processSingleServerGrowth(server, timesGrown, host.cpuCores);
|
||||
runningScript.log(`'${server.hostname}' grown by ${formatPercent(growth - 1, 6)} while offline`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -188,6 +188,14 @@ export function processSingleServerGrowth(server: Server, threads: number, cores
|
||||
usedCycles = Math.min(Math.max(0, Math.ceil(usedCycles)), threads);
|
||||
server.fortify(2 * ServerConstants.ServerFortifyAmount * usedCycles);
|
||||
}
|
||||
// Prevent returning NaN. This happens when server.moneyMax is 0.
|
||||
if (server.moneyAvailable === 0 && oldMoneyAvailable === 0) {
|
||||
return 1;
|
||||
}
|
||||
// Prevent returning Infinity. If server's money before growing is 0, we "pretend" that it's 1.
|
||||
if (oldMoneyAvailable === 0) {
|
||||
return server.moneyAvailable;
|
||||
}
|
||||
return server.moneyAvailable / oldMoneyAvailable;
|
||||
}
|
||||
|
||||
|
||||
@@ -310,12 +310,12 @@ export class Terminal {
|
||||
if (!(server instanceof Server)) throw new Error("server should be normal server");
|
||||
const expGain = calculateHackingExpGain(server, Player);
|
||||
const oldSec = server.hackDifficulty;
|
||||
const growth = processSingleServerGrowth(server, 25, server.cpuCores) - 1;
|
||||
const growth = processSingleServerGrowth(server, 25, server.cpuCores);
|
||||
const newSec = server.hackDifficulty;
|
||||
|
||||
Player.gainHackingExp(expGain);
|
||||
this.print(
|
||||
`Available money on '${server.hostname}' grown by ${formatPercent(growth, 6)}. Gained ${formatExp(
|
||||
`Available money on '${server.hostname}' grown by ${formatPercent(growth - 1, 6)}. Gained ${formatExp(
|
||||
expGain,
|
||||
)} hacking exp.`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user