/** * InnRoller * Classe de gestion des jets de tables d'auberge pour WFRP4e * Module de traduction française */ export default class InnRoller { static tableNames = { 'boissonsbase': 'BoissonsBase', 'boissonsfortes': 'BoissonsFortes', 'desserts': 'Desserts', 'platscommuns': 'PlatsCommuns', 'platsexcellents': 'PlatsExcellents', 'platsmaritimes': 'PlatsMaritimes', 'platsmediocres': 'PlatsMédiocres', 'platsqualite': 'PlatsQualité', 'platsrivieres': 'PlatsRivières' }; static displayNames = { 'BoissonsBase': 'Boissons de Base', 'BoissonsFortes': 'Boissons Fortes', 'Desserts': 'Desserts', 'PlatsCommuns': 'Plats Communs', 'PlatsExcellents': 'Plats Excellents', 'PlatsMaritimes': 'Plats Maritimes', 'PlatsMédiocres': 'Plats Médiocres', 'PlatsQualité': 'Plats de Qualité', 'PlatsRivières': 'Plats de Rivières' }; /** * Obtient le nom d'affichage formaté pour une table * @param {String} tableName * @returns {String} */ static getDisplayName(tableName) { return this.displayNames[tableName] || tableName; } /** * Normalise le nom d'une table (enlève accents, espaces, met en minuscules) * @param {String} name * @returns {String} */ static normalizeTableName(name) { return name .toLowerCase() .normalize("NFD") .replace(/[\u0300-\u036f]/g, "") .replace(/\s+/g, ''); } /** * Trouve la table correspondant au mot-clé * @param {String} keyword * @returns {String|null} */ static findTableByKeyword(keyword) { if (!keyword) return null; const normalized = this.normalizeTableName(keyword); // Recherche exacte if (this.tableNames[normalized]) { return this.tableNames[normalized]; } // Recherche partielle for (let [key, value] of Object.entries(this.tableNames)) { if (key.includes(normalized) || normalized.includes(key)) { return value; } } return null; } /** * Lance un jet sur une table d'auberge * @param {String} keyword Mot-clé pour identifier la table */ static async rollInnTable(keyword) { console.log(`InnRoller: rollInnTable appelé avec keyword="${keyword}"`); // Si pas de keyword, afficher l'aide if (!keyword) { this.displayHelp(); return; } // Rechercher la table const tableName = this.findTableByKeyword(keyword); if (!tableName) { this.displayHelp(); ui.notifications.warn(`Table d'auberge introuvable pour le mot-clé: "${keyword}"`); return; } console.log(`InnRoller: Table trouvée: ${tableName}`); // Charger le compendium const compendium = game.packs.get('wh4-fr-translation.plats-dauberges'); if (!compendium) { ui.notifications.error("Compendium 'plats-dauberges' introuvable"); console.error("InnRoller: Compendium wh4-fr-translation.plats-dauberges non trouvé"); return; } // Récupérer les tables const tables = await compendium.getDocuments(); // Trouver la table correspondante const rollTable = tables.find(t => t.name === tableName); if (!rollTable) { ui.notifications.error(`Table "${tableName}" non trouvée dans le compendium`); console.error(`InnRoller: Table ${tableName} non trouvée`); return; } console.log(`InnRoller: Jet sur la table ${rollTable.name}`); // Effectuer le jet sans affichage automatique try { const roll = await rollTable.draw({ displayChat: false }); console.log(`InnRoller: Jet effectué avec succès`, roll); // Créer un message personnalisé await this.displayRollResult(rollTable.name, roll); } catch (error) { console.error("InnRoller: Erreur lors du jet:", error); ui.notifications.error("Erreur lors du jet sur la table d'auberge"); } } /** * Affiche le résultat d'un jet de table avec un style personnalisé * @param {String} tableName Nom de la table * @param {Object} rollResult Résultat du jet */ static async displayRollResult(tableName, rollResult) { // Déterminer l'icône en fonction du type de table let icon = "fa-utensils"; let category = "Plat"; if (tableName.toLowerCase().includes('boisson')) { icon = "fa-wine-glass"; category = "Boisson"; } else if (tableName.toLowerCase().includes('dessert')) { icon = "fa-birthday-cake"; category = "Dessert"; } // Extraire les informations du résultat const resultText = rollResult.results[0]?.text || "Résultat inconnu"; const rollFormula = rollResult.roll?.formula || "1d100"; const rollTotal = rollResult.roll?.total || 0; // Construire le message HTML simplifié let message = `
Usage: /auberge [mot_clé]
Vous pouvez aussi taper /auberge [mot_clé] directement (ex: /auberge base)