diff --git a/module/actor.js b/module/actor.js index 677fea6f..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]); } @@ -541,9 +542,8 @@ export class RdDActor extends Actor { ChatMessage.create(message); } - /* -------------------------------------------- */ - async dormir(heures = 1) { + async dormir(heures) { let message = { whisper: ChatUtility.getWhisperRecipientsAndGMs(this.name), content: `${this.name}: Vous dormez ${heures == 1 ? 'une' : heures} heure${heures == 1 ? '' : 's'}.` @@ -552,9 +552,9 @@ export class RdDActor extends Actor { for (let i = 0; i < heures; i++) { await this._recupererEthylisme(message); await this.recupererFatigue(message); - await this.recuperationReve(message); + await this.recuperationReve(message, 1); if (EffetsDraconiques.isDonDoubleReve(this)) { - await this.recuperationReve(message); + await this.recuperationReve(message, 2); } } ChatMessage.create(message); @@ -620,11 +620,13 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ - async recuperationReve(message) { + async recuperationReve(message, demiHeure) { const seuil = Misc.templateData(this).reve.seuil.value; const reveActuel = this.getReveActuel(); if (reveActuel >= seuil) { - message.content += `Vous avez suffisament rêvé, au delà de votre seuil. `; + if (demiHeure == 1) { + message.content += `Vous avez suffisament rêvé, au delà de votre seuil. `; + } } else { let deRecuperation = (await DeDraconique.ddr("selfroll")).total; @@ -1967,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)]; } /* -------------------------------------------- */ @@ -2009,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) }, @@ -2028,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 }, { @@ -2035,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); } @@ -2095,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); @@ -2126,7 +2116,6 @@ export class RdDActor extends Actor { if (rollData.isSortReserve) { await this.sortMisEnReserve(rollData, selectedSort); - closeTMR = false; } } else { @@ -2146,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'); @@ -2320,7 +2309,7 @@ export class RdDActor extends Actor { { oeuvre: oeuvre, art: oeuvre.type, - competence: duplicate(Misc.data(this.getCompetence(oeuvre.data.competence ?? artData.art))), + competence: duplicate(Misc.data(this.getCompetence(artData.compName ?? oeuvre.data.competence ?? artData.art))), diffLibre: - (oeuvre.data.niveau ?? 0), diffConditions: 0, use: { libre: false, conditions: true }, @@ -2402,8 +2391,8 @@ export class RdDActor extends Actor { async rollRecetteCuisine(id) { const oeuvre = Misc.data(this.getRecetteCuisine(id)); const artData = { - art: 'cuisine', verbe: 'Cuisiner', + compName: 'cuisine', proportions: 1, ajouterEquipement: false }; diff --git a/module/de-draconique.js b/module/de-draconique.js index abfa4d45..4cd5d6bd 100644 --- a/module/de-draconique.js +++ b/module/de-draconique.js @@ -15,8 +15,7 @@ export class DeDraconique extends Roll{ evaluate() { super.evaluate(); const rerolls = Math.ceil(this.total / 8); - this.terms[this.terms.length - 1] = rerolls; - this.results[this.results.length - 1] = rerolls; + this.terms[this.terms.length - 1].number = rerolls; this._total -= rerolls; return this; } 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 5d690f0c..03a961e3 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -157,13 +157,15 @@ export class RdDUtility { 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-alchimie.html', '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/styles/simple.css b/styles/simple.css index d7fdb732..08607232 100644 --- a/styles/simple.css +++ b/styles/simple.css @@ -447,6 +447,16 @@ table {border: 1px solid #7a7971;} font-size: 0.70rem; text-align: right; } +.poesie-overflow { + color: rgba(82, 17, 131, 0.9); + max-height: 2.5rem; + overflow: hidden; +} +.poesie-overflow:hover { + max-height: unset; + overflow: visible; +} + /* ======================================== */ /* Sheet */ .window-app.sheet .window-content .sheet-header{ diff --git a/templates/dialog-roll-carac.html b/templates/dialog-roll-carac.html index e813a9bf..8d510bba 100644 --- a/templates/dialog-roll-carac.html +++ b/templates/dialog-roll-carac.html @@ -15,10 +15,8 @@ -