bitburner-src/src/Hacknet/formulas/HacknetNodes.ts

93 lines
2.7 KiB
TypeScript
Raw Normal View History

import { BitNodeMultipliers } from "../../BitNode/BitNodeMultipliers";
import { HacknetNodeConstants } from "../data/Constants";
2021-09-09 05:47:34 +02:00
export function calculateMoneyGainRate(level: number, ram: number, cores: number, mult: number): number {
2021-09-05 01:09:30 +02:00
const gainPerLevel = HacknetNodeConstants.MoneyGainPerLevel;
const levelMult = level * gainPerLevel;
const ramMult = Math.pow(1.035, ram - 1);
const coresMult = (cores + 5) / 6;
2021-09-09 05:47:34 +02:00
return levelMult * ramMult * coresMult * mult * BitNodeMultipliers.HacknetNodeMoney;
}
2021-09-09 05:47:34 +02:00
export function calculateLevelUpgradeCost(startingLevel: number, extraLevels = 1, costMult = 1): number {
2021-09-05 01:09:30 +02:00
const sanitizedLevels = Math.round(extraLevels);
if (isNaN(sanitizedLevels) || sanitizedLevels < 1) {
return 0;
}
if (startingLevel >= HacknetNodeConstants.MaxLevel) {
return Infinity;
}
const mult = HacknetNodeConstants.UpgradeLevelMult;
let totalMultiplier = 0;
let currLevel = startingLevel;
for (let i = 0; i < sanitizedLevels; ++i) {
2023-05-06 05:22:54 +02:00
totalMultiplier += Math.pow(mult, currLevel);
2021-09-05 01:09:30 +02:00
++currLevel;
}
2023-05-06 05:22:54 +02:00
return HacknetNodeConstants.LevelBaseCost * totalMultiplier * costMult;
}
2021-09-09 05:47:34 +02:00
export function calculateRamUpgradeCost(startingRam: number, extraLevels = 1, costMult = 1): number {
2021-09-05 01:09:30 +02:00
const sanitizedLevels = Math.round(extraLevels);
if (isNaN(sanitizedLevels) || sanitizedLevels < 1) {
return 0;
}
2021-09-05 01:09:30 +02:00
if (startingRam >= HacknetNodeConstants.MaxRam) {
return Infinity;
}
2021-09-05 01:09:30 +02:00
let totalCost = 0;
let numUpgrades = Math.round(Math.log2(startingRam));
let currentRam = startingRam;
2021-09-05 01:09:30 +02:00
for (let i = 0; i < sanitizedLevels; ++i) {
const baseCost = currentRam * HacknetNodeConstants.RamBaseCost;
const mult = Math.pow(HacknetNodeConstants.UpgradeRamMult, numUpgrades);
2021-09-05 01:09:30 +02:00
totalCost += baseCost * mult;
2021-09-05 01:09:30 +02:00
currentRam *= 2;
++numUpgrades;
}
2021-09-05 01:09:30 +02:00
totalCost *= costMult;
2021-09-05 01:09:30 +02:00
return totalCost;
}
2021-09-09 05:47:34 +02:00
export function calculateCoreUpgradeCost(startingCore: number, extraLevels = 1, costMult = 1): number {
2021-09-05 01:09:30 +02:00
const sanitizedCores = Math.round(extraLevels);
if (isNaN(sanitizedCores) || sanitizedCores < 1) {
return 0;
}
if (startingCore >= HacknetNodeConstants.MaxCores) {
return Infinity;
}
const coreBaseCost = HacknetNodeConstants.CoreBaseCost;
const mult = HacknetNodeConstants.UpgradeCoreMult;
let totalCost = 0;
let currentCores = startingCore;
for (let i = 0; i < sanitizedCores; ++i) {
totalCost += coreBaseCost * Math.pow(mult, currentCores - 1);
++currentCores;
}
totalCost *= costMult;
return totalCost;
}
2021-09-05 01:09:30 +02:00
export function calculateNodeCost(n: number, mult = 1): number {
if (n <= 0) {
return 0;
}
2021-09-09 05:47:34 +02:00
return HacknetNodeConstants.BaseCost * Math.pow(HacknetNodeConstants.PurchaseNextMult, n - 1) * mult;
2021-09-05 01:09:30 +02:00
}