From 18c7eb767d0f9987e489ae610f7d6052f4e41415 Mon Sep 17 00:00:00 2001 From: sladecraven Date: Wed, 2 Dec 2020 14:00:54 +0100 Subject: [PATCH] =?UTF-8?q?#54=20Gestion=20compl=C3=A8te=20du=20malus=20ar?= =?UTF-8?q?mure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/actor-sheet.js | 2 +- module/actor.js | 23 +++++++++++++++++++---- module/rdd-roll-dialog.js | 15 +++++++++++++-- module/rdd-utility.js | 2 +- templates/dialog-competence.html | 2 +- templates/dialog-roll-carac.html | 2 +- templates/dialog-roll-sort.html | 2 +- 7 files changed, 37 insertions(+), 11 deletions(-) diff --git a/module/actor-sheet.js b/module/actor-sheet.js index 5466a50e..c612005f 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -91,7 +91,7 @@ export class RdDActorSheet extends ActorSheet { data.data.nbCritiques = this.actor.countBlessures(data.data.blessures.critiques.liste ); // Mise à jour de l'encombrement total - this.actor.computeEncombrementTotal(); + this.actor.computeEncombrementTotalEtMalusArmure(); // Common data data.data.competenceByCategory = data.competenceByCategory; data.data.encombrementTotal = this.actor.encombrementTotal; diff --git a/module/actor.js b/module/actor.js index d90a164b..0b1cb027 100644 --- a/module/actor.js +++ b/module/actor.js @@ -91,7 +91,7 @@ export class RdDActor extends Actor { _prepareCharacterData(actorData) { // Initialize empty items RdDUtility.computeCarac(actorData.data); - this.computeEncombrementTotal(); + this.computeEncombrementTotalEtMalusArmure(); this.computeEtatGeneral(); } @@ -751,9 +751,15 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ - computeEncombrementTotal( ) { + async computeEncombrementTotalEtMalusArmure( ) { let totalEnc = 0; + let malusArmureData = duplicate(this.data.data.attributs.malusarmure); + let newMalusArmure = 0; for (const item of this.data.items) { + if ( item.type == 'armure' && item.data.equipe ) { // Armure équipée, intégration du malus armure total + newMalusArmure += item.data.malus; + } + // Calcul encombrement if ( item.data && item.data.encombrement != undefined ) { if ( !Number(item.data.encombrement) ) item.data.encombrement = 0; // Auto-fix if (!item.data.quantite) item.data.quantite = 1; // Auto-fix @@ -764,8 +770,14 @@ export class RdDActor extends Actor { item.data.encTotal = 0; // Force default enc } } + // Mise à jour valeur totale et états this.encombrementTotal = totalEnc; this.detectSurEncombrement(); + // Mise à jour éventuelle du malus armure + if (newMalusArmure != malusArmureData.value) { + malusArmureData.value = newMalusArmure; + await this.update( {"data.attributs.malusarmure": malusArmureData } ); + } } /* -------------------------------------------- */ @@ -1137,6 +1149,7 @@ export class RdDActor extends Actor { coutreve: Array(20).fill().map((item, index) => 1 + index), ajustementsConditions: CONFIG.RDD.ajustementsConditions, difficultesLibres: CONFIG.RDD.difficultesLibres, + malusArmureValue: 0, surencMalusFlag: false, // A ne pas utiliser pour les sorts surencMalusValue: 0, surencMalusApply: false, @@ -1164,10 +1177,11 @@ export class RdDActor extends Actor { selectedCarac: carac, ajustementsConditions: CONFIG.RDD.ajustementsConditions, difficultesLibres: CONFIG.RDD.difficultesLibres, - etat: this.data.data.compteurs.etat.value, + etat: this.data.data.compteurs.etat.value, finalLevel: 0, diffConditions: 0, diffLibre: 0, + malusArmureValue: (this.data.data.attributs) ? this.data.data.attributs.malusarmure.value : 0, surencMalusFlag: (this.data.data.compteurs.surenc.value < 0), surencMalusValue: this.data.data.compteurs.surenc.value, surencMalusApply: false, @@ -1249,6 +1263,7 @@ export class RdDActor extends Actor { attackerRoll: attackerRoll, finalLevel: 0, coupsNonMortels: false, + malusArmureValue: (this.data.data.attributs) ? this.data.data.attributs.malusarmure.value : 0, surencMalusFlag: (this.data.data.compteurs.surenc.value < 0), surencMalusValue: this.data.data.compteurs.surenc.value, surencMalusApply: false, @@ -1315,7 +1330,7 @@ export class RdDActor extends Actor { if ( item && item.data.data ) { let update = {_id: item._id, "data.equipe": !item.data.data.equipe }; await this.updateEmbeddedEntity("OwnedItem", update); - this.computeEncombrementTotal(); // Mise à jour encombrement + this.computeEncombrementTotalEtMalusArmure(); // Mise à jour encombrement } } diff --git a/module/rdd-roll-dialog.js b/module/rdd-roll-dialog.js index db7854ce..01833848 100644 --- a/module/rdd-roll-dialog.js +++ b/module/rdd-roll-dialog.js @@ -86,11 +86,11 @@ export class RdDRollDialog extends Dialog { } } + // Mise à jour valeurs $("#roll-param").text(rollData.selectedCarac.value + " / " + Misc.toSignedString(rollData.finalLevel)); $("#compdialogTitle").text(RdDRollDialog._getTitle(rollData)); $(".table-resolution").remove(); $("#resolutionTable").append(RdDResolutionTable.buildHTMLTableExtract(caracValue, rollLevel)); - } // Setup everything onload @@ -170,6 +170,16 @@ export class RdDRollDialog extends Dialog { let malusEnc = (rollData.surencMalusApply ) ? rollData.surencMalusValue : 0; let diffLibre = Misc.toInt(rollData.diffLibre); let malusEncNatation = (rollData.useEncForNatation) ? -rollData.encValueForNatation : 0; + + // Gestion malus armure + let malusArmureValue = 0; + if ( rollData.malusArmureValue != 0 && (rollData.selectedCarac.label == "Agilité" || rollData.selectedCarac.label == "Dérobée" )) { + $("#addon-message").text("Malus armure appliqué : " + rollData.malusArmureValue ); + malusArmureValue = rollData.malusArmureValue; + } else { + $("#addon-message").text("" ); + } + let diffCompetence = 0; if (rollData.competence) { diffCompetence = Misc.toInt(rollData.competence.data.niveau); @@ -178,7 +188,8 @@ export class RdDRollDialog extends Dialog { diffCompetence = Misc.toInt(rollData.selectedDraconic.data.niveau); diffLibre = RdDItemSort.getDifficulte(rollData.selectedSort, diffLibre); } - return etat + diffCompetence + diffLibre + diffConditions + malusEnc + malusEncNatation; + + return etat + diffCompetence + diffLibre + diffConditions + malusEnc + malusEncNatation + malusArmureValue; } /* -------------------------------------------- */ diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 76a8885a..89b8711b 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -219,7 +219,7 @@ export class RdDUtility { } } } - actorSheet.actor.computeEncombrementTotal(); + actorSheet.actor.computeEncombrementTotalEtMalusArmure(); } /* -------------------------------------------- */ diff --git a/templates/dialog-competence.html b/templates/dialog-competence.html index acb64a62..cfdc307a 100644 --- a/templates/dialog-competence.html +++ b/templates/dialog-competence.html @@ -43,7 +43,7 @@
- +    
diff --git a/templates/dialog-roll-carac.html b/templates/dialog-roll-carac.html index bbff3b5c..fcdda7fb 100644 --- a/templates/dialog-roll-carac.html +++ b/templates/dialog-roll-carac.html @@ -23,7 +23,7 @@
- +    
diff --git a/templates/dialog-roll-sort.html b/templates/dialog-roll-sort.html index 79090d55..98e86d83 100644 --- a/templates/dialog-roll-sort.html +++ b/templates/dialog-roll-sort.html @@ -63,7 +63,7 @@
- +