From a41a178d46fe7bec1375dfe0c1ae131a7f813cbb Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Thu, 28 Nov 2024 00:43:39 +0100 Subject: [PATCH] Corrections des tirages tmr/rencontres MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - on n'affiche plus le compendium d'origine des rencontres dans le tchat - utilisation de ChatMessageData#rolls (compat future v14) - le résultat d'un d100 n'a pas à afficher de signe '%' - utilistaion des types de TMR plutôt que les noms en minuscules --- module/rdd-commands.js | 17 +++++++++-------- module/settings/system-compendiums.js | 9 +++------ module/tmr-rencontres.js | 13 +++++-------- module/tmr-utility.js | 12 ++++++------ templates/chat-compendium-table-roll.hbs | 7 +++++-- 5 files changed, 28 insertions(+), 30 deletions(-) diff --git a/module/rdd-commands.js b/module/rdd-commands.js index fcaa5b4f..aabd3dc0 100644 --- a/module/rdd-commands.js +++ b/module/rdd-commands.js @@ -360,13 +360,14 @@ export class RdDCommands { async getTMRAleatoire(msg, params) { if (params.length < 2) { - let type = params[0]; - const tmr = await TMRUtility.getTMRAleatoire(type ? (it => it.type == type) : (it => true)); - return RdDCommands._chatAnswer(msg, `Case aléatoire: ${tmr.coord} - ${tmr.label}`); - } - else { - return false; + let type = params[0] + const solvedTerrain = TMRUtility.findTMRLike(type)?.type + if (solvedTerrain){ + const tmr = await TMRUtility.getTMRAleatoire(type ? (it => it.type == solvedTerrain) : (it => true)) + return RdDCommands._chatAnswer(msg, `Case aléatoire: ${tmr.coord} - ${tmr.label}`) + } } + return false; } async findTMR(msg, params) { @@ -384,11 +385,11 @@ export class RdDCommands { async tableRencontres(msg, params) { if (params && params.length > 0) { const search = Misc.join(params, ' '); - const solvedTerrain = TMRUtility.findTMRLike(search); + const solvedTerrain = TMRUtility.findTMRLike(search) if (solvedTerrain == undefined) { return RdDCommands._chatAnswer(msg, 'Aucune TMR correspondant à ' + search); } - return await game.system.rdd.rencontresTMR.chatTable(solvedTerrain); + return await game.system.rdd.rencontresTMR.chatTable(solvedTMRType.name) } return false; } diff --git a/module/settings/system-compendiums.js b/module/settings/system-compendiums.js index dc631caf..317f2054 100644 --- a/module/settings/system-compendiums.js +++ b/module/settings/system-compendiums.js @@ -284,23 +284,20 @@ export class CompendiumTableHelpers { } /* -------------------------------------------- */ - static async tableRowToChatMessage(row, type = 'Item') { + static async tableRowToChatMessage(row, type, options = {showSource: true}) { if (!row) { return; } - const percentages = (row.total == 100) ? '%' : '' const flavorContent = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-compendium-table-roll.hbs', { roll: row.roll, document: row.document, - percentages, typeName: Misc.typeName(type, row.document?.type ?? 'objet'), isGM: game.user.isGM, + options }); const messageData = { - // flavor: flavorContent, user: game.user.id, - type: CONST.CHAT_MESSAGE_TYPES.ROLL, - roll: row.roll, + rolls: [row.roll], sound: CONFIG.sounds.dice, content: flavorContent }; diff --git a/module/tmr-rencontres.js b/module/tmr-rencontres.js index ef8ea61a..61ad4ead 100644 --- a/module/tmr-rencontres.js +++ b/module/tmr-rencontres.js @@ -26,22 +26,19 @@ export class TMRRencontres { * @param {*} forcedRoll */ async rollRencontre(terrain, forcedRoll) { - terrain = TMRUtility.findTMRLike(terrain); - if (terrain == undefined) { + const tmrType = TMRUtility.findTMRLike(terrain)?.type + if (tmrType == undefined) { return undefined; } if (forcedRoll && (forcedRoll <= 0 || forcedRoll > 100)) { forcedRoll = undefined; } - const codeTerrain = Grammar.toLowerCaseNoAccent(terrain) - const filtreMauvaise = codeTerrain == 'mauvaise' ? it => it.system.mauvaiseRencontre : it => !it.system.mauvaiseRencontre; - const frequence = it => it.system.frequence[codeTerrain]; + const filtreMauvaise = tmrType == 'mauvaise' ? it => it.system.mauvaiseRencontre : it => !it.system.mauvaiseRencontre; + const frequence = it => it.system.frequence[tmrType]; const row = await this.table.getRandom(frequence, filtreMauvaise, forcedRoll); if (row) { - console.log("DORM", row); - //row.document.system.computedForce = new Roll(row.document.system.formula).roll({async: false}).total; - await CompendiumTableHelpers.tableRowToChatMessage(row); + await CompendiumTableHelpers.tableRowToChatMessage(row, 'Item', {showSource: false}); } return row?.document; diff --git a/module/tmr-utility.js b/module/tmr-utility.js index c6010725..e8ae35e6 100644 --- a/module/tmr-utility.js +++ b/module/tmr-utility.js @@ -284,18 +284,18 @@ export class TMRUtility { static findTMRLike(type, options = { inclusMauvaise: true }) { const choix = [...Object.values(TMRType)] if (options.inclusMauvaise) { - choix.push({ name: 'Mauvaise' }); + choix.push({ name: 'Mauvaise', type: 'mauvaise'}); } - const selection = Misc.findAllLike(type, choix).map(it => it.name); + const selection = Misc.findAllLike(type, choix) if (selection.length == 0) { ui.notifications.warn(`Un type de TMR doit être indiqué, '${type}' n'est pas trouvé dans ${choix}`); - return undefined; + return undefined } if (selection.length > 1) { - ui.notifications.warn(`Plusieurs types de TMR pourraient correspondre à '${type}': ${selection}`); + ui.notifications.warn(`Plusieurs types de TMR pourraient correspondre à '${type}': ${selection.map(it => it.name)}`); return undefined; } - return selection[0]; + return selection[0] } static typeTmrName(type) { @@ -320,7 +320,7 @@ export class TMRUtility { /* -------------------------------------------- */ static deplacement(coordOrig, moveName) { const tmrMove = TMR_MOVE[moveName]; - if (! tmrMove) { + if (!tmrMove) { ui.notifications.error(`Le déplacement dans les TMR '${moveName}' est inconnu`) return coordOrig } diff --git a/templates/chat-compendium-table-roll.hbs b/templates/chat-compendium-table-roll.hbs index 2981d9af..2f5a76c0 100644 --- a/templates/chat-compendium-table-roll.hbs +++ b/templates/chat-compendium-table-roll.hbs @@ -1,6 +1,9 @@

Tirage aléatoire: {{document.name}}

-
Tirage de {{typeName}} aléatoire depuis {{document.pack}}
-
Jet {{roll.formula}} : {{roll.total}}{{percentages}}
+
+ Tirage de {{typeName}} aléatoire + {{#if options.showSource}} depuis {{document.pack}}{{/if}} +
+
Jet {{roll.formula}} : {{roll.total}}