Feature/167 damage types and resistances (#330)

* Add Resistances

* Relocate Damage Reduction

* Damage Types

* dmg type fallback

* Actor getRollData

* Remove comments
This commit is contained in:
Dapoulp 2025-07-12 20:13:09 +02:00 committed by GitHub
parent 3f4c884974
commit 812a5e8dd7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 167 additions and 97 deletions

View file

@ -370,7 +370,10 @@ export default class DhpActor extends Actor {
}
getRollData() {
return this.system;
const rollData = super.getRollData();
rollData.prof = this.system.proficiency?.total ?? 1;
rollData.cast = this.system.spellcast?.total ?? 1;
return rollData;
}
formatRollModifier(roll) {
@ -462,7 +465,7 @@ export default class DhpActor extends Actor {
const canUseArmor =
this.system.armor &&
this.system.armor.system.marks.value < this.system.armorScore &&
this.system.armorApplicableDamageTypes[type];
type.every(t => this.system.armorApplicableDamageTypes[t] === true);
const canUseStress = Object.keys(this.system.rules.damageReduction.stressDamageReduction).reduce((acc, x) => {
const rule = this.system.rules.damageReduction.stressDamageReduction[x];
if (damageKeyToNumber(x) <= hpDamage) return acc || (rule.enabled && availableStress >= rule.cost);
@ -480,11 +483,9 @@ export default class DhpActor extends Actor {
return;
}
const flatReduction = this.system.bonuses.damageReduction[type];
const damage = Math.max(baseDamage - (flatReduction ?? 0), 0);
const hpDamage = this.convertDamageToThreshold(damage);
type = !Array.isArray(type) ? [type] : type;
if (Hooks.call(`${CONFIG.DH.id}.postDamageTreshold`, this, hpDamage, damage, type) === false) return null;
const hpDamage = this.calculateDamage(baseDamage, type);
if (!hpDamage) return;
@ -511,6 +512,35 @@ export default class DhpActor extends Actor {
if (Hooks.call(`${CONFIG.DH.id}.postTakeDamage`, this, damage, type) === false) return null;
}
calculateDamage(baseDamage, type) {
if (Hooks.call(`${CONFIG.DH.id}.preCalculateDamage`, this, baseDamage, type) === false) return null;
/* if(this.system.resistance[type]?.immunity) return 0;
if(this.system.resistance[type]?.resistance) baseDamage = Math.ceil(baseDamage / 2); */
if(this.canResist(type, 'immunity')) return 0;
if(this.canResist(type, 'resistance')) baseDamage = Math.ceil(baseDamage / 2);
// const flatReduction = this.system.resistance[type].reduction;
const flatReduction = this.getDamageTypeReduction(type);
const damage = Math.max(baseDamage - (flatReduction ?? 0), 0);
const hpDamage = this.convertDamageToThreshold(damage);
if (Hooks.call(`${CONFIG.DH.id}.postCalculateDamage`, this, baseDamage, type) === false) return null;
return hpDamage;
}
canResist(type, resistance) {
if(!type) return 0;
return type.every(t => this.system.resistance[t]?.[resistance] === true);
}
getDamageTypeReduction(type) {
if(!type) return 0;
const reduction = Object.entries(this.system.resistance).reduce((a, [index, value]) => type.includes(index) ? Math.min(value.reduction, a) : a, Infinity);
return reduction === Infinity ? 0 : reduction;
}
async takeHealing(resources) {
resources.forEach(r => (r.value *= -1));
await this.modifyResource(resources);
@ -553,18 +583,6 @@ export default class DhpActor extends Actor {
u.resources,
u.target.uuid
);
/* if (game.user.isGM) {
await u.target.update(u.resources);
} else {
await game.socket.emit(`system.${CONFIG.DH.id}`, {
action: socketEvent.GMUpdate,
data: {
action: GMUpdateEvent.UpdateDocument,
uuid: u.target.uuid,
update: u.resources
}
});
} */
}
});
}