Skip to content

Commit

Permalink
Fix combat skill item requirements (#6197)
Browse files Browse the repository at this point in the history
  • Loading branch information
themrrobert authored and gc committed Dec 11, 2024
1 parent ba51dee commit 9a1c905
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/lib/MUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -188,6 +189,10 @@ export class MUserClass {
return Math.floor(base + Math.max(melee, range, mage));
}

get skillsAsRequirements(): Required<SkillRequirements> {
return { ...this.skillsAsLevels, combat: this.combatLevel };
}

favAlchs(duration: number, agility?: boolean) {
const { bank } = this;
return this.user.favorite_alchables
Expand Down Expand Up @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions src/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type Skills = Partial<{
[key in SkillsEnum]: number;
}>;

export type SkillRequirements = Skills & { combat?: number };
export type SkillsRequired = Required<Skills>;

export type CategoryFlag =
Expand Down
6 changes: 3 additions & 3 deletions src/lib/util/smallUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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!) {
Expand All @@ -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)];
}
Expand Down

0 comments on commit 9a1c905

Please sign in to comment.