From d24b9c07fadf9a05f63391ff636832e0d71a5a81 Mon Sep 17 00:00:00 2001 From: sladecraven Date: Tue, 2 Feb 2021 07:56:45 +0100 Subject: [PATCH] Ameliorations lancer de sort --- module/actor.js | 52 +++++++++++++++++++++++++++++++-- module/rdd-roll.js | 4 +++ system.json | 2 +- templates/dialog-roll-sort.html | 5 ++-- 4 files changed, 56 insertions(+), 7 deletions(-) diff --git a/module/actor.js b/module/actor.js index 232d4235..4c5dc80f 100644 --- a/module/actor.js +++ b/module/actor.js @@ -275,7 +275,7 @@ export class RdDActor extends Actor { getBestDraconic() { const list = this.getDraconicList().sort((a, b) => b.data.niveau - a.data.niveau); if (list.length == 0) { - return { name: "none", niveau: -11 }; + return { name: "none", data: { niveau: -11 } }; } return duplicate(list[0]); } @@ -926,7 +926,7 @@ export class RdDActor extends Actor { if (item.data.quantite == undefined) item.data.quantite = 1; // Auto-fix if (item.data.cout < 0) item.data.cout = 0; // Auto-fix prixTotalEquipement += Number(item.data.cout) * Number(item.data.quantite); - console.log("cout équipement : ", item.name, item.data.cout, item.data.quantite, prixTotalEquipement); + //console.log("cout équipement : ", item.name, item.data.cout, item.data.quantite, prixTotalEquipement); } } // Mise à jour valeur totale de l'équipement @@ -1627,6 +1627,46 @@ export class RdDActor extends Actor { } } + /* -------------------------------------------- */ + filterSortList(sortList, coord) { + let tmr = TMRUtility.getTMRDescription( coord); + let letfilteredList = [] + for ( let sort of sortList) { + if (sort.data.caseTMR.toLowerCase().includes('variable') ) { + letfilteredList.push( sort); + } else if (sort.data.caseTMRspeciale.toLowerCase().includes('variable') ) { + letfilteredList.push( sort); + } else if (sort.data.caseTMR.toLowerCase() == tmr.type ) { + letfilteredList.push( sort); + } else if ( sort.data.caseTMR.toLowerCase().includes('spéciale') && sort.data.caseTMRspeciale.toLowerCase().includes( coord.toLowerCase() ) ) { + letfilteredList.push( sort); + } + } + + return letfilteredList; + } + + /* -------------------------------------------- */ + filterDraconicList(sortList ) { + let draconicDone = {}; + let newDraconicList = []; + let draconicList = this.getDraconicList(); + let bestDraconic = this.getBestDraconic(); + for ( let sort of sortList) { + let voie = sort.data.draconic.toLowerCase(); + let competenceVoie = draconicList.find(item => item.data.categorie == 'draconic' && item.name.toLowerCase().includes( voie ) ); + if ( sort.name.toLowerCase().includes('aura') ) { + competenceVoie = bestDraconic; + } + if (!draconicDone[competenceVoie.name]) { + newDraconicList.push( competenceVoie ); + draconicDone[competenceVoie.name] = newDraconicList.length-1; // Patch local pour relier facilement voie/compétence + } + sort.data.listIndex = draconicDone[competenceVoie.name] || 0; + } + return newDraconicList; + } + /* -------------------------------------------- */ async rollUnSort(coord) { let sortList = duplicate(this.getSortList()); // Duplication car les pts de reve sont modifiés dans le sort @@ -1634,11 +1674,17 @@ export class RdDActor extends Actor { ui.notifications.info("Aucun sort disponible!"); return; } + sortList = this.filterSortList(sortList, coord); + if (!sortList || sortList.length == 0) { + ui.notifications.info("Aucun sort disponible pour cette case !"); + return; + } if (this.currentTMR) this.currentTMR.minimize(); // Hide + let draconicList = this.filterDraconicList(sortList); let rollData = { selectedCarac: this.data.data.carac.reve, - draconicList: this.getDraconicList(), + draconicList: draconicList, sortList: sortList, competence: this.getBestDraconic(), selectedSort: sortList[0], diff --git a/module/rdd-roll.js b/module/rdd-roll.js index 6a931db8..4c81ad17 100644 --- a/module/rdd-roll.js +++ b/module/rdd-roll.js @@ -120,6 +120,9 @@ export class RdDRoll extends Dialog { rollData.selectedCarac = rollData.carac[rollData.competence.data.defaut_carac]; $("#carac").val(rollData.competence.data.defaut_carac); } + if (rollData.selectedSort) { + $("#draconic").val( rollData.selectedSort.data.listIndex ); // Uniquement a la selection du sort, pour permettre de changer + } RdDItemSort.setCoutReveReel(rollData.selectedSort); $("#diffLibre").val(Misc.toInt(rollData.diffLibre)); $("#diffConditions").val(Misc.toInt(rollData.diffConditions)); @@ -153,6 +156,7 @@ export class RdDRoll extends Dialog { this.rollData.selectedSort = this.rollData.sortList[sortKey]; // Update the selectedCarac this.rollData.bonus = RdDItemSort.getCaseBonus(this.rollData.selectedSort, this.rollData.coord); RdDItemSort.setCoutReveReel(this.rollData.selectedSort); + $("#draconic").val( this.rollData.selectedSort.data.listIndex ); // Uniquement a la selection du sort, pour permettre de changer this.updateRollResult(); }); html.find('#ptreve-variable').change((event) => { diff --git a/system.json b/system.json index a14eeb1f..a7986cd8 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": "1.3.7", + "version": "1.3.8", "manifestPlusVersion": "1.0.0", "minimumCoreVersion": "0.7.5", "compatibleCoreVersion": "0.7.9", diff --git a/templates/dialog-roll-sort.html b/templates/dialog-roll-sort.html index f247e9a6..3879df15 100644 --- a/templates/dialog-roll-sort.html +++ b/templates/dialog-roll-sort.html @@ -13,7 +13,7 @@ {{/each}} {{/select}} - + {{#select sort}} {{#each sortList as |sort key|}} - - + {{/each}} {{/select}}