Improved dependencies-only recalculations and fixed many calculation bugs

This commit is contained in:
Stefan Zermatten
2021-02-04 16:16:51 +02:00
parent 6d1e3f078c
commit 280f30dab5
16 changed files with 175 additions and 67 deletions

View File

@@ -4,7 +4,7 @@ import SimpleSchema from 'simpl-schema';
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties.js';
import getRootCreatureAncestor from '/imports/api/creature/creatureProperties/getRootCreatureAncestor.js';
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js';
import { recomputePropertyDependencies, recomputeCreatureByDoc, recomputeCreature } from '/imports/api/creature/computation/methods/recomputeCreature.js';
import { recomputePropertyDependencies } from '/imports/api/creature/computation/methods/recomputeCreature.js';
const damageProperty = new ValidatedMethod({
name: 'creatureProperties.damage',

View File

@@ -48,7 +48,8 @@ const dealDamage = new ValidatedMethod({
let totalDamage = Math.floor(amount * multiplier);
let damageLeft = totalDamage;
if (damageType === 'healing') damageLeft = -totalDamage;
let dependencies = [];
let propertyIds = [];
let propertiesDependedAponIds = [];
healthBars.forEach(healthBar => {
if (damageLeft === 0) return;
let damageAdded = damagePropertyWork({
@@ -57,10 +58,14 @@ const dealDamage = new ValidatedMethod({
value: damageLeft,
});
damageLeft -= damageAdded;
dependencies.push(healthBar.variableName);
dependencies.push(...healthBar.dependencies);
propertyIds.push(healthBar._id);
propertiesDependedAponIds.push(...healthBar.dependencies);
});
recomputeCreatureByDependencies({
creature,
propertyIds,
propertiesDependedAponIds,
});
recomputeCreatureByDependencies({creature, dependencies});
return totalDamage;
},
});