weaken message

This commit is contained in:
Olivier Gagnon 2021-12-20 14:13:56 -05:00
parent 4ec021c8f0
commit ddd0eaaf5c
2 changed files with 20 additions and 2 deletions

@ -212,13 +212,18 @@ export class Terminal implements ITerminal {
player.gainHackingExp(expGainedOnSuccess); player.gainHackingExp(expGainedOnSuccess);
player.gainIntelligenceExp(expGainedOnSuccess / CONSTANTS.IntelligenceTerminalHackBaseExpGain); player.gainIntelligenceExp(expGainedOnSuccess / CONSTANTS.IntelligenceTerminalHackBaseExpGain);
const oldSec = server.hackDifficulty;
server.fortify(CONSTANTS.ServerFortifyAmount); server.fortify(CONSTANTS.ServerFortifyAmount);
const newSec = server.hackDifficulty;
this.print( this.print(
`Hack successful! Gained ${numeralWrapper.formatMoney(moneyGained)} and ${numeralWrapper.formatExp( `Hack successful! Gained ${numeralWrapper.formatMoney(moneyGained)} and ${numeralWrapper.formatExp(
expGainedOnSuccess, expGainedOnSuccess,
)} hacking exp`, )} hacking exp`,
); );
this.print(
`Security increased from ${numeralWrapper.formatSecurity(oldSec)} to ${numeralWrapper.formatSecurity(newSec)}`,
);
} else { } else {
// Failure // Failure
player.gainHackingExp(expGainedOnFailure); player.gainHackingExp(expGainedOnFailure);
@ -237,13 +242,18 @@ export class Terminal implements ITerminal {
} }
if (!(server instanceof Server)) throw new Error("server should be normal server"); if (!(server instanceof Server)) throw new Error("server should be normal server");
const expGain = calculateHackingExpGain(server, player); const expGain = calculateHackingExpGain(server, player);
const oldSec = server.hackDifficulty;
const growth = processSingleServerGrowth(server, 25, player, server.cpuCores) - 1; const growth = processSingleServerGrowth(server, 25, player, server.cpuCores) - 1;
const newSec = server.hackDifficulty;
this.print( this.print(
`Available money on '${server.hostname}' grown by ${numeralWrapper.formatPercentage( `Available money on '${server.hostname}' grown by ${numeralWrapper.formatPercentage(
growth, growth,
6, 6,
)}. Gained ${numeralWrapper.formatExp(expGain)} hacking exp.`, )}. Gained ${numeralWrapper.formatExp(expGain)} hacking exp.`,
); );
this.print(
`Security increased from ${numeralWrapper.formatSecurity(oldSec)} to ${numeralWrapper.formatSecurity(newSec)}`,
);
} }
finishWeaken(player: IPlayer, cancelled = false): void { finishWeaken(player: IPlayer, cancelled = false): void {
@ -255,10 +265,14 @@ export class Terminal implements ITerminal {
} }
if (!(server instanceof Server)) throw new Error("server should be normal server"); if (!(server instanceof Server)) throw new Error("server should be normal server");
const expGain = calculateHackingExpGain(server, player); const expGain = calculateHackingExpGain(server, player);
const oldSec = server.hackDifficulty;
server.weaken(CONSTANTS.ServerWeakenAmount); server.weaken(CONSTANTS.ServerWeakenAmount);
const newSec = server.hackDifficulty;
this.print( this.print(
`'${server.hostname}' security level weakened to ${server.hackDifficulty.toFixed(3)} ` + `Security decreased from ${numeralWrapper.formatSecurity(oldSec)} to ${numeralWrapper.formatSecurity(
`and Gained ${numeralWrapper.formatExp(expGain)} hacking exp.`, newSec,
)} (min: ${numeralWrapper.formatSecurity(server.minDifficulty)})` +
` and Gained ${numeralWrapper.formatExp(expGain)} hacking exp.`,
); );
} }

@ -105,6 +105,10 @@ class NumeralFormatter {
return this.format(n, "0,0"); return this.format(n, "0,0");
} }
formatSecurity(n: number): string {
return n.toFixed(3);
}
formatRAM(n: number): string { formatRAM(n: number): string {
if (n < 1e3) return this.format(n, "0.00") + "GB"; if (n < 1e3) return this.format(n, "0.00") + "GB";
if (n < 1e6) return this.format(n / 1e3, "0.00") + "TB"; if (n < 1e6) return this.format(n / 1e3, "0.00") + "TB";