From 2b6ec5cd33104fb0e3bdd75f9f8a9da10989adf9 Mon Sep 17 00:00:00 2001 From: catloversg <152669316+catloversg@users.noreply.github.com> Date: Mon, 8 Jul 2024 04:49:23 +0700 Subject: [PATCH] BLADEBURNER: Fix wrong behavior of ns.bladeburner.getSkillUpgradeCost (#1471) --- markdown/bitburner.bladeburner.getskillupgradecost.md | 2 +- src/NetscriptFunctions/Bladeburner.ts | 6 +++++- src/ScriptEditor/NetscriptDefinitions.d.ts | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/markdown/bitburner.bladeburner.getskillupgradecost.md b/markdown/bitburner.bladeburner.getskillupgradecost.md index 6b99e0495..83173bdad 100644 --- a/markdown/bitburner.bladeburner.getskillupgradecost.md +++ b/markdown/bitburner.bladeburner.getskillupgradecost.md @@ -31,5 +31,5 @@ RAM cost: 4 GB This function returns the number of skill points needed to upgrade the specified skill the specified number of times. -The function returns -1 if an invalid skill name is passed in, and Infinity if the count overflows the maximum level. +The function returns Infinity if the sum of the current level and count exceeds the maximum level. diff --git a/src/NetscriptFunctions/Bladeburner.ts b/src/NetscriptFunctions/Bladeburner.ts index 15dc8beb6..6e6688daf 100644 --- a/src/NetscriptFunctions/Bladeburner.ts +++ b/src/NetscriptFunctions/Bladeburner.ts @@ -214,7 +214,11 @@ export function NetscriptBladeburner(): InternalAPI { const skillName = getEnumHelper("BladeSkillName").nsGetMember(ctx, _skillName, "skillName"); const count = helpers.positiveInteger(ctx, "count", _count ?? 1); const currentLevel = bladeburner.getSkillLevel(skillName); - return Skills[skillName].calculateCost(currentLevel, count); + const skill = Skills[skillName]; + if (currentLevel + count > skill.maxLvl) { + return Infinity; + } + return skill.calculateCost(currentLevel, count); }, upgradeSkill: (ctx) => (_skillName, _count) => { const bladeburner = getBladeburner(ctx); diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 6f18d1f44..bef96077f 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -3325,7 +3325,7 @@ export interface Bladeburner { * * This function returns the number of skill points needed to upgrade the specified skill the specified number of times. * - * The function returns -1 if an invalid skill name is passed in, and Infinity if the count overflows the maximum level. + * The function returns Infinity if the sum of the current level and count exceeds the maximum level. * * @param skillName - Name of skill. Case-sensitive and must be an exact match. * @param count - Number of times to upgrade the skill. Defaults to 1 if not specified.