BUGFIX: clamp Hackchance to prevent infinity / infinity (#1349)

This commit is contained in:
Caldwell 2024-06-05 03:19:41 +02:00 committed by GitHub
parent 18ae6ce215
commit c42d4143c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -2,6 +2,7 @@ import { currentNodeMults } from "./BitNode/BitNodeMultipliers";
import { Person as IPerson } from "@nsdefs";
import { calculateIntelligenceBonus } from "./PersonObjects/formulas/intelligence";
import { Server as IServer } from "@nsdefs";
import { clampNumber } from "./utils/helpers/clampNumber";
/** Returns the chance the person has to successfully hack a server */
export function calculateHackingChance(server: IServer, person: IPerson): number {
@ -11,14 +12,14 @@ export function calculateHackingChance(server: IServer, person: IPerson): number
if (!server.hasAdminRights || hackDifficulty >= 100) return 0;
const hackFactor = 1.75;
const difficultyMult = (100 - hackDifficulty) / 100;
const skillMult = hackFactor * person.skills.hacking;
const skillMult = clampNumber(hackFactor * person.skills.hacking, 1);
const skillChance = (skillMult - requiredHackingSkill) / skillMult;
const chance =
skillChance *
difficultyMult *
person.mults.hacking_chance *
calculateIntelligenceBonus(person.skills.intelligence, 1);
return Math.min(1, Math.max(chance, 0));
return clampNumber(chance, 0, 1);
}
/**