created a general way to fetch the active properties of an ancestor
This commit is contained in:
@@ -216,7 +216,4 @@ const propDetailsByType = {
|
||||
proficiency(){
|
||||
return {};
|
||||
},
|
||||
damageMultiplier(){
|
||||
return {};
|
||||
},
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import SimpleSchema from 'simpl-schema';
|
||||
import { assertEditPermission } from '/imports/api/creature/creaturePermissions.js';
|
||||
import ComputationMemo from '/imports/api/creature/computation/ComputationMemo.js';
|
||||
import computeMemo from '/imports/api/creature/computation/computeMemo.js';
|
||||
import getCalculationProperties from '/imports/api/creature/computation/getCalculationProperties.js';
|
||||
import getActiveProperties from '/imports/api/creature/getActiveProperties.js';
|
||||
import writeAlteredProperties from '/imports/api/creature/computation/writeAlteredProperties.js';
|
||||
import writeCreatureVariables from '/imports/api/creature/computation/writeCreatureVariables.js';
|
||||
import { recomputeDamageMultipliersById } from '/imports/api/creature/damageMultiplierDenormalise/recomputeDamageMultipliers.js'
|
||||
@@ -26,6 +26,14 @@ export const recomputeCreature = new ValidatedMethod({
|
||||
|
||||
});
|
||||
|
||||
const calculationPropertyTypes = [
|
||||
'attribute',
|
||||
'skill',
|
||||
'effect',
|
||||
'proficiency',
|
||||
'classLevel',
|
||||
];
|
||||
|
||||
/**
|
||||
* This function is the heart of DiceCloud. It recomputes a creature's stats,
|
||||
* distilling down effects and proficiencies into the final stats that make up
|
||||
@@ -63,7 +71,7 @@ export const recomputeCreature = new ValidatedMethod({
|
||||
* - Write the computed results back to the database
|
||||
*/
|
||||
export function recomputeCreatureById(creatureId){
|
||||
let props = getCalculationProperties(creatureId);
|
||||
let props = getActiveProperties(creatureId, {type: {$in: calculationPropertyTypes}});
|
||||
let computationMemo = new ComputationMemo(props);
|
||||
computeMemo(computationMemo);
|
||||
writeAlteredProperties(computationMemo);
|
||||
|
||||
@@ -2,7 +2,7 @@ import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import { assertEditPermission } from '/imports/api/creature/creaturePermissions.js';
|
||||
import Creatures from '/imports/api/creature/Creatures.js';
|
||||
import getCalculationProperties from '/imports/api/creature/computation/getCalculationProperties.js'
|
||||
import getActiveProperties from '/imports/api/creature/getActiveProperties.js';
|
||||
|
||||
export const recomputeDamageMultipliers = new ValidatedMethod({
|
||||
|
||||
@@ -24,7 +24,7 @@ export const recomputeDamageMultipliers = new ValidatedMethod({
|
||||
|
||||
export function recomputeDamageMultipliersById(creatureId){
|
||||
if (!creatureId) throw 'Creature ID is required';
|
||||
let props = getCalculationProperties(creatureId, ['damageMultiplier']);
|
||||
let props = getActiveProperties(creatureId, {type: 'damageMultiplier'});
|
||||
|
||||
// Count of how many weakness, resistances and immunities each damage type has
|
||||
let multipliersByName = {};
|
||||
|
||||
@@ -1,22 +1,26 @@
|
||||
import Creatures from '/imports/api/creature/Creatures.js';
|
||||
import CreatureProperties from '/imports/api/creature/CreatureProperties.js';
|
||||
|
||||
export default function getCalculationProperties(creatureId, types){
|
||||
// First get ids of disabled properties and unequiped items
|
||||
export default function getActiveProperties(ancestorId, filter = {}, options){
|
||||
if (!ancestorId){
|
||||
throw 'Ancestor Id is required to get active properties'
|
||||
}
|
||||
// First get ids of disabled properties, unequiped items, unapplied buffs
|
||||
let disabledAncestorIds = CreatureProperties.find({
|
||||
'ancestors.id': creatureId,
|
||||
'ancestors.id': ancestorId,
|
||||
$or: [
|
||||
{disabled: true},
|
||||
{equipped: false},
|
||||
{applied: false},
|
||||
],
|
||||
}, {
|
||||
fields: {_id: 1},
|
||||
}).map(prop => prop._id);
|
||||
|
||||
// Then get the ids of creatures that are children of this creature
|
||||
// to isolate their decendent properties from this calculation
|
||||
// to isolate their decendent properties
|
||||
Creatures.find({
|
||||
'ancestors.id': creatureId,
|
||||
'ancestors.id': ancestorId,
|
||||
}, {
|
||||
fields: {_id: 1},
|
||||
}).forEach(prop => {
|
||||
@@ -24,19 +28,10 @@ export default function getCalculationProperties(creatureId, types){
|
||||
});
|
||||
|
||||
// Get all the properties that aren't from the excluded decendents
|
||||
return CreatureProperties.find({
|
||||
'ancestors.id': {
|
||||
$eq: creatureId,
|
||||
$nin: disabledAncestorIds,
|
||||
},
|
||||
removed: {$ne: true},
|
||||
type: {$in: types || [
|
||||
'attribute',
|
||||
'skill',
|
||||
'damageMultiplier',
|
||||
'effect',
|
||||
'proficiency',
|
||||
'classLevel',
|
||||
]},
|
||||
}).fetch();
|
||||
filter['ancestors.id'] = {
|
||||
$eq: ancestorId,
|
||||
$nin: disabledAncestorIds,
|
||||
};
|
||||
filter.removed = {$ne: true};
|
||||
return CreatureProperties.find(filter, options).fetch();
|
||||
}
|
||||
Reference in New Issue
Block a user