mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-20 16:22:56 +02:00
prettify, sorry for the big ass commit
This commit is contained in:
@@ -1,96 +1,116 @@
|
||||
import { BitNodeMultipliers } from "../../BitNode/BitNodeMultipliers";
|
||||
import { HacknetNodeConstants } from "../data/Constants";
|
||||
|
||||
export function calculateMoneyGainRate(level: number, ram: number, cores: number, mult: number): number {
|
||||
const gainPerLevel = HacknetNodeConstants.MoneyGainPerLevel;
|
||||
export function calculateMoneyGainRate(
|
||||
level: number,
|
||||
ram: number,
|
||||
cores: number,
|
||||
mult: number,
|
||||
): number {
|
||||
const gainPerLevel = HacknetNodeConstants.MoneyGainPerLevel;
|
||||
|
||||
const levelMult = (level * gainPerLevel);
|
||||
const ramMult = Math.pow(1.035, ram - 1);
|
||||
const coresMult = ((cores + 5) / 6);
|
||||
return levelMult *
|
||||
ramMult *
|
||||
coresMult *
|
||||
mult *
|
||||
BitNodeMultipliers.HacknetNodeMoney;
|
||||
const levelMult = level * gainPerLevel;
|
||||
const ramMult = Math.pow(1.035, ram - 1);
|
||||
const coresMult = (cores + 5) / 6;
|
||||
return (
|
||||
levelMult * ramMult * coresMult * mult * BitNodeMultipliers.HacknetNodeMoney
|
||||
);
|
||||
}
|
||||
|
||||
export function calculateLevelUpgradeCost(startingLevel: number, extraLevels=1, costMult=1): number {
|
||||
const sanitizedLevels = Math.round(extraLevels);
|
||||
if (isNaN(sanitizedLevels) || sanitizedLevels < 1) {
|
||||
return 0;
|
||||
}
|
||||
export function calculateLevelUpgradeCost(
|
||||
startingLevel: number,
|
||||
extraLevels = 1,
|
||||
costMult = 1,
|
||||
): number {
|
||||
const sanitizedLevels = Math.round(extraLevels);
|
||||
if (isNaN(sanitizedLevels) || sanitizedLevels < 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (startingLevel >= HacknetNodeConstants.MaxLevel) {
|
||||
return Infinity;
|
||||
}
|
||||
if (startingLevel >= HacknetNodeConstants.MaxLevel) {
|
||||
return Infinity;
|
||||
}
|
||||
|
||||
const mult = HacknetNodeConstants.UpgradeLevelMult;
|
||||
let totalMultiplier = 0;
|
||||
let currLevel = startingLevel;
|
||||
for (let i = 0; i < sanitizedLevels; ++i) {
|
||||
totalMultiplier += (HacknetNodeConstants.LevelBaseCost * Math.pow(mult, currLevel));
|
||||
++currLevel;
|
||||
}
|
||||
const mult = HacknetNodeConstants.UpgradeLevelMult;
|
||||
let totalMultiplier = 0;
|
||||
let currLevel = startingLevel;
|
||||
for (let i = 0; i < sanitizedLevels; ++i) {
|
||||
totalMultiplier +=
|
||||
HacknetNodeConstants.LevelBaseCost * Math.pow(mult, currLevel);
|
||||
++currLevel;
|
||||
}
|
||||
|
||||
return HacknetNodeConstants.BaseCost / 2 * totalMultiplier * costMult;
|
||||
return (HacknetNodeConstants.BaseCost / 2) * totalMultiplier * costMult;
|
||||
}
|
||||
|
||||
export function calculateRamUpgradeCost(startingRam: number, extraLevels=1, costMult=1): number {
|
||||
const sanitizedLevels = Math.round(extraLevels);
|
||||
if (isNaN(sanitizedLevels) || sanitizedLevels < 1) {
|
||||
return 0;
|
||||
}
|
||||
export function calculateRamUpgradeCost(
|
||||
startingRam: number,
|
||||
extraLevels = 1,
|
||||
costMult = 1,
|
||||
): number {
|
||||
const sanitizedLevels = Math.round(extraLevels);
|
||||
if (isNaN(sanitizedLevels) || sanitizedLevels < 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (startingRam >= HacknetNodeConstants.MaxRam) {
|
||||
return Infinity;
|
||||
}
|
||||
if (startingRam >= HacknetNodeConstants.MaxRam) {
|
||||
return Infinity;
|
||||
}
|
||||
|
||||
let totalCost = 0;
|
||||
let numUpgrades = Math.round(Math.log2(startingRam));
|
||||
let currentRam = startingRam;
|
||||
let totalCost = 0;
|
||||
let numUpgrades = Math.round(Math.log2(startingRam));
|
||||
let currentRam = startingRam;
|
||||
|
||||
for (let i = 0; i < sanitizedLevels; ++i) {
|
||||
const baseCost = currentRam * HacknetNodeConstants.RamBaseCost;
|
||||
const mult = Math.pow(HacknetNodeConstants.UpgradeRamMult, numUpgrades);
|
||||
for (let i = 0; i < sanitizedLevels; ++i) {
|
||||
const baseCost = currentRam * HacknetNodeConstants.RamBaseCost;
|
||||
const mult = Math.pow(HacknetNodeConstants.UpgradeRamMult, numUpgrades);
|
||||
|
||||
totalCost += (baseCost * mult);
|
||||
totalCost += baseCost * mult;
|
||||
|
||||
currentRam *= 2;
|
||||
++numUpgrades;
|
||||
}
|
||||
currentRam *= 2;
|
||||
++numUpgrades;
|
||||
}
|
||||
|
||||
totalCost *= costMult;
|
||||
totalCost *= costMult;
|
||||
|
||||
return totalCost;
|
||||
return totalCost;
|
||||
}
|
||||
|
||||
export function calculateCoreUpgradeCost(startingCore: number, extraLevels=1, costMult=1): number {
|
||||
const sanitizedCores = Math.round(extraLevels);
|
||||
if (isNaN(sanitizedCores) || sanitizedCores < 1) {
|
||||
return 0;
|
||||
}
|
||||
export function calculateCoreUpgradeCost(
|
||||
startingCore: number,
|
||||
extraLevels = 1,
|
||||
costMult = 1,
|
||||
): number {
|
||||
const sanitizedCores = Math.round(extraLevels);
|
||||
if (isNaN(sanitizedCores) || sanitizedCores < 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (startingCore >= HacknetNodeConstants.MaxCores) {
|
||||
return Infinity;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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;
|
||||
totalCost *= costMult;
|
||||
|
||||
return totalCost;
|
||||
return totalCost;
|
||||
}
|
||||
|
||||
export function calculateNodeCost(n: number, mult=1): number {
|
||||
if(n <= 0) {
|
||||
return 0;
|
||||
}
|
||||
return HacknetNodeConstants.BaseCost * Math.pow(HacknetNodeConstants.PurchaseNextMult, n-1) * mult;
|
||||
}
|
||||
export function calculateNodeCost(n: number, mult = 1): number {
|
||||
if (n <= 0) {
|
||||
return 0;
|
||||
}
|
||||
return (
|
||||
HacknetNodeConstants.BaseCost *
|
||||
Math.pow(HacknetNodeConstants.PurchaseNextMult, n - 1) *
|
||||
mult
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,115 +1,144 @@
|
||||
import { BitNodeMultipliers } from "../../BitNode/BitNodeMultipliers";
|
||||
import { HacknetServerConstants } from "../data/Constants";
|
||||
|
||||
export function calculateHashGainRate(level: number, ramUsed: number, maxRam: number, cores: number, mult: number): number {
|
||||
const baseGain = HacknetServerConstants.HashesPerLevel * level;
|
||||
const ramMultiplier = Math.pow(1.07, Math.log2(maxRam));
|
||||
const coreMultiplier = 1 + (cores - 1) / 5;
|
||||
const ramRatio = (1 - ramUsed / maxRam);
|
||||
export function calculateHashGainRate(
|
||||
level: number,
|
||||
ramUsed: number,
|
||||
maxRam: number,
|
||||
cores: number,
|
||||
mult: number,
|
||||
): number {
|
||||
const baseGain = HacknetServerConstants.HashesPerLevel * level;
|
||||
const ramMultiplier = Math.pow(1.07, Math.log2(maxRam));
|
||||
const coreMultiplier = 1 + (cores - 1) / 5;
|
||||
const ramRatio = 1 - ramUsed / maxRam;
|
||||
|
||||
return baseGain *
|
||||
ramMultiplier *
|
||||
coreMultiplier *
|
||||
ramRatio *
|
||||
mult *
|
||||
BitNodeMultipliers.HacknetNodeMoney;
|
||||
return (
|
||||
baseGain *
|
||||
ramMultiplier *
|
||||
coreMultiplier *
|
||||
ramRatio *
|
||||
mult *
|
||||
BitNodeMultipliers.HacknetNodeMoney
|
||||
);
|
||||
}
|
||||
|
||||
export function calculateLevelUpgradeCost(startingLevel: number, extraLevels=1, costMult=1): number {
|
||||
const sanitizedLevels = Math.round(extraLevels);
|
||||
if (isNaN(sanitizedLevels) || sanitizedLevels < 1) {
|
||||
return 0;
|
||||
}
|
||||
export function calculateLevelUpgradeCost(
|
||||
startingLevel: number,
|
||||
extraLevels = 1,
|
||||
costMult = 1,
|
||||
): number {
|
||||
const sanitizedLevels = Math.round(extraLevels);
|
||||
if (isNaN(sanitizedLevels) || sanitizedLevels < 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (startingLevel >= HacknetServerConstants.MaxLevel) {
|
||||
return Infinity;
|
||||
}
|
||||
if (startingLevel >= HacknetServerConstants.MaxLevel) {
|
||||
return Infinity;
|
||||
}
|
||||
|
||||
const mult = HacknetServerConstants.UpgradeLevelMult;
|
||||
let totalMultiplier = 0;
|
||||
let currLevel = startingLevel;
|
||||
for (let i = 0; i < sanitizedLevels; ++i) {
|
||||
totalMultiplier += Math.pow(mult, currLevel);
|
||||
++currLevel;
|
||||
}
|
||||
const mult = HacknetServerConstants.UpgradeLevelMult;
|
||||
let totalMultiplier = 0;
|
||||
let currLevel = startingLevel;
|
||||
for (let i = 0; i < sanitizedLevels; ++i) {
|
||||
totalMultiplier += Math.pow(mult, currLevel);
|
||||
++currLevel;
|
||||
}
|
||||
|
||||
return 10 * HacknetServerConstants.BaseCost * totalMultiplier * costMult;
|
||||
return 10 * HacknetServerConstants.BaseCost * totalMultiplier * costMult;
|
||||
}
|
||||
|
||||
export function calculateRamUpgradeCost(startingRam: number, extraLevels=1, costMult=1): number {
|
||||
const sanitizedLevels = Math.round(extraLevels);
|
||||
if (isNaN(sanitizedLevels) || sanitizedLevels < 1) {
|
||||
return 0;
|
||||
}
|
||||
export function calculateRamUpgradeCost(
|
||||
startingRam: number,
|
||||
extraLevels = 1,
|
||||
costMult = 1,
|
||||
): number {
|
||||
const sanitizedLevels = Math.round(extraLevels);
|
||||
if (isNaN(sanitizedLevels) || sanitizedLevels < 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (startingRam >= HacknetServerConstants.MaxRam) {
|
||||
return Infinity;
|
||||
}
|
||||
if (startingRam >= HacknetServerConstants.MaxRam) {
|
||||
return Infinity;
|
||||
}
|
||||
|
||||
let totalCost = 0;
|
||||
let numUpgrades = Math.round(Math.log2(startingRam));
|
||||
let currentRam = startingRam;
|
||||
for (let i = 0; i < sanitizedLevels; ++i) {
|
||||
const baseCost = currentRam * HacknetServerConstants.RamBaseCost;
|
||||
const mult = Math.pow(HacknetServerConstants.UpgradeRamMult, numUpgrades);
|
||||
let totalCost = 0;
|
||||
let numUpgrades = Math.round(Math.log2(startingRam));
|
||||
let currentRam = startingRam;
|
||||
for (let i = 0; i < sanitizedLevels; ++i) {
|
||||
const baseCost = currentRam * HacknetServerConstants.RamBaseCost;
|
||||
const mult = Math.pow(HacknetServerConstants.UpgradeRamMult, numUpgrades);
|
||||
|
||||
totalCost += (baseCost * mult);
|
||||
totalCost += baseCost * mult;
|
||||
|
||||
currentRam *= 2;
|
||||
++numUpgrades;
|
||||
}
|
||||
totalCost *= costMult;
|
||||
currentRam *= 2;
|
||||
++numUpgrades;
|
||||
}
|
||||
totalCost *= costMult;
|
||||
|
||||
return totalCost;
|
||||
return totalCost;
|
||||
}
|
||||
|
||||
export function calculateCoreUpgradeCost(startingCores: number, extraLevels=1, costMult=1): number {
|
||||
const sanitizedLevels = Math.round(extraLevels);
|
||||
if (isNaN(sanitizedLevels) || sanitizedLevels < 1) {
|
||||
return 0;
|
||||
}
|
||||
export function calculateCoreUpgradeCost(
|
||||
startingCores: number,
|
||||
extraLevels = 1,
|
||||
costMult = 1,
|
||||
): number {
|
||||
const sanitizedLevels = Math.round(extraLevels);
|
||||
if (isNaN(sanitizedLevels) || sanitizedLevels < 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (startingCores >= HacknetServerConstants.MaxCores) {
|
||||
return Infinity;
|
||||
}
|
||||
if (startingCores >= HacknetServerConstants.MaxCores) {
|
||||
return Infinity;
|
||||
}
|
||||
|
||||
const mult = HacknetServerConstants.UpgradeCoreMult;
|
||||
let totalCost = 0;
|
||||
let currentCores = startingCores;
|
||||
for (let i = 0; i < sanitizedLevels; ++i) {
|
||||
totalCost += Math.pow(mult, currentCores-1);
|
||||
++currentCores;
|
||||
}
|
||||
totalCost *= HacknetServerConstants.CoreBaseCost;
|
||||
totalCost *= costMult;
|
||||
const mult = HacknetServerConstants.UpgradeCoreMult;
|
||||
let totalCost = 0;
|
||||
let currentCores = startingCores;
|
||||
for (let i = 0; i < sanitizedLevels; ++i) {
|
||||
totalCost += Math.pow(mult, currentCores - 1);
|
||||
++currentCores;
|
||||
}
|
||||
totalCost *= HacknetServerConstants.CoreBaseCost;
|
||||
totalCost *= costMult;
|
||||
|
||||
return totalCost;
|
||||
return totalCost;
|
||||
}
|
||||
|
||||
export function calculateCacheUpgradeCost(startingCache: number, extraLevels=1): number {
|
||||
const sanitizedLevels = Math.round(extraLevels);
|
||||
if (isNaN(sanitizedLevels) || sanitizedLevels < 1) {
|
||||
return 0;
|
||||
}
|
||||
export function calculateCacheUpgradeCost(
|
||||
startingCache: number,
|
||||
extraLevels = 1,
|
||||
): number {
|
||||
const sanitizedLevels = Math.round(extraLevels);
|
||||
if (isNaN(sanitizedLevels) || sanitizedLevels < 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (startingCache >= HacknetServerConstants.MaxCache) {
|
||||
return Infinity;
|
||||
}
|
||||
if (startingCache >= HacknetServerConstants.MaxCache) {
|
||||
return Infinity;
|
||||
}
|
||||
|
||||
const mult = HacknetServerConstants.UpgradeCacheMult;
|
||||
let totalCost = 0;
|
||||
let currentCache = startingCache;
|
||||
for (let i = 0; i < sanitizedLevels; ++i) {
|
||||
totalCost += Math.pow(mult, currentCache - 1);
|
||||
++currentCache;
|
||||
}
|
||||
totalCost *= HacknetServerConstants.CacheBaseCost;
|
||||
const mult = HacknetServerConstants.UpgradeCacheMult;
|
||||
let totalCost = 0;
|
||||
let currentCache = startingCache;
|
||||
for (let i = 0; i < sanitizedLevels; ++i) {
|
||||
totalCost += Math.pow(mult, currentCache - 1);
|
||||
++currentCache;
|
||||
}
|
||||
totalCost *= HacknetServerConstants.CacheBaseCost;
|
||||
|
||||
return totalCost;
|
||||
return totalCost;
|
||||
}
|
||||
|
||||
export function calculateServerCost(n: number, mult=1): number {
|
||||
if (n-1 >= HacknetServerConstants.MaxServers) { return Infinity; }
|
||||
export function calculateServerCost(n: number, mult = 1): number {
|
||||
if (n - 1 >= HacknetServerConstants.MaxServers) {
|
||||
return Infinity;
|
||||
}
|
||||
|
||||
return HacknetServerConstants.BaseCost * Math.pow(HacknetServerConstants.PurchaseMult, n-1) * mult;
|
||||
}
|
||||
return (
|
||||
HacknetServerConstants.BaseCost *
|
||||
Math.pow(HacknetServerConstants.PurchaseMult, n - 1) *
|
||||
mult
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user