Changed task triggers to be stored differently so that attribute check and damage triggers don't overlap
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -42,7 +42,7 @@ export default async function applyDamagePropTask(
|
||||
}
|
||||
|
||||
// Run the before triggers which may change scope properties
|
||||
await applyTriggers(action, targetProp, [action.creatureId], 'before', userInput);
|
||||
await applyTriggers(action, targetProp, [targetId], 'damageTriggerIds.before', userInput);
|
||||
|
||||
// Create a new result after triggers have run
|
||||
result = new TaskResult(task.prop._id, task.targetIds);
|
||||
@@ -136,8 +136,8 @@ export default async function applyDamagePropTask(
|
||||
});
|
||||
setScope(result, targetProp, newValue, damage);
|
||||
}
|
||||
await applyTriggers(action, targetProp, [action.creatureId], 'after', userInput);
|
||||
await applyTriggers(action, targetProp, [action.creatureId], 'afterChildren', userInput);
|
||||
await applyTriggers(action, targetProp, [targetId], 'damageTriggerIds.after', userInput);
|
||||
await applyTriggers(action, targetProp, [targetId], 'damageTriggerIds.afterChildren', userInput);
|
||||
return increment;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,11 @@ export default async function applyItemAsAmmoTask(task: ItemAsAmmoTask, action:
|
||||
result.pushScope = { ['~ammoConsumed']: { value } };
|
||||
|
||||
// Apply the before triggers
|
||||
await applyTriggers(action, item, [action.creatureId], 'ammo.before', userInput);
|
||||
await applyTriggers(action, item, task.targetIds, 'ammoTriggerIds.before', userInput);
|
||||
|
||||
// Create a new result after before triggers have run
|
||||
result = new TaskResult(task.prop._id, task.targetIds);
|
||||
action.results.push(result);
|
||||
|
||||
// Refetch the scope properties
|
||||
const scope = await getEffectiveActionScope(action);
|
||||
@@ -52,11 +56,12 @@ export default async function applyItemAsAmmoTask(task: ItemAsAmmoTask, action:
|
||||
},
|
||||
});
|
||||
|
||||
await applyTriggers(action, item, [action.creatureId], 'ammo.after', userInput);
|
||||
await applyTriggers(action, item, task.targetIds, 'ammoTriggerIds.after', userInput);
|
||||
|
||||
if (task.params.skipChildren) {
|
||||
return applyAfterTasksSkipChildren(action, item, task.targetIds, userInput);
|
||||
await applyAfterTasksSkipChildren(action, item, task.targetIds, userInput);
|
||||
} else {
|
||||
return applyDefaultAfterPropTasks(action, item, task.targetIds, userInput);
|
||||
await applyDefaultAfterPropTasks(action, item, task.targetIds, userInput);
|
||||
}
|
||||
return applyTriggers(action, item, task.targetIds, 'ammoTriggerIds.afterChildren', userInput);
|
||||
}
|
||||
Reference in New Issue
Block a user