CODEBASE: Follow-up of #2344 (#2345)

This commit is contained in:
catloversg
2025-10-13 03:26:03 +07:00
committed by GitHub
parent 030be41df9
commit 2dfc2126df
2 changed files with 16 additions and 4 deletions
+6 -2
View File
@@ -548,13 +548,17 @@ function hack(ctx: NetscriptContext, hostname: string, manual: boolean, opts: un
let moneyDrained = server.moneyAvailable * percentHacked * threads; let moneyDrained = server.moneyAvailable * percentHacked * threads;
// Over-the-top safety checks // Over-the-top safety checks
if (moneyDrained <= 0) { if (moneyDrained < 0) {
moneyDrained = 0; moneyDrained = 0;
expGainedOnSuccess = expGainedOnFailure;
} }
if (moneyDrained > server.moneyAvailable) { if (moneyDrained > server.moneyAvailable) {
moneyDrained = server.moneyAvailable; moneyDrained = server.moneyAvailable;
} }
if (moneyDrained === 0) {
expGainedOnSuccess = expGainedOnFailure;
}
server.moneyAvailable -= moneyDrained; server.moneyAvailable -= moneyDrained;
if (server.moneyAvailable < 0) { if (server.moneyAvailable < 0) {
server.moneyAvailable = 0; server.moneyAvailable = 0;
+10 -2
View File
@@ -253,7 +253,7 @@ export class Terminal {
// Calculate whether hack was successful // Calculate whether hack was successful
const hackChance = calculateHackingChance(server, Player); const hackChance = calculateHackingChance(server, Player);
const rand = Math.random(); const rand = Math.random();
const expGainedOnSuccess = calculateHackingExpGain(server, Player); let expGainedOnSuccess = calculateHackingExpGain(server, Player);
const expGainedOnFailure = expGainedOnSuccess / 4; const expGainedOnFailure = expGainedOnSuccess / 4;
if (rand < hackChance) { if (rand < hackChance) {
// Success! // Success!
@@ -268,9 +268,17 @@ export class Terminal {
let moneyDrained = server.moneyAvailable * calculatePercentMoneyHacked(server, Player); let moneyDrained = server.moneyAvailable * calculatePercentMoneyHacked(server, Player);
// Over-the-top safety checks
if (moneyDrained < 0) { if (moneyDrained < 0) {
moneyDrained = 0; moneyDrained = 0;
} // Safety check }
if (moneyDrained > server.moneyAvailable) {
moneyDrained = server.moneyAvailable;
}
if (moneyDrained === 0) {
expGainedOnSuccess = expGainedOnFailure;
}
server.moneyAvailable -= moneyDrained; server.moneyAvailable -= moneyDrained;
if (server.moneyAvailable < 0) { if (server.moneyAvailable < 0) {