From 64a7e93a46460f4c521d7381c4946fc17957739a Mon Sep 17 00:00:00 2001 From: Arturas Date: Fri, 9 Dec 2022 00:13:00 +0000 Subject: [PATCH] feat: Enemy attack type trigger --- .../combat/enemy-attack-type-trigger.mts | 42 +++++++++++++++++++ src/triggers/combat/index.mts | 1 + types/melvor/game/combat.d.ts | 2 +- 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/triggers/combat/enemy-attack-type-trigger.mts diff --git a/src/triggers/combat/enemy-attack-type-trigger.mts b/src/triggers/combat/enemy-attack-type-trigger.mts new file mode 100644 index 0000000..9b3c500 --- /dev/null +++ b/src/triggers/combat/enemy-attack-type-trigger.mts @@ -0,0 +1,42 @@ +import {upperFirst} from 'lodash-es'; +import type {Enemy} from 'melvor'; +import {InternalCategory} from '../../lib/registries/action-registry.mjs'; +import {defineLocalTrigger} from '../../lib/util/define-local.mjs'; +import type {Obj} from '../../public_api'; + +interface Data { + type: Enemy['attackType']; +} + +const triggerCtx = defineLocalTrigger({ + category: InternalCategory.COMBAT, + check: d => game.combat.isActive && game.combat.enemy.attackType === d.type, + init() { + ctx.patch(CombatManager, 'spawnEnemy').after(() => { + const ty = game.combat.enemy.attackType; + triggerCtx.notifyListeners(d => d.type === ty); + }); + }, + initOptions: () => ({type: AttackTypeID[AttackTypeID.melee] as Enemy['attackType']}), + label: 'Monster attack type in combat', + localID: 'mobAtkType', + media: cdnMedia('assets/media/skills/combat/combat.svg'), + options: [ + { + enum: [AttackTypeID.melee, AttackTypeID.magic, AttackTypeID.ranged] + .reduce>( + (acc, id) => { + const val = AttackTypeID[id] as Enemy['attackType']; + acc[val] = upperFirst(val); + + return acc; + }, + {} + ), + label: 'Type', + localID: 'type', + required: true, + type: String, + }, + ], +}); diff --git a/src/triggers/combat/index.mts b/src/triggers/combat/index.mts index 5ca7c72..5a73ad2 100644 --- a/src/triggers/combat/index.mts +++ b/src/triggers/combat/index.mts @@ -1,2 +1,3 @@ +import './enemy-attack-type-trigger.mjs'; import './enemy-id-trigger.mjs'; import './enemy-special-attack-trigger'; diff --git a/types/melvor/game/combat.d.ts b/types/melvor/game/combat.d.ts index 4e23198..537cdf2 100644 --- a/types/melvor/game/combat.d.ts +++ b/types/melvor/game/combat.d.ts @@ -31,7 +31,7 @@ export class CombatSkill extends Skill { } export class Enemy extends Character { - attackType: AttackTypeID; + attackType: Exclude; availableAttacks: Array<{ attack: SpecialAttack;