Tested and fixed buff remover properties

This commit is contained in:
ThaumRystra
2024-09-28 12:45:30 +02:00
parent d998d7d2ef
commit b1ab65f095
3 changed files with 114 additions and 6 deletions

View File

@@ -14,7 +14,6 @@ const [
const actionTestCreature = {
_id: creatureId,
props: [
// If branch
{
_id: buffId,
type: 'buff',

View File

@@ -0,0 +1,97 @@
import { assert } from 'chai';
import {
allMutations,
createTestCreature,
getRandomIds,
removeAllCreaturesAndProps,
runActionById
} from '/imports/api/engine/action/functions/actionEngineTest.testFn';
const [
creatureId, otherCreatureId, buffId, removeParentBuffId, removeTargetBuffsId,
] = getRandomIds(100);
const actionTestCreature = {
_id: creatureId,
props: [
{
_id: buffId,
type: 'buff',
description: { text: 'This buff reduces AC of target by difference between the strength of caster {strength} and the target {~target.strength}' },
tags: ['some buff'],
children: [
{
type: 'effect',
stats: ['armor'],
operation: 'add',
amount: { calculation: '~target.strength - strength' },
},
{
_id: removeParentBuffId,
type: 'buffRemover',
targetParentBuff: true,
target: 'self',
},
],
},
{
type: 'attribute',
attributeType: 'stat',
variableName: 'strength',
baseValue: { calculation: '18' },
},
],
};
const actionOtherCreature = {
_id: otherCreatureId,
props: [
{
_id: removeTargetBuffsId,
type: 'buffRemover',
target: 'target',
targetTags: ['some buff']
},
],
};
describe('Apply Buff Properties', function () {
// Increase timeout
this.timeout(8000);
beforeEach(async function () {
await removeAllCreaturesAndProps();
await createTestCreature(actionTestCreature);
await createTestCreature(actionOtherCreature);
});
it('removes a parent buff', async function () {
const action = await runActionById(removeParentBuffId);
const mutations = allMutations(action);
assert.deepEqual(mutations, [{
contents: [{
name: 'Removed',
value: 'Buff',
}],
removals: [{
propId: buffId,
}],
targetIds: []
}]);
});
it('removes a tag targeted buff', async function () {
const action = await runActionById(removeTargetBuffsId, [creatureId]);
const mutations = allMutations(action);
assert.deepEqual(mutations, [{
contents: [{
name: 'Removed',
value: 'Buff',
}],
removals: [{
propId: buffId,
}],
targetIds: [creatureId]
}]);
});
});

View File

@@ -4,7 +4,7 @@ import getPropertyTitle from '/imports/api/utility/getPropertyTitle';
import { findLast, filter, difference, intersection } from 'lodash';
import { getPropertiesOfType, getPropertyAncestors } from '/imports/api/engine/loadCreatures';
import getEffectivePropTags from '/imports/api/engine/computation/utility/getEffectivePropTags';
import { applyDefaultAfterPropTasks } from '/imports/api/engine/action/functions/applyTaskGroups';
import { applyDefaultAfterPropTasks, applyTaskToEachTarget } from '/imports/api/engine/action/functions/applyTaskGroups';
import { EngineAction } from '/imports/api/engine/action/EngineActions';
import InputProvider from '/imports/api/engine/action/functions/userInput/InputProvider';
@@ -13,13 +13,25 @@ export default async function applyBuffRemoverProperty(
) {
const prop = task.prop;
if (prop.name && !prop.silent) {
const targetIds = prop.target === 'self' ? [action.creatureId] : task.targetIds;
if (prop.name) {
// Log Name
result.appendLog({
name: getPropertyTitle(prop),
...prop.silent && { silenced: true },
}, task.targetIds)
}
if (targetIds.length > 1) {
return applyTaskToEachTarget(action, task, targetIds, userInput);
}
if (targetIds.length !== 1) {
throw 'At this step, only a single target is supported'
}
const targetId = targetIds[0];
// Remove buffs
if (prop.targetParentBuff) {
// Remove nearest ancestor buff
@@ -29,13 +41,13 @@ export default async function applyBuffRemoverProperty(
result.appendLog({
name: 'Error',
value: 'Buff remover does not have a parent buff to remove',
}, task.targetIds);
}, [targetId]);
return;
}
removeBuff(nearestBuff, prop, result);
} else {
// Get all the buffs targeted by tags
const allBuffs = getPropertiesOfType(action.creatureId, 'buff');
const allBuffs = getPropertiesOfType(targetId, 'buff');
const targetedBuffs = filter(allBuffs, buff => {
if (buff.inactive) return false;
if (buffRemoverMatchTags(prop, buff)) return true;
@@ -66,7 +78,7 @@ function removeBuff(buff: any, prop, result: TaskResult) {
contents: [{
name: 'Removed',
value: `${buff.name || 'Buff'}`,
silenced: prop.silent,
...prop.silent && { silenced: true },
}],
});
}