mwg API
    Preparing search index...

    Class CombatHooks<C>

    Generic combat lifecycle hooks; the game owns HP, formulas, and when each event fires.

    The registry is core.HookRegistry, the same one battle.BattleHooks uses - these were two copies of one class for a while. What is combat-specific is that a handler receives a single mutable DamageContext, and the modifyDamage seam below built on it.

    import { CombatHooks } from '@datamoc/mw_games/roguelike';

    const hooks = new CombatHooks<{ name: string }>();
    const invulnerability = {};

    hooks.on('beforeDamage', (ctx) => { ctx.amount = 0; }, invulnerability);

    const result = hooks.modifyDamage({ name: 'hero' }, { name: 'rat' }, 5);
    console.log(result.amount, result.prevented); // 0 true

    Type Parameters

    • C

    Hierarchy (View Summary)

    Index
    • get size(): number

      how many handlers are registered, across every event

      Returns number

    • removes every hook registered with this source - a fainted creature's ability leaving

      Parameters

      • source: unknown

      Returns void