mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-19 14:13:48 +01:00
convert Hacking.js to Hacking.ts
This commit is contained in:
parent
62c571ef3a
commit
4892f0bd79
@ -1,11 +1,12 @@
|
||||
import { BitNodeMultipliers } from "./BitNode/BitNodeMultipliers";
|
||||
import { Player } from "./Player";
|
||||
import { Server } from "./Server/Server";
|
||||
import { HacknetServer } from "./Hacknet/HacknetServer";
|
||||
|
||||
/**
|
||||
* Returns the chance the player has to successfully hack a server
|
||||
*/
|
||||
export function calculateHackingChance(server) {
|
||||
export function calculateHackingChance(server: Server): number {
|
||||
const hackFactor = 1.75;
|
||||
const intFactor = 0.2;
|
||||
const difficultyMult = (100 - server.hackDifficulty) / 100;
|
||||
@ -22,13 +23,13 @@ export function calculateHackingChance(server) {
|
||||
* Returns the amount of hacking experience the player will gain upon
|
||||
* successfully hacking a server
|
||||
*/
|
||||
export function calculateHackingExpGain(server) {
|
||||
export function calculateHackingExpGain(server: Server): number {
|
||||
const baseExpGain = 3;
|
||||
const diffFactor = 0.3;
|
||||
if (server.baseDifficulty == null) {
|
||||
server.baseDifficulty = server.hackDifficulty;
|
||||
}
|
||||
var expGain = baseExpGain;
|
||||
let expGain = baseExpGain;
|
||||
expGain += (server.baseDifficulty * Player.hacking_exp_mult * diffFactor);
|
||||
|
||||
return expGain * BitNodeMultipliers.HackExpGain;
|
||||
@ -38,7 +39,7 @@ export function calculateHackingExpGain(server) {
|
||||
* 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)
|
||||
*/
|
||||
export function calculatePercentMoneyHacked(server) {
|
||||
export function calculatePercentMoneyHacked(server: Server): number {
|
||||
// Adjust if needed for balancing. This is the divisor for the final calculation
|
||||
const balanceFactor = 240;
|
||||
|
||||
@ -54,7 +55,7 @@ export function calculatePercentMoneyHacked(server) {
|
||||
/**
|
||||
* Returns time it takes to complete a hack on a server, in seconds
|
||||
*/
|
||||
export function calculateHackingTime(server, hack, int) {
|
||||
export function calculateHackingTime(server: Server, hack: number, int: number): number {
|
||||
const difficultyMult = server.requiredHackingSkill * server.hackDifficulty;
|
||||
|
||||
const baseDiff = 500;
|
||||
@ -63,7 +64,7 @@ export function calculateHackingTime(server, hack, int) {
|
||||
const intFactor = 0.1;
|
||||
if (hack == null) {hack = Player.hacking_skill;}
|
||||
if (int == null) {int = Player.intelligence;}
|
||||
var skillFactor = (diffFactor * difficultyMult + baseDiff);
|
||||
let skillFactor = (diffFactor * difficultyMult + baseDiff);
|
||||
// tslint:disable-next-line
|
||||
skillFactor /= (hack + baseSkill + (intFactor * int));
|
||||
|
||||
@ -76,7 +77,7 @@ export function calculateHackingTime(server, hack, int) {
|
||||
/**
|
||||
* Returns time it takes to complete a grow operation on a server, in seconds
|
||||
*/
|
||||
export function calculateGrowTime(server, hack, int) {
|
||||
export function calculateGrowTime(server: Server, hack: number, int: number): number {
|
||||
const growTimeMultiplier = 3.2; // Relative to hacking time. 16/5 = 3.2
|
||||
|
||||
return growTimeMultiplier * calculateHackingTime(server, hack, int);
|
||||
@ -85,7 +86,7 @@ export function calculateGrowTime(server, hack, int) {
|
||||
/**
|
||||
* Returns time it takes to complete a weaken operation on a server, in seconds
|
||||
*/
|
||||
export function calculateWeakenTime(server, hack, int) {
|
||||
export function calculateWeakenTime(server: Server, hack: number, int: number): number {
|
||||
const weakenTimeMultiplier = 4; // Relative to hacking time
|
||||
|
||||
return weakenTimeMultiplier * calculateHackingTime(server, hack, int);
|
Loading…
Reference in New Issue
Block a user