mwg API
    Preparing search index...

    Function applyStatusEffect

    • A temporary buff or debuff: applies modifiers to stats and registers their expiry with clock, so a game never has to remember to remove what it added. The seam TurnClock and StatBlock never had on their own - TurnClock ticks and expires effects, StatBlock resolves modifiers, but nothing tied one's expiry to the other's removal.

      cancel() on the returned handle removes the modifiers immediately and unregisters the clock entry - needed because TurnClock.remove alone only stops future ticks, it does not know this entry ever touched a StatBlock at all.

      Parameters

      Returns StatusEffectHandle

      import { applyStatusEffect, StatBlock } from '@datamoc/mw_games/actors';
      import { TurnClock } from '@datamoc/mw_games/world';

      const stats = new StatBlock({ base: { hp: 20, attack: 5 } });
      const clock = new TurnClock();

      const poison = applyStatusEffect(stats, clock, {
      modifiers: [{ stat: 'attack', op: 'add', value: -2 }],
      duration: 3,
      tick: () => stats.setBase('hp', stats.base('hp') - 2),
      });

      clock.advance(); // one poison tick
      poison.cancel(); // a cure spell removes it early