diff --git a/fvtt-hamalron.mjs b/fvtt-hamalron.mjs index 4cb9cda..908047e 100644 --- a/fvtt-hamalron.mjs +++ b/fvtt-hamalron.mjs @@ -44,6 +44,7 @@ Hooks.once("init", function () { Combatant.prototype.getInitiativeRoll = function (formula) { const data = this.actor?.getRollData() ?? {} const roll = new Roll("1d6", data) + const combatantName = this.name const origEvaluate = roll.evaluate.bind(roll) roll.evaluate = async function (options = {}) { const deckManager = globalThis.HamalronTarotDeckManager?._instance @@ -55,6 +56,13 @@ Hooks.once("init", function () { this._total = val this._evaluated = true this._formula = `${card.name} (${val})` + this.options.cardDraw = { + name: card.name, + img: card.img, + valeur: card.valeur, + value: val, + } + if (combatantName) globalThis._initiativeCardMap.set(combatantName, this.options.cardDraw) deckManager.addToDiscard(card) await deckManager.saveDeckState() return this @@ -190,7 +198,38 @@ Hooks.on("getSceneControlButtons", (controls) => { } }) -Hooks.on("renderChatMessageHTML", (message, html, data) => { +// Store card info from initiative rolls for the chat hook +globalThis._initiativeCardMap = new Map() +Hooks.on("createChatMessage", async (message, options, userId) => { + const speakerName = message.speaker?.alias + if (!speakerName) return + const card = globalThis._initiativeCardMap.get(speakerName) + if (!card) return + globalThis._initiativeCardMap.delete(speakerName) + + await new Promise(r => setTimeout(r, 50)) + const actor = game.actors.getName(speakerName) + const actorImg = actor?.img || "icons/svg/mystery-man.svg" + const total = message.rolls?.[0]?.total ?? "" + const content = ` +
+
+
+ + ${speakerName} +
+
${total}
+
+
+ ${card.name} +
+ ${card.name} + ${game.i18n.localize("HAMALRON.Initiative.Value")} : ${card.value} +
+
+ +
` + await message.update({ content }) }) diff --git a/lang/fr.json b/lang/fr.json index 387995c..2bef2a0 100644 --- a/lang/fr.json +++ b/lang/fr.json @@ -839,6 +839,10 @@ "Last": "Dernière récup", "Success": "Récupération réussie ! +1 en {label}", "Failure": "Échec de la récupération en {label}. Réessayez demain." + }, + "Initiative": { + "Title": "Initiative", + "Value": "Valeur" } } } \ No newline at end of file diff --git a/templates/chat-initiative.hbs b/templates/chat-initiative.hbs new file mode 100644 index 0000000..c5ba987 --- /dev/null +++ b/templates/chat-initiative.hbs @@ -0,0 +1,23 @@ +
+
+
+ + {{actorName}} +
+
+ {{total}} +
+
+ {{#if card}} +
+ {{card.name}} +
+ {{card.name}} + {{localize "HAMALRON.Initiative.Value"}} : {{cardValue}} +
+
+ {{/if}} + +