From fe4fd0ce933e1ab0eee22d341230ac23a01c2854 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Sun, 20 Dec 2020 21:54:09 +0100 Subject: [PATCH] =?UTF-8?q?Appliquer=20encTotal=20=C3=A0=20l'acrobatie=20#?= =?UTF-8?q?75?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/actor-sheet.js | 2 +- module/actor.js | 14 ++++++++------ module/item-competence.js | 5 ++++- module/rdd-main.js | 2 +- module/rdd-roll.js | 15 ++++++++------- module/rdd-token-hud.js | 14 +++++++------- module/rdd-utility.js | 2 +- templates/actor-creature-sheet.html | 2 +- templates/actor-humanoide-sheet.html | 2 +- templates/actor-sheet.html | 2 +- templates/dialog-competence.html | 2 +- templates/dialog-roll-enctotal.html | 6 ++++++ templates/dialog-roll-natation.html | 6 ------ 13 files changed, 40 insertions(+), 34 deletions(-) create mode 100644 templates/dialog-roll-enctotal.html delete mode 100644 templates/dialog-roll-natation.html diff --git a/module/actor-sheet.js b/module/actor-sheet.js index 20bd8f12..088d4037 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -113,7 +113,7 @@ export class RdDActorSheet extends ActorSheet { this.actor.computeEncombrementTotalEtMalusArmure(); // Common data data.data.competenceByCategory = data.competenceByCategory; - data.data.encombrementTotal = this.actor.encombrementTotal; + data.data.encTotal = this.actor.encTotal; data.data.isGM = game.user.isGM; data.ajustementsConditions = CONFIG.RDD.ajustementsConditions; data.difficultesLibres = CONFIG.RDD.difficultesLibres; diff --git a/module/actor.js b/module/actor.js index 178110e3..1437c522 100644 --- a/module/actor.js +++ b/module/actor.js @@ -77,7 +77,7 @@ export class RdDActor extends Actor { const actorData = this.data; // Dynamic computing fields - this.encombrementTotal = 0; + this.encTotal = 0; /* // Auto-resize token @@ -158,7 +158,9 @@ export class RdDActor extends Actor { return duplicate(list[0]); } - + getEncombrementTotal() { + return this.encTotal ? Math.floor(this.encTotal) : 0 + } /* -------------------------------------------- */ async deleteSortReserve(coordTMR) { let reserve = duplicate(this.data.data.reve.reserve); @@ -618,7 +620,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ detectSurEncombrement( ) { - let diffEnc = Number(this.encombrementTotal) - Number(this.data.data.attributs.encombrement.value); + let diffEnc = Number(this.encTotal) - Number(this.data.data.attributs.encombrement.value); if ( diffEnc > 0 ) { // Sur-encombrement let malus = Math.round( diffEnc); malus = (malus == 0) ? 1 : malus; // Always 1 at least @@ -630,7 +632,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async computeEncombrementTotalEtMalusArmure( ) { - let totalEnc = 0; + let encTotal = 0; let malusArmureData = duplicate(this.data.data.attributs.malusarmure); let newMalusArmure = 0; for (const item of this.data.items) { @@ -643,13 +645,13 @@ export class RdDActor extends Actor { if (!item.data.quantite) item.data.quantite = 1; // Auto-fix item.data.encTotal = Number(item.data.encombrement) * Number(item.data.quantite); //console.log("Enc:", item.name, item.data.encombrement, item.data.quantite, item.data.encTotal); - totalEnc += item.data.encTotal; + encTotal += item.data.encTotal; } else { item.data.encTotal = 0; // Force default enc } } // Mise à jour valeur totale et états - this.encombrementTotal = totalEnc; + this.encTotal = encTotal; this.detectSurEncombrement(); // Mise à jour éventuelle du malus armure if (newMalusArmure != malusArmureData.value) { diff --git a/module/item-competence.js b/module/item-competence.js index 70e7ed9b..e48f8b3e 100644 --- a/module/item-competence.js +++ b/module/item-competence.js @@ -5,7 +5,10 @@ export class RdDItemCompetence extends Item { return name.toLowerCase().match(/(epée|épée|hache|fleau|fléau|masse|lance|hast|dague|bouclier)/); } static isArmeUneMain(competence) { - return competence.name.toLowerCase().includes("1 main"); + return competence && competence.name.toLowerCase().includes("1 main"); } + static isMalusEncombrementTotal(competence) { + return competence && competence.name.toLowerCase().match(/(natation|acrobatie)/); + } } \ No newline at end of file diff --git a/module/rdd-main.js b/module/rdd-main.js index dba749ea..1452d74d 100644 --- a/module/rdd-main.js +++ b/module/rdd-main.js @@ -252,7 +252,7 @@ Hooks.once("ready", function() { } // Integration du TokenHUD - Hooks.on('renderTokenHUD', (app, html, data) => { RdDTokenHud.addTokenHudExtensions(app, html, data) }); + Hooks.on('renderTokenHUD', (app, html, data) => { RdDTokenHud.addTokenHudExtensions(app, html, data._id) }); }); /* -------------------------------------------- */ diff --git a/module/rdd-roll.js b/module/rdd-roll.js index 156818a5..27fbd436 100644 --- a/module/rdd-roll.js +++ b/module/rdd-roll.js @@ -1,4 +1,5 @@ import { HtmlUtility } from "./html-utility.js"; +import { RdDItemCompetence } from "./item-competence.js"; import { RdDItemSort } from "./item-sort.js"; import { Misc } from "./misc.js"; import { RdDBonus } from "./rdd-bonus.js"; @@ -45,9 +46,9 @@ export class RdDRoll extends Dialog { surencMalusFlag: actor.isPersonnage() ? (actor.data.data.compteurs.surenc.value < 0) : false, surencMalusValue: actor.isPersonnage() ? actor.data.data.compteurs.surenc.value : 0, surencMalusApply: false, - isNatation: rollData.competence ? rollData.competence.name.toLowerCase().includes("natation") : false, - useEncForNatation: false, - encValueForNatation: actor.encombrementTotal ? Math.floor(actor.encombrementTotal) : 0, + isMalusEncombrementTotal: RdDItemCompetence.isMalusEncombrementTotal(rollData.competence), + useMalusEncTotal: false, + encTotal: actor.getEncombrementTotal(), ajustementAstrologique: actor.ajustementAstrologique() } mergeObject(rollData, defaultRollData, { overwrite: false }); @@ -210,8 +211,8 @@ export class RdDRoll extends Dialog { this.rollData.surencMalusApply = event.currentTarget.checked; updateRollResult(rollData); }); - html.find('#useEncForNatation').change((event) => { - this.rollData.useEncForNatation = event.currentTarget.checked; + html.find('#useMalusEncTotal').change((event) => { + this.rollData.useMalusEncTotal = event.currentTarget.checked; updateRollResult(rollData); }); } @@ -226,7 +227,7 @@ export class RdDRoll extends Dialog { const diffConditions = Misc.toInt(rollData.diffConditions); const malusEnc = (rollData.surencMalusApply) ? rollData.surencMalusValue : 0; const bonusTactique = RdDBonus.bonusAttaque(rollData.tactique); - const malusEncNatation = (rollData.useEncForNatation) ? -rollData.encValueForNatation : 0; + const malusEncTotal = (rollData.useMalusEncTotal) ? -rollData.encTotal : 0; const ajustementChance = rollData.selectedCarac.label.toLowerCase().includes('chance') ? rollData.ajustementAstrologique : 0; // Gestion malus armure const malusArmureValue = this._computeMalusArmure(rollData); @@ -235,7 +236,7 @@ export class RdDRoll extends Dialog { const diffCompetence = this._computeDiffCompetence(rollData); const diffMoral = rollData.selectedCarac == this.actor.data.data.carac.volonte ? rollData.moral : 0; - return etat + diffCompetence + diffLibre + diffMoral + diffConditions + malusEnc + malusEncNatation + malusArmureValue + ajustementChance + bonusTactique; + return etat + diffCompetence + diffLibre + diffMoral + diffConditions + malusEnc + malusEncTotal + malusArmureValue + ajustementChance + bonusTactique; } _computeDiffCompetence(rollData) { diff --git a/module/rdd-token-hud.js b/module/rdd-token-hud.js index 968c8b7c..96e2af19 100644 --- a/module/rdd-token-hud.js +++ b/module/rdd-token-hud.js @@ -7,8 +7,8 @@ export class RdDTokenHud { /* -------------------------------------------- */ - static async addTokenHudExtensions(app, html, data) { - let token = canvas.tokens.get(data._id); + static async addTokenHudExtensions(app, html, tokenId) { + let token = canvas.tokens.get(tokenId); let actor = token.actor; let combatant = game.combat.data.combatants.find(c => c.tokenId == token.data._id); @@ -17,10 +17,10 @@ export class RdDTokenHud { if (!token.inCombat) return; if (!combatant) return; - const dataUp = { combatant: combatant, armes: RdDTokenHud.buildListeActionsCombat(combatant) }; + const hudData = { combatant: combatant, armes: RdDTokenHud.buildListeActionsCombat(combatant) }; // initiative - await RdDTokenHud._configureSubMenu(html.find('.control-icon.combat'), 'systems/foundryvtt-reve-de-dragon/templates/hud-actor-init.html', dataUp, + await RdDTokenHud._configureSubMenu(html.find('.control-icon.combat'), 'systems/foundryvtt-reve-de-dragon/templates/hud-actor-init.html', hudData, (event) => { let armeIndex = event.currentTarget.attributes['data-arme-id'].value; let combatantId = event.currentTarget.attributes['data-combatant-id'].value; @@ -29,7 +29,7 @@ export class RdDTokenHud { }); // combat - await RdDTokenHud._configureSubMenu(html.find('.control-icon.target'), 'systems/foundryvtt-reve-de-dragon/templates/hud-actor-attaque.html', dataUp, + await RdDTokenHud._configureSubMenu(html.find('.control-icon.target'), 'systems/foundryvtt-reve-de-dragon/templates/hud-actor-attaque.html', hudData, (event) => { let armeIndex = event.currentTarget.attributes['data-arme-id'].value; let arme = armesList[armeIndex]; @@ -46,8 +46,8 @@ export class RdDTokenHud { return armesList; } - static async _configureSubMenu(insertionPoint, template, data, onMenuItem) { - const hud = $(await renderTemplate(template, data)); + static async _configureSubMenu(insertionPoint, template, hudData, onMenuItem) { + const hud = $(await renderTemplate(template, hudData)); const imgHud = hud.find('img.rdd-hud-togglebutton'); const list = hud.find('div.rdd-hud-list'); diff --git a/module/rdd-utility.js b/module/rdd-utility.js index df1b9126..b24746fd 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -179,7 +179,7 @@ export class RdDUtility { 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-encaisser.html', 'systems/foundryvtt-reve-de-dragon/templates/dialog-tmr.html', 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-surenc.html', - 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-natation.html', + 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-enctotal.html', 'systems/foundryvtt-reve-de-dragon/templates/dialog-astrologie-joueur.html', // Calendrier 'systems/foundryvtt-reve-de-dragon/templates/calendar-template.html', diff --git a/templates/actor-creature-sheet.html b/templates/actor-creature-sheet.html index 2cdd7fbd..8423dc8e 100644 --- a/templates/actor-creature-sheet.html +++ b/templates/actor-creature-sheet.html @@ -176,7 +176,7 @@ {{!-- Equipment Tab --}}
- Encombrement total/max : {{numberFormat data.encombrementTotal decimals=1}} / {{data.attributs.encombrement.value}} + Encombrement total/max : {{numberFormat data.encTotal decimals=1}} / {{data.attributs.encombrement.value}}
Porté sur soi
    diff --git a/templates/actor-humanoide-sheet.html b/templates/actor-humanoide-sheet.html index d4c48e97..137f9936 100644 --- a/templates/actor-humanoide-sheet.html +++ b/templates/actor-humanoide-sheet.html @@ -176,7 +176,7 @@ {{!-- Equipment Tab --}}
    - Encombrement total/max : {{numberFormat data.encombrementTotal decimals=1}} / {{data.attributs.encombrement.value}} + Encombrement total/max : {{numberFormat data.encTotal decimals=1}} / {{data.attributs.encombrement.value}}
    1. Nom diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index bfd5950c..50a17741 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -597,7 +597,7 @@ {{!-- Equipment Tab --}}
      - Encombrement total/max : {{numberFormat data.encombrementTotal decimals=1}} / {{data.attributs.encombrement.value}} {{data.surEncombrementMessage}} - + Encombrement total/max : {{numberFormat data.encTotal decimals=1}} / {{data.attributs.encombrement.value}} {{data.surEncombrementMessage}} - Créer un objet
      • diff --git a/templates/dialog-competence.html b/templates/dialog-competence.html index 4f869ae0..a51923d0 100644 --- a/templates/dialog-competence.html +++ b/templates/dialog-competence.html @@ -65,7 +65,7 @@
      {{>"systems/foundryvtt-reve-de-dragon/templates/dialog-roll-surenc.html"}} -{{>"systems/foundryvtt-reve-de-dragon/templates/dialog-roll-natation.html"}} +{{>"systems/foundryvtt-reve-de-dragon/templates/dialog-roll-enctotal.html"}}
      diff --git a/templates/dialog-roll-enctotal.html b/templates/dialog-roll-enctotal.html new file mode 100644 index 00000000..06055843 --- /dev/null +++ b/templates/dialog-roll-enctotal.html @@ -0,0 +1,6 @@ +{{#if isMalusEncombrementTotal}} +
      + + +
      +{{/if}} diff --git a/templates/dialog-roll-natation.html b/templates/dialog-roll-natation.html deleted file mode 100644 index 8eb686a2..00000000 --- a/templates/dialog-roll-natation.html +++ /dev/null @@ -1,6 +0,0 @@ -{{#if isNatation}} -
      - - -
      -{{/if}}