MISC: refactor weaken effect calculation (#1076)

so far we calculate the effect of weaken in three +1 places
ns.weaken
ns.weakenAnalyze
terminal weaken

and server.weaken where the bn mult is applied

i extracted the logic into a new netscript helper function getWeakenEffect
this gives us one place if we want to change the formula

a side effect i added the server.cpuCores to the terminal weaken to future proof it if the npc server core pr (#963) is merged
This commit is contained in:
Caldwell
2024-02-17 02:18:16 +01:00
committed by GitHub
parent 93b9a10e41
commit 8c8af38a3a
5 changed files with 21 additions and 17 deletions
+4 -6
View File
@@ -36,6 +36,7 @@ import {
processSingleServerGrowth,
safelyCreateUniqueServer,
getCoreBonus,
getWeakenEffect,
} from "./Server/ServerHelpers";
import {
getPurchasedServerUpgradeCost,
@@ -380,9 +381,7 @@ export const ns: InternalAPI<NSFull> = {
helpers.log(ctx, () => "Server is null, did it die?");
return Promise.resolve(0);
}
const cores = host.cpuCores;
const coreBonus = getCoreBonus(cores);
const weakenAmt = ServerConstants.ServerWeakenAmount * threads * coreBonus;
const weakenAmt = getWeakenEffect(threads, host.cpuCores);
server.weaken(weakenAmt);
ctx.workerScript.scriptRef.recordWeaken(server.hostname, threads);
const expGain = calculateHackingExpGain(server, Player) * threads;
@@ -396,7 +395,7 @@ export const ns: InternalAPI<NSFull> = {
ctx.workerScript.scriptRef.onlineExpGained += expGain;
Player.gainHackingExp(expGain);
// Account for hidden multiplier in Server.weaken()
return Promise.resolve(weakenAmt * currentNodeMults.ServerWeakenRate);
return Promise.resolve(weakenAmt);
});
},
weakenAnalyze:
@@ -404,8 +403,7 @@ export const ns: InternalAPI<NSFull> = {
(_threads, _cores = 1) => {
const threads = helpers.number(ctx, "threads", _threads);
const cores = helpers.number(ctx, "cores", _cores);
const coreBonus = getCoreBonus(cores);
return ServerConstants.ServerWeakenAmount * threads * coreBonus * currentNodeMults.ServerWeakenRate;
return getWeakenEffect(threads, cores);
},
share: (ctx) => () => {
const cores = helpers.getServer(ctx, ctx.workerScript.hostname).cpuCores;