From 5565bb7a48cc5ae0250f3be757da2fbf03480115 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Sat, 19 Nov 2022 01:35:01 +0100 Subject: [PATCH] Fix des malus encombrement --- module/actor.js | 4 ++++ module/rdd-roll.js | 21 +++++++++++++++++---- module/rolldata-ajustements.js | 6 +++--- templates/partial-roll-enctotal.html | 6 ++---- templates/partial-roll-surenc.html | 6 ++---- 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/module/actor.js b/module/actor.js index ee28c6f1..6632412a 100644 --- a/module/actor.js +++ b/module/actor.js @@ -1280,6 +1280,10 @@ export class RdDActor extends Actor { await item.delete(); } + isSurenc() { + return this.isPersonnage() ? (this.system.compteurs.surenc.value < 0) : false + } + /* -------------------------------------------- */ computeMalusSurEncombrement() { switch (this.type) { diff --git a/module/rdd-roll.js b/module/rdd-roll.js index e41587e3..3c10fcad 100644 --- a/module/rdd-roll.js +++ b/module/rdd-roll.js @@ -50,14 +50,16 @@ export class RdDRoll extends Dialog { diffConditions: 0, diffLibre: rollData.competence?.system.default_diffLibre ?? 0, malusArmureValue: actor.getMalusArmure(), - surencMalusFlag: actor.isPersonnage() ? (actorData.compteurs.surenc.value < 0) : false, surencMalusValue: actor.computeMalusSurEncombrement(), - useMalusSurenc: false, useMoral: false, /* Est-ce que le joueur demande d'utiliser le moral ? Utile si le joueur change plusieurs fois de carac associƩe. */ perteMoralEchec: false, /* Pour l'affichage dans le chat */ - use: { libre: true, conditions: true, surenc: false, encTotal: false }, + use: { + libre: true, + conditions: true, + surenc: false, + encTotal: false + }, isMalusEncombrementTotal: rollData.competence ? RdDItemCompetence.isMalusEncombrementTotal(rollData.competence) : 0, - useMalusEncTotal: false, encTotal: actor.getEncTotal(), ajustementAstrologique: actor.ajustementAstrologique(), surprise: actor.getSurprise(false), @@ -244,6 +246,14 @@ export class RdDRoll extends Dialog { this.rollData[attribute] = event.currentTarget.checked; this.updateRollResult(); }); + html.find('input.use-encTotal').change((event) => { + this.rollData.use.encTotal = event.currentTarget.checked; + this.updateRollResult(); + }); + html.find('input.use-surenc').change((event) => { + this.rollData.use.surenc = event.currentTarget.checked; + this.updateRollResult(); + }); html.find('.appel-moral').click((event) => { /* l'appel au moral, qui donne un bonus de +1 */ this.rollData.useMoral = !this.rollData.useMoral; const appelMoral = html.find('.icon-appel-moral')[0]; @@ -286,6 +296,7 @@ export class RdDRoll extends Dialog { $(".div-sort-ptreve-fixe").text(sort.system.ptreve); const diffVariable = RdDItemSort.isDifficulteVariable(sort); const coutVariable = RdDItemSort.isCoutVariable(sort); + HtmlUtility._showControlWhen($(".div-sort-non-rituel"), !sort.system.isrituel); HtmlUtility._showControlWhen($(".div-sort-difficulte-var"), diffVariable); HtmlUtility._showControlWhen($(".div-sort-difficulte-fixe"), !diffVariable); @@ -318,6 +329,8 @@ export class RdDRoll extends Dialog { RollDataAjustements.calcul(rollData, this.actor); rollData.finalLevel = this._computeFinalLevel(rollData); + HtmlUtility._showControlWhen($(".use-encTotal"), rollData.ajustements.encTotal.visible); + HtmlUtility._showControlWhen($(".use-surenc"), rollData.ajustements.surenc.visible); HtmlUtility._showControlWhen($(".diffMoral"), rollData.ajustements.moralTotal.used); HtmlUtility._showControlWhen($(".divAppelAuMoral"), rollData.use.appelAuMoral); HtmlUtility._showControlWhen($("#etat-general"), !RdDCarac.isIgnoreEtatGeneral(rollData)); diff --git a/module/rolldata-ajustements.js b/module/rolldata-ajustements.js index 2807065a..1824c60c 100644 --- a/module/rolldata-ajustements.js +++ b/module/rolldata-ajustements.js @@ -63,13 +63,13 @@ export const referenceAjustements = { }, encTotal: { isVisible: (rollData, actor) => RdDItemCompetence.isMalusEncombrementTotal(rollData.competence), - isUsed: (rollData, actor) => rollData.useMalusEncTotal, + isUsed: (rollData, actor) => rollData.use.encTotal, getLabel: (rollData, actor) => 'Encombrement total', getValue: (rollData, actor) => -actor.getEncTotal() }, surenc: { - isVisible: (rollData, actor) => rollData.useMalusSurenc, - isUsed: (rollData, actor) => rollData.useMalusSurenc, + isVisible: (rollData, actor) => actor.isSurenc(), + isUsed: (rollData, actor) => rollData.use.surenc, getLabel: (rollData, actor) => 'Sur-encombrement', getValue: (rollData, actor) => actor.computeMalusSurEncombrement() }, diff --git a/templates/partial-roll-enctotal.html b/templates/partial-roll-enctotal.html index dfe959d0..15be1eec 100644 --- a/templates/partial-roll-enctotal.html +++ b/templates/partial-roll-enctotal.html @@ -1,8 +1,6 @@ -{{#if ajustements.encTotal.visible}} -
+
-{{/if}} diff --git a/templates/partial-roll-surenc.html b/templates/partial-roll-surenc.html index 0f59e227..421e7752 100644 --- a/templates/partial-roll-surenc.html +++ b/templates/partial-roll-surenc.html @@ -1,8 +1,6 @@ -{{#if surencMalusFlag}} -
+
-{{/if}}