diff --git a/src/triggers/core/index.mts b/src/triggers/core/index.mts index 80416c4..77f0414 100644 --- a/src/triggers/core/index.mts +++ b/src/triggers/core/index.mts @@ -1,5 +1,6 @@ import './equipped-food-count'; import './equipped-item-count'; +import './item-charges-trigger'; import './item-quantity-trigger'; import './level-gained-trigger'; import './mastery-level-trigger.mjs'; diff --git a/src/triggers/core/item-charges-trigger.tsx b/src/triggers/core/item-charges-trigger.tsx new file mode 100644 index 0000000..988539b --- /dev/null +++ b/src/triggers/core/item-charges-trigger.tsx @@ -0,0 +1,54 @@ +import type {EquipmentItem as TEquipmentItem} from 'melvor'; +import {Fragment} from 'preact'; +import {InternalCategory} from '../../lib/registries/action-registry.mjs'; +import {defineLocalTrigger} from '../../lib/util/define-local.mjs'; +import {BigNum} from '../../ui/components/big-num'; +import {RenderNodeMedia} from '../../ui/pages/workflows-dashboard/render-node-media'; + +interface Data { + charges: number; + + item: TEquipmentItem; +} + +function check({charges, item}: Data): boolean { + return (game.itemCharges.charges.get(item) ?? 0) <= charges; +} + +const triggerCtx = defineLocalTrigger({ + category: InternalCategory.CORE, + check, + compactRender: ({charges, item}) => ( + + {'≤ '} + + {' charges on '} + + + ), + init() { + ctx.patch(Player, 'consumeEquipmentCharges').after(() => { + triggerCtx.notifyListeners(check); + }); + }, + label: 'Item charges left', + localID: 'itemCharges', + media: game.items.getObjectByID('melvorD:Gem_Gloves')!.media, + options: [ + { + label: 'Item', + localID: 'item', + mediaFilter: item => item instanceof EquipmentItem, + registry: 'items', + required: true, + type: 'MediaItem', + }, + { + label: 'Charges', + localID: 'charges', + min: 0, + required: true, + type: Number, + }, + ], +}); diff --git a/types/melvor/game/core.d.ts b/types/melvor/game/core.d.ts index ae40653..0ab64e1 100644 --- a/types/melvor/game/core.d.ts +++ b/types/melvor/game/core.d.ts @@ -32,6 +32,10 @@ import type { Woodcutting, } from './skilling'; +export class ItemCharges { + charges: Map; +} + export class NamespacedObject { constructor(namespace: Pick, localID: string); @@ -197,6 +201,8 @@ export class Game { herblore: Herblore; + itemCharges: ItemCharges; + items: ItemRegistry; mining: Mining; diff --git a/types/melvor/game/toon.d.ts b/types/melvor/game/toon.d.ts index f9458c3..a81ee4b 100644 --- a/types/melvor/game/toon.d.ts +++ b/types/melvor/game/toon.d.ts @@ -115,6 +115,8 @@ export class Player extends Character { changeEquipmentSet(setId: number): void; + consumeEquipmentCharges(event: unknown, interval: unknown): void; + consumePrayerPoints(amount: number): void; disableActivePrayers(): void;