Fix taking damage and start fixing healing

This commit is contained in:
Carlos Fernandez 2026-07-18 01:06:58 -04:00
parent 2ef78f2c89
commit ce37bd9c60
7 changed files with 45 additions and 50 deletions

View file

@ -656,26 +656,30 @@ export default class DhpActor extends Actor {
return;
}
const updates = [];
Object.entries(damages).forEach(([key, damage]) => {
if (key === CONFIG.DH.GENERAL.healingTypes.hitPoints.id)
damage.total = this.calculateDamage(damage.total, damage.damageTypes);
const update = updates.find(u => u.key === key);
if (update) {
update.value += damage.total;
update.damageTypes.add(...new Set(damage.damageTypes));
} else updates.push({ value: damage.total, key, damageTypes: new Set(damage.damageTypes) });
});
if (damages.main) {
damages.main.total = this.calculateDamage(damages.main.total, damages.main.damageTypes);
}
if (Hooks.call(`${CONFIG.DH.id}.postCalculateDamage`, this, damages) === false) return null;
if (!updates.length) return;
// Convert deducted resources and damage to a record of updates, merging damage to hp with hp marked
const updates = Object.entries(damages.resources).map(([key, damage]) => ({ key, value: damage.total }));
if (damages.main) {
const existing = updates.find(u => u.key === CONFIG.DH.GENERAL.healingTypes.hitPoints.id);
const value = this.convertDamageToThreshold(damages.main.total);
const damageTypes = new Set(damages.main.options.damageTypes);
if (existing) {
existing.value += value;
existing.damageTypes = damageTypes;
} else {
updates.push({ value, damageTypes, key: CONFIG.DH.GENERAL.healingTypes.hitPoints.id });
}
}
if (!updates.some(u => u.value)) return; // early return if nothing to do
const hpDamage = updates.find(u => u.key === CONFIG.DH.GENERAL.healingTypes.hitPoints.id);
if (hpDamage?.value) {
hpDamage.value = this.convertDamageToThreshold(hpDamage.value);
if (this.type === 'character' && !isDirect && this.#canReduceDamage(hpDamage.value, hpDamage.damageTypes)) {
if (this.type === 'character' && !isDirect && this.#canReduceDamage(hpDamage.total, hpDamage.damageTypes)) {
const armorSlotResult = await this.owner.query(
'armorSlot',
{
@ -689,7 +693,7 @@ export default class DhpActor extends Actor {
);
if (armorSlotResult) {
const { modifiedDamage, armorChanges, stressSpent } = armorSlotResult;
updates.find(u => u.key === 'hitPoints').value = modifiedDamage;
hpDamage.value = modifiedDamage;
for (const armorChange of armorChanges) {
updates.push({ value: armorChange.amount, key: 'armor', uuid: armorChange.uuid });
}
@ -699,18 +703,13 @@ export default class DhpActor extends Actor {
else updates.push({ value: stressSpent, key: 'stress' });
}
}
}
if (this.type === 'adversary') {
} else if (this.type === 'adversary') {
const reducedSeverity = hpDamage.damageTypes.reduce((value, curr) => {
return Math.max(this.system.rules.damageReduction.reduceSeverity[curr], value);
}, 0);
hpDamage.value = Math.max(hpDamage.value - reducedSeverity, 0);
if (
hpDamage.value &&
this.system.rules.damageReduction.thresholdImmunities[getDamageKey(hpDamage.value)]
) {
hpDamage.value -= 1;
if (this.system.rules.damageReduction.thresholdImmunities[getDamageKey(hpDamage.value)]) {
hpDamage.value = Math.max(0, hpDamage.value - 1);
}
}
}
@ -727,12 +726,10 @@ export default class DhpActor extends Actor {
for (var result of results) resourceMap.addResources(result.updates);
resourceMap.updateResources();
}
updates.forEach(
u =>
(u.value =
u.key === 'fear' || this.system?.resources?.[u.key]?.isReversed === false ? u.value * -1 : u.value)
);
for (const u of updates) {
u.value = u.key === 'fear' || this.system?.resources?.[u.key]?.isReversed === false ? u.value * -1 : u.value;
}
await this.modifyResource(updates);