Fixed a lot of UI to match new parenting API

This commit is contained in:
Thaum Rystra
2024-05-08 12:10:43 +02:00
parent 620634c6fd
commit 4a52c3af19
19 changed files with 108 additions and 77 deletions

View File

@@ -10,6 +10,7 @@ import EngineActions, { EngineAction } from '/imports/api/engine/action/EngineAc
import applyAction from '/imports/api/engine/action/functions/applyAction';
import { LogContent, Removal, Update } from '/imports/api/engine/action/tasks/TaskResult';
import inputProvider from './functions/userInput/inputProviderForTests.testFn';
import { removeAllCreaturesAndProps } from '/imports/api/engine/action/functions/actionEngineTest.testFn';
const creatureId = Random.id();
const targetId = Random.id();
@@ -19,11 +20,8 @@ describe('Interrupt action system', function () {
this.timeout(8000);
before(async function () {
// Remove old data
await Promise.all([
CreatureProperties.removeAsync({}),
Creatures.removeAsync({}),
CreatureVariables.removeAsync({}),
]);
await removeAllCreaturesAndProps();
// Add creatures
await Promise.all([
Creatures.insertAsync({

View File

@@ -16,7 +16,7 @@ const [
creatureId, targetCreatureId, targetCreature2Id, emptyActionId, selfActionId, attackActionId,
usesActionId, attackMissId, attackNoTargetId, usesResourcesActionId, ammoId, resourceAttId,
consumeAmmoId, consumeResourceId, noUsesActionId, insufficientResourcesActionId,
attributeResetByEventId, eventActionId, advantageAttackId, advantageEffectId
attributeResetByEventId, eventActionId, advantageAttackId, advantageEffectId, disadvantageAttackId, disadvantageEffectId,
] = randomIds;
const actionTestCreature = {
@@ -60,6 +60,20 @@ const actionTestCreature = {
targetByTags: true,
targetTags: ['hasAdvantage'],
},
// Attack that has Disadvantage
{
_id: disadvantageAttackId,
type: 'action',
attackRoll: { calculation: '0' },
tags: ['hasDisadvantage'],
},
{
_id: disadvantageEffectId,
type: 'effect',
operation: 'disadvantage',
targetByTags: true,
targetTags: ['hasDisadvantage'],
},
// Attack that has no target
{
_id: attackNoTargetId,
@@ -333,6 +347,26 @@ describe('Apply Action Properties', function () {
assert.deepEqual(allMutations(action), expectedMutations);
});
it('should make attack rolls that roll with disadvantage', async function () {
const prop = await CreatureProperties.findOneAsync(disadvantageAttackId);
assert.equal(prop.attackRoll.disadvantage, 1, 'The attack roll should have disadvantage');
const action = await runActionById(disadvantageAttackId, [targetCreatureId]);
const expectedMutations: Mutation[] = [
{
contents: [{ name: 'Action' }],
targetIds: [targetCreatureId],
}, {
contents: [{
inline: true,
name: 'Hit! (Disadvantage)',
value: '1d20 [ 10, ~~11~~ ] + 0\n**10**',
}],
targetIds: [targetCreatureId],
}
];
assert.deepEqual(allMutations(action), expectedMutations);
});
it('actions should consume resources', async function () {
const action = await runActionById(usesResourcesActionId, []);
const expectedMutations: Mutation[] = [
@@ -401,7 +435,7 @@ describe('Apply Action Properties', function () {
contents: [
{
inline: true,
name: 'Attribute damaged',
name: 'Attribute restored',
value: '+13 Attribute Reset By testEvent Event',
},
],

View File

@@ -1,8 +1,7 @@
import { EngineAction } from '/imports/api/engine/action/EngineActions';
import { PropTask } from '../tasks/Task';
import TaskResult, { LogContent } from '../tasks/TaskResult';
import { getPropertiesOfType, getVariables } from '/imports/api/engine/loadCreatures';
import applyTask from '/imports/api/engine/action/tasks/applyTask';
import { getVariables } from '/imports/api/engine/loadCreatures';
import getPropertyTitle from '/imports/api/utility/getPropertyTitle';
import recalculateInlineCalculations from '/imports/api/engine/action/functions/recalculateInlineCalculations';
import spendResources from '/imports/api/engine/action/functions/spendResources';
@@ -115,7 +114,7 @@ async function applyAttackToTarget(
if (targetArmor !== undefined) {
let name = criticalHit ? 'Critical Hit!' :
criticalMiss ? 'Critical Miss!' :
result > targetArmor ? 'Hit!' : 'Miss!';
result >= targetArmor ? 'Hit!' : 'Miss!';
if (advantage === 1) {
name += ' (Advantage)';
} else if (advantage === -1) {
@@ -170,18 +169,19 @@ async function applyAttackWithoutTarget(action, prop, attack, taskResult: TaskRe
result,
criticalHit,
criticalMiss,
advantage,
} = await rollAttack(attack, scope, taskResult.pushScope, userInput);
let name = criticalHit ? 'Critical Hit!' : criticalMiss ? 'Critical Miss!' : 'To Hit';
if (scope['~attackAdvantage']?.value === 1) {
if (advantage === 1) {
name += ' (Advantage)';
} else if (scope['~attackAdvantage']?.value === -1) {
} else if (advantage === -1) {
name += ' (Disadvantage)';
}
if (!criticalMiss) {
scope['~attackHit'] = { value: true }
taskResult.pushScope['~attackHit'] = { value: true }
}
if (!criticalHit) {
scope['~attackMiss'] = { value: true };
taskResult.pushScope['~attackMiss'] = { value: true };
}
taskResult.mutations.push({
contents: [{

View File

@@ -13,11 +13,17 @@ import inputProvider from './userInput/inputProviderForTests.testFn';
* Removes all creatures, properties, and creatureVariable documents from the database
*/
export async function removeAllCreaturesAndProps() {
return Promise.all([
CreatureProperties.removeAsync({}),
Creatures.removeAsync({}),
CreatureVariables.removeAsync({}),
]);
if (Meteor.isServer) {
return Promise.all([
CreatureProperties.removeAsync({}),
Creatures.removeAsync({}),
CreatureVariables.removeAsync({}),
]);
} else {
CreatureProperties.find({}).forEach(doc => CreatureProperties.remove(doc._id));
Creatures.find({}).forEach(doc => Creatures.remove(doc._id));
CreatureVariables.find({}).forEach((doc: any) => CreatureVariables.remove(doc._id));
}
}
/**

View File

@@ -17,20 +17,15 @@ export default async function applyResetTask(
throw new Meteor.Error('wrong-number-of-targets', `Must reset the properties of a single creature at a time, ${task.targetIds.length} targets were provided`)
}
// Print a title for the event
let name: string;
// Print a title for rest events
switch (task.eventName) {
case 'shortRest':
name = 'Short Rest';
result.appendLog({ name: 'Short Rest' }, task.targetIds);
break;
case 'longRest':
name = 'Long Rest';
break;
default:
name = task.eventName;
result.appendLog({ name: 'Long Rest' }, task.targetIds);
break;
}
result.appendLog({ name }, task.targetIds);
// Reset the properties by this event name
await resetProperties(task, action, result, userInput);