diff --git a/src/utils/formulas/constants.ts b/src/utils/formulas/constants.ts index f6e5a65..485973f 100644 --- a/src/utils/formulas/constants.ts +++ b/src/utils/formulas/constants.ts @@ -1,3 +1,5 @@ +import { Multipliers } from "./player"; + /** * Generic Game Constants * @@ -152,3 +154,59 @@ export const HacknetServerConstants = { MaxCores: 128, MaxCache: 15, } as const; + +export const ServerConstants = { + // Base RAM costs + BaseCostFor1GBOfRamHome: 32000, + BaseCostFor1GBOfRamServer: 55000, //1 GB of RAM + + // Server-related constants + HomeComputerMaxRam: 1073741824, // 2 ^ 30 + ServerBaseGrowthIncr: 0.03, // Unadjusted growth increment (growth rate is this * adjustment + 1) + ServerMaxGrowthLog: 0.00349388925425578, // Maximum possible growth rate accounting for server security, precomputed as log1p(.0035) + ServerFortifyAmount: 0.002, // Amount by which server's security increases when its hacked/grown + ServerWeakenAmount: 0.05, // Amount by which server's security decreases when weakened + + PurchasedServerLimit: 25, + PurchasedServerMaxRam: 1048576, // 2^20 +} as const; + +export const defaultMultipliers = (): Multipliers => { + return { + hacking_chance: 1, + hacking_speed: 1, + hacking_money: 1, + hacking_grow: 1, + hacking: 1, + hacking_exp: 1, + strength: 1, + strength_exp: 1, + defense: 1, + defense_exp: 1, + dexterity: 1, + dexterity_exp: 1, + agility: 1, + agility_exp: 1, + charisma: 1, + charisma_exp: 1, + hacknet_node_money: 1, + hacknet_node_purchase_cost: 1, + hacknet_node_ram_cost: 1, + hacknet_node_core_cost: 1, + hacknet_node_level_cost: 1, + company_rep: 1, + faction_rep: 1, + work_money: 1, + crime_success: 1, + crime_money: 1, + bladeburner_max_stamina: 1, + bladeburner_stamina_gain: 1, + bladeburner_analysis: 1, + bladeburner_success_chance: 1, + }; +}; + +export const MaxFavor = 35331; +// This is the nearest representable value of log(1.02), which is the base of our power. +// It is *not* the same as Math.log(1.02), since "1.02" lacks sufficient precision. +export const log1point02 = 0.019802627296179712; diff --git a/src/utils/formulas/hacking.ts b/src/utils/formulas/hacking.ts index 62e5063..0769aeb 100644 --- a/src/utils/formulas/hacking.ts +++ b/src/utils/formulas/hacking.ts @@ -1,30 +1,8 @@ import { Player as IPerson, Server as IServer } from "@ns"; import { currentNodeMults } from "./exports"; -import { clampNumber } from "./utils"; +import { clampNumber, isValidNumber } from "./utils"; import { Player } from "./player"; - -export const ServerConstants = { - // Base RAM costs - BaseCostFor1GBOfRamHome: 32000, - BaseCostFor1GBOfRamServer: 55000, //1 GB of RAM - // Server-related constants - HomeComputerMaxRam: 1073741824, // 2 ^ 30 - ServerBaseGrowthIncr: 0.03, // Unadjusted growth increment (growth rate is this * adjustment + 1) - ServerMaxGrowthLog: 0.00349388925425578, // Maximum possible growth rate accounting for server security, precomputed as log1p(.0035) - ServerFortifyAmount: 0.002, // Amount by which server's security increases when its hacked/grown - ServerWeakenAmount: 0.05, // Amount by which server's security decreases when weakened - - PurchasedServerLimit: 25, - PurchasedServerMaxRam: 1048576, // 2^20 -} as const; - -/** - * Checks that a variable is a valid number. A valid number - * must be a "number" type and cannot be NaN - */ -export function isValidNumber(n: number): boolean { - return typeof n === "number" && !isNaN(n); -} +import { ServerConstants } from "./constants"; export function calculateIntelligenceBonus(intelligence: number, weight = 1): number { const effectiveIntelligence = diff --git a/src/utils/formulas/player.ts b/src/utils/formulas/player.ts index a1e7a97..da7caf3 100644 --- a/src/utils/formulas/player.ts +++ b/src/utils/formulas/player.ts @@ -15,7 +15,7 @@ import { Sleeve, WorkStats, } from "@ns"; -import { CONSTANTS } from "./constants"; +import { CONSTANTS, defaultMultipliers } from "./constants"; import { currentNodeMults, PartialRecord } from "./exports"; import { calculateSkill } from "./skills"; @@ -52,41 +52,6 @@ export interface Multipliers { bladeburner_success_chance: number; } -export const defaultMultipliers = (): Multipliers => { - return { - hacking_chance: 1, - hacking_speed: 1, - hacking_money: 1, - hacking_grow: 1, - hacking: 1, - hacking_exp: 1, - strength: 1, - strength_exp: 1, - defense: 1, - defense_exp: 1, - dexterity: 1, - dexterity_exp: 1, - agility: 1, - agility_exp: 1, - charisma: 1, - charisma_exp: 1, - hacknet_node_money: 1, - hacknet_node_purchase_cost: 1, - hacknet_node_ram_cost: 1, - hacknet_node_core_cost: 1, - hacknet_node_level_cost: 1, - company_rep: 1, - faction_rep: 1, - work_money: 1, - crime_success: 1, - crime_money: 1, - bladeburner_max_stamina: 1, - bladeburner_stamina_gain: 1, - bladeburner_analysis: 1, - bladeburner_success_chance: 1, - }; -}; - export let Player: PlayerObject; // Base class representing a person-like object diff --git a/src/utils/formulas/reputation.ts b/src/utils/formulas/reputation.ts index 0e32f34..ebb9916 100644 --- a/src/utils/formulas/reputation.ts +++ b/src/utils/formulas/reputation.ts @@ -1,14 +1,9 @@ import { Person as IPerson } from "@ns"; import { currentNodeMults } from "./exports"; import { clampNumber } from "./utils"; -import { CONSTANTS } from "./constants"; +import { CONSTANTS, log1point02, MaxFavor } from "./constants"; import { Player } from "./player"; -export const MaxFavor = 35331; -// This is the nearest representable value of log(1.02), which is the base of our power. -// It is *not* the same as Math.log(1.02), since "1.02" lacks sufficient precision. -const log1point02 = 0.019802627296179712; - export function favorToRep(f: number): number { // expm1 is e^x - 1, which is more accurate for small x than doing it the obvious way. return clampNumber(25000 * Math.expm1(log1point02 * f), 0); diff --git a/src/utils/formulas/utils.ts b/src/utils/formulas/utils.ts index 3d394db..14a2067 100644 --- a/src/utils/formulas/utils.ts +++ b/src/utils/formulas/utils.ts @@ -7,8 +7,7 @@ import { CONSTANTS } from "./constants"; * @param {number} max Upper bound, defaults to Number.MAX_VALUE * @returns {number} Clamped value */ - -export function clampNumber(value: number, min = -Number.MAX_VALUE, max = Number.MAX_VALUE) { +export function clampNumber(value: number, min: number = -Number.MAX_VALUE, max: number = Number.MAX_VALUE): number { if (isNaN(value)) { if (CONSTANTS.isDevBranch) throw new Error("NaN passed into clampNumber()"); return min; @@ -23,3 +22,12 @@ export function clampInteger(value: number, min = -Number.MAX_SAFE_INTEGER, max } return Math.round(Math.max(Math.min(value, max), min)); } + +/** + * Checks that a variable is a valid number. A valid number + * must be a "number" type and cannot be NaN + */ + +export function isValidNumber(n: number): boolean { + return typeof n === "number" && !isNaN(n); +}