Skip to content

Commit

Permalink
API: Allow passing 0 SkillPoints to skillMaxUpgradeCount
Browse files Browse the repository at this point in the history
  • Loading branch information
catloversg committed Dec 11, 2024
1 parent bf095ea commit 9b6dec5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:**

Expand Down
15 changes: 11 additions & 4 deletions src/NetscriptFunctions/Formulas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IFormulas> {
const checkFormulasAccess = function (ctx: NetscriptContext): void {
Expand Down Expand Up @@ -433,15 +434,21 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
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);
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/ScriptEditor/NetscriptDefinitions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5396,7 +5396,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(
Expand Down

0 comments on commit 9b6dec5

Please sign in to comment.