diff --git a/module/actor.js b/module/actor.js index 5be84288..78e19e36 100644 --- a/module/actor.js +++ b/module/actor.js @@ -2177,36 +2177,18 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ computeArmure(attackerRoll) { - let dmg = attackerRoll.dmg.dmgArme + attackerRoll.dmg.dmgActor; + let dmg = (attackerRoll.dmg.dmgArme ??0) + (attackerRoll.dmg.dmgActor ?? 0); let arme = attackerRoll.arme; - // TODO: arc ignore armure let protection = 0; - for (const item of this.data.items) { - if (item.type == "armure" && item.data.equipe) { - let update = duplicate(item); - protection += new Roll(update.data.protection.toString()).roll().total; - update.data.deterioration = Misc.toInt(update.data.deterioration) + dmg; - dmg = 0; // Reset it - if (update.data.deterioration >= 10) { - update.data.deterioration = 0; - let res = /\d+/.exec(update.data.protection); - if (res) - update.data.protection = "1d" + update.data.protection; - // if ( update.data.protection.toString().length == 1 ) - // update.data.protection = "1d"+update.data.protection; - else if (res = /(\d+d\d+)(\-\d+)?/.exec(update.data.protection)) { - let malus = Misc.toInt(res[2]) - 1; - update.data.protection = res[1] + malus; - } - else { - ui.notifications.warn(`La valeur d'armure de votre ${item.name} est incorrecte`) - } - ChatMessage.create({ content: "Détérioration d'armure: " + update.data.protection }); - } - this.updateEmbeddedEntity("OwnedItem", update); + const armures = this.data.items.filter(it => it.type == "armure" && it.data.equipe); + for (const item of armures) { + protection += new Roll(item.data.protection.toString()).roll().total; + if (dmg > 0) { + this._deteriorerArmure(item, dmg); + dmg = 0; } } - // TODO: max armure (chutes) + // TODO: max armure sur chutes... const penetration = arme ? Misc.toInt(arme.data.penetration) : 0; protection = Math.max(protection - penetration, 0); protection += this.getProtectionNaturelle(); @@ -2214,6 +2196,27 @@ export class RdDActor extends Actor { return protection; } + _deteriorerArmure(item, dmg) { + let update = duplicate(item); + update.data.deterioration = (update.data.deterioration ?? 0) + dmg; + if (update.data.deterioration >= 10) { + update.data.deterioration = 0; + let res = /\d+/.exec(update.data.protection); + if (!res) { + update.data.protection = "1d" + update.data.protection; + } + else if (res = /(\d+d\d+)(\-\d+)?/.exec(update.data.protection)) { + let malus = Misc.toInt(res[2]) - 1; + update.data.protection = res[1] + malus; + } + else { + ui.notifications.warn(`La valeur d'armure de votre ${item.name} est incorrecte`); + } + ChatMessage.create({ content: "Votre armure s'est détériorée, elle protège maintenant de " + update.data.protection }); + } + this.updateEmbeddedEntity("OwnedItem", update); + } + /* -------------------------------------------- */ async encaisser() { let data = { ajustementsEncaissement: RdDUtility.getAjustementsEncaissement() };