diff --git a/module/actor.js b/module/actor.js index 18480bd0..e85ed5d7 100644 --- a/module/actor.js +++ b/module/actor.js @@ -324,12 +324,13 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ getDraconicList() { return this.items.filter(it => Misc.data(it).type == 'competence' && Misc.templateData(it).categorie == 'draconic') + .sort(Misc.descending(it => Misc.templateData(it).niveau)); } /* -------------------------------------------- */ getBestDraconic() { - const list = this.getDraconicList().sort(Misc.descending(it => Misc.templateData(it).niveau)); + const list = this.getDraconicList(); if (list.length == 0) { - return { name: "Aucun", data: { name: "Aucun", data: { niveau: -11 } } }; + return { name: "Aucun", data: { name: "Aucun", data: { niveau: 0 } } }; } return duplicate(list[0]); } @@ -1968,28 +1969,29 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ - filterDraconicList(sortList) { - let draconicDone = {}; - let newDraconicList = []; - let draconicList = this.getDraconicList(); - let bestDraconic = this.getBestDraconic(); + computeDraconicAndSortIndex(sortList) { + let draconicList = this.getDraconicList().map(d => duplicate(Misc.data(d))); for (let sort of sortList) { - let voie = sort.data.draconic; - let draconic = RdDItemCompetence.getVoieDraconic(draconicList, voie); - //console.log(draconicList, bestDraconic, draconic, voie); - if (sort.name.toLowerCase().includes('aura')) { - draconic = bestDraconic; + let draconicsSort = this.getDraconicsSort(draconicList, sort).map(it => it.name); + for (let index = 0; index < draconicList.length && sort.data.listIndex==undefined; index++){ + if (draconicsSort.includes(draconicList[index].name)){ + sort.data.listIndex = index; + } } - // TODO: duplicate sur Misc.data? - draconic = duplicate(Misc.data(draconic)); - if (draconicDone[draconic.name] == undefined) { - draconic.data.defaut_carac = 'reve'; - newDraconicList.push(draconic); - draconicDone[draconic.name] = newDraconicList.length - 1; // Patch local pour relier facilement voie/compétence - } - sort.data.listIndex = draconicDone[draconic.name] || 0; } - return newDraconicList; + return draconicList; + } + + getDraconicsSort(draconicList, sort) { + //console.log(draconicList, bestDraconic, draconic, voie); + switch (Grammar.toLowerCaseNoAccent(sort.name)) { + case "lecture d'aura": + case "detection d'aura": + return draconicList; + case "annulation de magie": + return draconicList.filter(it => !Grammar.toLowerCaseNoAccent(Misc.data(it).name).includes('thanatos')); + } + return [RdDItemCompetence.getVoieDraconic(draconicList, sort.data.draconic)]; } /* -------------------------------------------- */ @@ -2010,7 +2012,7 @@ export class RdDActor extends Actor { } if (this.currentTMR) this.currentTMR.minimize(); // Hide - let draconicList = this.filterDraconicList(sortList); + let draconicList = this.computeDraconicAndSortIndex(sortList); const actorData = Misc.data(this); let rollData = { forceCarac: { 'reve': duplicate(actorData.data.carac.reve) }, @@ -2029,6 +2031,7 @@ export class RdDActor extends Actor { const dialog = await RdDRoll.create(this, rollData, { html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-sort.html', + options: { height: 600 }, close: html => { this.currentTMR.maximize() } // Re-display TMR }, { @@ -2036,17 +2039,9 @@ export class RdDActor extends Actor { label: 'Lancer un sort', callbacks: [ this.createCallbackExperience(), - { action: r => this._rollUnSortResult(r, false) } + { action: r => this._rollUnSortResult(r) } ] - }, - { - name: 'mettre-en-reserve', - label: 'Mettre un sort en réserve', - callbacks: [ - this.createCallbackExperience(), - { action: r => this._rollUnSortResult(r, true) } - ] - }, + } ); dialog.render(true); } @@ -2096,17 +2091,11 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ - async _rollUnSortResult(rollData, isSortReserve = false) { + async _rollUnSortResult(rollData) { let rolled = rollData.rolled; let selectedSort = rollData.selectedSort; - let closeTMR = !isSortReserve; - if (selectedSort.data.isrituel && isSortReserve) { - ui.notifications.error("Impossible de mettre le rituel '" + selectedSort.name + "' en réserve"); - this.currentTMR.close(); // Close TMR ! - return; - } - rollData.isSortReserve = isSortReserve; + rollData.isSortReserve = rollData.mettreEnReserve && !selectedSort.data.isrituel; rollData.show = {} rollData.depenseReve = Number(selectedSort.data.ptreve_reel); @@ -2127,7 +2116,6 @@ export class RdDActor extends Actor { if (rollData.isSortReserve) { await this.sortMisEnReserve(rollData, selectedSort); - closeTMR = false; } } else { @@ -2147,10 +2135,10 @@ export class RdDActor extends Actor { reveActuel = Math.max(reveActuel - rollData.depenseReve, 0); await this.update({ "data.reve.reve.value": reveActuel }); - if (closeTMR) { - this.currentTMR.close(); // Close TMR ! - } else { + if (rollData.isSortReserve) { this.currentTMR.maximize(); // Re-display TMR + } else { + this.currentTMR.close(); // Close TMR ! } // Final chat message RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-sort.html'); diff --git a/module/rdd-roll.js b/module/rdd-roll.js index 943d4697..e305965f 100644 --- a/module/rdd-roll.js +++ b/module/rdd-roll.js @@ -1,7 +1,6 @@ import { RollDataAjustements } from "./rolldata-ajustements.js"; import { HtmlUtility } from "./html-utility.js"; import { RdDItemCompetence } from "./item-competence.js"; -import { RdDItemMeditation } from "./item-meditation.js"; import { RdDItemSort } from "./item-sort.js"; import { Misc } from "./misc.js"; import { RdDBonus } from "./rdd-bonus.js"; @@ -64,7 +63,7 @@ export class RdDRoll extends Dialog { surprise: actor.getSurprise(false), canClose: true }; - + mergeObject(rollData, defaultRollData, { recursive: true, overwrite: false }); if (rollData.forceCarac) { rollData.carac = rollData.forceCarac; @@ -169,7 +168,8 @@ export class RdDRoll extends Dialog { $("#carac").val(defaut_carac); } if (rollData.selectedSort) { - $("#draconic").val(rollData.selectedSort.data.listIndex); // Uniquement a la selection du sort, pour permettre de changer + dialog.setSelectedSort(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)); @@ -194,20 +194,16 @@ export class RdDRoll extends Dialog { this.rollData.selectedCarac = this.rollData.carac[caracKey]; // Update the selectedCarac this.updateRollResult(); }); - html.find('#draconic').change((event) => { + html.find('.roll-draconic').change((event) => { let draconicKey = Misc.toInt(event.currentTarget.value); this.rollData.competence = this.rollData.draconicList[draconicKey]; // Update the selectedCarac this.updateRollResult(); }); - html.find('#sort').change((event) => { + html.find('.roll-sort').change((event) => { let sortKey = Misc.toInt(event.currentTarget.value); - this.rollData.selectedSort = this.rollData.sortList[sortKey]; // Update the selectedCarac - this.rollData.bonus = RdDItemSort.getCaseBonus(this.rollData.selectedSort, this.rollData.tmr.coord); - this.rollData.diffLibre = RdDItemSort.getDifficulte(this.rollData.selectedSort, -7) - RdDItemSort.setCoutReveReel(this.rollData.selectedSort); - $("#draconic").val(this.rollData.selectedSort.data.listIndex); // Uniquement a la selection du sort, pour permettre de changer - $("#diffLibre").val(this.rollData.diffLibre); + this.setSelectedSort(this.rollData.sortList[sortKey]); this.updateRollResult(); + $("#diffLibre").val(this.rollData.diffLibre); }); html.find('#ptreve-variable').change((event) => { let ptreve = Misc.toInt(event.currentTarget.value); @@ -257,6 +253,29 @@ export class RdDRoll extends Dialog { }); } + async setSelectedSort(sort) { + this.rollData.selectedSort = sort; // Update the selectedCarac + this.rollData.competence = RdDItemCompetence.getVoieDraconic(this.rollData.draconicList, sort.data.draconic); + this.rollData.bonus = RdDItemSort.getCaseBonus(sort, this.rollData.tmr.coord); + this.rollData.diffLibre = RdDItemSort.getDifficulte(sort, -7); + RdDItemSort.setCoutReveReel(sort); + const htmlSortDescription = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/partial-description-sort.html", { sort: sort }); + $(".sort-ou-rituel").text(sort.data.isrituel ? "rituel" : "sort"); + $(".bonus-case").text(`${this.rollData.bonus}%`); + $(".details-sort").remove(); + $(".description-sort").append(htmlSortDescription); + $(".roll-draconic").val(sort.data.listIndex); + $(".div-sort-difficulte-fixe").text(Misc.toSignedString(sort.data.difficulte)); + $(".div-sort-ptreve-fixe").text(sort.data.ptreve); + const diffVariable = RdDItemSort.isDifficulteVariable(sort); + const coutVariable = RdDItemSort.isCoutVariable(sort); + HtmlUtility._showControlWhen($(".div-sort-non-rituel"), !sort.data.isrituel); + HtmlUtility._showControlWhen($(".div-sort-difficulte-var"), diffVariable); + HtmlUtility._showControlWhen($(".div-sort-difficulte-fixe"), !diffVariable); + HtmlUtility._showControlWhen($(".div-sort-ptreve-var"), coutVariable); + HtmlUtility._showControlWhen($(".div-sort-ptreve-fixe"), !coutVariable); + } + /* -------------------------------------------- */ async updateRollResult() { let rollData = this.rollData; @@ -270,11 +289,6 @@ export class RdDRoll extends Dialog { if (rollData.coupsNonMortels) { dmgText = `(${dmgText}) non-mortel` } - if (rollData.selectedSort) { - rollData.bonus = RdDItemSort.getCaseBonus(rollData.selectedSort, rollData.tmr.coord); - HtmlUtility._showControlWhen($("#div-sort-difficulte"), RdDItemSort.isDifficulteVariable(rollData.selectedSort)) - HtmlUtility._showControlWhen($("#div-sort-ptreve"), RdDItemSort.isCoutVariable(rollData.selectedSort)) - } RollDataAjustements.calcul(rollData, this.actor); rollData.finalLevel = this._computeFinalLevel(rollData); diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 2efb0b21..03a961e3 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -158,14 +158,14 @@ export class RdDUtility { 'systems/foundryvtt-reve-de-dragon/templates/dialog-astrologie-joueur.html', // Partials 'systems/foundryvtt-reve-de-dragon/templates/partial-description-overflow.html', + 'systems/foundryvtt-reve-de-dragon/templates/partial-description-sort.html', 'systems/foundryvtt-reve-de-dragon/templates/partial-roll-ajustements.html', 'systems/foundryvtt-reve-de-dragon/templates/partial-roll-diffLibre.html', 'systems/foundryvtt-reve-de-dragon/templates/partial-roll-diffCondition.html', 'systems/foundryvtt-reve-de-dragon/templates/partial-roll-surenc.html', 'systems/foundryvtt-reve-de-dragon/templates/partial-roll-enctotal.html', 'systems/foundryvtt-reve-de-dragon/templates/partial-roll-moral.html', - 'systems/foundryvtt-reve-de-dragon/templates/partial-select-carac.html', - + 'systems/foundryvtt-reve-de-dragon/templates/partial-select-carac.html', // Calendrier 'systems/foundryvtt-reve-de-dragon/templates/calendar-template.html', 'systems/foundryvtt-reve-de-dragon/templates/calendar-editor-template.html', diff --git a/templates/dialog-roll-sort.html b/templates/dialog-roll-sort.html index 4f36de4a..4501ef0c 100644 --- a/templates/dialog-roll-sort.html +++ b/templates/dialog-roll-sort.html @@ -1,66 +1,80 @@ +{{log 'lancer de sort' this}}
-
- - -
- -
- - - - -
- -
- - -
- -
- - -
- -
- - + {{#select sort}} + {{#each sortList as |sort key|}} + {{/each}} {{/select}} + + {{competence.name}} +
+
+
+ +
+
+ +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + + +
+ {{>"systems/foundryvtt-reve-de-dragon/templates/partial-roll-diffCondition.html"}} +
+ + +
+
+
+
+
+
+ {{> "systems/foundryvtt-reve-de-dragon/templates/partial-description-sort.html" sort=selectedSort}}
-
-
+ \ No newline at end of file diff --git a/templates/partial-description-sort.html b/templates/partial-description-sort.html new file mode 100644 index 00000000..1174e0c7 --- /dev/null +++ b/templates/partial-description-sort.html @@ -0,0 +1,10 @@ +
+ {{#if sort.data.cible}}{{/if}} + {{#if sort.data.JR}}{{/if}} + {{#if sort.data.portee}}{{/if}} + {{#if sort.data.duree}}{{/if}} + {{#if sort.data.coutseuil}}{{/if}} +
+
+ {{> "systems/foundryvtt-reve-de-dragon/templates/partial-description-overflow.html" sort.data}} +
\ No newline at end of file