From 45ddf106512c580a4cc8f2aa516ba9745ffa8570 Mon Sep 17 00:00:00 2001 From: themrrobert <10122432+themrrobert@users.noreply.github.com> Date: Mon, 18 Nov 2024 04:16:10 -0800 Subject: [PATCH] Fix combat skill item requirements --- src/lib/MUser.ts | 10 +++++++--- src/lib/types/index.ts | 1 + src/lib/util/smallUtils.ts | 6 +++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/lib/MUser.ts b/src/lib/MUser.ts index 6a9c8c8577..8e72dc2816 100644 --- a/src/lib/MUser.ts +++ b/src/lib/MUser.ts @@ -43,7 +43,7 @@ import { ChargeBank } from './structures/Bank'; import { Gear, defaultGear } from './structures/Gear'; import { GearBank } from './structures/GearBank'; import type { XPBank } from './structures/XPBank'; -import type { ItemBank, Skills } from './types'; +import {ItemBank, SkillRequirements, Skills} from './types'; import { addItemToBank, convertXPtoLVL, fullGearToBank, hasSkillReqsRaw, itemNameFromID } from './util'; import { determineRunes } from './util/determineRunes'; import { getKCByName } from './util/getKCByName'; @@ -174,6 +174,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 @@ -666,8 +670,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 c5cd06cf32..8066bf6fac 100644 --- a/src/lib/types/index.ts +++ b/src/lib/types/index.ts @@ -18,6 +18,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 9699518863..e60279a565 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 {SkillRequirements, Skills} from '../types'; export function itemNameFromID(itemID: number | string) { return Items.get(itemID)?.name; @@ -192,7 +192,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!) { @@ -203,7 +203,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)]; }