Add reaction engine and action skeletons

This commit is contained in:
ChatGPT
2026-06-04 16:07:28 +00:00
parent 927ea528b7
commit a243776070
15 changed files with 642 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
import { TRIGGER_TYPES } from "../constants.js";
import { handleTrigger } from "../engine/reaction-engine.js";
import { getBestTokenDocumentForActor } from "../utils/token-utils.js";
export function registerDnd5eDamageTrigger() {
Hooks.on("dnd5e.applyDamage", async (actor, amount, options = {}) => {
if (!game.user.isGM) return;
if (!actor) return;
const tokenDocument = options.token ?? options.tokenDocument ?? getBestTokenDocumentForActor(actor);
const damageTypes = extractDamageTypes(options);
await handleTrigger(TRIGGER_TYPES.DAMAGE_RECEIVED, {
actor,
targetActor: actor,
tokenDocument,
targetTokenDocument: tokenDocument,
targetToken: tokenDocument?.object ?? null,
amount: Number(amount) || 0,
damageAmount: Number(amount) || 0,
damageTypes,
options
});
});
}
function extractDamageTypes(options) {
const candidates = [
options.damageTypes,
options.types,
options.damage?.types,
options.workflow?.damageItem?.damageDetail?.map?.(part => part.type)
];
const values = candidates.flat().filter(Boolean);
return [...new Set(values)];
}
+18
View File
@@ -0,0 +1,18 @@
import { TRIGGER_TYPES } from "../constants.js";
import { handleTrigger } from "../engine/reaction-engine.js";
export function registerTargetSelectedTrigger() {
Hooks.on("targetToken", async (user, token, targeted) => {
if (!game.user.isGM) return;
if (!targeted || !token?.actor) return;
await handleTrigger(TRIGGER_TYPES.TARGET_SELECTED, {
targetUser: user,
targetToken: token,
targetTokenDocument: token.document,
targetActor: token.actor,
tokenDocument: token.document,
actor: token.actor
});
});
}