cleaned up formulas

This commit is contained in:
Vomitblood 2026-05-01 20:12:31 +08:00
parent ed98896238
commit b972588825
5 changed files with 72 additions and 68 deletions

View file

@ -1,3 +1,5 @@
import { Multipliers } from "./player";
/** /**
* Generic Game Constants * Generic Game Constants
* *
@ -152,3 +154,59 @@ export const HacknetServerConstants = {
MaxCores: 128, MaxCores: 128,
MaxCache: 15, MaxCache: 15,
} as const; } 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;

View file

@ -1,30 +1,8 @@
import { Player as IPerson, Server as IServer } from "@ns"; import { Player as IPerson, Server as IServer } from "@ns";
import { currentNodeMults } from "./exports"; import { currentNodeMults } from "./exports";
import { clampNumber } from "./utils"; import { clampNumber, isValidNumber } from "./utils";
import { Player } from "./player"; import { Player } from "./player";
import { ServerConstants } from "./constants";
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);
}
export function calculateIntelligenceBonus(intelligence: number, weight = 1): number { export function calculateIntelligenceBonus(intelligence: number, weight = 1): number {
const effectiveIntelligence = const effectiveIntelligence =

View file

@ -15,7 +15,7 @@ import {
Sleeve, Sleeve,
WorkStats, WorkStats,
} from "@ns"; } from "@ns";
import { CONSTANTS } from "./constants"; import { CONSTANTS, defaultMultipliers } from "./constants";
import { currentNodeMults, PartialRecord } from "./exports"; import { currentNodeMults, PartialRecord } from "./exports";
import { calculateSkill } from "./skills"; import { calculateSkill } from "./skills";
@ -52,41 +52,6 @@ export interface Multipliers {
bladeburner_success_chance: number; 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; export let Player: PlayerObject;
// Base class representing a person-like object // Base class representing a person-like object

View file

@ -1,14 +1,9 @@
import { Person as IPerson } from "@ns"; import { Person as IPerson } from "@ns";
import { currentNodeMults } from "./exports"; import { currentNodeMults } from "./exports";
import { clampNumber } from "./utils"; import { clampNumber } from "./utils";
import { CONSTANTS } from "./constants"; import { CONSTANTS, log1point02, MaxFavor } from "./constants";
import { Player } from "./player"; 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 { export function favorToRep(f: number): number {
// expm1 is e^x - 1, which is more accurate for small x than doing it the obvious way. // 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); return clampNumber(25000 * Math.expm1(log1point02 * f), 0);

View file

@ -7,8 +7,7 @@ import { CONSTANTS } from "./constants";
* @param {number} max Upper bound, defaults to Number.MAX_VALUE * @param {number} max Upper bound, defaults to Number.MAX_VALUE
* @returns {number} Clamped value * @returns {number} Clamped value
*/ */
export function clampNumber(value: number, min: number = -Number.MAX_VALUE, max: number = Number.MAX_VALUE): number {
export function clampNumber(value: number, min = -Number.MAX_VALUE, max = Number.MAX_VALUE) {
if (isNaN(value)) { if (isNaN(value)) {
if (CONSTANTS.isDevBranch) throw new Error("NaN passed into clampNumber()"); if (CONSTANTS.isDevBranch) throw new Error("NaN passed into clampNumber()");
return min; 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)); 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);
}