From a2f859a4601ad3a0373f8dfb4bd00a4c6f356abe Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Sat, 20 Nov 2021 01:19:29 +0100 Subject: [PATCH] Fix armes 2m dans l'onglet Combat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Les armes 1 ou 2 mains n'étaient pas bien choisies dans l'onglet combat de la feuille de personnage. Un message d'erreur pour les dommages 1/2 mains était faux depuis cet onglet --- module/actor-sheet.js | 26 ++++++++++++++------------ module/item-arme.js | 1 + module/rdd-combat.js | 22 +++++++++++++++++----- templates/actor-sheet.html | 16 ++++++++++++---- 4 files changed, 44 insertions(+), 21 deletions(-) diff --git a/module/actor-sheet.js b/module/actor-sheet.js index d8dd83e2..9281bb0f 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -344,24 +344,16 @@ export class RdDActorSheet extends ActorSheet { // Roll Weapon1 html.find('.arme-label a').click(async event => { - let armeName = event.currentTarget.text; - let compName = event.currentTarget.attributes['data-competence-name'].value; - let arme = this.actor.data.items.find(it => - it.name == armeName && - RdDItemArme.isArme(it) && - ((compName || it.data.data.competence) == it.data.data.competence) - ); - if (!arme) { - arme = { name: armeName, data: { competence: compName } }; - } + const li = $(event.currentTarget).parents(".item"); + let arme = this._getArmeCombat(li); this.actor.rollArme( duplicate(arme) ); }); // Initiative pour l'arme html.find('.arme-initiative a').click(async event => { let combatant = game.combat.data.combatants.find(c => c.actor.data._id == this.actor.data._id); if (combatant) { - let armeName = event.currentTarget.attributes['data-arme-name'].value; - let arme = this.armesList.find(a => a.name == armeName); + const li = $(event.currentTarget).parents(".item"); + let arme = this._getArmeCombat(li); RdDCombatManager.rollInitiativeCompetence(combatant._id, arme); } else { ui.notifications.info("Impossible de lancer l'initiative sans être dans un combat."); @@ -543,6 +535,16 @@ export class RdDActorSheet extends ActorSheet { } + _getArmeCombat(li) { + let armeName = li.data("arme-name"); + let compName = li.data('competence-name'); + const arme = this.armesList.find(a => a.name == armeName && a.data.competence == compName); + if (!arme) { + return { name: armeName, data: { competence: compName } }; + } + return arme; + } + /* -------------------------------------------- */ /** @override */ setPosition(options = {}) { diff --git a/module/item-arme.js b/module/item-arme.js index d55bc3e7..b1f1aafa 100644 --- a/module/item-arme.js +++ b/module/item-arme.js @@ -177,6 +177,7 @@ export class RdDItemArme extends Item { static corpsACorps(actorData) { const corpsACorps = { name: 'Corps à corps', + img: 'systems/foundryvtt-reve-de-dragon/icons/competence_corps_a_corps.webp', data: { equipe: true, rapide: true, diff --git a/module/rdd-combat.js b/module/rdd-combat.js index c3312887..e8de4d6e 100644 --- a/module/rdd-combat.js +++ b/module/rdd-combat.js @@ -151,11 +151,12 @@ export class RdDCombatManager extends Combat { // Gestion des armes 1/2 mains let armesEquipe = []; for (const arme of armes) { - let armeData = Misc.data(arme); + let armeData = duplicate(Misc.data(arme)); if (armeData.data.equipe) { let compData = competences.map(c => Misc.data(c)).find(c => c.name == armeData.data.competence); armesEquipe.push(armeData); + armeData.data.dommagesReels = Number(armeData.data.dommages); armeData.data.niveau = compData.data.niveau; armeData.data.initiative = RdDCombatManager.calculInitiative(compData.data.niveau, carac[compData.data.defaut_carac].value); // Dupliquer les armes pouvant être à 1 main et 2 mains en patchant la compétence @@ -165,14 +166,25 @@ export class RdDCombatManager extends Combat { armeData.data.mainInfo = "(2m)"; } else if (armeData.data.unemain && armeData.data.deuxmains) { armeData.data.mainInfo = "(1m)"; - let arme2main = duplicate(armeData); + + const comp2m = armeData.data.competence.replace(" 1 main", " 2 mains"); // Replace ! + const comp = Misc.data(competences.find(c => c.name == comp2m)); + + const arme2main = duplicate(armeData); arme2main.data.mainInfo = "(2m)"; - arme2main.data.dommages = arme2main.data.dommages.split("/")[1]; // Existence temporaire uniquement dans la liste des armes, donc OK - arme2main.data.competence = arme2main.data.competence.replace(" 1 main", " 2 mains"); // Replace ! - let comp = Misc.data(competences.find(c => c.name == arme2main.data.competence)); arme2main.data.niveau = comp.data.niveau; + arme2main.data.competence = comp2m; arme2main.data.initiative = RdDCombatManager.calculInitiative(arme2main.data.niveau, carac[comp.data.defaut_carac].value); armesEquipe.push(arme2main); + const containsSlash = armeData.data.dommages.includes("/"); + if (containsSlash) { + const tableauDegats = armeData.data.dommages.split("/"); + armeData.data.dommagesReels = Number(tableauDegats[0]); + arme2main.data.dommagesReels = Number(tableauDegats[1]); + } + else{ + ui.notifications.info("Les dommages de l'arme à 1/2 mains " + armeData.name + " ne sont pas corrects (ie sous la forme X/Y)"); + } } } } diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index 0d364290..a739487c 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -274,12 +274,20 @@ +dom {{#each combat as |arme key|}} -
  • - {{arme.name}} - {{arme.data.initiative}} +
  • + + + {{#if arme.img}} + + {{/if}} + {{arme.name}} + + + {{arme.data.initiative}} {{arme.data.competence}} {{numberFormat arme.data.niveau decimals=0 sign=true}} - {{numberFormat arme.data.dommages decimals=0 sign=true}} + {{numberFormat arme.data.dommagesReels decimals=0 sign=true}}
  • {{/each}}