Actions in tabletops show logs correctly

This commit is contained in:
ThaumRystra
2024-05-31 20:01:42 +02:00
parent 028c1b7463
commit 6e8c970287
11 changed files with 373 additions and 64 deletions

View File

@@ -9,8 +9,29 @@ export const insertAction = new ValidatedMethod({
validate: new SimpleSchema({
action: ActionSchema
}).validator({ clean: true }),
rateLimit: {
numRequests: 5,
timeInterval: 1000,
},
run: function ({ action }: { action: EngineAction }) {
assertEditPermission(getCreature(action.creatureId), this.userId);
const creature = getCreature(action.creatureId);
assertEditPermission(getCreature(creature), this.userId);
// Make sure the action shares the creature's tabletopId
// It is assumed that if a character you control is in a tabletop, you have the rights
// to do actions in that tabletop
action.tabletopId = creature.tabletopId;
// Ensure that all the targeted creatures exist and share a tabletop
if (action.targetIds) for (const targetId of action.targetIds) {
const target = getCreature(targetId);
if (!target) {
throw new Meteor.Error('not-found', 'Target creature does not exist');
}
if (target.tabletopId !== action.tabletopId) {
throw new Meteor.Error('permission-denied', 'Target creature does not share a tabletop with the acting creature');
}
}
// First remove all other actions on this creature
// only do one action at a time, don't wait for this to finish
EngineActions.remove({ creatureId: action.creatureId });