Skip to content

Commit

Permalink
feat: Item charges left trigger
Browse files Browse the repository at this point in the history
Closes #71
  • Loading branch information
Alorel committed Dec 29, 2022
1 parent 0c9ba5a commit 719db68
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/triggers/core/index.mts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
54 changes: 54 additions & 0 deletions src/triggers/core/item-charges-trigger.tsx
Original file line number Diff line number Diff line change
@@ -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<Data>({
category: InternalCategory.CORE,
check,
compactRender: ({charges, item}) => (
<Fragment>
<span>{'≤ '}</span>
<BigNum num={charges}/>
<span>{' charges on '}</span>
<RenderNodeMedia label={item.name} media={item.media}/>
</Fragment>
),
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,
},
],
});
6 changes: 6 additions & 0 deletions types/melvor/game/core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ import type {
Woodcutting,
} from './skilling';

export class ItemCharges {
charges: Map<Item, number>;
}

export class NamespacedObject {
constructor(namespace: Pick<Namespace, 'name'>, localID: string);

Expand Down Expand Up @@ -197,6 +201,8 @@ export class Game {

herblore: Herblore;

itemCharges: ItemCharges;

items: ItemRegistry;

mining: Mining;
Expand Down
2 changes: 2 additions & 0 deletions types/melvor/game/toon.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 719db68

Please sign in to comment.