diff --git a/app/imports/api/engine/action/ActionEngine.test.ts b/app/imports/api/engine/action/ActionEngine.test.ts index 9d079adc..31041ba8 100644 --- a/app/imports/api/engine/action/ActionEngine.test.ts +++ b/app/imports/api/engine/action/ActionEngine.test.ts @@ -205,10 +205,12 @@ describe('Interrupt action system', function () { function createAction(prop, targetIds?) { const action: EngineAction = { creatureId: prop.root.id, - rootPropId: prop._id, results: [], taskCount: 0, - targetIds, + task: { + prop, + targetIds, + } }; return EngineActions.insertAsync(action); } diff --git a/app/imports/api/engine/action/applyProperties/applyDamageProperty.test.ts b/app/imports/api/engine/action/applyProperties/applyDamageProperty.test.ts index a93e3f77..a77c1ba3 100644 --- a/app/imports/api/engine/action/applyProperties/applyDamageProperty.test.ts +++ b/app/imports/api/engine/action/applyProperties/applyDamageProperty.test.ts @@ -8,8 +8,8 @@ import { } from '/imports/api/engine/action/functions/actionEngineTest.testFn'; const [ - creatureId, targetCreatureId, targetCreature2Id, damageTargetId, damageSelfId, targetCreatureHitPointsId, targetCreature2HitPointsId, selfHitPointsId -] = getRandomIds(100); + creatureId, targetCreatureId, targetCreature2Id, damageTargetId, damageSelfId, targetCreatureHitPointsId, targetCreature2HitPointsId, selfHitPointsId, damageWithEffectsId, effectId, effect2Id, +] = getRandomIds(20); const actionTestCreature = { _id: creatureId, @@ -34,6 +34,29 @@ const actionTestCreature = { variableName: 'hitPoints', baseValue: { calculation: '20' }, }, + { + _id: damageWithEffectsId, + type: 'damage', + target: 'target', + amount: { calculation: '1d13 + 3' }, + tags: ['tag'] + }, + { + _id: effectId, + type: 'effect', + operation: 'add', + amount: { calculation: '1' }, + targetByTags: true, + targetTags: ['tag'], + }, + { + _id: effect2Id, + type: 'effect', + operation: 'mul', + amount: { calculation: '2' }, + targetByTags: true, + targetTags: ['tag'], + }, ], } @@ -187,4 +210,35 @@ describe('Apply Damage Properties', function () { ], }]); }); + + it.only('Applies effects when doing damage', async function () { + const action = await runActionById(damageWithEffectsId, [targetCreatureId]); + assert.exists(action); + assert.deepEqual(allMutations(action), [{ + contents: [ + { + inline: true, + name: 'Damage', + value: '(1d13 [7] + 4) * 2', + } + ], + targetIds: [targetCreatureId], + }, { + contents: [ + { + inline: true, + name: 'Attribute damaged', + value: '−22 Hit Points', + } + ], + targetIds: [targetCreatureId], + updates: [ + { + propId: targetCreatureHitPointsId, + type: 'attribute', + inc: { damage: 22, value: -22 }, + }, + ], + }]); + }); }); diff --git a/app/imports/api/engine/action/functions/actionEngineTest.testFn.ts b/app/imports/api/engine/action/functions/actionEngineTest.testFn.ts index 722c0892..4c389c19 100644 --- a/app/imports/api/engine/action/functions/actionEngineTest.testFn.ts +++ b/app/imports/api/engine/action/functions/actionEngineTest.testFn.ts @@ -82,10 +82,12 @@ export async function runActionById(propId, targetIds?, userInput = inputProvide function createAction(prop: any, targetIds?: string[]) { const action: EngineAction = { creatureId: prop.root.id, - rootPropId: prop._id, results: [], taskCount: 0, - targetIds, + task: { + prop, + targetIds: targetIds || [], + } }; return EngineActions.insertAsync(action); } diff --git a/app/imports/api/engine/action/functions/recalculateCalculation.ts b/app/imports/api/engine/action/functions/recalculateCalculation.ts index 7e01b481..1258cfd2 100644 --- a/app/imports/api/engine/action/functions/recalculateCalculation.ts +++ b/app/imports/api/engine/action/functions/recalculateCalculation.ts @@ -48,7 +48,7 @@ export default async function recalculateCalculation( // Resolve the modified valueNode, use the same context const { result: finalResult - } = await resolve(parseLevel, calcObj.parseNode, scope, context); + } = await resolve(parseLevel, calcObj.valueNode, scope, context); // Store the errors calcObj.errors = context.errors; diff --git a/app/imports/api/engine/computation/computeComputation/computeByType/computeCalculation.js b/app/imports/api/engine/computation/computeComputation/computeByType/computeCalculation.js index 46852665..09ba91d4 100644 --- a/app/imports/api/engine/computation/computeComputation/computeByType/computeCalculation.js +++ b/app/imports/api/engine/computation/computeComputation/computeByType/computeCalculation.js @@ -133,7 +133,7 @@ export function aggregateCalculationEffects(calcObj, getEffectFromId) { // Multiply if (aggregator.mul) { // Wrap the previous node in brackets if it's another operator - if (calcObj.parseType === 'operator') { + if (calcObj.valueNode.parseType === 'operator') { calcObj.valueNode = parenthesis.create({ content: calcObj.valueNode });