From 003fa8c43a679bb4d5800aec800b0ad9e9be4fc9 Mon Sep 17 00:00:00 2001
From: Vincent Vandemeulebrouck <vincent.vandemeulebrouck@itiviti.com>
Date: Fri, 22 Jan 2021 23:19:17 +0100
Subject: [PATCH] Plus d'attaque avec l'esquive

---
 module/actor-sheet.js      | 15 +++++----------
 templates/actor-sheet.html | 17 ++++++++++++-----
 2 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/module/actor-sheet.js b/module/actor-sheet.js
index 06db623b..79880544 100644
--- a/module/actor-sheet.js
+++ b/module/actor-sheet.js
@@ -90,16 +90,11 @@ export class RdDActorSheet extends ActorSheet {
     data.data.combat = duplicate(RdDUtility.checkNull(data.itemsByType['arme']));
     data.data.combat = RdDUtility._finalizeArmeList(data.data.combat, data.itemsByType.competence, data.data.carac);
 
-    if (data.competenceByCategory && data.competenceByCategory.melee) {
-      //Specific case for Esquive and Corps à Corps
-      for (const melee of data.competenceByCategory.melee) {
-        if (melee.name == "Esquive")
-          data.data.combat.push({ name: "Esquive", data: { niveau: melee.data.niveau, description: "", force: 6, initiative: "", competence: "Esquive", dommages: 0 } });
-        if (melee.name == "Corps à corps") {
-          let cc_init = RdDUtility.calculInitiative(melee.data.niveau, data.data.carac['melee'].value);
-          data.data.combat.push(RdDItemArme.mainsNues({ niveau: melee.data.niveau, initiative: cc_init }));
-        }
-      }
+    data.esquive = { name: "Esquive", niveau: data.competenceByCategory?.melee.find(it => it.name == 'Esquive')?.data.niveau ?? -6};
+    let corpsACorps = data.competenceByCategory?.melee.find(it => it.name == 'Corps à corps');
+    if (corpsACorps) {
+      let cc_init = RdDUtility.calculInitiative(corpsACorps.data.niveau, data.data.carac['melee'].value);
+      data.data.combat.push(RdDItemArme.mainsNues({ niveau: corpsACorps.data.niveau, initiative: cc_init }));
     }
     this.armesList = duplicate(data.data.combat);
 
diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html
index f3c9bcc3..5597990d 100644
--- a/templates/actor-sheet.html
+++ b/templates/actor-sheet.html
@@ -529,14 +529,21 @@
               </li>
             {{#each data.combat as |arme key|}}
               <li class="item flexrow list-item" data-item-id="{{arme._id}}">
-                  <span class="arme-label" name="data.armes[{{key}}].name"><a data-competence-name="{{arme.data.competence}}">{{arme.name}}</a></span>
-                  <span class="arme-initiative" ><a data-arme-name="{{arme.name}}" data-competence-name="{{arme.data.competence}}">{{arme.data.initiative}}</a></span>
+                  <span class="arme-label"><a data-competence-name="{{arme.data.competence}}">{{arme.name}}</a></span>
+                  <span class="arme-initiative"><a data-arme-name="{{arme.name}}" data-competence-name="{{arme.data.competence}}">{{arme.data.initiative}}</a></span>
                   <span class="competence-label">{{arme.data.competence}}</span>
-                  <span class="competence-value" name="data.armes[{{key}}].data.niveau">{{numberFormat arme.data.niveau decimals=0 sign=true}}</span>
-                  <span class="competence-value" name="data.armes[{{key}}].data.dommages">{{numberFormat arme.data.dommages decimals=0 sign=true}}</span>
+                  <span class="competence-value">{{numberFormat arme.data.niveau decimals=0 sign=true}}</span>
+                  <span class="competence-value">{{numberFormat arme.data.dommages decimals=0 sign=true}}</span>
               </li>
             {{/each}}
-            </ul>
+            <li class="item flexrow list-item">
+              <span class="competence-label"><a data-competence-name="{{esquive.name}}">{{esquive.name}}</a></span>
+              <span class="arme-initiative"></span>
+              <span class="competence-label"></span>
+              <span class="competence-value">{{numberFormat esquive.niveau decimals=0 sign=true}}</span>
+              <span class="competence-value"></span>
+          </li>
+        </ul>
         </div>
 
         {{!-- Compteurs/Blessures Tab --}}