22 lines
886 B
JavaScript

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));
}