configurable-reactions/scripts/engine/condition-runner.js

22 lines
660 B
JavaScript

import { checkDamageCondition } from "../conditions/damage-condition.js";
import { checkHpAfterDamageCondition } from "../conditions/hp-threshold-condition.js";
const CONDITION_HANDLERS = Object.freeze({
damage: checkDamageCondition,
hpAfterDamage: checkHpAfterDamageCondition
});
export async function checkConditions(reaction, context) {
for (const [conditionType, config] of Object.entries(reaction.conditions ?? {})) {
if (!config?.enabled) continue;
const handler = CONDITION_HANDLERS[conditionType];
if (!handler) return false;
const passed = await handler(config, context);
if (!passed) return false;
}
return true;
}