diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index 475e0a5be..1d27fbbf7 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -36,6 +36,7 @@ import { processSingleServerGrowth, safelyCreateUniqueServer, getCoreBonus, + getWeakenEffect, } from "./Server/ServerHelpers"; import { getPurchasedServerUpgradeCost, @@ -380,9 +381,7 @@ export const ns: InternalAPI = { 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 = { 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 = { (_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; diff --git a/src/Script/ScriptHelpers.ts b/src/Script/ScriptHelpers.ts index 5d0e971de..d182f4290 100644 --- a/src/Script/ScriptHelpers.ts +++ b/src/Script/ScriptHelpers.ts @@ -3,14 +3,13 @@ import { Player } from "@player"; import { BaseServer } from "../Server/BaseServer"; import { Server } from "../Server/Server"; import { RunningScript } from "./RunningScript"; -import { processSingleServerGrowth } from "../Server/ServerHelpers"; +import { getWeakenEffect, processSingleServerGrowth } from "../Server/ServerHelpers"; import { GetServer } from "../Server/AllServers"; import { formatPercent } from "../ui/formatNumber"; import { workerScripts } from "../Netscript/WorkerScripts"; import { scriptKey } from "../utils/helpers/scriptKey"; import type { ScriptFilePath } from "../Paths/ScriptFilePath"; -import { ServerConstants } from "../Server/data/Constants"; export function scriptCalculateOfflineProduction(runningScript: RunningScript): void { //The Player object stores the last update time from when we were online @@ -83,8 +82,8 @@ export function scriptCalculateOfflineProduction(runningScript: RunningScript): ((0.5 * runningScript.dataMap[hostname][3]) / runningScript.onlineRunningTime) * timePassed, ); runningScript.log(`Called weaken() on ${serv.hostname} ${timesWeakened} times while offline`); - const coreBonus = 1 + (host.cpuCores - 1) / 16; - serv.weaken(ServerConstants.ServerWeakenAmount * timesWeakened * coreBonus); + const weakenAmount = getWeakenEffect(runningScript.threads, host.cpuCores); + serv.weaken(weakenAmount * timesWeakened); } } } diff --git a/src/Server/Server.ts b/src/Server/Server.ts index 36702c8ba..510de3fed 100644 --- a/src/Server/Server.ts +++ b/src/Server/Server.ts @@ -141,7 +141,7 @@ export class Server extends BaseServer { /** Lowers the server's security level (difficulty) by the specified amount) */ weaken(amt: number): void { - this.hackDifficulty -= amt * currentNodeMults.ServerWeakenRate; + this.hackDifficulty -= amt; this.capDifficulty(); } diff --git a/src/Server/ServerHelpers.ts b/src/Server/ServerHelpers.ts index 05796e8ae..90a2711d6 100644 --- a/src/Server/ServerHelpers.ts +++ b/src/Server/ServerHelpers.ts @@ -2,7 +2,7 @@ import { GetServer, createUniqueRandomIp, ipExists } from "./AllServers"; import { Server, IConstructorParams } from "./Server"; import { BaseServer } from "./BaseServer"; import { calculateServerGrowth, calculateServerGrowthLog } from "./formulas/grow"; - +import { currentNodeMults } from "../BitNode/BitNodeMultipliers"; import { ServerConstants } from "./data/Constants"; import { Player } from "@player"; import { CompletedProgramName, LiteratureName } from "@enums"; @@ -258,3 +258,8 @@ export function getCoreBonus(cores = 1): number { const coreBonus = 1 + (cores - 1) / 16; return coreBonus; } + +export function getWeakenEffect(threads: number, cores: number): number { + const coreBonus = getCoreBonus(cores); + return ServerConstants.ServerWeakenAmount * threads * coreBonus * currentNodeMults.ServerWeakenRate; +} diff --git a/src/Terminal/Terminal.ts b/src/Terminal/Terminal.ts index 0c8498a13..d37411fb0 100644 --- a/src/Terminal/Terminal.ts +++ b/src/Terminal/Terminal.ts @@ -17,7 +17,7 @@ import { GetServer } from "../Server/AllServers"; import { checkIfConnectedToDarkweb } from "../DarkWeb/DarkWeb"; import { iTutorialNextStep, iTutorialSteps, ITutorial } from "../InteractiveTutorial"; -import { processSingleServerGrowth } from "../Server/ServerHelpers"; +import { processSingleServerGrowth, getWeakenEffect } from "../Server/ServerHelpers"; import { parseCommand, parseCommands } from "./Parser"; import { SpecialServers } from "../Server/data/SpecialServers"; import { Settings } from "../Settings/Settings"; @@ -280,14 +280,16 @@ export class Terminal { if (!(server instanceof Server)) throw new Error("server should be normal server"); const expGain = calculateHackingExpGain(server, Player); const oldSec = server.hackDifficulty; - server.weaken(ServerConstants.ServerWeakenAmount); + const weakenAmt = getWeakenEffect(1, server.cpuCores); + server.weaken(weakenAmt); const newSec = server.hackDifficulty; Player.gainHackingExp(expGain); this.print( - `Security decreased on '${server.hostname}' from ${formatSecurity(oldSec)} to ${formatSecurity( - newSec, - )} (min: ${formatSecurity(server.minDifficulty)})` + ` and Gained ${formatExp(expGain)} hacking exp.`, + `Security decreased on '${server.hostname}' by ${formatSecurity(weakenAmt)} from ${formatSecurity( + oldSec, + )} to ${formatSecurity(newSec)} (min: ${formatSecurity(server.minDifficulty)})` + + ` and Gained ${formatExp(expGain)} hacking exp.`, ); }