mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-18 13:43:49 +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 { Person as IPerson } from "@nsdefs";
|
||||||
import { calculateIntelligenceBonus } from "./PersonObjects/formulas/intelligence";
|
import { calculateIntelligenceBonus } from "./PersonObjects/formulas/intelligence";
|
||||||
import { Server as IServer } from "@nsdefs";
|
import { Server as IServer } from "@nsdefs";
|
||||||
|
import { clampNumber } from "./utils/helpers/clampNumber";
|
||||||
|
|
||||||
/** Returns the chance the person has to successfully hack a server */
|
/** Returns the chance the person has to successfully hack a server */
|
||||||
export function calculateHackingChance(server: IServer, person: IPerson): number {
|
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;
|
if (!server.hasAdminRights || hackDifficulty >= 100) return 0;
|
||||||
const hackFactor = 1.75;
|
const hackFactor = 1.75;
|
||||||
const difficultyMult = (100 - hackDifficulty) / 100;
|
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 skillChance = (skillMult - requiredHackingSkill) / skillMult;
|
||||||
const chance =
|
const chance =
|
||||||
skillChance *
|
skillChance *
|
||||||
difficultyMult *
|
difficultyMult *
|
||||||
person.mults.hacking_chance *
|
person.mults.hacking_chance *
|
||||||
calculateIntelligenceBonus(person.skills.intelligence, 1);
|
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