Skip to content

Commit

Permalink
BUGFIX: clamp Hackchance to prevent infinity / infinity (bitburner-of…
Browse files Browse the repository at this point in the history
  • Loading branch information
Caldwell-74 authored and antoinedube committed Aug 5, 2024
1 parent f63c221 commit 924bdc4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Hacking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit 924bdc4

Please sign in to comment.