Tested and fixed critical hits not doubling damage
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
removeAllCreaturesAndProps,
|
||||
runActionById
|
||||
} from '/imports/api/engine/action/functions/actionEngineTest.testFn';
|
||||
import { critInputProvider } from '../functions/userInput/inputProviderForTests.testFn';
|
||||
|
||||
const [
|
||||
creatureId, targetCreatureId, targetCreature2Id, damageTargetId, damageSelfId, targetCreatureHitPointsId, targetCreature2HitPointsId, selfHitPointsId, damageWithEffectsId, effectId, effect2Id,
|
||||
@@ -241,4 +242,50 @@ describe('Apply Damage Properties', function () {
|
||||
],
|
||||
}]);
|
||||
});
|
||||
|
||||
it('Doubles damage on a critical hit', async function () {
|
||||
const [
|
||||
creatureId, damageId, actionId
|
||||
] = getRandomIds(3);
|
||||
const testCreature = {
|
||||
_id: creatureId,
|
||||
props: [
|
||||
{
|
||||
_id: actionId,
|
||||
type: 'action',
|
||||
attackRoll: { calculation: '10' },
|
||||
children: [
|
||||
{
|
||||
_id: damageId,
|
||||
type: 'damage',
|
||||
target: 'target',
|
||||
amount: { calculation: '2d6 + 7' }
|
||||
},
|
||||
]
|
||||
},
|
||||
],
|
||||
};
|
||||
await createTestCreature(testCreature);
|
||||
|
||||
const action = await runActionById(actionId, [], critInputProvider);
|
||||
assert.exists(action);
|
||||
assert.deepEqual(allMutations(action), [{
|
||||
'contents': [{ 'name': 'Action' }],
|
||||
'targetIds': []
|
||||
}, {
|
||||
'contents': [{
|
||||
'inline': true,
|
||||
'name': 'Critical Hit!',
|
||||
'value': '1d20 [20] + 10\n**30**'
|
||||
}],
|
||||
'targetIds': [],
|
||||
}, {
|
||||
'contents': [{
|
||||
'inline': true,
|
||||
'name': 'Damage',
|
||||
'value': '2d6 [3, 4, 5, 6] + 7\n**25** critical slashing damage',
|
||||
}],
|
||||
'targetIds': [],
|
||||
}]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -21,7 +21,7 @@ export default async function applyDamageProperty(
|
||||
task: PropTask, action: EngineAction, result: TaskResult, inputProvider: InputProvider
|
||||
) {
|
||||
const prop = task.prop;
|
||||
const scope = getEffectiveActionScope(action);
|
||||
const scope = await getEffectiveActionScope(action);
|
||||
|
||||
// Choose target
|
||||
const damageTargets = prop.target === 'self' ? [action.creatureId] : task.targetIds;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import InputProvider from '/imports/api/engine/action/functions/userInput/InputProvider';
|
||||
import InputProvider, { CastSpellParams } from '/imports/api/engine/action/functions/userInput/InputProvider';
|
||||
|
||||
const inputProviderForTests: InputProvider = {
|
||||
async targetIds(target, currentTargetIds = []) {
|
||||
@@ -43,8 +43,19 @@ const inputProviderForTests: InputProvider = {
|
||||
return suggestedParams;
|
||||
},
|
||||
async castSpell(suggestedParams) {
|
||||
return suggestedParams;
|
||||
return suggestedParams as CastSpellParams;
|
||||
},
|
||||
}
|
||||
|
||||
export const critInputProvider: InputProvider = {
|
||||
...inputProviderForTests,
|
||||
async rollDice(dice = []) {
|
||||
// when rolling 1d20, crit, otherwise use the normal test roll provider
|
||||
if (dice.length === 1 && dice[0].diceSize === 20 && dice[0].number === 1) {
|
||||
return [[20]];
|
||||
}
|
||||
return inputProviderForTests.rollDice(dice);
|
||||
},
|
||||
};
|
||||
|
||||
export default inputProviderForTests;
|
||||
|
||||
Reference in New Issue
Block a user