From ca20330e29da0a73a88f7223eb6d4b41149c59f7 Mon Sep 17 00:00:00 2001 From: LeRatierBretonnier Date: Fri, 10 Jul 2026 20:21:25 +0200 Subject: [PATCH] feat: initiative par tirage de carte de tarot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Override Combatant.getInitiativeRoll pour piocher une carte du paquet de tarot au lieu de lancer 1d6. - Chaque combatant tire une carte → valeur = initiative - Les cartes vont à la défausse après usage - Fallback sur 1d6 si le paquet n'est pas disponible - globalThis.HamalronTarotDeckManager exposé pour l'override --- fvtt-hamalron.mjs | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/fvtt-hamalron.mjs b/fvtt-hamalron.mjs index a29d9df..67701d9 100644 --- a/fvtt-hamalron.mjs +++ b/fvtt-hamalron.mjs @@ -31,10 +31,38 @@ Hooks.once("init", function () { openTarotDeckManager: () => applications.HamalronTarotDeckManager.openManager(), } + // Global reference needed by initiative override + globalThis.HamalronTarotDeckManager = applications.HamalronTarotDeckManager + CONFIG.Combat.initiative = { - formula: '1d6', - decimals: 0 - }; + formula: "1d6", + decimals: 0, + } + + // Override initiative: draw a card from the tarot deck instead of rolling dice + Combatant.prototype.getInitiativeRoll = function (formula) { + const data = this.actor?.getRollData() ?? {} + const roll = new Roll(CONFIG.Combat.initiative.formula || "1d6", data) + const origEvaluate = roll.evaluate.bind(roll) + roll.evaluate = async function (options = {}) { + const deckManager = globalThis.HamalronTarotDeckManager?._instance + if (deckManager?.deck?.length > 0) { + const drawn = deckManager.drawCards(1) + if (drawn.length > 0) { + const card = drawn[0] + this._total = SYSTEM.TAROT_VALEURS[card.valeur]?.value ?? 0 + this._evaluated = true + this._dice = [] + this._terms = [{ results: [{ result: this._total }] }] + deckManager.addToDiscard(card) + await deckManager.saveDeckState() + return this + } + } + return origEvaluate(options) + } + return roll + } CONFIG.Actor.documentClass = documents.HamalronActor CONFIG.Actor.dataModels = {