Fixed characters not recalculating on action
This commit is contained in:
@@ -5,12 +5,14 @@ import { union } from 'lodash';
|
||||
import CreatureLogs from '/imports/api/creature/log/CreatureLogs';
|
||||
import bulkWrite from '/imports/api/engine/shared/bulkWrite';
|
||||
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties';
|
||||
import Creatures from '/imports/api/creature/creatures/Creatures';
|
||||
|
||||
export default async function writeActionResults(action: EngineAction) {
|
||||
if (!action._id) throw new Meteor.Error('type-error', 'Action does not have an _id');
|
||||
EngineActions.remove(action._id);
|
||||
const engineActionPromise = EngineActions.removeAsync(action._id);
|
||||
const creaturePropUpdates: any[] = [];
|
||||
const logContents: any[] = [];
|
||||
|
||||
// Collect all the updates and log content
|
||||
action.results.forEach(result => {
|
||||
result.mutations.forEach(mutation => {
|
||||
@@ -18,7 +20,7 @@ export default async function writeActionResults(action: EngineAction) {
|
||||
logContents.push(...mutationToLogUpdates(mutation));
|
||||
});
|
||||
});
|
||||
const allTargetIds = union(...logContents.map(c => c.targetIds));
|
||||
const allTargetIds: string[] = union(...logContents.map(c => c.targetIds));
|
||||
|
||||
// Write the log
|
||||
const logPromise = CreatureLogs.insertAsync({
|
||||
@@ -30,5 +32,14 @@ export default async function writeActionResults(action: EngineAction) {
|
||||
// Write the bulk updates
|
||||
const bulkWritePromise = bulkWrite(creaturePropUpdates, CreatureProperties);
|
||||
|
||||
return Promise.all([logPromise, bulkWritePromise]);
|
||||
// Mark the creatures as dirty
|
||||
const creaturePromise = Creatures.updateAsync({
|
||||
_id: { $in: [action.creatureId, ...allTargetIds] },
|
||||
}, {
|
||||
$set: { dirty: true },
|
||||
}, {
|
||||
multi: true,
|
||||
});
|
||||
|
||||
return Promise.all([engineActionPromise, logPromise, bulkWritePromise, creaturePromise]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user