Refactored actions, 'cast a spell' task now works
This commit is contained in:
@@ -22,7 +22,7 @@ export const insertAction = new ValidatedMethod({
|
||||
action.tabletopId = creature.tabletopId;
|
||||
|
||||
// Ensure that all the targeted creatures exist and share a tabletop
|
||||
if (action.targetIds) for (const targetId of action.targetIds) {
|
||||
if (action.task.targetIds) for (const targetId of action.task.targetIds) {
|
||||
const target = getCreature(targetId);
|
||||
if (!target) {
|
||||
throw new Meteor.Error('not-found', 'Target creature does not exist');
|
||||
|
||||
@@ -6,33 +6,17 @@ import { getCreature } from '/imports/api/engine/loadCreatures';
|
||||
import applyAction from '/imports/api/engine/action/functions/applyAction';
|
||||
import writeActionResults from '../functions/writeActionResults';
|
||||
import getReplayChoicesInputProvider from '/imports/api/engine/action/functions/userInput/getReplayChoicesInputProvider';
|
||||
import Task from '/imports/api/engine/action/tasks/Task';
|
||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||
|
||||
export const runAction = new ValidatedMethod({
|
||||
name: 'actions.runAction',
|
||||
validate: new SimpleSchema({
|
||||
actionId: String,
|
||||
decisions: {
|
||||
type: Array,
|
||||
optional: true,
|
||||
},
|
||||
'decisions.$': {
|
||||
type: Object,
|
||||
blackbox: true,
|
||||
},
|
||||
task: {
|
||||
type: Object,
|
||||
optional: true,
|
||||
blackbox: true,
|
||||
},
|
||||
}).validator(),
|
||||
validate: null,
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 10,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run: async function ({ actionId, decisions = [], task }: { actionId: string, decisions?: any[], task?: Task }) {
|
||||
run: async function ({ actionId, decisions = [] }: { actionId: string, decisions?: any[] }) {
|
||||
// Get the action
|
||||
const action = await EngineActions.findOneAsync(actionId);
|
||||
if (!action) throw new Meteor.Error('not-found', 'Action not found');
|
||||
@@ -44,7 +28,7 @@ export const runAction = new ValidatedMethod({
|
||||
const userInput = getReplayChoicesInputProvider(actionId, decisions);
|
||||
|
||||
// Apply the action
|
||||
await applyAction(action, userInput, { task });
|
||||
await applyAction(action, userInput);
|
||||
|
||||
// Persist changes
|
||||
const writePromise = writeActionResults(action);
|
||||
|
||||
@@ -2,6 +2,7 @@ import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import EngineActions from '/imports/api/engine/action/EngineActions';
|
||||
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions';
|
||||
import { getCreature } from '/imports/api/engine/loadCreatures';
|
||||
import { RateLimiterMixin } from 'ddp-rate-limiter-mixin';
|
||||
|
||||
export const updateAction = new ValidatedMethod({
|
||||
name: 'actions.updateAction',
|
||||
@@ -11,6 +12,11 @@ export const updateAction = new ValidatedMethod({
|
||||
if (path !== 'targetIds') throw new Meteor.Error('Can only update target ids');
|
||||
if (!Array.isArray(value)) throw new Meteor.Error('TargetIds must be an array');
|
||||
},
|
||||
mixins: [RateLimiterMixin],
|
||||
rateLimit: {
|
||||
numRequests: 10,
|
||||
timeInterval: 5000,
|
||||
},
|
||||
run: async function ({ _id, path, value }: { _id: string, path: 'targetIds', value: string[] }) {
|
||||
const action = await EngineActions.findOneAsync(_id);
|
||||
if (!action) {
|
||||
|
||||
Reference in New Issue
Block a user