mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-11 02:03:58 +01:00
Added count to NS cost function, input checking, fixed documentation
Also changed upgradeSkill back to returning a bool instead of a number.
This commit is contained in:
parent
f8f3c099e0
commit
06acc423ae
@ -2276,7 +2276,7 @@ export class Bladeburner implements IBladeburner {
|
||||
}
|
||||
}
|
||||
|
||||
getSkillUpgradeCostNetscriptFn(skillName: string, workerScript: WorkerScript): number {
|
||||
getSkillUpgradeCostNetscriptFn(skillName: string, count: number, workerScript: WorkerScript): number {
|
||||
if (skillName === "" || !Skills.hasOwnProperty(skillName)) {
|
||||
workerScript.log("bladeburner.getSkillUpgradeCost", () => `Invalid skill: '${skillName}'`);
|
||||
return -1;
|
||||
@ -2284,9 +2284,9 @@ export class Bladeburner implements IBladeburner {
|
||||
|
||||
const skill = Skills[skillName];
|
||||
if (this.skills[skillName] == null) {
|
||||
return skill.calculateCost(0);
|
||||
return skill.calculateCost(0, count);
|
||||
} else {
|
||||
return skill.calculateCost(this.skills[skillName]);
|
||||
return skill.calculateCost(this.skills[skillName], count);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ export interface IBladeburner {
|
||||
getActionEstimatedSuccessChanceNetscriptFn(person: IPerson, type: string, name: string): [number, number] | string;
|
||||
getActionCountRemainingNetscriptFn(type: string, name: string, workerScript: WorkerScript): number;
|
||||
getSkillLevelNetscriptFn(skillName: string, workerScript: WorkerScript): number;
|
||||
getSkillUpgradeCostNetscriptFn(skillName: string, workerScript: WorkerScript): number;
|
||||
getSkillUpgradeCostNetscriptFn(skillName: string, count: number, workerScript: WorkerScript): number;
|
||||
upgradeSkillNetscriptFn(skillName: string, count: number, workerScript: WorkerScript): boolean;
|
||||
getTeamSizeNetscriptFn(type: string, name: string, workerScript: WorkerScript): number;
|
||||
setTeamSizeNetscriptFn(type: string, name: string, size: number, workerScript: WorkerScript): number;
|
||||
|
@ -136,8 +136,8 @@ export class Skill {
|
||||
calculateCost(currentLevel: number, count = 1): number {
|
||||
if (count == 1) {
|
||||
return Math.floor((this.baseCost + currentLevel * this.costInc) * BitNodeMultipliers.BladeburnerSkillCost);
|
||||
} else if (count < 0 || isNaN(count)) {
|
||||
throw new Error(`Attempted to find cost of ${count} BB upgrades`);
|
||||
} else if (count < 0 || isNaN(count) || count == Infinity || count % 1 != 0) {
|
||||
throw new Error(`${count} is an invalid number of upgrades`);
|
||||
} else if (count < 100) {
|
||||
const thisUpgrade = Math.floor(
|
||||
(this.baseCost + currentLevel * this.costInc) * BitNodeMultipliers.BladeburnerSkillCost,
|
||||
|
@ -279,30 +279,28 @@ export function NetscriptBladeburner(player: IPlayer, workerScript: WorkerScript
|
||||
},
|
||||
getSkillUpgradeCost:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_skillName: unknown): number => {
|
||||
(_skillName: unknown, _count = 1): number => {
|
||||
const skillName = ctx.helper.string("skillName", _skillName);
|
||||
const count = ctx.helper.number("count", _count);
|
||||
checkBladeburnerAccess(ctx);
|
||||
const bladeburner = player.bladeburner;
|
||||
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
|
||||
try {
|
||||
return bladeburner.getSkillUpgradeCostNetscriptFn(skillName, workerScript);
|
||||
return bladeburner.getSkillUpgradeCostNetscriptFn(skillName, count, workerScript);
|
||||
} catch (e: any) {
|
||||
throw ctx.makeRuntimeErrorMsg(e);
|
||||
}
|
||||
},
|
||||
upgradeSkill:
|
||||
(ctx: NetscriptContext) =>
|
||||
(_skillName: unknown, count = 1): number => {
|
||||
(_skillName: unknown, _count = 1): boolean => {
|
||||
const skillName = ctx.helper.string("skillName", _skillName);
|
||||
const count = ctx.helper.number("count", _count);
|
||||
checkBladeburnerAccess(ctx);
|
||||
const bladeburner = player.bladeburner;
|
||||
if (bladeburner === null) throw new Error("Should not be called without Bladeburner");
|
||||
try {
|
||||
if (bladeburner.upgradeSkillNetscriptFn(skillName, count, workerScript)) {
|
||||
return count;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
return bladeburner.upgradeSkillNetscriptFn(skillName, count, workerScript);
|
||||
} catch (e: any) {
|
||||
throw ctx.makeRuntimeErrorMsg(e);
|
||||
}
|
||||
|
10
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
10
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -3080,28 +3080,30 @@ export interface Bladeburner {
|
||||
* @remarks
|
||||
* RAM cost: 4 GB
|
||||
*
|
||||
* This function returns the number of skill points needed to upgrade the specified skill.
|
||||
* 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.
|
||||
*
|
||||
* @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.
|
||||
* @returns Number of skill points needed to upgrade the specified skill.
|
||||
*/
|
||||
getSkillUpgradeCost(name: string): number;
|
||||
getSkillUpgradeCost(name: string, count?: number): number;
|
||||
|
||||
/**
|
||||
* Upgrade skill.
|
||||
* @remarks
|
||||
* RAM cost: 4 GB
|
||||
*
|
||||
* Attempts to upgrade the specified Bladeburner skill.
|
||||
* Attempts to upgrade the specified Bladeburner skill the specified number of times.
|
||||
*
|
||||
* Returns true if the skill is successfully upgraded, and false otherwise.
|
||||
*
|
||||
* @param skillName - Name of skill to be upgraded. Case-sensitive and must be an exact match
|
||||
* @param count - Number of times to upgrade the skill. Defaults to 1 if not specified.
|
||||
* @returns true if the skill is successfully upgraded, and false otherwise.
|
||||
*/
|
||||
upgradeSkill(name: string, count: number): number;
|
||||
upgradeSkill(name: string, count?: number): boolean;
|
||||
|
||||
/**
|
||||
* Get team size.
|
||||
|
Loading…
Reference in New Issue
Block a user