mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2025-01-20 13:01:27 +01:00
API: Allow passing 0 SkillPoints to skillMaxUpgradeCount (#1844)
This commit is contained in:
parent
7c732689dd
commit
37ddb43b82
@ -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. |
|
| 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. |
|
| 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:**
|
**Returns:**
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@ import { getEnumHelper } from "../utils/EnumHelper";
|
|||||||
import { CompanyPositions } from "../Company/CompanyPositions";
|
import { CompanyPositions } from "../Company/CompanyPositions";
|
||||||
import { findCrime } from "../Crime/CrimeHelpers";
|
import { findCrime } from "../Crime/CrimeHelpers";
|
||||||
import { Skills } from "../Bladeburner/data/Skills";
|
import { Skills } from "../Bladeburner/data/Skills";
|
||||||
|
import type { PositiveNumber } from "../types";
|
||||||
|
|
||||||
export function NetscriptFormulas(): InternalAPI<IFormulas> {
|
export function NetscriptFormulas(): InternalAPI<IFormulas> {
|
||||||
const checkFormulasAccess = function (ctx: NetscriptContext): void {
|
const checkFormulasAccess = function (ctx: NetscriptContext): void {
|
||||||
@ -433,15 +434,21 @@ export function NetscriptFormulas(): InternalAPI<IFormulas> {
|
|||||||
checkFormulasAccess(ctx);
|
checkFormulasAccess(ctx);
|
||||||
const name = getEnumHelper("BladeburnerSkillName").nsGetMember(ctx, _name, "name");
|
const name = getEnumHelper("BladeburnerSkillName").nsGetMember(ctx, _name, "name");
|
||||||
const level = helpers.number(ctx, "level", _level);
|
const level = helpers.number(ctx, "level", _level);
|
||||||
if (level < 0) {
|
if (!Number.isFinite(level) || level < 0) {
|
||||||
throw new Error(`Level must be a non-negative number.`);
|
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];
|
const skill = Skills[name];
|
||||||
if (level >= skill.maxLvl) {
|
if (level >= skill.maxLvl) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return skill.calculateMaxUpgradeCount(level, skillPoints);
|
if (skillPoints === 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return skill.calculateMaxUpgradeCount(level, skillPoints as PositiveNumber);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
2
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
2
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -5419,7 +5419,7 @@ interface BladeburnerFormulas {
|
|||||||
*
|
*
|
||||||
* @param name - Skill name. It's case-sensitive and must be an exact match.
|
* @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 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.
|
* @returns Number of times that you can upgrade the skill.
|
||||||
*/
|
*/
|
||||||
skillMaxUpgradeCount(
|
skillMaxUpgradeCount(
|
||||||
|
Loading…
Reference in New Issue
Block a user