Migrating UI for new data structures

This commit is contained in:
Stefan Zermatten
2021-10-15 11:12:40 +02:00
parent f3c52999e8
commit ea68cdf86f
35 changed files with 511 additions and 271 deletions

View File

@@ -47,17 +47,17 @@ const damageProperty = new ValidatedMethod({
export function damagePropertyWork({property, operation, value}){
let damage, newValue;
if (operation === 'set'){
const currentValue = property.value;
const total = property.total;
// Set represents what we want the value to be after damage
// So we need the actual damage to get to that value
damage = currentValue - value;
damage = total - value;
// Damage can't exceed total value
if (damage > currentValue) damage = currentValue;
if (damage > total) damage = total;
// Damage must be positive
if (damage < 0) damage = 0;
newValue = property.total - damage;
} else if (operation === 'increment'){
let currentValue = property.value - (property.damage || 0);
let currentValue = property.value;
let currentDamage = property.damage;
let increment = value;
// Can't increase damage above the remaining value
@@ -74,6 +74,7 @@ export function damagePropertyWork({property, operation, value}){
}, {
selector: property
});
return damage;
}
export default damageProperty;

View File

@@ -25,7 +25,6 @@ const dealDamage = new ValidatedMethod({
// permissions
let creature = Creatures.findOne(creatureId, {
fields: {
damageMultipliers: 1,
owner: 1,
readers: 1,
writers: 1,
@@ -33,37 +32,42 @@ const dealDamage = new ValidatedMethod({
});
assertEditPermission(creature, this.userId);
// Get all the health bars and do damage to them
let healthBars = CreatureProperties.find({
'ancestors.id': creatureId,
type: 'attribute',
attributeType:'healthBar',
removed: {$ne: true},
inactive: {$ne: true},
}, {
sort: {order: -1},
});
let multiplier = creature.damageMultipliers[damageType];
if (multiplier === undefined) multiplier = 1;
let totalDamage = Math.floor(amount * multiplier);
let damageLeft = totalDamage;
if (damageType === 'healing') damageLeft = -totalDamage;
let propertyIds = [];
let propertiesDependedAponIds = [];
healthBars.forEach(healthBar => {
if (damageLeft === 0) return;
let damageAdded = damagePropertyWork({
property: healthBar,
operation: 'increment',
value: damageLeft,
});
damageLeft -= damageAdded;
propertyIds.push(healthBar._id);
propertiesDependedAponIds.push(...healthBar.dependencies);
});
const totalDamage = dealDamageWork({creature, damageType, amount})
computeCreature(creatureId);
return totalDamage;
},
});
export function dealDamageWork({creature, damageType, amount}){
console.log({damageType, amount})
// Get all the health bars and do damage to them
let healthBars = CreatureProperties.find({
'ancestors.id': creature._id,
type: 'attribute',
attributeType:'healthBar',
removed: {$ne: true},
inactive: {$ne: true},
}, {
sort: {order: -1},
});
//let multiplier = creature.damageMultipliers[damageType];
//if (multiplier === undefined) multiplier = 1;
//let totalDamage = Math.floor(amount * multiplier);
const totalDamage = amount;
let damageLeft = totalDamage;
if (damageType === 'healing') damageLeft = -totalDamage;
let propertyIds = [];
healthBars.forEach(healthBar => {
if (damageLeft === 0) return;
let damageAdded = damagePropertyWork({
property: healthBar,
operation: 'increment',
value: damageLeft,
});
damageLeft -= damageAdded;
propertyIds.push(healthBar._id);
});
return totalDamage;
}
export default dealDamage;