mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-18 05:33:54 +01:00
BUGFIX: clamp Hackchance to prevent infinity / infinity (#1349)
This commit is contained in:
parent
18ae6ce215
commit
c42d4143c9
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user