Began migration of queries to nested sets
This commit is contained in:
@@ -8,7 +8,7 @@ import { damagePropertyWork } from '/imports/api/creature/creatureProperties/met
|
||||
import numberToSignedString from '/imports/api/utility/numberToSignedString';
|
||||
import { applyNodeTriggers } from '/imports/api/engine/actions/applyTriggers';
|
||||
import { resetProperties } from '/imports/api/creature/creatures/methods/restCreature';
|
||||
import { TreeNode } from '/imports/api/parenting/parentingFunctions';
|
||||
import { TreeNode, hasAncestorRelationship } from '/imports/api/parenting/parentingFunctions';
|
||||
import { Action } from '/imports/api/properties/Actions';
|
||||
import { LogContent } from '/imports/api/creature/log/LogContentSchema';
|
||||
import { Item } from '/imports/api/properties/Items';
|
||||
@@ -327,20 +327,3 @@ function spendResources(prop: Action, actionContext) {
|
||||
inline: true,
|
||||
});
|
||||
}
|
||||
|
||||
function hasAncestorRelationship(a, b) {
|
||||
let top, bottom;
|
||||
if (a.ancestors.length === b.ancestors.length) {
|
||||
// Can't be ancestors of one another if they have the same number of ancestors
|
||||
return false;
|
||||
} else if (a.ancestors.length > b.ancestors.length) {
|
||||
// longer ancestor list goes on the bottom
|
||||
top = b;
|
||||
bottom = a;
|
||||
} else {
|
||||
top = a;
|
||||
bottom = b;
|
||||
}
|
||||
const expectedAncestorPosition = top.ancestors.length;
|
||||
return bottom.ancestors[expectedAncestorPosition]?.id === top._id;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ const doAction = new ValidatedMethod({
|
||||
run({ spellId, slotId, ritual, targetIds = [], scope = {} }) {
|
||||
// Get action context
|
||||
let spell = CreatureProperties.findOne(spellId);
|
||||
const creatureId = spell.ancestors[0].id;
|
||||
const creatureId = spell.root.id;
|
||||
const actionContext = new ActionContext(creatureId, targetIds, this);
|
||||
|
||||
// Check permissions
|
||||
|
||||
@@ -25,7 +25,8 @@ const doCheck = new ValidatedMethod({
|
||||
},
|
||||
run({ propId, scope }) {
|
||||
const prop = CreatureProperties.findOne(propId);
|
||||
const creatureId = prop.ancestors[0].id;
|
||||
if (!prop) throw new Meteor.Error('not-found', 'The property was not found');
|
||||
const creatureId = prop.root.id;
|
||||
const actionContext = new ActionContext(creatureId, [creatureId], this);
|
||||
Object.assign(actionContext.scope, scope);
|
||||
actionContext.scope[`#${prop.type}`] = prop;
|
||||
|
||||
Reference in New Issue
Block a user