diff --git a/src/lib/MUser.ts b/src/lib/MUser.ts index c53d19673e..0f109fd087 100644 --- a/src/lib/MUser.ts +++ b/src/lib/MUser.ts @@ -47,6 +47,7 @@ import { Gear } from './structures/Gear'; import { GearBank } from './structures/GearBank'; import { MTame } from './structures/MTame'; import type { Skills } from './types'; +import type { SkillRequirements } from './types'; import { addItemToBank, convertXPtoLVL, fullGearToBank, hasSkillReqsRaw, itemNameFromID } from './util'; import { determineRunes } from './util/determineRunes'; import { findGroupOfUser } from './util/findGroupOfUser'; @@ -188,6 +189,10 @@ export class MUserClass { return Math.floor(base + Math.max(melee, range, mage)); } + get skillsAsRequirements(): Required { + return { ...this.skillsAsLevels, combat: this.combatLevel }; + } + favAlchs(duration: number, agility?: boolean) { const { bank } = this; return this.user.favorite_alchables @@ -684,8 +689,8 @@ Charge your items using ${mentionCommand(globalClient, 'minion', 'charge')}.` return updates; } - hasSkillReqs(requirements: Skills) { - return hasSkillReqsRaw(this.skillsAsLevels, requirements); + hasSkillReqs(requirements: SkillRequirements) { + return hasSkillReqsRaw(this.skillsAsRequirements, requirements); } allEquippedGearBank() { diff --git a/src/lib/types/index.ts b/src/lib/types/index.ts index 07e79bd952..52ad48e646 100644 --- a/src/lib/types/index.ts +++ b/src/lib/types/index.ts @@ -25,6 +25,7 @@ export type Skills = Partial<{ [key in SkillsEnum]: number; }>; +export type SkillRequirements = Skills & { combat?: number }; export type SkillsRequired = Required; export type CategoryFlag = diff --git a/src/lib/util/smallUtils.ts b/src/lib/util/smallUtils.ts index 6b88483793..b9df9d2478 100644 --- a/src/lib/util/smallUtils.ts +++ b/src/lib/util/smallUtils.ts @@ -9,7 +9,7 @@ import z from 'zod'; import { skillEmoji } from '../data/emojis'; import type { UserFullGearSetup } from '../gear/types'; -import type { Skills } from '../types'; +import type { SkillRequirements, Skills } from '../types'; export function itemNameFromID(itemID: number | string) { return Items.get(itemID)?.name; @@ -219,7 +219,7 @@ export function parseStaticTimeInterval(input: string): input is StaticTimeInter return false; } -export function hasSkillReqsRaw(skills: Skills, requirements: Skills) { +export function hasSkillReqsRaw(skills: SkillRequirements, requirements: SkillRequirements) { for (const [skillName, requiredLevel] of objectEntries(requirements)) { const lvl = skills[skillName]; if (!lvl || lvl < requiredLevel!) { @@ -230,7 +230,7 @@ export function hasSkillReqsRaw(skills: Skills, requirements: Skills) { } export function hasSkillReqs(user: MUser, reqs: Skills): [boolean, string | null] { - const hasReqs = hasSkillReqsRaw(user.skillsAsLevels, reqs); + const hasReqs = hasSkillReqsRaw(user.skillsAsRequirements, reqs); if (!hasReqs) { return [false, formatSkillRequirements(reqs)]; }