HACKNET: fix application of limits in cost functions (#2696)

This commit is contained in:
lucebac
2026-04-28 09:16:45 +02:00
committed by GitHub
parent ed6df3dfa7
commit 9e85068cbb
3 changed files with 156 additions and 9 deletions
+5 -5
View File
@@ -16,7 +16,7 @@ export function calculateLevelUpgradeCost(startingLevel: number, extraLevels = 1
return 0;
}
if (startingLevel >= HacknetNodeConstants.MaxLevel) {
if (startingLevel + sanitizedLevels > HacknetNodeConstants.MaxLevel) {
return Infinity;
}
@@ -37,7 +37,7 @@ export function calculateRamUpgradeCost(startingRam: number, extraLevels = 1, co
return 0;
}
if (startingRam >= HacknetNodeConstants.MaxRam) {
if (startingRam * Math.pow(2, sanitizedLevels) > HacknetNodeConstants.MaxRam) {
return Infinity;
}
@@ -60,20 +60,20 @@ export function calculateRamUpgradeCost(startingRam: number, extraLevels = 1, co
return totalCost;
}
export function calculateCoreUpgradeCost(startingCore: number, extraLevels = 1, costMult = 1): number {
export function calculateCoreUpgradeCost(startingCores: number, extraLevels = 1, costMult = 1): number {
const sanitizedCores = Math.round(extraLevels);
if (isNaN(sanitizedCores) || sanitizedCores < 1) {
return 0;
}
if (startingCore >= HacknetNodeConstants.MaxCores) {
if (startingCores + sanitizedCores > HacknetNodeConstants.MaxCores) {
return Infinity;
}
const coreBaseCost = HacknetNodeConstants.CoreBaseCost;
const mult = HacknetNodeConstants.UpgradeCoreMult;
let totalCost = 0;
let currentCores = startingCore;
let currentCores = startingCores;
for (let i = 0; i < sanitizedCores; ++i) {
totalCost += coreBaseCost * Math.pow(mult, currentCores - 1);
++currentCores;
+4 -4
View File
@@ -22,7 +22,7 @@ export function calculateLevelUpgradeCost(startingLevel: number, extraLevels = 1
return 0;
}
if (startingLevel >= HacknetServerConstants.MaxLevel) {
if (startingLevel + sanitizedLevels > HacknetServerConstants.MaxLevel) {
return Infinity;
}
@@ -43,7 +43,7 @@ export function calculateRamUpgradeCost(startingRam: number, extraLevels = 1, co
return 0;
}
if (startingRam >= HacknetServerConstants.MaxRam) {
if (startingRam * Math.pow(2, sanitizedLevels) > HacknetServerConstants.MaxRam) {
return Infinity;
}
@@ -70,7 +70,7 @@ export function calculateCoreUpgradeCost(startingCores: number, extraLevels = 1,
return 0;
}
if (startingCores >= HacknetServerConstants.MaxCores) {
if (startingCores + sanitizedLevels > HacknetServerConstants.MaxCores) {
return Infinity;
}
@@ -93,7 +93,7 @@ export function calculateCacheUpgradeCost(startingCache: number, extraLevels = 1
return 0;
}
if (startingCache >= HacknetServerConstants.MaxCache) {
if (startingCache + sanitizedLevels > HacknetServerConstants.MaxCache) {
return Infinity;
}