From 218c88a924c1998e30df8c4d91c10ee8c5f1955b Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Mon, 6 Jun 2022 21:29:30 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20d=C3=A9t=C3=A9rioration=20armure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Support des armures sous forme: * entier * 0 * d4, d4-1 * 1d4, 1d4-1 Détérioration diminuée de 10 (au lieu de remise à 0) Décrémentation correcte de l'armure --- module/actor.js | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/module/actor.js b/module/actor.js index a6e5f525..7bb90623 100644 --- a/module/actor.js +++ b/module/actor.js @@ -3277,11 +3277,11 @@ export class RdDActor extends Actor { protection = Math.max(protection - penetration, 0); protection += this.getProtectionNaturelle(); // Gestion des cas particuliers sur la fenêtre d'encaissement - if (attackerRoll.dmg.encaisserSpecial && attackerRoll.dmg.encaisserSpecial == "noarmure") { + if (attackerRoll.dmg.encaisserSpecial == "noarmure") { protection = 0; } - if (attackerRoll.dmg.encaisserSpecial && attackerRoll.dmg.encaisserSpecial == "chute" && Number(protection) > 2) { - protection = 2; + if (attackerRoll.dmg.encaisserSpecial == "chute") { + protection = Math.min(protection, 2); } console.log("Final protect", protection, attackerRoll); return protection; @@ -3289,20 +3289,25 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ _deteriorerArmure(item, dmg) { - if (!ReglesOptionelles.isUsing('deteriorationArmure')) { + let itemData = duplicate(Misc.data(item)); + if (!ReglesOptionelles.isUsing('deteriorationArmure') || itemData.data.protection == '0') { return; } - let itemData = duplicate(Misc.data(item)); itemData.data.deterioration = (itemData.data.deterioration ?? 0) + dmg; if (itemData.data.deterioration >= 10) { - itemData.data.deterioration = 0; - let res = /\d+/.exec(itemData.data.protection); - if (!res) { - itemData.data.protection = "1d" + itemData.data.protection; + itemData.data.deterioration -= 10; + let res = /(\d+)?d(\d+)(\-\d+)?/.exec(itemData.data.protection); + if (res) { + let malus = Misc.toInt(res[3]) - 1; + let armure = Misc.toInt(res[2]); + if (armure+malus <= 0){ + itemData.data.protection = 0; + } else { + itemData.data.protection = '' + (res[1]??'1') + 'd' + armure + malus; + } } - else if (res = /(\d+d\d+)(\-\d+)?/.exec(itemData.data.protection)) { - let malus = Misc.toInt(res[2]) - 1; - itemData.data.protection = res[1] + malus; + else if (/\d+/.exec(itemData.data.protection)) { + itemData.data.protection = "1d" + itemData.data.protection; } else { ui.notifications.warn(`La valeur d'armure de votre ${item.name} est incorrecte`);