2024-03-29 02:52:37 +01:00
|
|
|
import type { BladeMultName, BladeSkillName } from "@enums";
|
|
|
|
|
2023-06-16 23:52:42 +02:00
|
|
|
import { currentNodeMults } from "../BitNode/BitNodeMultipliers";
|
2024-03-29 02:52:37 +01:00
|
|
|
import { Bladeburner } from "./Bladeburner";
|
|
|
|
import { Availability } from "./Types";
|
2024-04-08 12:33:45 +02:00
|
|
|
import { PositiveInteger, PositiveSafeInteger, isPositiveInteger } from "../types";
|
2024-03-29 02:52:37 +01:00
|
|
|
import { PartialRecord, getRecordEntries } from "../Types/Record";
|
2021-03-13 21:10:55 +01:00
|
|
|
|
2024-03-29 02:52:37 +01:00
|
|
|
interface SkillParams {
|
|
|
|
name: BladeSkillName;
|
2021-09-05 01:09:30 +02:00
|
|
|
desc: string;
|
|
|
|
baseCost?: number;
|
|
|
|
costInc?: number;
|
|
|
|
maxLvl?: number;
|
2024-03-29 02:52:37 +01:00
|
|
|
mults: PartialRecord<BladeMultName, number>;
|
2021-03-13 21:10:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export class Skill {
|
2024-03-29 02:52:37 +01:00
|
|
|
name: BladeSkillName;
|
2021-09-05 01:09:30 +02:00
|
|
|
desc: string;
|
|
|
|
// Cost is in Skill Points
|
2024-03-29 19:27:36 +01:00
|
|
|
baseCost: number;
|
2021-09-05 01:09:30 +02:00
|
|
|
// Additive cost increase per level
|
2024-03-29 19:27:36 +01:00
|
|
|
costInc: number;
|
|
|
|
maxLvl: number;
|
2024-03-29 02:52:37 +01:00
|
|
|
mults: PartialRecord<BladeMultName, number> = {};
|
2021-09-05 01:09:30 +02:00
|
|
|
|
2024-03-29 02:52:37 +01:00
|
|
|
constructor(params: SkillParams) {
|
2021-09-05 01:09:30 +02:00
|
|
|
this.name = params.name;
|
|
|
|
this.desc = params.desc;
|
2024-03-29 02:52:37 +01:00
|
|
|
this.baseCost = params.baseCost ?? 1;
|
|
|
|
this.costInc = params.costInc ?? 1;
|
2024-03-29 19:27:36 +01:00
|
|
|
this.maxLvl = params.maxLvl ?? Number.MAX_SAFE_INTEGER;
|
2024-03-29 02:52:37 +01:00
|
|
|
for (const [multName, mult] of getRecordEntries(params.mults)) this.mults[multName] = mult;
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
|
2024-04-08 12:33:45 +02:00
|
|
|
calculateCost(currentLevel: number, count = 1 as PositiveInteger): number {
|
2024-03-29 02:52:37 +01:00
|
|
|
if (currentLevel + count > this.maxLvl) return Infinity;
|
2024-04-08 12:33:45 +02:00
|
|
|
|
2024-03-29 02:52:37 +01:00
|
|
|
const recursiveMode = (currentLevel: number, count: PositiveSafeInteger): number => {
|
2022-05-29 18:35:28 +02:00
|
|
|
if (count <= 1) {
|
2023-06-16 23:52:42 +02:00
|
|
|
return Math.floor((this.baseCost + currentLevel * this.costInc) * currentNodeMults.BladeburnerSkillCost);
|
2022-05-29 18:35:28 +02:00
|
|
|
} else {
|
|
|
|
const thisUpgrade = Math.floor(
|
2023-06-16 23:52:42 +02:00
|
|
|
(this.baseCost + currentLevel * this.costInc) * currentNodeMults.BladeburnerSkillCost,
|
2022-05-29 18:35:28 +02:00
|
|
|
);
|
2024-03-29 02:52:37 +01:00
|
|
|
return this.calculateCost(currentLevel + 1, (count - 1) as PositiveSafeInteger) + thisUpgrade;
|
2022-05-29 18:35:28 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-04-08 12:33:45 +02:00
|
|
|
// Use recursive mode if count is small
|
|
|
|
if (count <= 100) return recursiveMode(currentLevel, count as PositiveSafeInteger);
|
|
|
|
// Use optimized mode if count is large
|
2022-05-29 18:35:28 +02:00
|
|
|
else {
|
2022-05-29 04:06:25 +02:00
|
|
|
//unFloored is roughly equivalent to
|
|
|
|
//(this.baseCost + currentLevel * this.costInc) * BitNodeMultipliers.BladeburnerSkillCost
|
|
|
|
//being repeated for increasing currentLevel
|
2022-05-29 04:35:20 +02:00
|
|
|
const preMult = (count * (2 * this.baseCost + this.costInc * (2 * currentLevel + count + 1))) / 2;
|
2023-06-16 23:52:42 +02:00
|
|
|
const unFloored = preMult * currentNodeMults.BladeburnerSkillCost - count / 2;
|
2022-05-29 04:06:25 +02:00
|
|
|
return Math.floor(unFloored);
|
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
|
2024-03-29 02:52:37 +01:00
|
|
|
canUpgrade(bladeburner: Bladeburner, count = 1): Availability<{ cost: number }> {
|
|
|
|
const currentLevel = bladeburner.skills[this.name] ?? 0;
|
2024-04-08 12:33:45 +02:00
|
|
|
if (!isPositiveInteger(count)) return { error: `Invalid upgrade count ${count}` };
|
2024-03-29 02:52:37 +01:00
|
|
|
if (currentLevel + count > this.maxLvl) return { error: `Upgraded level ${currentLevel + count} exceeds max` };
|
|
|
|
const cost = this.calculateCost(currentLevel, count);
|
|
|
|
if (cost > bladeburner.skillPoints) return { error: `Insufficient skill points for upgrade` };
|
|
|
|
return { available: true, cost };
|
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
|
2024-03-29 02:52:37 +01:00
|
|
|
getMultiplier(name: BladeMultName): number {
|
|
|
|
return this.mults[name] ?? 0;
|
2021-09-05 01:09:30 +02:00
|
|
|
}
|
|
|
|
}
|