Changed task triggers to be stored differently so that attribute check and damage triggers don't overlap

This commit is contained in:
Thaum Rystra
2024-05-21 17:41:20 +02:00
parent 8eb702cde3
commit 772e55ece5
9 changed files with 154 additions and 173 deletions

View File

@@ -1,10 +1,10 @@
import { applyDefaultAfterPropTasks } from '/imports/api/engine/action/functions/applyTaskGroups';
import { applyTriggers } from '/imports/api/engine/action/functions/applyTaskGroups';
import { CheckTask } from '/imports/api/engine/action/tasks/Task';
import { EngineAction } from '/imports/api/engine/action/EngineActions';
import { getEffectiveActionScope } from '/imports/api/engine/action/functions/getEffectiveActionScope';
import { getFromScope } from '/imports/api/creature/creatures/CreatureVariables';
import { getVariables } from '/imports/api/engine/loadCreatures';
import InputProvider, { CheckParams } from '/imports/api/engine/action/functions/userInput/InputProvider';
import InputProvider from '/imports/api/engine/action/functions/userInput/InputProvider';
import numberToSignedString from '/imports/api/utility/numberToSignedString';
import TaskResult from '/imports/api/engine/action/tasks/TaskResult';
@@ -38,6 +38,17 @@ export default async function applyCheckTask(
const ability = checkParams.abilityVariableName && getFromScope(checkParams.abilityVariableName, scope) || null;
const abilityModifier = ability?.modifier || 0;
// Run the before triggers which may change scope properties
if (skill) await applyTriggers(action, skill, [targetId], 'checkTriggerIds.before', userInput);
if (ability) await applyTriggers(action, ability, [targetId], 'checkTriggerIds.before', userInput);
if (skill || ability) {
// Create a new result after before triggers have run
result = new TaskResult(task.prop._id, task.targetIds);
action.results.push(result);
}
const totalModifier = skillBonus + abilityModifier;
const rollModifierText = numberToSignedString(totalModifier);
@@ -100,9 +111,15 @@ export default async function applyCheckTask(
inline: true,
...prop?.silent && { silenced: prop.silent }
}, [targetId]);
}
return applyDefaultAfterPropTasks(action, prop, targetIds, userInput);
// After check triggers
if (skill) await applyTriggers(action, skill, [targetId], 'checkTriggerIds.after', userInput);
if (ability) await applyTriggers(action, ability, [targetId], 'checkTriggerIds.after', userInput);
// After children check triggers
if (skill) await applyTriggers(action, skill, [targetId], 'checkTriggerIds.afterChildren', userInput);
if (ability) await applyTriggers(action, ability, [targetId], 'checkTriggerIds.afterChildren', userInput);
}
}
// TODO set these and potentially read them again if triggers can change them