mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-23 22:52:29 +01:00
BLADEBURNER: Allow unsafe positive integers for skill upgrade count (#1211)
This commit is contained in:
parent
7ae309edda
commit
be437c83f6
@ -3,7 +3,7 @@ import type { BladeMultName, BladeSkillName } from "@enums";
|
|||||||
import { currentNodeMults } from "../BitNode/BitNodeMultipliers";
|
import { currentNodeMults } from "../BitNode/BitNodeMultipliers";
|
||||||
import { Bladeburner } from "./Bladeburner";
|
import { Bladeburner } from "./Bladeburner";
|
||||||
import { Availability } from "./Types";
|
import { Availability } from "./Types";
|
||||||
import { PositiveSafeInteger, isPositiveSafeInteger } from "../types";
|
import { PositiveInteger, PositiveSafeInteger, isPositiveInteger } from "../types";
|
||||||
import { PartialRecord, getRecordEntries } from "../Types/Record";
|
import { PartialRecord, getRecordEntries } from "../Types/Record";
|
||||||
|
|
||||||
interface SkillParams {
|
interface SkillParams {
|
||||||
@ -34,10 +34,9 @@ export class Skill {
|
|||||||
for (const [multName, mult] of getRecordEntries(params.mults)) this.mults[multName] = mult;
|
for (const [multName, mult] of getRecordEntries(params.mults)) this.mults[multName] = mult;
|
||||||
}
|
}
|
||||||
|
|
||||||
calculateCost(currentLevel: number, count = 1 as PositiveSafeInteger): number {
|
calculateCost(currentLevel: number, count = 1 as PositiveInteger): number {
|
||||||
if (currentLevel + count > this.maxLvl) return Infinity;
|
if (currentLevel + count > this.maxLvl) return Infinity;
|
||||||
//Recursive mode does not handle invalid inputs properly, but it should never
|
|
||||||
//be possible for it to run with them. For the sake of not crashing the game,
|
|
||||||
const recursiveMode = (currentLevel: number, count: PositiveSafeInteger): number => {
|
const recursiveMode = (currentLevel: number, count: PositiveSafeInteger): number => {
|
||||||
if (count <= 1) {
|
if (count <= 1) {
|
||||||
return Math.floor((this.baseCost + currentLevel * this.costInc) * currentNodeMults.BladeburnerSkillCost);
|
return Math.floor((this.baseCost + currentLevel * this.costInc) * currentNodeMults.BladeburnerSkillCost);
|
||||||
@ -49,15 +48,9 @@ export class Skill {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//Count must be a positive integer.
|
// Use recursive mode if count is small
|
||||||
if (count < 0 || count % 1 != 0) {
|
if (count <= 100) return recursiveMode(currentLevel, count as PositiveSafeInteger);
|
||||||
throw new Error(`${count} is an invalid number of upgrades`);
|
// Use optimized mode if count is large
|
||||||
}
|
|
||||||
//Use recursive mode if count is small
|
|
||||||
if (count <= 100) {
|
|
||||||
return recursiveMode(currentLevel, count);
|
|
||||||
}
|
|
||||||
//Use optimized mode if count is large
|
|
||||||
else {
|
else {
|
||||||
//unFloored is roughly equivalent to
|
//unFloored is roughly equivalent to
|
||||||
//(this.baseCost + currentLevel * this.costInc) * BitNodeMultipliers.BladeburnerSkillCost
|
//(this.baseCost + currentLevel * this.costInc) * BitNodeMultipliers.BladeburnerSkillCost
|
||||||
@ -70,7 +63,7 @@ export class Skill {
|
|||||||
|
|
||||||
canUpgrade(bladeburner: Bladeburner, count = 1): Availability<{ cost: number }> {
|
canUpgrade(bladeburner: Bladeburner, count = 1): Availability<{ cost: number }> {
|
||||||
const currentLevel = bladeburner.skills[this.name] ?? 0;
|
const currentLevel = bladeburner.skills[this.name] ?? 0;
|
||||||
if (!isPositiveSafeInteger(count)) return { error: `Invalid upgrade count ${count}` };
|
if (!isPositiveInteger(count)) return { error: `Invalid upgrade count ${count}` };
|
||||||
if (currentLevel + count > this.maxLvl) return { error: `Upgraded level ${currentLevel + count} exceeds max` };
|
if (currentLevel + count > this.maxLvl) return { error: `Upgraded level ${currentLevel + count} exceeds max` };
|
||||||
const cost = this.calculateCost(currentLevel, count);
|
const cost = this.calculateCost(currentLevel, count);
|
||||||
if (cost > bladeburner.skillPoints) return { error: `Insufficient skill points for upgrade` };
|
if (cost > bladeburner.skillPoints) return { error: `Insufficient skill points for upgrade` };
|
||||||
|
@ -202,14 +202,14 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
|||||||
getSkillUpgradeCost: (ctx) => (_skillName, _count) => {
|
getSkillUpgradeCost: (ctx) => (_skillName, _count) => {
|
||||||
const bladeburner = getBladeburner(ctx);
|
const bladeburner = getBladeburner(ctx);
|
||||||
const skillName = getEnumHelper("BladeSkillName").nsGetMember(ctx, _skillName, "skillName");
|
const skillName = getEnumHelper("BladeSkillName").nsGetMember(ctx, _skillName, "skillName");
|
||||||
const count = helpers.positiveSafeInteger(ctx, "count", _count ?? 1);
|
const count = helpers.positiveInteger(ctx, "count", _count ?? 1);
|
||||||
const currentLevel = bladeburner.getSkillLevel(skillName);
|
const currentLevel = bladeburner.getSkillLevel(skillName);
|
||||||
return Skills[skillName].calculateCost(currentLevel, count);
|
return Skills[skillName].calculateCost(currentLevel, count);
|
||||||
},
|
},
|
||||||
upgradeSkill: (ctx) => (_skillName, _count) => {
|
upgradeSkill: (ctx) => (_skillName, _count) => {
|
||||||
const bladeburner = getBladeburner(ctx);
|
const bladeburner = getBladeburner(ctx);
|
||||||
const skillName = getEnumHelper("BladeSkillName").nsGetMember(ctx, _skillName, "skillName");
|
const skillName = getEnumHelper("BladeSkillName").nsGetMember(ctx, _skillName, "skillName");
|
||||||
const count = helpers.positiveSafeInteger(ctx, "count", _count ?? 1);
|
const count = helpers.positiveInteger(ctx, "count", _count ?? 1);
|
||||||
const attempt = bladeburner.upgradeSkill(skillName, count);
|
const attempt = bladeburner.upgradeSkill(skillName, count);
|
||||||
helpers.log(ctx, () => attempt.message);
|
helpers.log(ctx, () => attempt.message);
|
||||||
return !!attempt.success;
|
return !!attempt.success;
|
||||||
|
Loading…
Reference in New Issue
Block a user