feat: initiative par tirage de carte de tarot
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
This commit is contained in:
+31
-3
@@ -31,10 +31,38 @@ Hooks.once("init", function () {
|
|||||||
openTarotDeckManager: () => applications.HamalronTarotDeckManager.openManager(),
|
openTarotDeckManager: () => applications.HamalronTarotDeckManager.openManager(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Global reference needed by initiative override
|
||||||
|
globalThis.HamalronTarotDeckManager = applications.HamalronTarotDeckManager
|
||||||
|
|
||||||
CONFIG.Combat.initiative = {
|
CONFIG.Combat.initiative = {
|
||||||
formula: '1d6',
|
formula: "1d6",
|
||||||
decimals: 0
|
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.documentClass = documents.HamalronActor
|
||||||
CONFIG.Actor.dataModels = {
|
CONFIG.Actor.dataModels = {
|
||||||
|
|||||||
Reference in New Issue
Block a user