Corrections des tirages tmr/rencontres
- 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
This commit is contained in:
parent
c6d64e09d5
commit
6af5a85dc1
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
};
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
<h4>Tirage aléatoire: {{document.name}}</h4>
|
||||
<div>Tirage de {{typeName}} aléatoire depuis {{document.pack}}</div>
|
||||
<div>Jet {{roll.formula}} : {{roll.total}}{{percentages}}</div>
|
||||
<div>
|
||||
Tirage de {{typeName}} aléatoire
|
||||
{{#if options.showSource}} depuis {{document.pack}}{{/if}}
|
||||
</div>
|
||||
<div>Jet {{roll.formula}} : {{roll.total}}</div>
|
||||
<hr>
|
||||
<div>
|
||||
<img class="chat-icon" src="{{document.img}}" data-tooltip="{{document.name}}" />
|
||||
|
Loading…
Reference in New Issue
Block a user