Made inactive toggle decendants specifically included when recomputing active properties

This commit is contained in:
Stefan Zermatten
2021-01-11 22:03:54 +02:00
parent 75835d74f6
commit ae5b4b7d5c
2 changed files with 18 additions and 2 deletions

View File

@@ -97,12 +97,26 @@ export function recomputeCreatureById(creatureId){
*/
export function recomputeCreatureByDoc(creature){
const creatureId = creature._id;
recomputeInactiveProperties(creatureId);
// find all toggles that have conditions, even if they are inactive
let toggleIds = CreatureProperties.find({
'ancestors.id': creatureId,
type: 'toggle',
removed: {$ne: true},
condition: { $exists: true },
}, {
fields: {_id: 1},
}).map(t => t._id);
// Find all the active properties
let props = CreatureProperties.find({
'ancestors.id': creatureId,
inactive: {$ne: true},
removed: {$ne: true},
type: {$in: calculationPropertyTypes},
$or: [
{inactive: {$ne: true}},
// But also the inactive computed toggles and their decendants
{'ancestors.id': {$in: toggleIds}},
{_id: {$in: toggleIds}},
]
}, {
fields: { // Filter out potentially large fields
icon: 0,
@@ -114,6 +128,7 @@ export function recomputeCreatureByDoc(creature){
}
}).fetch();
let computationMemo = new ComputationMemo(props, creature);
recomputeInactiveProperties(creatureId);
computeMemo(computationMemo);
writeAlteredProperties(computationMemo);
writeCreatureVariables(computationMemo, creatureId);

View File

@@ -7,6 +7,7 @@ export default function recomputeInactiveProperties(ancestorId){
{disabled: true}, // Everything can be disabled
{type: 'buff', applied: false}, // Buffs can be applied
{type: 'item', equipped: {$ne: true}},
{type: 'toggle', toggleResult: false},
{type: 'spell', prepared: {$ne: true}, alwaysPrepared: {$ne: true}},
],
};