Fixed effects not applying to damage in actions

This commit is contained in:
Thaum Rystra
2024-10-30 10:03:47 +02:00
parent 74bd291426
commit ce9753fa9c
5 changed files with 66 additions and 8 deletions

View File

@@ -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);
}

View File

@@ -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 },
},
],
}]);
});
});

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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
});