diff --git a/markdown/bitburner.bladeburnerformulas.skillmaxupgradecount.md b/markdown/bitburner.bladeburnerformulas.skillmaxupgradecount.md index 3c815cd2e..7ab4f10c5 100644 --- a/markdown/bitburner.bladeburnerformulas.skillmaxupgradecount.md +++ b/markdown/bitburner.bladeburnerformulas.skillmaxupgradecount.md @@ -22,7 +22,7 @@ skillMaxUpgradeCount( | --- | --- | --- | | name | [BladeburnerSkillName](./bitburner.bladeburnerskillname.md) \| \`${[BladeburnerSkillName](./bitburner.bladeburnerskillname.md)}\` | Skill name. It's case-sensitive and must be an exact match. | | level | number | Skill level. It must be a non-negative number. | -| skillPoints | number | Number of skill points to upgrade the skill. It must be a positive number. | +| skillPoints | number | Number of skill points to upgrade the skill. It must be a non-negative number. | **Returns:** diff --git a/src/NetscriptFunctions/Formulas.ts b/src/NetscriptFunctions/Formulas.ts index 032bbaa0a..290be500c 100644 --- a/src/NetscriptFunctions/Formulas.ts +++ b/src/NetscriptFunctions/Formulas.ts @@ -52,6 +52,7 @@ import { getEnumHelper } from "../utils/EnumHelper"; import { CompanyPositions } from "../Company/CompanyPositions"; import { findCrime } from "../Crime/CrimeHelpers"; import { Skills } from "../Bladeburner/data/Skills"; +import type { PositiveNumber } from "../types"; export function NetscriptFormulas(): InternalAPI { const checkFormulasAccess = function (ctx: NetscriptContext): void { @@ -433,15 +434,21 @@ export function NetscriptFormulas(): InternalAPI { checkFormulasAccess(ctx); const name = getEnumHelper("BladeburnerSkillName").nsGetMember(ctx, _name, "name"); const level = helpers.number(ctx, "level", _level); - if (level < 0) { - throw new Error(`Level must be a non-negative number.`); + if (!Number.isFinite(level) || level < 0) { + throw new Error(`Level must be a finite, non-negative number. Its value is ${level}.`); + } + const skillPoints = helpers.number(ctx, "skillPoints", _skillPoints); + if (!Number.isFinite(skillPoints) || skillPoints < 0) { + throw new Error(`SkillPoints must be a finite, non-negative number. Its value is ${skillPoints}.`); } - const skillPoints = helpers.positiveNumber(ctx, "skillPoints", _skillPoints); const skill = Skills[name]; if (level >= skill.maxLvl) { return 0; } - return skill.calculateMaxUpgradeCount(level, skillPoints); + if (skillPoints === 0) { + return 0; + } + return skill.calculateMaxUpgradeCount(level, skillPoints as PositiveNumber); }, }, }; diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 4e38919a9..29d370a4d 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -5419,7 +5419,7 @@ interface BladeburnerFormulas { * * @param name - Skill name. It's case-sensitive and must be an exact match. * @param level - Skill level. It must be a non-negative number. - * @param skillPoints - Number of skill points to upgrade the skill. It must be a positive number. + * @param skillPoints - Number of skill points to upgrade the skill. It must be a non-negative number. * @returns Number of times that you can upgrade the skill. */ skillMaxUpgradeCount(