Custom actions/reactions to changes in any object's state - HP dropping past a
threshold, a durability hitting zero, a quest flag flipping true - watched declaratively
instead of as a branch cascade of if checks scattered through game code.
A ReactionRule pairs a when predicate over some state with an action the framework
calls the moment that predicate turns true; check() runs every rule against a fresh
reading, edge-triggered so a condition that stays true never re-fires on every call.
Rules make no assumption about what shape they watch - an actor's StatBlock values, a
plain object's own fields (an item's durability, a door's open flag), whatever the game
passes to check, so the same table works for a character or an inanimate object alike.
A once: true rule (a bond breaking, a boss entering phase two) fires a single time ever
and then retires; the default is edge-triggered, firing again each time the condition
leaves and returns, the shape a recurring low-health warning needs.
reactions.check({ hp:40, maxHp:100 }); // ['critical'] - fires once, not every call after reactions.check({ hp:38, maxHp:100 }); // [] - still true, already fired reactions.check({ hp:90, maxHp:100 }); // [] - condition left; 'critical' may fire again later
Custom actions/reactions to changes in any object's state - HP dropping past a threshold, a durability hitting zero, a quest flag flipping true - watched declaratively instead of as a branch cascade of
ifchecks scattered through game code.A
ReactionRulepairs awhenpredicate over some state with anactionthe framework calls the moment that predicate turns true;check()runs every rule against a fresh reading, edge-triggered so a condition that stays true never re-fires on every call. Rules make no assumption about what shape they watch - an actor'sStatBlockvalues, a plain object's own fields (an item's durability, a door's open flag), whatever the game passes tocheck, so the same table works for a character or an inanimate object alike. Aonce: truerule (a bond breaking, a boss entering phase two) fires a single time ever and then retires; the default is edge-triggered, firing again each time the condition leaves and returns, the shape a recurring low-health warning needs.Example