2019-01-15 14:11:14 +01:00
|
|
|
import { BitNodeMultipliers } from "./BitNode/BitNodeMultipliers";
|
2022-09-20 07:57:46 +02:00
|
|
|
import { Person } from "./PersonObjects/Person";
|
2021-03-31 06:45:21 +02:00
|
|
|
import { calculateIntelligenceBonus } from "./PersonObjects/formulas/intelligence";
|
2019-03-05 02:40:28 +01:00
|
|
|
import { Server } from "./Server/Server";
|
2018-08-30 19:00:38 +02:00
|
|
|
|
|
|
|
/**
|
2022-09-06 15:07:12 +02:00
|
|
|
* Returns the chance the person has to successfully hack a server
|
2018-08-30 19:00:38 +02:00
|
|
|
*/
|
2022-09-20 07:57:46 +02:00
|
|
|
export function calculateHackingChance(server: Server, person: Person): number {
|
2021-09-05 01:09:30 +02:00
|
|
|
const hackFactor = 1.75;
|
|
|
|
const difficultyMult = (100 - server.hackDifficulty) / 100;
|
2022-09-06 15:07:12 +02:00
|
|
|
const skillMult = hackFactor * person.skills.hacking;
|
2021-09-05 01:09:30 +02:00
|
|
|
const skillChance = (skillMult - server.requiredHackingSkill) / skillMult;
|
|
|
|
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);
|
2021-09-05 01:09:30 +02:00
|
|
|
if (chance > 1) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (chance < 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
2018-08-30 19:00:38 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
return chance;
|
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
|
|
|
|
*/
|
2022-09-20 07:57:46 +02:00
|
|
|
export function calculateHackingExpGain(server: Server, person: Person): 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;
|
2022-01-23 20:30:36 +01:00
|
|
|
expGain += server.baseDifficulty * diffFactor;
|
2018-08-30 19:00:38 +02:00
|
|
|
|
2022-09-06 15:07:12 +02:00
|
|
|
return expGain * person.mults.hacking_exp * BitNodeMultipliers.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)
|
|
|
|
*/
|
2022-09-20 07:57:46 +02:00
|
|
|
export function calculatePercentMoneyHacked(server: Server, person: Person): 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;
|
2018-08-30 19:00:38 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
const difficultyMult = (100 - server.hackDifficulty) / 100;
|
2022-09-06 15:07:12 +02:00
|
|
|
const skillMult = (person.skills.hacking - (server.requiredHackingSkill - 1)) / person.skills.hacking;
|
2022-04-07 01:30:08 +02:00
|
|
|
const percentMoneyHacked =
|
2022-09-06 15:07:12 +02:00
|
|
|
(difficultyMult * skillMult * person.mults.hacking_money * BitNodeMultipliers.ScriptHackMoney) / balanceFactor;
|
2021-09-05 01:09:30 +02:00
|
|
|
if (percentMoneyHacked < 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (percentMoneyHacked > 1) {
|
|
|
|
return 1;
|
|
|
|
}
|
2018-08-30 19:00:38 +02:00
|
|
|
|
2022-01-08 08:12:44 +01:00
|
|
|
return percentMoneyHacked;
|
2018-08-30 19:00:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns time it takes to complete a hack on a server, in seconds
|
|
|
|
*/
|
2022-09-20 07:57:46 +02:00
|
|
|
export function calculateHackingTime(server: Server, person: Person): number {
|
2021-09-05 01:09:30 +02:00
|
|
|
const difficultyMult = server.requiredHackingSkill * server.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;
|
|
|
|
// tslint:disable-next-line
|
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) /
|
2022-09-06 15:07:12 +02:00
|
|
|
(person.mults.hacking_speed * 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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns time it takes to complete a grow operation on a server, in seconds
|
|
|
|
*/
|
2022-09-20 07:57:46 +02:00
|
|
|
export function calculateGrowTime(server: Server, person: Person): 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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns time it takes to complete a weaken operation on a server, in seconds
|
|
|
|
*/
|
2022-09-20 07:57:46 +02:00
|
|
|
export function calculateWeakenTime(server: Server, person: Person): 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
|
|
|
}
|