Added ancestor references to action context so that #spellList references work, closes #270
This commit is contained in:
@@ -62,6 +62,7 @@ function applyPropertyAndWalkChildren({prop, children, targets, ...options}){
|
||||
export default function applyProperties({ forest, targets, ...options}){
|
||||
forest.forEach(node => {
|
||||
let prop = node.node;
|
||||
options.actionContext[`#${prop.type}`] = prop;
|
||||
let children = node.children;
|
||||
if (shouldSplit(prop) && targets.length){
|
||||
targets.forEach(target => {
|
||||
|
||||
@@ -8,6 +8,7 @@ import { assertEditPermission } from '/imports/api/creature/creatures/creaturePe
|
||||
import { recomputeCreatureByDoc } from '/imports/api/creature/computation/methods/recomputeCreature.js';
|
||||
import { doActionWork } from '/imports/api/creature/actions/doAction.js';
|
||||
import getRootCreatureAncestor from '/imports/api/creature/creatureProperties/getRootCreatureAncestor.js';
|
||||
import getAncestorContext from '/imports/api/creature/actions/getAncestorContext.js';
|
||||
|
||||
const castSpellWithSlot = new ValidatedMethod({
|
||||
name: 'creatureProperties.castSpellWithSlot',
|
||||
@@ -61,9 +62,11 @@ const castSpellWithSlot = new ValidatedMethod({
|
||||
value: 1,
|
||||
});
|
||||
}
|
||||
let actionContext = getAncestorContext(spell);
|
||||
|
||||
doActionWork({
|
||||
action: spell,
|
||||
context: {slotLevel},
|
||||
actionContext: {slotLevel, ...actionContext},
|
||||
creature,
|
||||
targets: target ? [target] : [],
|
||||
method: this,
|
||||
|
||||
@@ -11,6 +11,7 @@ import { nodesToTree } from '/imports/api/parenting/parenting.js';
|
||||
import applyProperties from '/imports/api/creature/actions/applyProperties.js';
|
||||
import recomputeInventory from '/imports/api/creature/denormalise/recomputeInventory.js';
|
||||
import recomputeInactiveProperties from '/imports/api/creature/denormalise/recomputeInactiveProperties.js';
|
||||
import getAncestorContext from '/imports/api/creature/actions/getAncestorContext.js';
|
||||
|
||||
const doAction = new ValidatedMethod({
|
||||
name: 'creatureProperties.doAction',
|
||||
@@ -36,6 +37,10 @@ const doAction = new ValidatedMethod({
|
||||
let action = CreatureProperties.findOne(actionId);
|
||||
// Check permissions
|
||||
let creature = getRootCreatureAncestor(action);
|
||||
|
||||
// Build ancestor context
|
||||
let actionContext = getAncestorContext(action);
|
||||
|
||||
assertEditPermission(creature, this.userId);
|
||||
let targets = [];
|
||||
targetIds.forEach(targetId => {
|
||||
@@ -43,7 +48,7 @@ const doAction = new ValidatedMethod({
|
||||
assertEditPermission(target, this.userId);
|
||||
targets.push(target);
|
||||
});
|
||||
doActionWork({action, creature, targets, method: this});
|
||||
doActionWork({action, creature, targets, actionContext, method: this});
|
||||
|
||||
// The acting creature might have used ammo
|
||||
recomputeInventory(creature._id);
|
||||
@@ -64,7 +69,7 @@ export function doActionWork({
|
||||
action,
|
||||
creature,
|
||||
targets,
|
||||
context = {},
|
||||
actionContext = {},
|
||||
method
|
||||
}){
|
||||
// Create the log
|
||||
@@ -83,7 +88,7 @@ export function doActionWork({
|
||||
}];
|
||||
applyProperties({
|
||||
forest: startingForest,
|
||||
actionContext: context,
|
||||
actionContext,
|
||||
creature,
|
||||
targets,
|
||||
log,
|
||||
|
||||
15
app/imports/api/creature/actions/getAncestorContext.js
Normal file
15
app/imports/api/creature/actions/getAncestorContext.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
|
||||
|
||||
export default function getAncestorContext(prop){
|
||||
// Build ancestor context
|
||||
const actionContext = {};
|
||||
let ancestorIds = prop.ancestors.map(ref => ref.id);
|
||||
CreatureProperties.find({
|
||||
_id: {$in: ancestorIds}
|
||||
}, {
|
||||
sort: {order: 1},
|
||||
}).forEach(ancestor => {
|
||||
actionContext[`#${ancestor.type}`] = ancestor;
|
||||
});
|
||||
return actionContext;
|
||||
}
|
||||
Reference in New Issue
Block a user