From a00f187f9f299d4726fbc268b61d988f096532a1 Mon Sep 17 00:00:00 2001 From: sladecraven Date: Fri, 13 Nov 2020 11:24:56 +0100 Subject: [PATCH] #13 Support des sorts de difficulte et de cout variables + correction de regression --- module/actor.js | 33 ++++++++++----------- module/rdd-roll-dialog.js | 52 +++++++++++++++++++++++---------- system.json | 2 +- templates/dialog-roll-sort.html | 24 ++++++++++++++- 4 files changed, 77 insertions(+), 34 deletions(-) diff --git a/module/actor.js b/module/actor.js index 1fd83fca..3e8dbbae 100644 --- a/module/actor.js +++ b/module/actor.js @@ -151,7 +151,7 @@ export class RdDActor extends Actor { // Fight management ! let defenseMsg; let encaisser = false; - if (rollData.arme || rollData.competence.name.toLowerCase() == 'esquive' ) { + if (rollData.arme || (rollData.competence && rollData.competence.name.toLowerCase() == 'esquive') ) { // In case of fight, replace the message per dommages + localization. it indicates if result is OK or not if (rollData.attackerRoll) { // Defense case ! if (rolled.isSuccess) { @@ -161,7 +161,7 @@ export class RdDActor extends Actor { encaisser = true; } } else { // This is the attack roll! - if (rolled.isSuccess > 0) { + if (rolled.isSuccess) { rollData.domArmePlusDom = parseInt(rollData.arme.data.dommages); if (rollData.selectedCarac.label == "Mêlée") // +dom only for Melee rollData.domArmePlusDom += parseInt(this.data.data.attributs.plusdom.value); @@ -189,14 +189,14 @@ export class RdDActor extends Actor { let lvl = "" if (rollData.selectedSort) { // Lancement de sort ! let draconic = rollData.selectedSort.data.draconic; + let costReve = rollData.selectedSort.data.ptreve_reel || rollData.selectedSort.data.ptreve; // cas de sort à ptreve variables specialStr = "
Lancement du sort " + rollData.selectedSort.name + " : " + draconic.charAt(0).toUpperCase() + draconic.slice(1) + "/" + rollData.selectedSort.data.difficulte + - "/" + rollData.selectedSort.data.caseTMR + "/R" + rollData.selectedSort.data.ptreve; + "/" + rollData.selectedSort.data.caseTMR + "/R" + costReve; specialStr += "
Depuis la case " + rollData.coord + " (" + TMRUtility.getTMRDescription(rollData.coord).label + ")"; lvl = rollData.selectedDraconic.name + "/" + rollData.selectedSort.name; - let costReve = rollData.selectedSort.data.ptreve; let myReve = duplicate(this.data.data.reve.reve); - if (rollData.tache > 0) { // Réussite du sort ! - if (rollData.tache >= 4) costReve = Math.ceil(costReve / 2); + if (rolled.isSuccess) { // Réussite du sort ! + if (rolled.tache >= 4) costReve = Math.ceil(costReve / 2); if (costReve < 1) costReve = 1; myReve.value = myReve.value - costReve; // Todo 0 pts de reve !!!! if (myReve.value < 0) myReve.value = 0; @@ -211,7 +211,7 @@ export class RdDActor extends Actor { this.currentTMR.updateSortReserve(); } } else { - if (rollData.tache == -4) { // Echec total ! + if (rolled.tache == -4) { // Echec total ! costReve *= 2; myReve.value = myReve.value - costReve; // Todo 0 pts de reve !!!! if (myReve.value < 0) myReve.value = 0; @@ -231,9 +231,6 @@ export class RdDActor extends Actor { } // Save it for fight in the flags area - console.log("Saving Flag", this); - await this.setFlag('world', 'rollData', null); - await this.setFlag('world', 'rollData', rollData); game.system.rdd.rollDataHandler[this.data._id] = duplicate(rollData); // Final chat message @@ -642,7 +639,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async rollUnSort(coord) { let draconicList = this.getDraconicList(); - let sortList = this.getSortList(); + let sortList = duplicate(this.getSortList()); // Duplication car les pts de reve sont modifiés dans le sort let rollData = { selectedCarac: this.data.data.carac.reve, @@ -653,7 +650,9 @@ export class RdDActor extends Actor { selectedSort: sortList[0], coord: coord, finalLevel: 0, - bmValue: 0 + bmValue: sortList[0].data.difficulte, // Per default at startup + coutreve: Array(20).fill().map((item, index) => 1 + index), + bonusmalusTable: CONFIG.RDD.bonusmalus } let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-roll-sort.html', rollData); new RdDRollDialog("sort", html, rollData, this ).render(true); @@ -663,11 +662,11 @@ export class RdDActor extends Actor { async rollCarac( caracName ) { let rollData = { - "selectedCarac": this.data.data.carac[caracName], - "bonusmalusTable": CONFIG.RDD.bonusmalus, - "etat": this.data.data.compteurs.etat.value, - "finalLevel": 0, - "bmValue": 0 + selectedCarac: this.data.data.carac[caracName], + bonusmalusTable: CONFIG.RDD.bonusmalus, + etat: this.data.data.compteurs.etat.value, + finalLevel: 0, + bmValue: 0 } console.log(caracName, rollData); let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-roll-carac.html', rollData); diff --git a/module/rdd-roll-dialog.js b/module/rdd-roll-dialog.js index a14ecec3..8176fed9 100644 --- a/module/rdd-roll-dialog.js +++ b/module/rdd-roll-dialog.js @@ -67,6 +67,21 @@ export class RdDRollDialog extends Dialog { rollData.finalLevel = rollLevel; rollData.finalLevelStr = (rollLevel > 0 ? "+" : "") + rollLevel; rollData.rollTarget = RdDResolutionTable.computeChances(rollData.selectedCarac.value, rollData.finalLevel); + + // Sort management + if ( rollData.selectedSort ) { + //console.log("Toggle show/hide", rollData.selectedSort); + if (rollData.selectedSort.data.difficulte.toLowerCase() == "variable") { + $("#div-sort-difficulte").show(); + } else { + $("#div-sort-difficulte").hide(); + } + if (rollData.selectedSort.data.ptreve.toLowerCase() == "variable") { + $("#div-sort-ptreve").show(); + } else { + $("#div-sort-ptreve").hide(); + } + } $("#roll-param").text(rollData.selectedCarac.value + " / " + rollData.finalLevelStr); $("#compdialogTitle").text(RdDRollDialog._getTitle(rollData)); @@ -79,41 +94,44 @@ export class RdDRollDialog extends Dialog { // Update html, according to data if (rollData.competence) { // Set the default carac from the competence item - console.log("RdDDialogRoll", rollData.competence.data.defaut_carac, rollData.carac); - + //console.log("RdDDialogRoll", rollData.competence.data.defaut_carac, rollData.carac); rollData.selectedCarac = rollData.carac[rollData.competence.data.defaut_carac]; $("#carac").val(rollData.competence.data.defaut_carac); } $("#bonusmalus").val(rollData.bmValue); updateRollResult(rollData); }); - + // Update ! html.find('#bonusmalus').click((event) => { rollData.bmValue = event.currentTarget.value; // Update the selected bonus/malus - console.debug("RdDRollDialog","BM CLICKED !!!", rollData); + //console.log("RdDRollDialog","BM CLICKED !!!", rollData); updateRollResult(rollData); }); html.find('#carac').click((event) => { let caracKey = event.currentTarget.value; - rollData.selectedCarac = rollData.carac[caracKey]; // Update the selectedCarac - console.debug("RdDRollDialog","CARAC CLICKED !!!", rollData); + this.rollData.selectedCarac = rollData.carac[caracKey]; // Update the selectedCarac + //console.log("RdDRollDialog","CARAC CLICKED !!!", rollData); updateRollResult(rollData); }); html.find('#draconic').click((event) => { - let draconicKey = event.currentTarget.value; - rollData.selectedDraconic = rollData.draconicList[draconicKey]; // Update the selectedCarac - console.debug("RdDRollDialog","CARAC CLICKED !!!", rollData); + let draconicKey = Number(event.currentTarget.value); + this.rollData.selectedDraconic = rollData.draconicList[draconicKey]; // Update the selectedCarac + //console.log("RdDRollDialog","CARAC CLICKED !!!", rollData); updateRollResult(rollData); }); html.find('#sort').click((event) => { - let sortKey = event.currentTarget.value; - rollData.selectedSort = rollData.sortList[sortKey]; // Update the selectedCarac - console.debug("RdDRollDialog","CARAC CLICKED !!!", rollData); + let sortKey = Number(event.currentTarget.value); + this.rollData.selectedSort = rollData.sortList[sortKey]; // Update the selectedCarac + //console.log("RdDRollDialog - Sort selection", rollData.selectedSort); + updateRollResult(rollData); + }); + html.find('#ptreve-variable').click((event) => { + let ptreve = Number(event.currentTarget.value); + this.rollData.selectedSort.data.ptreve_reel = ptreve; // Update the selectedCarac + console.log("RdDRollDialog - Cout reve", ptreve); updateRollResult(rollData); }); - - } /* -------------------------------------------- */ @@ -123,7 +141,11 @@ export class RdDRollDialog extends Dialog { return etat + parseInt(rollData.competence.data.niveau) + parseInt(rollData.bmValue); } if (rollData.draconicList) { - return etat + parseInt(rollData.selectedDraconic.data.niveau) + parseInt(rollData.selectedSort.data.difficulte); + let difficulte = rollData.selectedSort.data.difficulte; // Sort de difficulté variable + if (difficulte.toLowerCase() == "variable") { + difficulte = parseInt(rollData.bmValue); // Récupérer la valeur de la listbox dans ce cas + } + return etat + parseInt(rollData.selectedDraconic.data.niveau) + parseInt(difficulte); } return etat + parseInt(rollData.bmValue); } diff --git a/system.json b/system.json index 3de13da2..1aefb817 100644 --- a/system.json +++ b/system.json @@ -2,7 +2,7 @@ "name": "foundryvtt-reve-de-dragon", "title": "Rêve de Dragon", "description": "Rêve de Dragon RPG for FoundryVTT", - "version": "0.9.36", + "version": "0.9.37", "minimumCoreVersion": "0.7.5", "compatibleCoreVersion": "0.7.6", "templateVersion": 44, diff --git a/templates/dialog-roll-sort.html b/templates/dialog-roll-sort.html index f6e6d10c..84e202b9 100644 --- a/templates/dialog-roll-sort.html +++ b/templates/dialog-roll-sort.html @@ -20,12 +20,34 @@ +
+ + +
+ +
+ + +
+