From 1c2a60017daca7e728f8be05cefc23ea73572b20 Mon Sep 17 00:00:00 2001 From: sladecraven Date: Mon, 23 Nov 2020 20:40:56 +0100 Subject: [PATCH] #38 - Gestion des armes 1/2mains --- module/actor-sheet.js | 19 ++++++++++++++++--- module/actor.js | 24 ++++++++++++++++++------ system.json | 4 ++-- template.json | 8 +++++--- templates/actor-sheet.html | 2 +- templates/dialog-competence.html | 2 +- templates/item-arme-sheet.html | 12 ++++++++++-- 7 files changed, 53 insertions(+), 18 deletions(-) diff --git a/module/actor-sheet.js b/module/actor-sheet.js index 30072932..2a395576 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -62,7 +62,8 @@ export class RdDActorSheet extends ActorSheet { // Force empty arme, at least for Esquive if (data.itemsByType.arme == undefined ) data.itemsByType.arme = []; - for (const arme of data.itemsByType.arme) { + let arme2mains = []; // tablea contenant la duplication des armes 1m/2m + for (const arme of data.itemsByType.arme) { arme.data.niveau = 0; // Per default, TODO to be fixed for ( const melee of data.competenceByCategory.melee ) { if (melee.name == arme.data.competence ) @@ -76,8 +77,19 @@ export class RdDActorSheet extends ActorSheet { if (lancer.name == arme.data.competence ) arme.data.niveau = lancer.data.niveau } + // Dupliquer les armes pouvant être à 1 main et 2 mains en patchant la compétence + if (arme.data.unemain && arme.data.deuxmains) { + let arme2main = duplicate(arme); + arme2main.data.competence = arme2main.data.competence.replace(" 1 main", " 2 mains"); // Replace ! + for ( const melee of data.competenceByCategory.melee ) { + if (melee.name == arme2main.data.competence ) + arme2main.data.niveau = melee.data.niveau + } + arme2mains.push(arme2main); + } } - + data.itemsByType.arme = data.itemsByType.arme.concat(arme2mains); // Merge all cases + // To avoid armour and so on... data.data.combat = duplicate( RdDUtility.checkNull(data.itemsByType['arme'])); @@ -237,7 +249,8 @@ export class RdDActorSheet extends ActorSheet { // Roll Weapon1 html.find('.arme-label a').click((event) => { let armeName = event.currentTarget.text; - this.actor.rollArme( armeName); + let competenceName = event.currentTarget.attributes['data-competence-name'].value; + this.actor.rollArme( armeName, competenceName); }); // Display TMR, normal html.find('.visu-tmr a').click((event) => { diff --git a/module/actor.js b/module/actor.js index f62d8fb8..118ba836 100644 --- a/module/actor.js +++ b/module/actor.js @@ -1032,13 +1032,15 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ - rollArme( armeName ) + rollArme( armeName, competenceName=undefined ) { let armeItem = this.data.items.find(item=>item.type==="arme" && (item.name === armeName)); - if ( armeItem && armeItem.data.competence ) - this.rollCompetence( armeItem.data.competence, armeItem ); - else - this.rollCompetence( armeName ); //Bypass mode! + if (armeItem ) { + if ( competenceName == undefined) competenceName = armeItem.data.competence; + this.rollCompetence( competenceName, armeItem ); + } else { + this.rollCompetence( armeName ); //Bypass mode! + } } /* -------------------------------------------- */ @@ -1059,7 +1061,7 @@ export class RdDActor extends Actor { if ( competence.type == 'competencecreature') { // Specific case for Creatures if ( competence.data.iscombat ) { - armeItem = { name: name, data: { dommages: competence.data.dommages} }; + armeItem = { name: name, data: { dommages: competence.data.dommages, dommagesReels: competence.data.dommages} }; } competence.data.defaut_carac = "carac_creature"; // Fake default competence competence.data.categorie = "creature"; // Fake default competence @@ -1068,6 +1070,16 @@ export class RdDActor extends Actor { rollData.carac = { carac_creature: { label: name, value: competence.data.carac_value } }; } else { // Usual competence rollData.competence = competence; + armeItem.data.dommagesReels = armeItem.data.dommages; // Per default + if ( !armeItem.data.unemain && !armeItem.data.deuxmains) // Force default + armeItem.data.unemain = true; + if (armeItem.data.unemain && armeItem.data.deuxmains) { // manage 1/2 main + //console.log("Weapon", armeItem.data.dommages); + if ( name.toLowerCase().includes("1 main") ) + armeItem.data.dommagesReels = Number(armeItem.data.dommages.split("/")[0]); + else // 2 mains + armeItem.data.dommagesReels = Number(armeItem.data.dommages.split("/")[1]); + } rollData.arme = armeItem; rollData.carac = this.data.data.carac; } diff --git a/system.json b/system.json index e2a62f66..f73d3652 100644 --- a/system.json +++ b/system.json @@ -2,10 +2,10 @@ "name": "foundryvtt-reve-de-dragon", "title": "Rêve de Dragon", "description": "Rêve de Dragon RPG for FoundryVTT", - "version": "0.9.77", + "version": "0.9.78", "minimumCoreVersion": "0.7.5", "compatibleCoreVersion": "0.7.6", - "templateVersion": 47, + "templateVersion": 48, "author": "LeRatierBretonnien", "esmodules": [ "module/rdd-main.js", "module/hook-renderChatLog.js" ], "styles": ["styles/simple.css"], diff --git a/template.json b/template.json index 8f62bfce..ec00cf38 100644 --- a/template.json +++ b/template.json @@ -537,15 +537,17 @@ "quantite": 1, "encombrement": 0, "equipe": false, - "dommages": 0, - "force": 0, + "dommages": "0", + "force": "0", "resistance": 0, "competence": "", "cout": 0, "portee_courte": 0, "portee_moyenne": 0, "portee_extreme": 0, - "rapide": false + "rapide": false, + "deuxmains": false, + "unemain": false }, "munition": { "description": "", diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index e2c3578f..214a3d44 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -320,7 +320,7 @@
    {{#each data.combat as |arme key|}}
  1. - {{arme.name}} + {{arme.name}} {{arme.data.competence}} {{numberFormat arme.data.niveau decimals=0 sign=true}} {{numberFormat arme.data.dommages decimals=0 sign=true}} diff --git a/templates/dialog-competence.html b/templates/dialog-competence.html index f1eeccce..3bda146d 100644 --- a/templates/dialog-competence.html +++ b/templates/dialog-competence.html @@ -32,7 +32,7 @@ {{#if arme}}
    - +
    diff --git a/templates/item-arme-sheet.html b/templates/item-arme-sheet.html index 6323fa04..1302efeb 100644 --- a/templates/item-arme-sheet.html +++ b/templates/item-arme-sheet.html @@ -18,7 +18,7 @@
    - +
    @@ -30,12 +30,20 @@
    - +
    +
    + + +
    +
    + + +