Tested damage property

This commit is contained in:
ThaumRystra
2024-09-28 14:45:46 +02:00
parent b1ab65f095
commit efc52b4f68
3 changed files with 192 additions and 3 deletions

View File

@@ -55,7 +55,7 @@ const actionOtherCreature = {
],
};
describe('Apply Buff Properties', function () {
describe('Apply Buff Remover Properties', function () {
// Increase timeout
this.timeout(8000);

View File

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

View File

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