From efc52b4f68f3c2c5421f7396603a4a945f8023b9 Mon Sep 17 00:00:00 2001 From: ThaumRystra Date: Sat, 28 Sep 2024 14:45:46 +0200 Subject: [PATCH] Tested damage property --- .../applyBuffRemoverProperty.test.ts | 2 +- .../applyDamageProperty.test.ts | 190 ++++++++++++++++++ app/imports/api/properties/Damages.js | 3 +- 3 files changed, 192 insertions(+), 3 deletions(-) create mode 100644 app/imports/api/engine/action/applyProperties/applyDamageProperty.test.ts diff --git a/app/imports/api/engine/action/applyProperties/applyBuffRemoverProperty.test.ts b/app/imports/api/engine/action/applyProperties/applyBuffRemoverProperty.test.ts index b3a2bccb..49d32e75 100644 --- a/app/imports/api/engine/action/applyProperties/applyBuffRemoverProperty.test.ts +++ b/app/imports/api/engine/action/applyProperties/applyBuffRemoverProperty.test.ts @@ -55,7 +55,7 @@ const actionOtherCreature = { ], }; -describe('Apply Buff Properties', function () { +describe('Apply Buff Remover Properties', function () { // Increase timeout this.timeout(8000); diff --git a/app/imports/api/engine/action/applyProperties/applyDamageProperty.test.ts b/app/imports/api/engine/action/applyProperties/applyDamageProperty.test.ts new file mode 100644 index 00000000..a93e3f77 --- /dev/null +++ b/app/imports/api/engine/action/applyProperties/applyDamageProperty.test.ts @@ -0,0 +1,190 @@ +import { assert } from 'chai'; +import { + allMutations, + createTestCreature, + getRandomIds, + removeAllCreaturesAndProps, + runActionById +} from '/imports/api/engine/action/functions/actionEngineTest.testFn'; + +const [ + creatureId, targetCreatureId, targetCreature2Id, damageTargetId, damageSelfId, targetCreatureHitPointsId, targetCreature2HitPointsId, selfHitPointsId +] = getRandomIds(100); + +const actionTestCreature = { + _id: creatureId, + props: [ + { + _id: damageTargetId, + type: 'damage', + target: 'target', + amount: { calculation: '2d6 + 7' } + }, + { + _id: damageSelfId, + type: 'damage', + target: 'self', + amount: { calculation: '1d12 + 7' } + }, + { + _id: selfHitPointsId, + type: 'attribute', + name: 'Hit Points', + attributeType: 'healthBar', + variableName: 'hitPoints', + baseValue: { calculation: '20' }, + }, + ], +} + +const actionTargetCreature = { + _id: targetCreatureId, + props: [ + { + _id: targetCreatureHitPointsId, + type: 'attribute', + name: 'Hit Points', + attributeType: 'healthBar', + variableName: 'hitPoints', + baseValue: { calculation: '33' }, + } + ] +} + +const actionTargetCreature2 = { + _id: targetCreature2Id, + props: [ + { + _id: targetCreature2HitPointsId, + type: 'attribute', + name: 'Hit Points', + attributeType: 'healthBar', + variableName: 'hitPoints', + baseValue: { calculation: '47' }, + } + ] +} + +describe('Apply Damage Properties', function () { + // Increase timeout + this.timeout(8000); + + before(async function () { + await removeAllCreaturesAndProps(); + await createTestCreature(actionTestCreature); + await createTestCreature(actionTargetCreature); + await createTestCreature(actionTargetCreature2); + }); + + it('Damages self', async function () { + const action = await runActionById(damageSelfId); + assert.exists(action); + assert.deepEqual(allMutations(action), [{ + contents: [ + { + inline: true, + name: 'Damage', + value: '1d12 [6] + 7', + } + ], + targetIds: [creatureId], + }, { + contents: [{ + inline: true, + name: 'Attribute damaged', + value: '−13 Hit Points', + }], + updates: [ + { + propId: selfHitPointsId, + type: 'attribute', + inc: { damage: 13, value: -13 }, + }, + ], + targetIds: [creatureId], + }]); + }); + + it('Damages a single target', async function () { + const action = await runActionById(damageTargetId, [targetCreatureId]); + assert.exists(action); + assert.deepEqual(allMutations(action), [{ + contents: [ + { + inline: true, + name: 'Damage', + value: '2d6 [3, 4] + 7', + } + ], + targetIds: [targetCreatureId], + }, { + contents: [ + { + inline: true, + name: 'Attribute damaged', + value: '−14 Hit Points', + } + ], + targetIds: [targetCreatureId], + updates: [ + { + propId: targetCreatureHitPointsId, + type: 'attribute', + inc: { damage: 14, value: -14 }, + }, + ], + }]); + }); + + it('Damages multiple targets', async function () { + const action = await runActionById(damageTargetId, [ + targetCreatureId, targetCreature2Id + ]); + assert.exists(action); + assert.deepEqual(allMutations(action), [{ + contents: [ + { + inline: true, + name: 'Damage', + value: '2d6 [3, 4] + 7', + } + ], + targetIds: [ + targetCreatureId, + targetCreature2Id, + ], + }, { + contents: [ + { + inline: true, + name: 'Attribute damaged', + value: '−14 Hit Points', + } + ], + targetIds: [targetCreatureId], + updates: [ + { + propId: targetCreatureHitPointsId, + type: 'attribute', + inc: { damage: 14, value: -14 }, + }, + ], + }, { + contents: [ + { + inline: true, + name: 'Attribute damaged', + value: '−14 Hit Points', + } + ], + targetIds: [targetCreature2Id], + updates: [ + { + propId: targetCreature2HitPointsId, + type: 'attribute', + inc: { damage: 14, value: -14 }, + }, + ], + }]); + }); +}); diff --git a/app/imports/api/properties/Damages.js b/app/imports/api/properties/Damages.js index 34ee997c..7964839f 100644 --- a/app/imports/api/properties/Damages.js +++ b/app/imports/api/properties/Damages.js @@ -2,7 +2,6 @@ import SimpleSchema from 'simpl-schema'; import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema'; import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS'; import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX'; -import { SavingThrowSchema, ComputedOnlySavingThrowSchema } from '/imports/api/properties/SavingThrows'; const DamageSchema = createPropertySchema({ // The roll that determines how much to damage the attribute @@ -79,7 +78,7 @@ const ComputedOnlyDamageSchema = createPropertySchema({ }, }); -const ComputedDamageSchema = new SimpleSchema() +const ComputedDamageSchema = new SimpleSchema({}) .extend(DamageSchema) .extend(ComputedOnlyDamageSchema);