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
+21
View File
@@ -0,0 +1,21 @@
export async function checkDamageCondition(config, context) {
const amount = Number(context.amount ?? context.damageAmount ?? 0);
const absoluteAmount = Math.abs(amount);
if (absoluteAmount < (Number(config.minAmount) || 0)) return false;
if (config.amountMode === "damageOnly" && amount <= 0) return false;
if (config.amountMode === "healingOnly" && amount >= 0) return false;
if (config.amountMode === "healingOnly") return true;
const configuredTypes = config.types ?? [];
if (!configuredTypes.length) return true;
const eventTypes = new Set(context.damageTypes ?? []);
if (!eventTypes.size) return false;
if (config.typeMode === "all") return configuredTypes.every(type => eventTypes.has(type));
if (config.typeMode === "none") return configuredTypes.every(type => !eventTypes.has(type));
return configuredTypes.some(type => eventTypes.has(type));
}
@@ -0,0 +1,21 @@
export async function checkHpAfterDamageCondition(config, context) {
const actor = context.targetActor ?? context.actor;
if (!actor) return false;
const hp = actor.system?.attributes?.hp;
const value = Number(hp?.value ?? 0);
const max = Number(hp?.max ?? 0);
if (max <= 0) return false;
const actual = config.mode === "percent" ? (value / max) * 100 : value;
const threshold = Number(config.value ?? 0);
switch (config.operator ?? "lte") {
case "lt": return actual < threshold;
case "lte": return actual <= threshold;
case "gt": return actual > threshold;
case "gte": return actual >= threshold;
case "eq": return actual === threshold;
default: return actual <= threshold;
}
}