This commit is contained in:
@@ -10,21 +10,30 @@ export async function handleTrigger(triggerType, context) {
|
||||
const assignedReactions = await getAssignedReactionsForContext(context);
|
||||
|
||||
for (const reaction of assignedReactions) {
|
||||
try {
|
||||
if (!reaction?.enabled) continue;
|
||||
if (reaction.trigger?.type !== triggerType) continue;
|
||||
if (!matchesTriggerSpellFilter(reaction.trigger, context)) continue;
|
||||
if (!await checkConsumptionAvailable(reaction, context)) continue;
|
||||
if (!await checkConditions(reaction, context)) continue;
|
||||
|
||||
const result = await executeReactionActions(reaction, context);
|
||||
if (result.shouldConsume) await consumeReactionUse(reaction, context);
|
||||
} catch (error) {
|
||||
console.error(`${MODULE_ID} | Failed to handle reaction`, reaction, error);
|
||||
}
|
||||
await handleAssignedReaction(triggerType, context, reaction);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleAssignedReaction(triggerType, context, reaction) {
|
||||
try {
|
||||
if (!await shouldExecuteReaction(triggerType, context, reaction)) return;
|
||||
|
||||
const result = await executeReactionActions(reaction, context);
|
||||
if (result.shouldConsume) await consumeReactionUse(reaction, context);
|
||||
} catch (error) {
|
||||
console.error(`${MODULE_ID} | Failed to handle reaction`, reaction, error);
|
||||
}
|
||||
}
|
||||
|
||||
async function shouldExecuteReaction(triggerType, context, reaction) {
|
||||
if (!reaction?.enabled) return false;
|
||||
if (reaction.trigger?.type !== triggerType) return false;
|
||||
if (!matchesTriggerSpellFilter(reaction.trigger, context)) return false;
|
||||
if (!await checkConsumptionAvailable(reaction, context)) return false;
|
||||
|
||||
return checkConditions(reaction, context);
|
||||
}
|
||||
|
||||
function matchesTriggerSpellFilter(trigger, context) {
|
||||
const expectedName = trigger?.spell?.itemName;
|
||||
if (!expectedName) return true;
|
||||
|
||||
Reference in New Issue
Block a user