From 4d7317b96468af87ff6b6c2f392b3a37803d2cc1 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Wed, 24 May 2023 21:59:17 +0200 Subject: [PATCH] Gestion de l'armure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Correction de la détérioration d'une armure variable Séparation du code d'armure dans l'Item RdDArmureItem --- module/actor.js | 33 ++-------------------------- module/item/armure.js | 51 +++++++++++++++++++++++++++++++++++++++++++ module/rdd-main.js | 2 ++ 3 files changed, 55 insertions(+), 31 deletions(-) create mode 100644 module/item/armure.js diff --git a/module/actor.js b/module/actor.js index abcfb45b..ed20d6ab 100644 --- a/module/actor.js +++ b/module/actor.js @@ -3149,8 +3149,8 @@ export class RdDActor extends RdDBaseActor { const armures = this.items.filter(it => it.type == "armure" && it.system.equipe); for (const armure of armures) { protection += await RdDDice.rollTotal(armure.system.protection.toString()); - if (dmg > 0) { - this._deteriorerArmure(armure, dmg); + if (dmg > 0 && attackerRoll.dmg.encaisserSpecial != "noarmure") { + armure.deteriorerArmure(dmg); dmg = 0; } } @@ -3168,35 +3168,6 @@ export class RdDActor extends RdDBaseActor { return protection; } - /* -------------------------------------------- */ - _deteriorerArmure(armure, dmg) { - armure = duplicate(armure); - if (!ReglesOptionelles.isUsing('deteriorationArmure') || armure.system.protection == '0') { - return; - } - armure.system.deterioration = (armure.system.deterioration ?? 0) + dmg; - if (armure.system.deterioration >= 10) { - armure.system.deterioration -= 10; - let res = /(\d+)?d(\d+)(\-\d+)?/.exec(armure.system.protection); - if (res) { - let malus = Misc.toInt(res[3]) - 1; - let armure = Misc.toInt(res[2]); - if (armure + malus <= 0) { - armure.system.protection = 0; - } else { - armure.system.protection = '' + (res[1] ?? '1') + 'd' + armure + malus; - } - } - else if (/\d+/.exec(armure.system.protection)) { - armure.system.protection = "1d" + armure.system.protection; - } - else { - ui.notifications.warn(`La valeur d'armure de votre ${armure.name} est incorrecte`); - } - ChatMessage.create({ content: "Votre armure s'est détériorée, elle protège maintenant de " + armure.system.protection }); - } - this.updateEmbeddedDocuments('Item', [armure]); - } /* -------------------------------------------- */ async encaisser() { diff --git a/module/item/armure.js b/module/item/armure.js new file mode 100644 index 00000000..101977a5 --- /dev/null +++ b/module/item/armure.js @@ -0,0 +1,51 @@ +import { RdDItem } from "../item.js"; +import { Misc } from "../misc.js"; +import { ReglesOptionelles } from "../settings/regles-optionelles.js"; + +export class RdDItemArmure extends RdDItem { + + static get defaultIcon() { + return "systems/foundryvtt-reve-de-dragon/icons/armes_armures/armure_plaques.webp"; + } + + deteriorerArmure(dmg) { + if (!ReglesOptionelles.isUsing('deteriorationArmure') || this.system.protection == '0') { + return; + } + let deterioration = (this.system.deterioration ?? 0) + dmg; + let protection = this.system.protection; + + if (deterioration >= 10) { + deterioration -= 10; + protection = this.calculProtectionDeterioree(); + ChatMessage.create({ content: `Votre armure ${this.name} s'est détériorée, elle protège maintenant de ${protection}` }); + } + this.update({ + system: { + deterioration: deterioration, + protection: protection + } + }); + } + + calculProtectionDeterioree() { + const protectionCourante = this.system.protection; + let res = /(\d+)?d(\d+)(\-\d+)?/.exec(protectionCourante); + if (res) { + let protection = Misc.toInt(res[2]); + let malus = Misc.toInt(res[3]) - 1; + if (protection + malus <= 0) { + return 0; + } else { + return `1d${protection}${malus}`; + } + } + else if (/\d+/.exec(protectionCourante)) { + return `1d${protectionCourante}`; + } + else { + ui.notifications.warn(`La valeur d'armure de votre ${this.name} est incorrecte`); + return undefined; + } + } +} \ No newline at end of file diff --git a/module/rdd-main.js b/module/rdd-main.js index a45f2a9f..65d4b106 100644 --- a/module/rdd-main.js +++ b/module/rdd-main.js @@ -58,6 +58,7 @@ import { RdDConteneurItemSheet } from "./item/sheet-conteneur.js"; import { RdDSigneDraconiqueItemSheet } from "./item/sheet-signedraconique.js"; import { RdDItemInventaireSheet } from "./item/sheet-base-inventaire.js"; import { AppAstrologie } from "./sommeil/app-astrologie.js"; +import { RdDItemArmure } from "./item/armure.js"; /** * RdD system @@ -76,6 +77,7 @@ export class SystemReveDeDragon { this.RdDUtility = RdDUtility; this.RdDHotbar = RdDHotbar; this.itemClasses = { + armure: RdDItemArmure, blessure: RdDItemBlessure, maladie: RdDItemMaladie, ombre: RdDItemOmbre,