Effects targeting calculations by tag now work in the engine and actions

This commit is contained in:
Stefan Zermatten
2022-02-15 15:59:41 +02:00
parent e0f621cc44
commit 378da71f5d
19 changed files with 454 additions and 98 deletions

View File

@@ -3,4 +3,46 @@ import evaluateCalculation from '../../utility/evaluateCalculation.js';
export default function computeCalculation(computation, node){
const calcObj = node.data;
evaluateCalculation(calcObj, computation.scope);
aggregateCalculationEffects(node, computation);
}
export function aggregateCalculationEffects(node, computation){
const calcObj = node.data;
delete calcObj.effects;
computation.dependencyGraph.forEachLinkedNode(
node.id,
(linkedNode, link) => {
// Only effect links
if (link.data !== 'effect') return;
// That have effect data
if (!linkedNode.data) return;
// Ignore inactive props
if (linkedNode.data.inactive) return;
// Collate effects
calcObj.effects = calcObj.effects || [];
calcObj.effects.push({
_id: linkedNode.data._id,
name: linkedNode.data.name,
operation: linkedNode.data.operation,
amount: linkedNode.data.amount && {
value: linkedNode.data.amount.value,
//parseNode: linkedNode.data.amount.parseNode,
},
// ancestors: linkedNode.data.ancestors,
});
},
true // enumerate only outbound links
);
if (calcObj.effects && typeof calcObj.value === 'number'){
calcObj.baseValue = calcObj.value;
calcObj.effects.forEach(effect => {
if (
effect.operation === 'add' &&
effect.amount && typeof effect.amount.value === 'number'
){
calcObj.value += effect.amount.value
}
});
}
}

View File

@@ -28,7 +28,7 @@ function aggregateLinks(computation, node){
// Ignore inactive props
if (linkedNode.data.inactive) return;
// Apply all the aggregations
let arg = {node, linkedNode, link};
let arg = {node, linkedNode, link, computation};
aggregate.classLevel(arg);
aggregate.damageMultiplier(arg);
aggregate.definition(arg);

View File

@@ -16,10 +16,23 @@ export default function aggregateEffect({node, linkedNode, link}){
conditional: [],
rollBonus: [],
};
// Store a summary of the effect itself
node.data.effects = node.data.effects || [];
node.data.effects.push({
_id: linkedNode.data._id,
name: linkedNode.data.name,
operation: linkedNode.data.operation,
amount: linkedNode.data.amount && {value: linkedNode.data.amount.value},
// ancestors: linkedNode.data.ancestors,
});
// get a shorter reference to the aggregator document
const aggregator = node.data.effectAggregator;
// Get the result of the effect
const result = linkedNode.data.amount?.value;
// Skip aggregating if the result is not resolved completely
if (typeof result === 'string') return;
// Aggregate the effect based on its operation
switch(linkedNode.data.operation){
case 'base':

View File

@@ -23,4 +23,7 @@ export default function computeVariableAsAttribute(computation, node, prop){
prop.hide = !node.data.effectAggregator &&
prop.baseValue === undefined ||
undefined
// Store effects
prop.effects = node.data.effects;
}