From df5954bf7518460066d122bde0642715e5b16da5 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Wed, 9 Dec 2020 00:00:59 +0100 Subject: [PATCH 1/2] =?UTF-8?q?Fix=20ref=C3=A9rence=20circulaire?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit La méthode rollData fait le jet fourni dans rollData et l'ajoute dans rollData.rolled. Pas besoin de retourner rollData, la tentation est forte de mettre le résultat dans "rolled" --- module/actor.js | 2 +- module/rdd-resolution-table.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/module/actor.js b/module/actor.js index 9d7fade3..d2419f50 100644 --- a/module/actor.js +++ b/module/actor.js @@ -142,7 +142,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async performRoll(rollData, attacker = undefined) { // garder le résultat - rollData.rolled = await RdDResolutionTable.rollData(rollData); + await RdDResolutionTable.rollData(rollData); //console.log("performRoll", rollData) if ( !rollData.attackerRoll) {// Store in the registry if not a defense roll diff --git a/module/rdd-resolution-table.js b/module/rdd-resolution-table.js index 534667f3..66f3a8f6 100644 --- a/module/rdd-resolution-table.js +++ b/module/rdd-resolution-table.js @@ -100,7 +100,6 @@ export class RdDResolutionTable { /* -------------------------------------------- */ static async rollData(rollData ) { rollData.rolled = await this.roll(rollData.caracValue, rollData.finalLevel, rollData.bonus); - return rollData; } /* -------------------------------------------- */ From 1d525c4bacf18df671190a54bee4e186b51918ba Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Wed, 9 Dec 2020 00:36:38 +0100 Subject: [PATCH 2/2] Fix Initiative MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - affichage incorrect sur valeurs positive - "1d60+5" pour une compétence à zéro - arrondi inférieur pour carac (p120) - afficher le résultat de niveau + carac (plus lisible) --- module/actor-sheet.js | 2 +- module/rdd-main.js | 4 ++-- module/rdd-utility.js | 12 +++++++++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/module/actor-sheet.js b/module/actor-sheet.js index f5e3303b..d7071f44 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -96,7 +96,7 @@ export class RdDActorSheet extends ActorSheet { 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 = "1d6" + melee.data.niveau + "+" + Math.ceil(data.data.carac['melee'].value / 2 ); + let cc_init = RdDUtility.calculInitiative(melee.data.niveau, data.data.carac['melee'].value); data.data.combat.push( { name: "Corps à corps", data: { niveau: melee.data.niveau, description: "", force: 6, initiative: cc_init, competence: "Corps à corps", dommages: data.data.attributs.plusdom.value } } ); } } diff --git a/module/rdd-main.js b/module/rdd-main.js index cd171d48..7fb9dec1 100644 --- a/module/rdd-main.js +++ b/module/rdd-main.js @@ -54,7 +54,7 @@ const _patch_initiative = () => { competence = duplicate(competenceItem); } } - rollFormula = "1d6+" + competence.data.niveau + "+" + Math.ceil(competence.data.carac_value / 2); + rollFormula = RdDUtility.calculInitiative(competence.data.niveau, competence.data.carac_value); } else { for (const item of c.actor.data.items) { if (item.type == "arme" && item.data.equipe) { @@ -63,7 +63,7 @@ const _patch_initiative = () => { } let compName = ( armeCombat == undefined ) ? "Corps à corps" : armeCombat.data.competence; competence = RdDUtility.findCompetence( c.actor.data.items, compName ); - rollFormula = "1d6+" + competence.data.niveau + "+" + Math.ceil(c.actor.data.data.carac[competence.data.defaut_carac].value/2); + rollFormula = RdDUtility.calculInitiative(competence.data.niveau, c.actor.data.data.carac[competence.data.defaut_carac].value); } } //console.log("Combatat", c); diff --git a/module/rdd-utility.js b/module/rdd-utility.js index ace85b4a..360f5756 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -3,6 +3,7 @@ import { TMRUtility } from "./tmr-utility.js"; import { RdDRollTables } from "./rdd-rolltables.js"; import { ChatUtility } from "./chat-utility.js"; +import { Misc } from "./misc.js"; /* -------------------------------------------- */ const level_category = { @@ -425,7 +426,7 @@ export class RdDUtility { let arme2mains = []; // Tableau contenant la duplication des armes 1m/2m for (const arme of armeList) { let comp = competenceList.find(c => c.name == arme.data.competence); - arme.data.initiative = "1d6+" + arme.data.niveau + "+" + Math.ceil(carac[comp.data.defaut_carac].value/2); + arme.data.initiative = RdDUtility.calculInitiative(arme.data.niveau, carac[comp.data.defaut_carac].value); // 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); @@ -433,7 +434,7 @@ export class RdDUtility { arme2main.data.competence = arme2main.data.competence.replace(" 1 main", " 2 mains"); // Replace ! let comp = competenceList.find(c => c.name == arme2main.data.competence); arme2main.data.niveau = comp.data.niveau; - arme2main.data.initiative = "1d6+" + arme2main.data.niveau + "+" + Math.ceil(carac[comp.data.defaut_carac].value/2); + arme2main.data.initiative = RdDUtility.calculInitiative(arme2main.data.niveau, carac[comp.data.defaut_carac].value); arme2mains.push(arme2main); } } @@ -442,6 +443,11 @@ export class RdDUtility { return armeList } + static calculInitiative(niveau, caracValue) { + let base = niveau + Math.floor(caracValue/2); + return "1d6" + (base >= 0 ? "+" : "") + base; + } + /* -------------------------------------------- */ static computeCarac( data) { @@ -786,7 +792,7 @@ export class RdDUtility { } } // Cas des créatures et entités vs personnages - let rollFormula = "1d6+" + competence.data.niveau + "+" + Math.ceil(caracForInit/2) + "+" + initOffset; + let rollFormula = RdDUtility.calculInitiative(competence.data.niveau, caracForInit) + "+" + initOffset; game.combat.rollInitiative(combatantId, rollFormula ); } }