feat: boutons Sous tension et Opposé fonctionnels dans le chat
- Clic 'Sous tension' : tire une carte du deck, compare avec le score - Clic 'Opposé' : idem avec libellé Opposant - Résultat affiché dans un nouveau message de chat
This commit is contained in:
@@ -243,6 +243,75 @@ Hooks.on("createChatMessage", async (message, options, userId) => {
|
||||
})
|
||||
|
||||
|
||||
// Chat action buttons (Sous tension / Opposé)
|
||||
$(document).on("click", "[data-action='sousTension']", async function () {
|
||||
const msgEl = $(this).closest(".chat-message")
|
||||
const msgId = msgEl?.data("messageId")
|
||||
const msg = game.messages?.get(msgId)
|
||||
if (!msg) return
|
||||
|
||||
// Extract the player's total from the message content
|
||||
const totalText = msgEl.find(".calc-total")?.text()?.trim()
|
||||
const totalJoueur = Number(totalText) || 0
|
||||
const actorName = msg.speaker?.alias || "Inconnu"
|
||||
|
||||
// Draw a card and apply tension modifier (default 0)
|
||||
const deckManager = globalThis.HamalronTarotDeckManager?._instance
|
||||
if (!deckManager || deckManager.deck.length === 0) {
|
||||
ui.notifications.warn(game.i18n.localize("HAMALRON.Notifications.deckEmpty"))
|
||||
return
|
||||
}
|
||||
const drawn = deckManager.drawCards(1)
|
||||
if (!drawn.length) return
|
||||
const card = drawn[0]
|
||||
const valData = SYSTEM.TAROT_VALEURS[card.valeur]
|
||||
const valeurMJ = valData?.value ?? 0
|
||||
deckManager.addToDiscard(card)
|
||||
await deckManager.saveDeckState()
|
||||
|
||||
const totalMJ = valeurMJ
|
||||
const success = totalJoueur >= totalMJ
|
||||
ChatMessage.create({
|
||||
content: `<div class="fvtt-hamalron"><h3>${game.i18n.localize("HAMALRON.Label.sousTension")}</h3>
|
||||
<p><strong>${actorName}</strong>: ${totalJoueur} vs <strong>MJ</strong>: ${card.name} (${totalMJ})</p>
|
||||
<p>${success ? game.i18n.localize("HAMALRON.Label.success") : game.i18n.localize("HAMALRON.Label.failure")}</p></div>`,
|
||||
style: CONST.CHAT_MESSAGE_STYLES.OTHER,
|
||||
})
|
||||
})
|
||||
|
||||
$(document).on("click", "[data-action='oppose']", async function () {
|
||||
const msgEl = $(this).closest(".chat-message")
|
||||
const msgId = msgEl?.data("messageId")
|
||||
const msg = game.messages?.get(msgId)
|
||||
if (!msg) return
|
||||
|
||||
const totalText = msgEl.find(".calc-total")?.text()?.trim()
|
||||
const totalJoueur = Number(totalText) || 0
|
||||
const actorName = msg.speaker?.alias || "Inconnu"
|
||||
|
||||
// Draw opposition card
|
||||
const deckManager = globalThis.HamalronTarotDeckManager?._instance
|
||||
if (!deckManager || deckManager.deck.length === 0) {
|
||||
ui.notifications.warn(game.i18n.localize("HAMALRON.Notifications.deckEmpty"))
|
||||
return
|
||||
}
|
||||
const drawn = deckManager.drawCards(1)
|
||||
if (!drawn.length) return
|
||||
const card = drawn[0]
|
||||
const valData = SYSTEM.TAROT_VALEURS[card.valeur]
|
||||
const valeurOpposant = valData?.value ?? 0
|
||||
deckManager.addToDiscard(card)
|
||||
await deckManager.saveDeckState()
|
||||
|
||||
const success = totalJoueur >= valeurOpposant
|
||||
ChatMessage.create({
|
||||
content: `<div class="fvtt-hamalron"><h3>${game.i18n.localize("HAMALRON.Label.oppose")}</h3>
|
||||
<p><strong>${actorName}</strong>: ${totalJoueur} vs <strong>Opposant</strong>: ${card.name} (${valeurOpposant})</p>
|
||||
<p>${success ? game.i18n.localize("HAMALRON.Label.success") : game.i18n.localize("HAMALRON.Label.failure")}</p></div>`,
|
||||
style: CONST.CHAT_MESSAGE_STYLES.OTHER,
|
||||
})
|
||||
})
|
||||
|
||||
Hooks.on("hotbarDrop", (bar, data, slot) => {
|
||||
if (data.type === "Actor") {
|
||||
const actor = fromUuidSync(data.uuid)
|
||||
|
||||
Reference in New Issue
Block a user