Fixed: tagless triggers should target everything not nothing.
also fixed: check triggers now correctly fire on skill used for checks
This commit is contained in:
@@ -1,48 +0,0 @@
|
||||
import { get, set } from 'lodash';
|
||||
import { getEffectTagTargets } from '/imports/api/engine/computation/buildComputation/linkTypeDependencies';
|
||||
|
||||
export default function computeTrigger(computation, node) {
|
||||
const prop = node.data;
|
||||
|
||||
// Triggers that aren't active aren't linked to properties
|
||||
if (prop.inactive) return;
|
||||
|
||||
// Link triggers to all the properties that would fire them when applied
|
||||
const tagTargets = getEffectTagTargets(prop, computation);
|
||||
for (const targetId of tagTargets) {
|
||||
const targetProp = computation.propsById[targetId];
|
||||
switch (prop.event) {
|
||||
case 'doActionProperty':
|
||||
// Only apply if the trigger matches this property type
|
||||
if (targetProp.type === prop.actionPropertyType) {
|
||||
setTrigger(prop, targetProp, 'triggerIds');
|
||||
}
|
||||
// Or on an item used as ammo
|
||||
else if (prop.actionPropertyType === 'ammo' && targetProp.type === 'item') {
|
||||
setTrigger(prop, targetProp, 'ammoTriggerIds');
|
||||
}
|
||||
break;
|
||||
case 'damageProperty':
|
||||
// Only apply to attributes
|
||||
if (targetProp.type === 'attribute') {
|
||||
setTrigger(prop, targetProp, 'damageTriggerIds');
|
||||
}
|
||||
break;
|
||||
case 'check':
|
||||
// Only apply to attributes and skills
|
||||
if (targetProp.type === 'attribute' || targetProp.type === 'skill') {
|
||||
setTrigger(prop, targetProp, 'checkTriggerIds');
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setTrigger(prop, targetProp, field = 'triggerIds') {
|
||||
let triggerIdArray = get(targetProp, `${field}.${prop.timing}`);
|
||||
if (!triggerIdArray) {
|
||||
triggerIdArray = [];
|
||||
set(targetProp, `${field}.${prop.timing}`, triggerIdArray);
|
||||
}
|
||||
triggerIdArray.push(prop._id);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import { getEffectTagTargets } from '/imports/api/engine/computation/buildComputation/linkTypeDependencies';
|
||||
import CreatureComputation from '/imports/api/engine/computation/CreatureComputation';
|
||||
import { CreaturePropertyTypes } from '/imports/api/creature/creatureProperties/CreatureProperties';
|
||||
|
||||
export default function computeTrigger(computation: CreatureComputation, node: { data: CreaturePropertyTypes['trigger'] }) {
|
||||
const prop = node.data;
|
||||
|
||||
// Triggers that aren't active aren't linked to properties
|
||||
if (prop.inactive) return;
|
||||
|
||||
// Link triggers to all the properties that would fire them when applied
|
||||
let tagTargets: string[] = getEffectTagTargets(prop, computation);
|
||||
// If we have no tags or extra tags, target everything
|
||||
if (!prop.targetTags?.length && !prop.extraTags?.length) {
|
||||
tagTargets = computation.props.map(targetProp => targetProp._id).filter(id => id !== prop._id);
|
||||
}
|
||||
for (const targetId of tagTargets) {
|
||||
const targetProp = computation.propsById[targetId];
|
||||
switch (prop.event) {
|
||||
case 'doActionProperty':
|
||||
// Only apply if the trigger matches this property type
|
||||
if (targetProp.type === prop.actionPropertyType) {
|
||||
targetProp.triggerIds ??= {};
|
||||
(targetProp.triggerIds[prop.timing] ??= []).push(prop._id);
|
||||
}
|
||||
// Or on an item used as ammo
|
||||
else if (prop.actionPropertyType === 'ammo' && targetProp.type === 'item') {
|
||||
targetProp.ammoTriggerIds ??= {};
|
||||
(targetProp.ammoTriggerIds[prop.timing] ??= []).push(prop._id);
|
||||
}
|
||||
break;
|
||||
case 'damageProperty':
|
||||
// Only apply to attributes
|
||||
if (targetProp.type === 'attribute') {
|
||||
targetProp.damageTriggerIds ??= {};
|
||||
(targetProp.damageTriggerIds[prop.timing] ??= []).push(prop._id);
|
||||
}
|
||||
break;
|
||||
case 'check':
|
||||
// Only apply to attributes and skills
|
||||
if (targetProp.type === 'attribute' || targetProp.type === 'skill') {
|
||||
targetProp.checkTriggerIds ??= {};
|
||||
(targetProp.checkTriggerIds[prop.timing] ??= []).push(prop._id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user