Skip to content

Commit

Permalink
Fix combat skill item requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
themrrobert committed Nov 18, 2024
1 parent d07bfb7 commit 45ddf10
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/lib/MUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -174,6 +174,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 @@ -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() {
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 @@ -18,6 +18,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 {SkillRequirements, Skills} from '../types';

export function itemNameFromID(itemID: number | string) {
return Items.get(itemID)?.name;
Expand Down Expand Up @@ -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!) {
Expand All @@ -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)];
}
Expand Down

0 comments on commit 45ddf10

Please sign in to comment.