Reworked toggles, again, to try and catch more edge cases. Made toggles set the inactive status of their property children in the compute step instead of the inactive denormalisation step
This commit is contained in:
@@ -10,7 +10,7 @@ import applySave from '/imports/api/creature/actions/applySave.js';
|
|||||||
function applyProperty(options){
|
function applyProperty(options){
|
||||||
let prop = options.prop;
|
let prop = options.prop;
|
||||||
if (prop.type === 'buff'){
|
if (prop.type === 'buff'){
|
||||||
// ignore only applied buffs
|
// ignore only applied buffs, don't apply them again
|
||||||
if (prop.applied === true){
|
if (prop.applied === true){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ function applyProperty(options){
|
|||||||
break;
|
break;
|
||||||
case 'buff':
|
case 'buff':
|
||||||
applyBuff(options);
|
applyBuff(options);
|
||||||
break;
|
return false;
|
||||||
case 'toggle':
|
case 'toggle':
|
||||||
return applyToggle(options);
|
return applyToggle(options);
|
||||||
case 'roll':
|
case 'roll':
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ export default function spendResources({prop, log}){
|
|||||||
// Now that we have confirmed that there are no errors, do actual work
|
// Now that we have confirmed that there are no errors, do actual work
|
||||||
//Items
|
//Items
|
||||||
itemQuantityAdjustments.forEach(adjustQuantityWork);
|
itemQuantityAdjustments.forEach(adjustQuantityWork);
|
||||||
|
|
||||||
// Use uses
|
// Use uses
|
||||||
if (prop.usesResult){
|
if (prop.usesResult){
|
||||||
CreatureProperties.update(prop._id, {
|
CreatureProperties.update(prop._id, {
|
||||||
@@ -61,7 +61,7 @@ export default function spendResources({prop, log}){
|
|||||||
});
|
});
|
||||||
log.content.push({
|
log.content.push({
|
||||||
name: 'Uses left',
|
name: 'Uses left',
|
||||||
result: prop.usesResult - prop.usesUsed - 1,
|
result: prop.usesResult - (prop.usesUsed || 0) - 1,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -256,7 +256,6 @@ const propDetailsByType = {
|
|||||||
default(){
|
default(){
|
||||||
return {
|
return {
|
||||||
toggleAncestors: [],
|
toggleAncestors: [],
|
||||||
disabledByToggle: false,
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
toggle(){
|
toggle(){
|
||||||
@@ -264,7 +263,6 @@ const propDetailsByType = {
|
|||||||
computed: false,
|
computed: false,
|
||||||
busyComputing: false,
|
busyComputing: false,
|
||||||
toggleAncestors: [],
|
toggleAncestors: [],
|
||||||
disabledByToggle: false,
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
attribute(){
|
attribute(){
|
||||||
@@ -273,7 +271,6 @@ const propDetailsByType = {
|
|||||||
busyComputing: false,
|
busyComputing: false,
|
||||||
effects: [],
|
effects: [],
|
||||||
toggleAncestors: [],
|
toggleAncestors: [],
|
||||||
disabledByToggle: false,
|
|
||||||
idsOfSameName: [],
|
idsOfSameName: [],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -284,7 +281,6 @@ const propDetailsByType = {
|
|||||||
effects: [],
|
effects: [],
|
||||||
proficiencies: [],
|
proficiencies: [],
|
||||||
toggleAncestors: [],
|
toggleAncestors: [],
|
||||||
disabledByToggle: false,
|
|
||||||
idsOfSameName: [],
|
idsOfSameName: [],
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -293,26 +289,22 @@ const propDetailsByType = {
|
|||||||
computed: false,
|
computed: false,
|
||||||
busyComputing: false,
|
busyComputing: false,
|
||||||
toggleAncestors: [],
|
toggleAncestors: [],
|
||||||
disabledByToggle: false,
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
classLevel(){
|
classLevel(){
|
||||||
return {
|
return {
|
||||||
computed: true,
|
computed: true,
|
||||||
toggleAncestors: [],
|
toggleAncestors: [],
|
||||||
disabledByToggle: false,
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
proficiency(){
|
proficiency(){
|
||||||
return {
|
return {
|
||||||
toggleAncestors: [],
|
toggleAncestors: [],
|
||||||
disabledByToggle: false,
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
denormalizedStat(){
|
denormalizedStat(){
|
||||||
return {
|
return {
|
||||||
toggleAncestors: [],
|
toggleAncestors: [],
|
||||||
disabledByToggle: false,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,9 @@ export default function applyToggles(prop, memo){
|
|||||||
toggle.dependencies,
|
toggle.dependencies,
|
||||||
);
|
);
|
||||||
if (!toggle.toggleResult){
|
if (!toggle.toggleResult){
|
||||||
prop.computationDetails.disabledByToggle = true;
|
prop.inactive = true;
|
||||||
|
prop.deactivatedByAncestor = true;
|
||||||
|
prop.deactivatedByToggle = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ function combineSkill(stat, aggregator, memo){
|
|||||||
let prof = stat.computationDetails.proficiencies[i];
|
let prof = stat.computationDetails.proficiencies[i];
|
||||||
applyToggles(prof, memo);
|
applyToggles(prof, memo);
|
||||||
if (
|
if (
|
||||||
!prof.computationDetails.disabledByToggle &&
|
!prof.deactivatedByToggle &&
|
||||||
prof.value > stat.proficiency
|
prof.value > stat.proficiency
|
||||||
){
|
){
|
||||||
stat.proficiency = prof.value;
|
stat.proficiency = prof.value;
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export default function computeStat(stat, memo){
|
|||||||
// Apply any toggles
|
// Apply any toggles
|
||||||
applyToggles(stat, memo);
|
applyToggles(stat, memo);
|
||||||
|
|
||||||
if (!stat.computationDetails.disabledByToggle){
|
if (!stat.deactivatedByToggle){
|
||||||
// Compute and aggregate all the effects
|
// Compute and aggregate all the effects
|
||||||
let aggregator = new EffectAggregator(stat, memo)
|
let aggregator = new EffectAggregator(stat, memo)
|
||||||
each(stat.computationDetails.effects, (effect) => {
|
each(stat.computationDetails.effects, (effect) => {
|
||||||
@@ -37,7 +37,7 @@ export default function computeStat(stat, memo){
|
|||||||
stat.dependencies,
|
stat.dependencies,
|
||||||
effect.dependencies
|
effect.dependencies
|
||||||
)
|
)
|
||||||
if (!effect.computationDetails.disabledByToggle){
|
if (!effect.deactivatedByToggle){
|
||||||
aggregator.addEffect(effect);
|
aggregator.addEffect(effect);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import evaluateCalculation from '/imports/api/creature/computation/engine/evaluateCalculation.js';
|
import evaluateCalculation from '/imports/api/creature/computation/engine/evaluateCalculation.js';
|
||||||
|
import applyToggles from '/imports/api/creature/computation/engine/applyToggles.js';
|
||||||
import { union } from 'lodash';
|
import { union } from 'lodash';
|
||||||
|
|
||||||
export default function computeToggle(toggle, memo){
|
export default function computeToggle(toggle, memo){
|
||||||
@@ -16,6 +17,9 @@ export default function computeToggle(toggle, memo){
|
|||||||
// Before doing any work, mark this toggle as busy
|
// Before doing any work, mark this toggle as busy
|
||||||
toggle.computationDetails.busyComputing = true;
|
toggle.computationDetails.busyComputing = true;
|
||||||
|
|
||||||
|
// Apply any parent toggles
|
||||||
|
applyToggles(toggle, memo);
|
||||||
|
|
||||||
// Do work
|
// Do work
|
||||||
delete toggle.errors;
|
delete toggle.errors;
|
||||||
if (toggle.enabled){
|
if (toggle.enabled){
|
||||||
@@ -41,6 +45,11 @@ export default function computeToggle(toggle, memo){
|
|||||||
toggle.errors = context.errors;
|
toggle.errors = context.errors;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!toggle.toggleResult){
|
||||||
|
toggle.inactive = true;
|
||||||
|
toggle.deactivatedBySelf = true;
|
||||||
|
toggle.deactivatedByToggle = true;
|
||||||
|
}
|
||||||
toggle.computationDetails.computed = true;
|
toggle.computationDetails.computed = true;
|
||||||
toggle.computationDetails.busyComputing = false;
|
toggle.computationDetails.busyComputing = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,14 @@ export default function writeAlteredProperties(memo){
|
|||||||
ids.forEach(id => {
|
ids.forEach(id => {
|
||||||
let op = undefined;
|
let op = undefined;
|
||||||
let original = memo.originalPropsById[id];
|
let original = memo.originalPropsById[id];
|
||||||
let keys = ['dependencies', ...schema.objectKeys()];
|
let keys = [
|
||||||
|
'dependencies',
|
||||||
|
'inactive',
|
||||||
|
'deactivatedBySelf',
|
||||||
|
'deactivatedByAncestor',
|
||||||
|
'deactivatedByToggle',
|
||||||
|
...schema.objectKeys(),
|
||||||
|
];
|
||||||
op = addChangedKeysToOp(op, keys, original, changed);
|
op = addChangedKeysToOp(op, keys, original, changed);
|
||||||
if (op){
|
if (op){
|
||||||
bulkWriteOperations.push(op);
|
bulkWriteOperations.push(op);
|
||||||
|
|||||||
@@ -89,7 +89,6 @@ export function recomputeCreatureByDoc(creature){
|
|||||||
writeCreatureVariables(computationMemo, creatureId);
|
writeCreatureVariables(computationMemo, creatureId);
|
||||||
recomputeDamageMultipliersById(creatureId);
|
recomputeDamageMultipliersById(creatureId);
|
||||||
recomputeSlotFullness(creatureId);
|
recomputeSlotFullness(creatureId);
|
||||||
recomputeInactiveProperties(creatureId);
|
|
||||||
return computationMemo;
|
return computationMemo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,13 @@ let CreaturePropertySchema = new SimpleSchema({
|
|||||||
optional: true,
|
optional: true,
|
||||||
index: 1,
|
index: 1,
|
||||||
},
|
},
|
||||||
|
// Denormalised flag if this property was made inactive because of a toggle
|
||||||
|
// calculation. Either an ancestor toggle calculation or its own.
|
||||||
|
deactivatedByToggle: {
|
||||||
|
type: Boolean,
|
||||||
|
optional: true,
|
||||||
|
index: 1,
|
||||||
|
},
|
||||||
// Denormalised list of all properties or creatures this property depends on
|
// Denormalised list of all properties or creatures this property depends on
|
||||||
dependencies: {
|
dependencies: {
|
||||||
type: Array,
|
type: Array,
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ export default function recomputeInactiveProperties(ancestorId){
|
|||||||
{disabled: true}, // Everything can be disabled
|
{disabled: true}, // Everything can be disabled
|
||||||
{type: 'buff', applied: false}, // Buffs can be applied
|
{type: 'buff', applied: false}, // Buffs can be applied
|
||||||
{type: 'item', equipped: {$ne: true}},
|
{type: 'item', equipped: {$ne: true}},
|
||||||
{type: 'toggle', toggleResult: false},
|
|
||||||
{type: 'spell', prepared: {$ne: true}, alwaysPrepared: {$ne: true}},
|
{type: 'spell', prepared: {$ne: true}, alwaysPrepared: {$ne: true}},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
@@ -56,6 +55,8 @@ export default function recomputeInactiveProperties(ancestorId){
|
|||||||
CreatureProperties.update({
|
CreatureProperties.update({
|
||||||
'ancestors.id': {$eq: ancestorId, $nin: disabledIds},
|
'ancestors.id': {$eq: ancestorId, $nin: disabledIds},
|
||||||
'_id': {$nin: disabledIds},
|
'_id': {$nin: disabledIds},
|
||||||
|
// if it was a toggle responsible, we leave it alone
|
||||||
|
deactivatedByToggle: {$ne: true},
|
||||||
$or: [
|
$or: [
|
||||||
{inactive: true},
|
{inactive: true},
|
||||||
{deactivatedByAncestor: true},
|
{deactivatedByAncestor: true},
|
||||||
|
|||||||
Reference in New Issue
Block a user