Fixed tag targeted effects on overridden attributes applying multiple times

Closes #358
This commit is contained in:
ThaumRystra
2024-11-09 15:24:56 +02:00
parent 5c80975bc1
commit 7c648f67a3
3 changed files with 93 additions and 1 deletions

View File

@@ -16,6 +16,7 @@
"healthbars",
"jank",
"meteortesting",
"multigraph",
"nearley",
"ngraph",
"ostrio",

View File

@@ -156,7 +156,10 @@ function linkEffects(dependencyGraph, prop, computation) {
) {
// If the field wasn't specified and we're targeting an attribute or
// skill, just treat it like a normal effect on its variable name
dependencyGraph.addLink(targetProp.variableName, prop._id, 'effect');
// But ensure only a single link is created
if (!dependencyGraph.hasLink(targetProp.variableName, prop._id)) {
dependencyGraph.addLink(targetProp.variableName, prop._id, 'effect');
}
} else {
// Otherwise target a field on that property
const key = prop.targetField || getDefaultCalculationField(targetProp);

View File

@@ -0,0 +1,88 @@
import { assert } from 'chai';
import {
createTestCreature,
getRandomIds,
removeAllCreaturesAndProps,
} from '/imports/api/engine/action/functions/actionEngineTest.testFn';
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties';
describe('Apply Action Properties', function () {
// Increase timeout
this.timeout(8000);
beforeEach(async function () {
await removeAllCreaturesAndProps();
});
it('Should apply a single tag targeted effect', async function () {
const [
creatureId, singleEffectAttId, tag1Effect
] = getRandomIds(100);
const testCreature = {
_id: creatureId,
props: [
{
_id: singleEffectAttId,
type: 'attribute',
attributeType: 'ability',
variableName: 'strength',
baseValue: { calculation: '10' },
tags: ['tag1'],
},
{
_id: tag1Effect,
type: 'effect',
targetByTags: true,
targetTags: ['tag1'],
operation: 'add',
amount: { calculation: '2' },
},
],
};
await createTestCreature(testCreature);
const singleEffectAtt = await CreatureProperties.findOneAsync(singleEffectAttId);
assert.equal(singleEffectAtt.value, 12, 'The attribute should have the correct value after the effect is applied');
});
it('Should apply a multiple tag targeted effects, ignoring overridden attributes', async function () {
const [
creatureId, multipleEffectsAttId, tag1Effect, overriddenAttId
] = getRandomIds(100);
const testCreature = {
_id: creatureId,
props: [
{
_id: overriddenAttId,
type: 'attribute',
attributeType: 'ability',
variableName: 'strength',
baseValue: { calculation: '13' },
tags: ['tag2'],
},
{
_id: multipleEffectsAttId,
type: 'attribute',
attributeType: 'ability',
variableName: 'strength',
baseValue: { calculation: '11' },
tags: ['tag2'],
},
{
_id: tag1Effect,
type: 'effect',
targetByTags: true,
targetTags: ['tag2'],
operation: 'mul',
amount: { calculation: '2' },
},
],
};
await createTestCreature(testCreature);
const singleEffectAtt = await CreatureProperties.findOneAsync(multipleEffectsAttId);
assert.equal(singleEffectAtt.value, 26, 'The attribute should have the correct value after the effect is applied');
});
});