diff --git a/app/imports/api/engine/actions/applyPropertyByType/shared/recalculateCalculation.js b/app/imports/api/engine/actions/applyPropertyByType/shared/recalculateCalculation.js index 83997120..2993e0f1 100644 --- a/app/imports/api/engine/actions/applyPropertyByType/shared/recalculateCalculation.js +++ b/app/imports/api/engine/actions/applyPropertyByType/shared/recalculateCalculation.js @@ -10,7 +10,7 @@ import resolve from '/imports/parser/resolve.js'; // Redo the work of imports/api/engine/computation/computeComputation/computeByType/computeCalculation.js // But in the action scope -export default function recalculateCalculation(calcObj, actionContext, context, parseLevel = 'reduce') { +export default function recalculateCalculation(calcObj, actionContext, parseLevel = 'reduce', context) { if (!calcObj?.parseNode) return; calcObj._parseLevel = parseLevel; // Re-resolve the parse node @@ -40,7 +40,7 @@ export default function recalculateCalculation(calcObj, actionContext, context, export function rollAndReduceCalculation(calcObj, actionContext, context) { // Compile - recalculateCalculation(calcObj, actionContext, context, 'compile'); + recalculateCalculation(calcObj, actionContext, 'compile', context); const compiled = calcObj.valueNode; const compileErrors = context.errors; diff --git a/app/imports/api/engine/actions/doCheck.js b/app/imports/api/engine/actions/doCheck.js index 8614741d..69343c78 100644 --- a/app/imports/api/engine/actions/doCheck.js +++ b/app/imports/api/engine/actions/doCheck.js @@ -8,6 +8,7 @@ import numberToSignedString from '/imports/api/utility/numberToSignedString.js'; import { applyTriggers } from '/imports/api/engine/actions/applyTriggers.js'; import ActionContext from '/imports/api/engine/actions/ActionContext.js'; import recalculateCalculation from '/imports/api/engine/actions/applyPropertyByType/shared/recalculateCalculation'; +import { getSingleProperty } from '/imports/api/engine/loadCreatures'; const doCheck = new ValidatedMethod({ name: 'creatureProperties.doCheck', @@ -120,13 +121,14 @@ function rollCheck(prop, actionContext) { export function applyUnresolvedEffects(prop, actionContext) { let effectBonus = 0; let effectString = ''; - if (!prop.effects) { + if (!prop.effectIds) { return { effectBonus, effectString }; } - prop.effects.forEach(effect => { + prop.effectIds.forEach(id => { + const effect = getSingleProperty(actionContext.creature._id, id); if (!effect.amount?.parseNode) return; if (effect.operation !== 'add') return; - recalculateCalculation(effect.amount, actionContext, context, 'reduce'); + recalculateCalculation(effect.amount, actionContext, undefined, 'reduce'); if (typeof effect.amount?.value !== 'number') return; effectBonus += effect.amount.value; effectString += ` ${effect.amount.value < 0 ? '-' : '+'} [${effect.amount.calculation}] ${Math.abs(effect.amount.value)}` diff --git a/app/imports/api/engine/computation/buildComputation/linkTypeDependencies.js b/app/imports/api/engine/computation/buildComputation/linkTypeDependencies.js index 7ff3f578..f1cbd104 100644 --- a/app/imports/api/engine/computation/buildComputation/linkTypeDependencies.js +++ b/app/imports/api/engine/computation/buildComputation/linkTypeDependencies.js @@ -272,6 +272,7 @@ function linkPointBuy(dependencyGraph, prop) { type: 'pointBuyRow', tableName: prop.name, tableId: prop._id, + rowIndex: index, } dependencyGraph.addNode(pointBuyRow._id, pointBuyRow); linkVariableName(dependencyGraph, pointBuyRow); diff --git a/app/imports/api/engine/computation/computeComputation/computeByType/computeCalculation.js b/app/imports/api/engine/computation/computeComputation/computeByType/computeCalculation.js index efe9a7ed..9e067c0d 100644 --- a/app/imports/api/engine/computation/computeComputation/computeByType/computeCalculation.js +++ b/app/imports/api/engine/computation/computeComputation/computeByType/computeCalculation.js @@ -32,10 +32,10 @@ export default function computeCalculation(computation, node) { delete calcObj._localScope; } -export function resolveCalculationNode(calculation, parseNode, scope) { +export function resolveCalculationNode(calculation, parseNode, scope, givenContext) { const fn = calculation._parseLevel; const calculationScope = { ...calculation._localScope, ...scope }; - const { result: resultNode, context } = resolve(fn, parseNode, calculationScope); + const { result: resultNode, context } = resolve(fn, parseNode, calculationScope, givenContext); calculation.errors = context.errors; calculation.valueNode = resultNode; } diff --git a/app/imports/api/engine/computation/computeComputation/computeByType/computeVariable/aggregate/aggregateDefinition.js b/app/imports/api/engine/computation/computeComputation/computeByType/computeVariable/aggregate/aggregateDefinition.js index f1fed346..7b63db25 100644 --- a/app/imports/api/engine/computation/computeComputation/computeByType/computeVariable/aggregate/aggregateDefinition.js +++ b/app/imports/api/engine/computation/computeComputation/computeByType/computeVariable/aggregate/aggregateDefinition.js @@ -32,11 +32,12 @@ export default function aggregateDefinition({ node, linkedNode, link }) { if (propBaseValue === undefined) return; // Store a summary of the definition as a base value effect - node.data.effectIds = node.data.effectIds || []; + node.data.definitions = node.data.definitions || []; + if (prop.type === 'pointBuyRow') { - node.data.effectIds.push(prop.tableId); + node.data.definitions.push({ _id: prop.tableId, type: 'pointBuy', row: prop.index }); } else { - node.data.effectIds.push(prop._id); + node.data.definitions.push({ _id: prop._id, type: node.data.type }); } if (node.data.baseValue === undefined || propBaseValue > node.data.baseValue) { node.data.baseValue = propBaseValue; diff --git a/app/imports/api/engine/computation/computeComputation/computeByType/computeVariable/computeVariableAsAttribute.js b/app/imports/api/engine/computation/computeComputation/computeByType/computeVariable/computeVariableAsAttribute.js index a56028fc..70b16186 100644 --- a/app/imports/api/engine/computation/computeComputation/computeByType/computeVariable/computeVariableAsAttribute.js +++ b/app/imports/api/engine/computation/computeComputation/computeByType/computeVariable/computeVariableAsAttribute.js @@ -50,5 +50,6 @@ export default function computeVariableAsAttribute(computation, node, prop) { // Store effects and proficiencies prop.effectIds = node.data.effectIds; + prop.definitions = node.data.definitions; prop.proficiencyIds = node.data.proficiencyIds; } diff --git a/app/imports/api/engine/computation/computeComputation/computeByType/computeVariable/computeVariableAsSkill.js b/app/imports/api/engine/computation/computeComputation/computeByType/computeVariable/computeVariableAsSkill.js index dedb4e3d..8a260810 100644 --- a/app/imports/api/engine/computation/computeComputation/computeByType/computeVariable/computeVariableAsSkill.js +++ b/app/imports/api/engine/computation/computeComputation/computeByType/computeVariable/computeVariableAsSkill.js @@ -35,6 +35,7 @@ export default function computeVariableAsSkill(computation, node, prop) { // Store effects and proficiencies prop.effectIds = node.data.effectIds; + prop.definitions = node.data.definitions; prop.proficiencyIds = node.data.proficiencyIds; // If there is no aggregator, determine if the prop can hide, then exit diff --git a/app/imports/api/properties/Attributes.js b/app/imports/api/properties/Attributes.js index d5a46524..33fa4ca5 100644 --- a/app/imports/api/properties/Attributes.js +++ b/app/imports/api/properties/Attributes.js @@ -215,6 +215,24 @@ let ComputedOnlyAttributeSchema = createPropertySchema({ 'proficiencyIds.$': { type: String, }, + 'definitions': { + type: Array, + optional: true, + removeBeforeCompute: true, + }, + 'definitions.$': { + type: Object, + }, + 'definitions.$._id': { + type: String, + }, + 'definitions.$.type': { + type: String, + }, + 'definitions.$.row': { + type: Number, + optional: true, + }, }); const ComputedAttributeSchema = new SimpleSchema() diff --git a/app/imports/api/properties/Skills.js b/app/imports/api/properties/Skills.js index dc00cdec..4f677417 100644 --- a/app/imports/api/properties/Skills.js +++ b/app/imports/api/properties/Skills.js @@ -150,6 +150,24 @@ let ComputedOnlySkillSchema = createPropertySchema({ 'proficiencyIds.$': { type: String, }, + 'definitions': { + type: Array, + optional: true, + removeBeforeCompute: true, + }, + 'definitions.$': { + type: Object, + }, + 'definitions.$._id': { + type: String, + }, + 'definitions.$.type': { + type: String, + }, + 'definitions.$.row': { + type: Number, + optional: true, + }, }) const ComputedSkillSchema = new SimpleSchema()