-- RynthAi's combat hook from a script (rynth.ai SetAttackHandler / SetHealHandler, RynthLua's -- CombatHookPump against a fake "RynthAi.Combat" table): the handler's answer reaches Decide, a -- yielding handler still answers, an error declines, three in a row unregister, one script per -- kind, a stopped script releases its kinds, and no table means a refusal with the reason. local ai = require("rynth.ai") local ATTACK, HEAL = 1, 2 local function decisions() return harness.combatDecisions() end local function waitDecisions(n) return waitfor(function() return #decisions() >= n end, 3000) end -- No table: RynthAi without the hook (or not loaded). harness.combatTable(false) local ok, why = ai.SetAttackHandler(function() return 1 end) eq(ok, false, "no combat table: refused") eq(why, "RynthAi has no combat hook", "and says why") eq(ai.CombatHook.Supported, false, "CombatHook.Supported is false") eq(ai.CombatHook.AttackOwner, nil, "no owner") harness.combatTable(true) sleep(10) -- RynthLua looks the table up again on its next tick eq(ai.CombatHook.Supported, true, "table on: supported") -- 1. A decision is posted, with the request's context. local seen ok = ai.SetAttackHandler(function(ctx) seen = ctx return 1234, ctx.monsters[2].id end) eq(ok, true, "attack handler registered") eq(ai.CombatHook.AttackOwner, "combathook", "the owner is this script") check(waitfor(function() return harness.combatState().kinds == ATTACK end, 2000), "the pump claims the attack kind") eq(harness.combatState().owner, "RynthLua/combathook", "claimed under RynthLua/