diff --git a/module/actor.js b/module/actor.js index f6882e78..ca2898d6 100644 --- a/module/actor.js +++ b/module/actor.js @@ -517,7 +517,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async sortMisEnReserve(rollData, sort) { let reserve = duplicate(this.data.data.reve.reserve); - reserve.list.push({ coord: rollData.coord, sort: sort, draconic: duplicate(rollData.selectedDraconic) }); + reserve.list.push({ coord: rollData.coord, sort: sort, draconic: duplicate(rollData.competence) }); await this.update({ "data.reve.reserve": reserve }); this.currentTMR.updateSortReserve(); } @@ -1319,7 +1319,7 @@ export class RdDActor extends Actor { selectedCarac: this.data.data.carac.reve, draconicList: this.getDraconicList(), sortList: sortList, - selectedDraconic: this.getBestDraconic(), + competence: this.getBestDraconic(), selectedSort: sortList[0], coord: coord, coordLabel: TMRUtility.getTMRDescription( coord).label, @@ -1447,82 +1447,67 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async _rollUnSortResult(rollData, isSortReserve = false) { - rollData.isSortReserve = isSortReserve; let rolled = rollData.rolled; - let sort = rollData.selectedSort; - let closeTMR = !rollData.isSortReserve; - if (sort.data.isrituel && isSortReserve) { - ui.notifications.error("Impossible de mettre le rituel '" + sort.name + "' en réserve"); + 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.show = {} + rollData.depenseReve = Number(selectedSort.data.ptreve_reel); - let explications = rollData.isSortReserve - ? ("
Mise en réserve du sort en " + rollData.coordLabel + "(" + rollData.coord + ")") - : "
Lancement du sort "; - explications += sort.name + " : " + Misc.upperFirst(sort.data.draconic) - + " pour " + sort.data.ptreve_reel + " points de Rêve" - + "
Depuis la case " + rollData.coord + " (" + TMRUtility.getTMRDescription(rollData.coord).label + ")"; - - let depenseReve = Number(sort.data.ptreve_reel); let myReve = duplicate(this.data.data.reve.reve); if (rolled.isSuccess) { // Réussite du sort ! - //sort.ptreve_reel = coutReve; if (rolled.isPart) { - depenseReve = Math.max(Math.floor(depenseReve / 2), 1); + rollData.depenseReve = Math.max(Math.floor(rollData.depenseReve / 2), 1); } if (rollData.isSortReserve) { - depenseReve++; + rollData.depenseReve++; } - if (myReve.value > depenseReve) { - explications += "
Réussite du sort: " + depenseReve + " points de Rêve sont dépensés (Bonus de case en " + rollData.coord + ": +" + rolled.bonus + "%)"; - + if (myReve.value > rollData.depenseReve) { // Incrémenter/gére le bonus de case - RdDItemSort.incrementBonusCase(this, sort, rollData.coord); - + RdDItemSort.incrementBonusCase(this, selectedSort, rollData.coord); + if (rollData.isSortReserve) { - await this.sortMisEnReserve(rollData, sort); + await this.sortMisEnReserve(rollData, selectedSort); closeTMR = false; } } else { - // Todo 0 pts de reve !!!! - depenseReve = 0; - explications += "
Pas assez de rêve"; - mergeObject(rollData, RdDResolutionTable.getResultat("echec")); + rollData.depenseReve = 0; + rollData.show.reveInsuffisant = true; + mergeObject(rollData.rolled, RdDResolutionTable.getResultat("echec"), {overwrite:true}); } } else { if (rolled.isETotal) { // Echec total ! - depenseReve = Math.min(myReve.value, Math.floor(depenseReve * 1.5)); - explications += "
Echec TOTAL du sort : " + depenseReve + " Points de Rêve"; + rollData.depenseReve = Math.min(myReve.value, Math.floor(rollData.depenseReve * 1.5)) // TODO: mise en réserve d'un échec total... } else { - depenseReve = 0 - explications += "
Echec du sort !"; + rollData.depenseReve = 0 } } - myReve.value = Math.max(myReve.value - depenseReve, 0); + myReve.value = Math.max(myReve.value - rollData.depenseReve, 0); await this.update({ "data.reve.reve": myReve }); - if (myReve.value == 0) { // 0 points de reve - ChatMessage.create({ content: this.name + " est réduit à 0 Points de Rêve, et tombe endormi !" }); - closeTMR = true; - } if (closeTMR) { this.currentTMR.close(); // Close TMR ! } else { this.currentTMR.maximize(); // Re-display TMR } // Final chat message - let chatOptions = { - content: "Test : " + rollData.selectedCarac.label + " / " + rollData.selectedDraconic.name + " / " + rollData.selectedSort.name + "" - + RdDResolutionTable.explainRollData(rollData) - + explications - } - + let chatOptions = { content: await RdDResolutionTable.explainRollDataV2(rollData, 'chat-resultat-sort.html') } ChatUtility.chatWithRollMode(chatOptions, this.name) + + if (myReve.value == 0) { // 0 points de reve + ChatMessage.create({ content: this.name + " est réduit à 0 Points de Rêve, et tombe endormi !" }); + closeTMR = true; + } } /* -------------------------------------------- */ diff --git a/module/rdd-resolution-table.js b/module/rdd-resolution-table.js index 09eb8338..bd9e97c4 100644 --- a/module/rdd-resolution-table.js +++ b/module/rdd-resolution-table.js @@ -70,7 +70,7 @@ export class RdDResolutionTable { /* -------------------------------------------- */ static getResultat(code) { - let resultat = reussites.filter(r => code == r.code); + let resultat = reussites.find(r => code == r.code); if (resultat == undefined) { resultat = reussites.find(r => r.code == "error"); } @@ -117,6 +117,9 @@ export class RdDResolutionTable { if (RdDResolutionTable.isAjustementAstrologique(rollData)) { list.push({ label: 'astrologique', value: rollData.ajustementAstrologique||0 }); } + if (rollData.rolled.bonus && rollData.selectedSort) { + list.push({ label: 'Bonus de case', value: rollData.rolled.bonus, unit: '%' }); + } return list; } diff --git a/module/rdd-roll.js b/module/rdd-roll.js index a35cb5a9..8230efe2 100644 --- a/module/rdd-roll.js +++ b/module/rdd-roll.js @@ -176,7 +176,7 @@ export class RdDRoll extends Dialog { }); html.find('#draconic').change((event) => { let draconicKey = Misc.toInt(event.currentTarget.value); - this.rollData.selectedDraconic = rollData.draconicList[draconicKey]; // Update the selectedCarac + this.rollData.competence = rollData.draconicList[draconicKey]; // Update the selectedCarac //console.log("RdDRollSelectDialog","CARAC CLICKED !!!", rollData); updateRollResult(rollData); }); @@ -245,7 +245,7 @@ export class RdDRoll extends Dialog { return Misc.toInt(rollData.competence.data.niveau); } if (rollData.draconicList) { - return Misc.toInt(rollData.selectedDraconic.data.niveau); + return Misc.toInt(rollData.competence.data.niveau); } return 0; } @@ -278,7 +278,7 @@ export class RdDRoll extends Dialog { return rollData.selectedCarac.label + "/" + rollData.competence.name + armeTitle + " " + niveau } if (rollData.draconicList) { - return rollData.selectedDraconic.name + " - " + rollData.selectedSort.name; + return rollData.competence.name + " - " + rollData.selectedSort.name; } return rollData.selectedCarac.label; } diff --git a/templates/chat-resultat-sort.html b/templates/chat-resultat-sort.html new file mode 100644 index 00000000..8da601a7 --- /dev/null +++ b/templates/chat-resultat-sort.html @@ -0,0 +1,40 @@ +

+ {{#if isSortReserve}}Mise en réserve{{else}}Lancement{{/if}} du sort {{selectedSort.name}} r{{selectedSort.data.ptreve_reel}} +
+ + {{competence.name}}: {{rolled.caracValue}} à {{numberFormat rolled.finalLevel decimals=0 sign=true}} +
+
Ajustements
+ {{#each ajustements as |item key|}} +
{{item.label}}: {{numberFormat item.value decimals=0 sign=true}}{{#if item.unit}}{{item.unit}}{{/if}}
+ {{/each}} +
+
+ {{#if rolled.needSignificative}}{{/if}} = + {{rolled.score}}% +

+
Pour {{selectedSort.data.ptreve_reel}} points de rêve en {{coordLabel}} ({{coord}})
+
+
+ {{rolled.roll}} : + {{rolled.quality}} + {{#if show.reveInsuffisant}}Pas assez de rêve!{{/if}} + + {{#if rolled.isETotal}} + Echec TOTAL du sort! + {{else if rolled.isEchec}} + Echec du sort, + {{else}} + Réussite du sort, + {{/if~}} + + + {{#if (eq depenseReve 0)}} + pas de dépense de rêve + {{else if (eq depenseReve 1)}} + 1 point de rêve a été dépensé + {{else}} + {{depenseReve}} points de rêve ont été dépensés + {{/if}} + +
\ No newline at end of file