Allowed some properties to return damaged action values

When a prop is damaged during an action, it now tries
to show its new value during the rest of that action
This commit is contained in:
Stefan Zermatten
2022-08-25 15:10:36 +02:00
parent 11a527481e
commit 249aebea0f
2 changed files with 25 additions and 1 deletions

View File

@@ -24,7 +24,7 @@ const damageProperty = new ValidatedMethod({
run({ _id, operation, value }) {
// Get action context
const prop = CreatureProperties.findOne(_id);
let prop = CreatureProperties.findOne(_id);
if (!prop) throw new Meteor.Error(
'Damage property failed', 'Property doesn\'t exist'
);
@@ -42,6 +42,14 @@ const damageProperty = new ValidatedMethod({
`Property of type "${prop.type}" can't be damaged`
);
}
// Replace the prop by its actionContext counterpart if possible
if (prop.variableName) {
const actionContextProp = actionContext.scope[prop.variableName];
if (actionContextProp?._id === prop._id) {
prop = actionContextProp;
}
}
const result = damagePropertyWork({ prop, operation, value, actionContext });
@@ -94,6 +102,9 @@ export function damagePropertyWork({ prop, operation, value, actionContext }) {
}, {
selector: prop
});
// Also write it straight to the prop so that it is updated in the actionContext
prop.damage = damage;
prop.value = newValue;
} else if (operation === 'increment'){
let currentValue = prop.value || 0;
let currentDamage = prop.damage || 0;
@@ -111,6 +122,9 @@ export function damagePropertyWork({ prop, operation, value, actionContext }) {
}, {
selector: prop
});
// Also write it straight to the prop so that it is updated in the actionContext
prop.damage += increment;
prop.value -= increment;
}
applyTriggers(actionContext.triggers?.damageProperty?.after, prop, actionContext);