2023-06-16 23:52:42 +02:00
|
|
|
import { currentNodeMults } from "./BitNode/BitNodeMultipliers";
|
2022-12-30 02:28:53 +01:00
|
|
|
import { Person as IPerson } from "@nsdefs";
|
2021-03-31 06:45:21 +02:00
|
|
|
import { calculateIntelligenceBonus } from "./PersonObjects/formulas/intelligence";
|
2023-04-11 21:12:55 +02:00
|
|
|
import { Server as IServer } from "@nsdefs";
|
2024-06-05 03:19:41 +02:00
|
|
|
import { clampNumber } from "./utils/helpers/clampNumber";
|
2018-08-30 19:00:38 +02:00
|
|
|
|
2022-10-04 12:40:10 +02:00
|
|
|
/** Returns the chance the person has to successfully hack a server */
|
2023-04-11 21:12:55 +02:00
|
|
|
export function calculateHackingChance(server: IServer, person: IPerson): number {
|
|
|
|
const hackDifficulty = server.hackDifficulty ?? 100;
|
|
|
|
const requiredHackingSkill = server.requiredHackingSkill ?? 1e9;
|
|
|
|
// Unrooted or unhackable server
|
|
|
|
if (!server.hasAdminRights || hackDifficulty >= 100) return 0;
|
2021-09-05 01:09:30 +02:00
|
|
|
const hackFactor = 1.75;
|
2023-04-11 21:12:55 +02:00
|
|
|
const difficultyMult = (100 - hackDifficulty) / 100;
|
2024-06-05 03:19:41 +02:00
|
|
|
const skillMult = clampNumber(hackFactor * person.skills.hacking, 1);
|
2023-04-11 21:12:55 +02:00
|
|
|
const skillChance = (skillMult - requiredHackingSkill) / skillMult;
|
2021-09-05 01:09:30 +02:00
|
|
|
const chance =
|
2022-07-27 05:54:17 +02:00
|
|
|
skillChance *
|
|
|
|
difficultyMult *
|
2022-09-06 15:07:12 +02:00
|
|
|
person.mults.hacking_chance *
|
|
|
|
calculateIntelligenceBonus(person.skills.intelligence, 1);
|
2024-06-05 03:19:41 +02:00
|
|
|
return clampNumber(chance, 0, 1);
|
2018-08-30 19:00:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-06 15:07:12 +02:00
|
|
|
* Returns the amount of hacking experience the person will gain upon
|
2018-08-30 19:00:38 +02:00
|
|
|
* successfully hacking a server
|
|
|
|
*/
|
2023-04-11 21:12:55 +02:00
|
|
|
export function calculateHackingExpGain(server: IServer, person: IPerson): number {
|
|
|
|
const baseDifficulty = server.baseDifficulty;
|
|
|
|
if (!baseDifficulty) return 0;
|
2021-09-05 01:09:30 +02:00
|
|
|
const baseExpGain = 3;
|
|
|
|
const diffFactor = 0.3;
|
|
|
|
let expGain = baseExpGain;
|
2023-04-11 21:12:55 +02:00
|
|
|
expGain += baseDifficulty * diffFactor;
|
2023-06-16 23:52:42 +02:00
|
|
|
return expGain * person.mults.hacking_exp * currentNodeMults.HackExpGain;
|
2018-08-30 19:00:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the percentage of money that will be stolen from a server if
|
|
|
|
* it is successfully hacked (returns the decimal form, not the actual percent value)
|
|
|
|
*/
|
2023-04-11 21:12:55 +02:00
|
|
|
export function calculatePercentMoneyHacked(server: IServer, person: IPerson): number {
|
|
|
|
const hackDifficulty = server.hackDifficulty ?? 100;
|
|
|
|
if (hackDifficulty >= 100) return 0;
|
|
|
|
const requiredHackingSkill = server.requiredHackingSkill ?? 1e9;
|
2021-09-05 01:09:30 +02:00
|
|
|
// Adjust if needed for balancing. This is the divisor for the final calculation
|
|
|
|
const balanceFactor = 240;
|
2018-08-30 19:00:38 +02:00
|
|
|
|
2023-04-11 21:12:55 +02:00
|
|
|
const difficultyMult = (100 - hackDifficulty) / 100;
|
|
|
|
const skillMult = (person.skills.hacking - (requiredHackingSkill - 1)) / person.skills.hacking;
|
2022-04-07 01:30:08 +02:00
|
|
|
const percentMoneyHacked =
|
2023-06-16 23:52:42 +02:00
|
|
|
(difficultyMult * skillMult * person.mults.hacking_money * currentNodeMults.ScriptHackMoney) / balanceFactor;
|
2018-08-30 19:00:38 +02:00
|
|
|
|
2023-04-11 21:12:55 +02:00
|
|
|
return Math.min(1, Math.max(percentMoneyHacked, 0));
|
2018-08-30 19:00:38 +02:00
|
|
|
}
|
|
|
|
|
2022-10-04 12:40:10 +02:00
|
|
|
/** Returns time it takes to complete a hack on a server, in seconds */
|
2023-04-11 21:12:55 +02:00
|
|
|
export function calculateHackingTime(server: IServer, person: IPerson): number {
|
2023-06-02 18:32:06 +02:00
|
|
|
const { hackDifficulty, requiredHackingSkill } = server;
|
|
|
|
if (typeof hackDifficulty !== "number" || typeof requiredHackingSkill !== "number") return Infinity;
|
2023-04-11 21:12:55 +02:00
|
|
|
const difficultyMult = requiredHackingSkill * hackDifficulty;
|
2018-08-30 19:00:38 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
const baseDiff = 500;
|
|
|
|
const baseSkill = 50;
|
|
|
|
const diffFactor = 2.5;
|
|
|
|
let skillFactor = diffFactor * difficultyMult + baseDiff;
|
2022-09-06 15:07:12 +02:00
|
|
|
skillFactor /= person.skills.hacking + baseSkill;
|
2018-08-30 19:00:38 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
const hackTimeMultiplier = 5;
|
|
|
|
const hackingTime =
|
|
|
|
(hackTimeMultiplier * skillFactor) /
|
2023-12-26 17:45:27 +01:00
|
|
|
(person.mults.hacking_speed *
|
|
|
|
currentNodeMults.HackingSpeedMultiplier *
|
|
|
|
calculateIntelligenceBonus(person.skills.intelligence, 1));
|
2018-08-30 19:00:38 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
return hackingTime;
|
2018-08-30 19:00:38 +02:00
|
|
|
}
|
|
|
|
|
2022-10-04 12:40:10 +02:00
|
|
|
/** Returns time it takes to complete a grow operation on a server, in seconds */
|
2023-04-11 21:12:55 +02:00
|
|
|
export function calculateGrowTime(server: IServer, person: IPerson): number {
|
2021-09-05 01:09:30 +02:00
|
|
|
const growTimeMultiplier = 3.2; // Relative to hacking time. 16/5 = 3.2
|
2018-08-30 19:00:38 +02:00
|
|
|
|
2022-09-06 15:07:12 +02:00
|
|
|
return growTimeMultiplier * calculateHackingTime(server, person);
|
2018-08-30 19:00:38 +02:00
|
|
|
}
|
|
|
|
|
2022-10-04 12:40:10 +02:00
|
|
|
/** Returns time it takes to complete a weaken operation on a server, in seconds */
|
2023-04-11 21:12:55 +02:00
|
|
|
export function calculateWeakenTime(server: IServer, person: IPerson): number {
|
2021-09-05 01:09:30 +02:00
|
|
|
const weakenTimeMultiplier = 4; // Relative to hacking time
|
2018-08-30 19:00:38 +02:00
|
|
|
|
2022-09-06 15:07:12 +02:00
|
|
|
return weakenTimeMultiplier * calculateHackingTime(server, person);
|
2018-08-30 19:00:38 +02:00
|
|
|
}
|