BUGFIX: hacknetNodeCost formula API throws when using documented optional parameter (#2577)

This commit is contained in:
catloversg
2026-03-17 02:46:06 +07:00
committed by GitHub
parent 06e6479408
commit c00da0cd87
3 changed files with 11 additions and 9 deletions

View File

@@ -9,7 +9,7 @@ Calculate the cost of a hacknet node.
**Signature:**
```typescript
hacknetNodeCost(n: number, mult: number): number;
hacknetNodeCost(n: number, mult?: number): number;
```
## Parameters
@@ -58,7 +58,7 @@ number
</td><td>
player cost reduction (defaults to 1)
_(Optional)_ player cost reduction (defaults to 1)
</td></tr>

View File

@@ -274,12 +274,14 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
checkFormulasAccess(ctx);
return calculateCoreUpgradeCost(startingCore, extraCores, costMult);
},
hacknetNodeCost: (ctx) => (_n, _mult) => {
const n = helpers.number(ctx, "n", _n);
const mult = helpers.number(ctx, "mult", _mult);
checkFormulasAccess(ctx);
return calculateNodeCost(n, mult);
},
hacknetNodeCost:
(ctx) =>
(_n, _mult = 1) => {
const n = helpers.number(ctx, "n", _n);
const mult = helpers.number(ctx, "mult", _mult);
checkFormulasAccess(ctx);
return calculateNodeCost(n, mult);
},
constants: (ctx) => () => {
checkFormulasAccess(ctx);
return Object.assign({}, HacknetNodeConstants);

View File

@@ -6328,7 +6328,7 @@ interface HacknetNodesFormulas {
* @param mult - player cost reduction (defaults to 1)
* @returns The calculated cost.
*/
hacknetNodeCost(n: number, mult: number): number;
hacknetNodeCost(n: number, mult?: number): number;
/**
* All constants used by the game.
* @returns An object with all hacknet node constants used by the game.