bitburner-src/src/Hacking.ts

102 lines
3.3 KiB
TypeScript
Raw Normal View History

import { BitNodeMultipliers } from "./BitNode/BitNodeMultipliers";
import { IPlayer } from "./PersonObjects/IPlayer";
import { calculateIntelligenceBonus } from "./PersonObjects/formulas/intelligence";
import { Server } from "./Server/Server";
/**
* Returns the chance the player has to successfully hack a server
*/
2021-09-09 05:47:34 +02:00
export function calculateHackingChance(server: Server, player: IPlayer): number {
2021-09-05 01:09:30 +02:00
const hackFactor = 1.75;
const difficultyMult = (100 - server.hackDifficulty) / 100;
2021-11-05 22:12:52 +01:00
const skillMult = hackFactor * player.hacking;
2021-09-05 01:09:30 +02:00
const skillChance = (skillMult - server.requiredHackingSkill) / skillMult;
const chance =
2022-07-15 00:43:33 +02:00
skillChance * difficultyMult * player.mults.hacking_chance * calculateIntelligenceBonus(player.intelligence, 1);
2021-09-05 01:09:30 +02:00
if (chance > 1) {
return 1;
}
if (chance < 0) {
return 0;
}
2021-09-05 01:09:30 +02:00
return chance;
}
/**
* Returns the amount of hacking experience the player will gain upon
* successfully hacking a server
*/
2021-09-09 05:47:34 +02:00
export function calculateHackingExpGain(server: Server, player: IPlayer): number {
2021-09-05 01:09:30 +02:00
const baseExpGain = 3;
const diffFactor = 0.3;
if (server.baseDifficulty == null) {
server.baseDifficulty = server.hackDifficulty;
}
let expGain = baseExpGain;
expGain += server.baseDifficulty * diffFactor;
2022-07-15 00:43:33 +02:00
return expGain * player.mults.hacking_exp * BitNodeMultipliers.HackExpGain;
}
/**
* 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)
*/
2021-09-09 05:47:34 +02:00
export function calculatePercentMoneyHacked(server: Server, player: IPlayer): number {
2021-09-05 01:09:30 +02:00
// Adjust if needed for balancing. This is the divisor for the final calculation
const balanceFactor = 240;
2021-09-05 01:09:30 +02:00
const difficultyMult = (100 - server.hackDifficulty) / 100;
2021-11-05 22:12:52 +01:00
const skillMult = (player.hacking - (server.requiredHackingSkill - 1)) / player.hacking;
2022-04-07 01:30:08 +02:00
const percentMoneyHacked =
2022-07-15 00:43:33 +02:00
(difficultyMult * skillMult * player.mults.hacking_money * BitNodeMultipliers.ScriptHackMoney) / balanceFactor;
2021-09-05 01:09:30 +02:00
if (percentMoneyHacked < 0) {
return 0;
}
if (percentMoneyHacked > 1) {
return 1;
}
return percentMoneyHacked;
}
/**
* Returns time it takes to complete a hack on a server, in seconds
*/
export function calculateHackingTime(server: Server, player: IPlayer): number {
2021-09-05 01:09:30 +02:00
const difficultyMult = server.requiredHackingSkill * server.hackDifficulty;
2021-09-05 01:09:30 +02:00
const baseDiff = 500;
const baseSkill = 50;
const diffFactor = 2.5;
let skillFactor = diffFactor * difficultyMult + baseDiff;
// tslint:disable-next-line
2021-11-05 22:12:52 +01:00
skillFactor /= player.hacking + baseSkill;
2021-09-05 01:09:30 +02:00
const hackTimeMultiplier = 5;
const hackingTime =
(hackTimeMultiplier * skillFactor) /
2022-07-15 00:43:33 +02:00
(player.mults.hacking_speed * calculateIntelligenceBonus(player.intelligence, 1));
2021-09-05 01:09:30 +02:00
return hackingTime;
}
/**
* Returns time it takes to complete a grow operation on a server, in seconds
*/
export function calculateGrowTime(server: Server, player: IPlayer): number {
2021-09-05 01:09:30 +02:00
const growTimeMultiplier = 3.2; // Relative to hacking time. 16/5 = 3.2
2021-09-05 01:09:30 +02:00
return growTimeMultiplier * calculateHackingTime(server, player);
}
/**
* Returns time it takes to complete a weaken operation on a server, in seconds
*/
export function calculateWeakenTime(server: Server, player: IPlayer): number {
2021-09-05 01:09:30 +02:00
const weakenTimeMultiplier = 4; // Relative to hacking time
2021-09-05 01:09:30 +02:00
return weakenTimeMultiplier * calculateHackingTime(server, player);
}