Workable system, firt step

This commit is contained in:
2026-01-02 20:30:29 +01:00
parent 70d1720176
commit 8a27cef9a4
69 changed files with 6081 additions and 1767 deletions
+250 -35
View File
@@ -1,4 +1,5 @@
import HamalronActorSheet from "./base-actor-sheet.mjs"
import { SYSTEM } from "../../config/system.mjs"
export default class HamalronPersonnageSheet extends HamalronActorSheet {
/** @override */
@@ -20,6 +21,12 @@ export default class HamalronPersonnageSheet extends HamalronActorSheet {
createRitual: HamalronPersonnageSheet.#onCreateRitual,
createPerk: HamalronPersonnageSheet.#onCreatePerk,
modifyAmmo: HamalronPersonnageSheet.#onModifyAmmo,
modifyResistance: HamalronPersonnageSheet.#onModifyResistance,
discardCard: HamalronPersonnageSheet.#onDiscardCard,
rollCompetence: HamalronPersonnageSheet.#onRollCompetence,
drawCard: HamalronPersonnageSheet.#onDrawCard,
selectCard: HamalronPersonnageSheet.#onSelectCard,
discardAndDraw: HamalronPersonnageSheet.#onDiscardAndDraw,
},
}
@@ -31,18 +38,18 @@ export default class HamalronPersonnageSheet extends HamalronActorSheet {
tabs: {
template: "templates/generic/tab-navigation.hbs",
},
status: {
competences: {
template: "systems/fvtt-hamalron/templates/personnage-status.hbs",
},
maleficas: {
tarot: {
template: "systems/fvtt-hamalron/templates/personnage-tarot.hbs",
},
sortileges: {
template: "systems/fvtt-hamalron/templates/personnage-sortileges.hbs",
},
equipment: {
template: "systems/fvtt-hamalron/templates/personnage-equipement.hbs",
},
tarot: {
template: "systems/fvtt-hamalron/templates/personnage-tarot.hbs",
},
biography: {
template: "systems/fvtt-hamalron/templates/personnage-biographie.hbs",
},
@@ -50,7 +57,7 @@ export default class HamalronPersonnageSheet extends HamalronActorSheet {
/** @override */
tabGroups = {
sheet: "status",
sheet: "competences",
}
/**
@@ -59,10 +66,10 @@ export default class HamalronPersonnageSheet extends HamalronActorSheet {
*/
#getTabs() {
const tabs = {
status: { id: "status", group: "sheet", icon: "fa-solid fa-compass", label: "HAMALRON.Label.status" },
maleficas: { id: "maleficas", group: "sheet", icon: "fa-solid fa-compass", label: "HAMALRON.Label.maleficas" },
equipment: { id: "equipment", group: "sheet", icon: "fa-solid fa-shapes", label: "HAMALRON.Label.equipment" },
competences: { id: "competences", group: "sheet", icon: "fa-solid fa-list-check", label: "HAMALRON.Label.competences" },
tarot: { id: "tarot", group: "sheet", icon: "fa-solid fa-cards", label: "HAMALRON.Label.tarot" },
sortileges: { id: "sortileges", group: "sheet", icon: "fa-solid fa-wand-magic-sparkles", label: "HAMALRON.Label.sortileges" },
equipment: { id: "equipment", group: "sheet", icon: "fa-solid fa-shapes", label: "HAMALRON.Label.equipment" },
biography: { id: "biography", group: "sheet", icon: "fa-solid fa-book", label: "HAMALRON.Label.biography" },
}
for (const v of Object.values(tabs)) {
@@ -78,9 +85,6 @@ export default class HamalronPersonnageSheet extends HamalronActorSheet {
context.tabs = this.#getTabs()
const doc = this.document
context.trait = doc.itemTypes['species-trait']?.[0]
context.upright = doc.itemTypes.tarot.find(t => t.system.orientation === "Upright")
context.downright = doc.itemTypes.tarot.find(t => t.system.orientation === "Downright")
return context
}
@@ -91,30 +95,36 @@ export default class HamalronPersonnageSheet extends HamalronActorSheet {
context.systemFields = this.document.system.schema.fields
switch (partId) {
case "main":
// Get peuple and faction items (only one of each allowed)
context.peuple = doc.itemTypes.peuple?.[0] || null
context.faction = doc.itemTypes.faction?.[0] || null
context.isEditMode = this.isEditMode
context.isPlayMode = this.isPlayMode
break
case "status":
context.tab = context.tabs.status
context.perks = doc.itemTypes.perk || []
// Sort the perks by system.role and then by the system.level
context.perks.sort((a, b) => {
if (a.system.role === b.system.role) {
return a.system.level.localeCompare(b.system.level)
}
return a.system.role.localeCompare(b.system.role)
case "competences":
context.tab = context.tabs.competences
const allCompetences = doc.itemTypes.competence || []
// Ajouter les données de niveau enrichies à chaque compétence
allCompetences.forEach(c => {
const niveauData = SYSTEM.NIVEAU_COMPETENCES[c.system.niveau]
c.niveauName = niveauData?.name || c.system.niveau
c.niveauModificateur = niveauData?.modificateur ?? 0
})
// Grouper les compétences par type et trier par nom dans chaque groupe
context.competencesCommunes = allCompetences.filter(c => c.system.type === 'commune').sort((a, b) => a.name.localeCompare(b.name))
context.competencesPeuple = allCompetences.filter(c => c.system.type === 'peuple').sort((a, b) => a.name.localeCompare(b.name))
context.competencesFaction = allCompetences.filter(c => c.system.type === 'faction').sort((a, b) => a.name.localeCompare(b.name))
break;
case "maleficas":
context.tab = context.tabs.maleficas
context.maleficas = doc.itemTypes.malefica || []
// Sort the maleficas by system.domain and then by the system.level
context.maleficas.sort((a, b) => {
case "sortileges":
context.tab = context.tabs.sortileges
context.sortileges = doc.itemTypes.sortilege || []
// Sort the sortileges by system.domain and then by the system.level
context.sortileges.sort((a, b) => {
if (a.system.domain === b.system.domain) {
return a.system.level.localeCompare(b.system.level)
}
return a.system.domain.localeCompare(b.system.domain)
})
context.rituals = doc.itemTypes.ritual || []
context.rituals.sort((a, b) => a.name.localeCompare(b.name))
break
case "equipment":
context.tab = context.tabs.equipment
@@ -129,9 +139,23 @@ export default class HamalronPersonnageSheet extends HamalronActorSheet {
context.tab = context.tabs.tarot
context.tarotCards = doc.itemTypes.tarot || []
context.tarotCards.sort((a, b) => a.name.localeCompare(b.name))
// Enrich descriptions for each tarot card
context.handLimit = 7
context.handSize = context.tarotCards.length
context.isOverLimit = context.handSize > context.handLimit
context.canAddCard = context.handSize < 8
// Marquer les cartes de succès et enrichir les descriptions
for (const card of context.tarotCards) {
card.enrichedDescription = await foundry.applications.ux.TextEditor.implementation.enrichHTML(card.system.description, { async: true })
// Vérifier si c'est une carte de succès
if (doc.system.cartesSucces && card.system.type !== "atout") {
card.isSuccessCard = Object.keys(doc.system.cartesSucces).some(symbole => {
const successCardData = doc.system.cartesSucces[symbole]
return card.system.symbole === symbole &&
card.system.valeur === successCardData.value.toString()
})
} else {
card.isSuccessCard = false
}
}
break
case "biography":
@@ -196,6 +220,190 @@ export default class HamalronPersonnageSheet extends HamalronActorSheet {
await item.update({ "system.ammoQuantity": newAmmo })
}
static async #onModifyResistance(event, target) {
const symbole = target.dataset.symbole
const delta = Number.parseInt(target.dataset.delta)
if (!symbole || isNaN(delta)) {
console.warn(`HamalronPersonnageSheet: Invalid resistance modification parameters`)
return
}
const resistance = this.document.system.resistances[symbole]
if (!resistance) {
console.warn(`HamalronPersonnageSheet: Resistance ${symbole} not found`)
return
}
const newValue = Math.max(0, Math.min(resistance.max, resistance.value + delta))
await this.document.update({ [`system.resistances.${symbole}.value`]: newValue })
}
static async #onDiscardCard(event, target) {
const itemId = $(event.target).data("item-id")
const item = this.document.items.get(itemId)
if (!item || item.type !== "tarot") {
console.warn(`HamalronPersonnageSheet: Tarot card with ID ${itemId} not found`)
return
}
// Supprimer la carte du personnage
await item.delete()
ui.notifications.info(game.i18n.localize("HAMALRON.Notifications.cardDiscarded") + item.name)
}
static async #onSelectCard(event, target) {
const cardWrapper = $(target).closest(".tarot-card-wrapper")
const wasSelected = cardWrapper.hasClass("selected")
// Désélectionner toutes les cartes
$(".tarot-card-wrapper").removeClass("selected")
// Sélectionner la carte cliquée si elle n'était pas déjà sélectionnée
if (!wasSelected) {
cardWrapper.addClass("selected")
}
}
static async #onDiscardAndDraw(event, target) {
const itemId = $(target).data("item-id")
const item = this.document.items.get(itemId)
if (!item || item.type !== "tarot") {
console.warn(`HamalronPersonnageSheet: Tarot card with ID ${itemId} not found`)
return
}
// Dialog de confirmation
const confirmed = await foundry.applications.api.DialogV2.confirm({
window: {
title: game.i18n.localize("HAMALRON.Dialog.discardCardTitle"),
},
content: `<p>${game.i18n.format("HAMALRON.Dialog.discardCardContent", { cardName: item.name })}</p>`,
rejectClose: false,
modal: true,
})
if (!confirmed) return
// Récupérer le deck manager
const module = await import("../tarot-deck-manager.mjs")
const HamalronTarotDeckManager = module.default
if (!HamalronTarotDeckManager._instance) {
HamalronTarotDeckManager._instance = new HamalronTarotDeckManager()
}
const deckManager = HamalronTarotDeckManager._instance
if (!deckManager) {
ui.notifications.warn(game.i18n.localize("HAMALRON.Notifications.deckManagerNotAvailable"))
return
}
// Ajouter la carte à la défausse
deckManager.addToDiscard({
id: item.id,
name: item.name,
img: item.img,
symbole: item.system.symbole,
valeur: item.system.valeur,
type: item.system.type,
description: item.system.description,
})
// Supprimer la carte du personnage
await item.delete()
// Tirer une nouvelle carte si le deck n'est pas vide
if (deckManager.deck.length > 0) {
const newCards = deckManager.drawCards(1)
if (newCards.length > 0) {
const newCard = newCards[0]
// Cas spécial : Le Mat
if (newCard.valeur === "lemat") {
console.log("Le Mat drawn! Executing special rules...")
const { default: HamalronTirageTarot } = await import("../../documents/tirage-tarot.mjs")
await HamalronTirageTarot.handleLeMatEffect(this.document, deckManager)
} else {
const originalItem = game.items.get(newCard.id)
if (originalItem) {
await this.document.createEmbeddedDocuments("Item", [originalItem.toObject()])
ui.notifications.info(game.i18n.localize("HAMALRON.Notifications.cardDiscardedAndDrawn") + newCard.name)
}
}
}
} else {
ui.notifications.info(game.i18n.localize("HAMALRON.Notifications.cardDiscardedNoNew"))
}
deckManager.saveDeckState()
deckManager.render()
}
static async #onDrawCard(event, target) {
const currentTarotCount = this.document.items.filter(i => i.type === "tarot").length
// Vérifier que le joueur a moins de 7 cartes
if (currentTarotCount >= 7) {
ui.notifications.warn(game.i18n.localize("HAMALRON.Notifications.cannotDrawCard"))
return
}
// Récupérer le deck manager singleton
const module = await import("../tarot-deck-manager.mjs")
const HamalronTarotDeckManager = module.default
// Vérifier si l'instance existe, sinon la créer
if (!HamalronTarotDeckManager._instance) {
HamalronTarotDeckManager._instance = new HamalronTarotDeckManager()
}
const deckManager = HamalronTarotDeckManager._instance
if (!deckManager) {
ui.notifications.warn(game.i18n.localize("HAMALRON.Notifications.deckManagerNotAvailable"))
return
}
if (deckManager.deck.length === 0) {
ui.notifications.warn(game.i18n.localize("HAMALRON.Notifications.deckEmpty"))
return
}
// Tirer une nouvelle carte
const newCards = deckManager.drawCards(1)
if (newCards.length > 0) {
const newCard = newCards[0]
// Cas spécial : Le Mat
if (newCard.valeur === "lemat") {
console.log("Le Mat drawn! Executing special rules...")
const { default: HamalronTirageTarot } = await import("../../documents/tirage-tarot.mjs")
await HamalronTirageTarot.handleLeMatEffect(this.document, deckManager)
} else {
// Trouver l'item original pour le dupliquer
const originalItem = game.items.get(newCard.id)
if (originalItem) {
await this.document.createEmbeddedDocuments("Item", [originalItem.toObject()])
ui.notifications.info(game.i18n.localize("HAMALRON.Notifications.newCardDrawn") + newCard.name)
}
}
deckManager.saveDeckState()
deckManager.render()
}
}
static async #onRollCompetence(event, target) {
const itemId = $(target).data("item-id")
const item = this.document.items.get(itemId)
if (!item || item.type !== "competence") {
console.warn(`HamalronPersonnageSheet: Competence with ID ${itemId} not found`)
return
}
await this.document.system.roll("competence", item)
}
/**
* Handles the roll action triggered by user interaction.
*
@@ -239,12 +447,19 @@ export default class HamalronPersonnageSheet extends HamalronActorSheet {
if (data.type === "Item") {
const item = await fromUuid(data.uuid)
if (item.type === "tarot") {
// Delete the existing tarot item
const existingTarot = this.document.items.find(i => i.type === "tarot" && i.system.orientation === item.system.orientation)
if (existingTarot) {
await existingTarot.delete()
// Display info message
ui.notifications.info(game.i18n.localize("HAMALRON.Notifications.tarotDeleted") + existingTarot.name)
// Check if a card with the same name already exists
const existingCard = this.document.items.find(i => i.type === "tarot" && i.name === item.name)
if (existingCard) {
ui.notifications.warn(game.i18n.localize("HAMALRON.Notifications.tarotCardAlreadyExists") + item.name)
return
}
const currentTarotCount = this.document.items.filter(i => i.type === "tarot").length
// Check if we already have 8 cards (hard limit)
if (currentTarotCount >= 8) {
ui.notifications.warn(game.i18n.localize("HAMALRON.Notifications.tarotHandFull"))
return
}
}
if (item.type === "species-trait") {
+347 -7
View File
@@ -4,8 +4,8 @@ export default class HamalronTarotDeckManager extends HandlebarsApplicationMixin
constructor(options = {}) {
super(options)
this.deck = []
this.drawnCards = []
this.resetDeck()
this.discard = []
this.loadDeckState()
}
/** @override */
@@ -26,6 +26,10 @@ export default class HamalronTarotDeckManager extends HandlebarsApplicationMixin
resetDeck: HamalronTarotDeckManager.#onResetDeck,
drawCard: HamalronTarotDeckManager.#onDrawCard,
drawMultiple: HamalronTarotDeckManager.#onDrawMultiple,
shuffleDiscard: HamalronTarotDeckManager.#onShuffleDiscard,
collectHands: HamalronTarotDeckManager.#onCollectHands,
distributeCards: HamalronTarotDeckManager.#onDistributeCards,
drawTension: HamalronTarotDeckManager.#onDrawTension,
},
}
@@ -36,12 +40,39 @@ export default class HamalronTarotDeckManager extends HandlebarsApplicationMixin
},
}
/**
* Save the current deck state to settings
*/
async saveDeckState() {
const state = {
deck: this.deck,
discard: this.discard,
}
await game.settings.set("fvtt-hamalron", "tarotDeckState", state)
console.log("Deck state saved:", state)
}
/**
* Load the deck state from settings
*/
loadDeckState() {
const state = game.settings.get("fvtt-hamalron", "tarotDeckState")
if (state && state.deck && state.deck.length > 0) {
this.deck = state.deck
this.discard = state.discard || []
console.log("Deck state loaded:", state)
} else {
// Si aucun état sauvegardé, initialiser un nouveau deck
this.resetDeck()
}
}
/**
* Reset the deck to a full tarot deck
*/
resetDeck() {
this.deck = []
this.drawnCards = []
this.discard = []
// Créer toutes les cartes du jeu de tarot
const items = game.items.filter(i => i.type === "tarot")
@@ -63,6 +94,7 @@ export default class HamalronTarotDeckManager extends HandlebarsApplicationMixin
// Mélanger le deck
this.shuffleDeck()
this.saveDeckState()
this.render()
}
@@ -90,7 +122,6 @@ export default class HamalronTarotDeckManager extends HandlebarsApplicationMixin
const drawn = []
for (let i = 0; i < count && this.deck.length > 0; i++) {
const card = this.deck.shift()
this.drawnCards.push(card)
drawn.push(card)
}
@@ -130,10 +161,10 @@ export default class HamalronTarotDeckManager extends HandlebarsApplicationMixin
const context = await super._prepareContext(options)
context.deckCount = this.deck.length
context.drawnCount = this.drawnCards.length
context.totalCards = this.deck.length + this.drawnCards.length
context.discardCount = this.discard.length
context.totalCards = this.deck.length + this.discard.length
context.hasCards = this.deck.length > 0
context.drawnCards = this.drawnCards.slice(-5).reverse() // Show last 5 drawn cards
context.hasDiscard = this.discard.length > 0
return context
}
@@ -166,6 +197,9 @@ export default class HamalronTarotDeckManager extends HandlebarsApplicationMixin
const cards = this.drawCards(1)
if (cards.length > 0) {
await this.sendCardsToChat(cards)
// Ajouter les cartes directement à la défausse
cards.forEach(card => this.addToDiscard(card))
this.saveDeckState()
this.render()
}
}
@@ -180,10 +214,316 @@ export default class HamalronTarotDeckManager extends HandlebarsApplicationMixin
const cards = this.drawCards(count)
if (cards.length > 0) {
await this.sendCardsToChat(cards)
// Ajouter les cartes directement à la défausse
cards.forEach(card => this.addToDiscard(card))
this.saveDeckState()
this.render()
}
}
/**
* Add a card to the discard pile
* @param {Object} card - Card to add to discard
*/
addToDiscard(card) {
// Vérifier que la carte n'est pas déjà dans la défausse
const cardExists = this.discard.some(c => c.id === card.id)
if (!cardExists) {
this.discard.push(card)
this.saveDeckState()
this.render()
}
}
/**
* Collect all tarot cards from player characters and return them to the deck
* @param {Event} event
* @param {HTMLElement} target
*/
static async #onCollectHands(event, target) {
const confirmed = await foundry.applications.api.DialogV2.confirm({
window: { title: game.i18n.localize("HAMALRON.TarotDeck.CollectHandsConfirm") },
content: `<p>${game.i18n.localize("HAMALRON.TarotDeck.CollectHandsWarning")}</p>`,
rejectClose: false,
modal: true,
})
if (!confirmed) return
let totalCollected = 0
// Récupérer tous les acteurs de type personnage (incluant tous, pas seulement ceux avec propriété joueur)
const playerCharacters = game.actors.filter(a => a.type === "personnage")
console.log("Found characters:", playerCharacters.length)
// Collecter toutes les cartes de tarot de tous les personnages
for (const actor of playerCharacters) {
const tarotCards = actor.items.filter(i => i.type === "tarot")
console.log(`Actor ${actor.name} has ${tarotCards.length} tarot cards`)
if (tarotCards.length > 0) {
// Supprimer les cartes de l'acteur
const cardIds = tarotCards.map(c => c.id)
console.log(`Deleting ${cardIds.length} cards from ${actor.name}`)
await actor.deleteEmbeddedDocuments("Item", cardIds)
console.log(`Deleted cards from ${actor.name}`)
totalCollected += tarotCards.length
}
}
// Réinitialiser le deck avec toutes les cartes de tarot disponibles
this.deck = []
this.discard = []
const items = game.items.filter(i => i.type === "tarot")
if (items.length > 0) {
// Créer un Map pour éviter les doublons (utiliser l'ID unique)
const uniqueCards = new Map()
items.forEach(item => {
const key = `${item.system.symbole}_${item.system.valeur}_${item.system.type}`
if (!uniqueCards.has(key)) {
uniqueCards.set(key, {
id: item.id,
name: item.name,
img: item.img,
symbole: item.system.symbole,
valeur: item.system.valeur,
type: item.system.type,
description: item.system.description,
})
}
})
this.deck = Array.from(uniqueCards.values())
}
// Mélanger le deck
this.shuffleDeck()
this.saveDeckState()
ui.notifications.info(
game.i18n.format("HAMALRON.TarotDeck.HandsCollected", {
collected: totalCollected,
deckSize: this.deck.length
})
)
this.render()
}
/**
* Distribute 8 cards to all connected players
* @param {Event} event
* @param {HTMLElement} target
*/
static async #onDistributeCards(event, target) {
if (this.deck.length < 8) {
ui.notifications.warn(game.i18n.localize("HAMALRON.TarotDeck.NotEnoughCards"))
return
}
const confirmed = await foundry.applications.api.DialogV2.confirm({
window: { title: game.i18n.localize("HAMALRON.TarotDeck.DistributeConfirm") },
content: `<p>${game.i18n.localize("HAMALRON.TarotDeck.DistributeWarning")}</p>`,
rejectClose: false,
modal: true,
})
if (!confirmed) return
let distributedCount = 0
let playersCount = 0
// Récupérer tous les utilisateurs connectés (sauf le GM)
const connectedPlayers = game.users.filter(u => u.active && !u.isGM)
for (const user of connectedPlayers) {
// Trouver le personnage du joueur (premier actor de type personnage dont il est propriétaire)
const playerCharacter = game.actors.find(a =>
a.type === "personnage" &&
a.testUserPermission(user, "OWNER")
)
if (playerCharacter) {
// Tirer 8 cartes pour ce personnage
const cardsToDistribute = []
for (let i = 0; i < 8 && this.deck.length > 0; i++) {
const card = this.deck.shift()
cardsToDistribute.push(card)
}
// Créer les items sur l'acteur
for (const card of cardsToDistribute) {
const originalItem = game.items.get(card.id)
if (originalItem) {
await playerCharacter.createEmbeddedDocuments("Item", [originalItem.toObject()])
distributedCount++
// Cas spécial : Le Mat
if (card.valeur === "lemat") {
console.log(`Le Mat distributed to ${playerCharacter.name}! Executing special rules...`)
// Import de TirageTarot pour accéder à la fonction helper
const { default: HamalronTirageTarot } = await import("../documents/tirage-tarot.mjs")
await HamalronTirageTarot.handleLeMatEffect(playerCharacter, this)
}
}
}
playersCount++
}
}
this.saveDeckState()
ui.notifications.info(
game.i18n.format("HAMALRON.TarotDeck.CardsDistributed", {
cards: distributedCount,
players: playersCount
})
)
this.render()
}
/**
* Shuffle discard pile back into deck
* @param {Event} event
* @param {HTMLElement} target
*/
static async #onShuffleDiscard(event, target) {
if (this.discard.length === 0) {
ui.notifications.warn(game.i18n.localize("HAMALRON.TarotDeck.NoDiscard"))
return
}
// Ajouter toutes les cartes de la défausse au deck
this.deck.push(...this.discard)
this.discard = []
// Mélanger le deck
this.shuffleDeck()
this.saveDeckState()
ui.notifications.info(game.i18n.localize("HAMALRON.TarotDeck.DiscardShuffled"))
this.render()
}
/**
* Handle draw tension action
* @param {Event} event
* @param {HTMLElement} target
*/
static async #onDrawTension(event, target) {
// Import system config
const { DIFFICULTY_CHOICES } = await import('../config/system.mjs')
// Créer les options de difficulté
const difficulties = Object.entries(DIFFICULTY_CHOICES)
.filter(([key]) => key !== 'soustension_oppose')
.map(([key, value]) => ({
value: key,
label: value.label
}))
// Créer le contenu HTML du dialogue
const selectOptions = difficulties.map(d =>
`<option value="${d.value}">${d.label}</option>`
).join('')
const content = `
<div class="form-group">
<label>{{localize "HAMALRON.Label.difficulty"}}</label>
<select id="tension-difficulty" style="width: 100%;">
${selectOptions}
</select>
</div>
`
// Afficher le dialogue
const result = await foundry.applications.api.DialogV2.wait({
window: { title: game.i18n.localize("HAMALRON.TarotDeck.SelectDifficulty") },
content: content,
buttons: [
{
action: "draw",
label: game.i18n.localize("HAMALRON.TarotDeck.DrawCard"),
default: true,
callback: (event, button, dialog) => {
const select = button.form.elements["tension-difficulty"]
return select.value
}
},
{
action: "cancel",
label: game.i18n.localize("Cancel")
}
],
rejectClose: false,
modal: true
})
if (!result) return
// Tirer une carte
const cards = this.drawCards(1)
if (cards.length === 0) return
const card = cards[0]
const difficultyKey = result
const difficulty = DIFFICULTY_CHOICES[difficultyKey]
// Récupérer la valeur numérique de la carte
const { TAROT_VALEURS } = await import('../config/system.mjs')
const cardValue = TAROT_VALEURS[card.valeur]?.value || 0
const tensionBonus = difficulty.soustension || 0
const totalScore = cardValue + tensionBonus
// Afficher dans le chat
await this.sendTensionDrawToChat(card, difficulty, cardValue, tensionBonus, totalScore)
// Ajouter à la défausse
this.addToDiscard(card)
this.saveDeckState()
this.render()
}
/**
* Send tension draw to chat
* @param {Object} card - The drawn card
* @param {Object} difficulty - The selected difficulty
* @param {number} cardValue - Card numeric value
* @param {number} tensionBonus - Tension modifier
* @param {number} totalScore - Total score
*/
async sendTensionDrawToChat(card, difficulty, cardValue, tensionBonus, totalScore) {
const speaker = ChatMessage.getSpeaker({ alias: "Maître du Jeu" })
const content = await foundry.applications.handlebars.renderTemplate(
"systems/fvtt-hamalron/templates/chat-tarot-tension.hbs",
{
card: card,
symboleLabel: game.i18n.localize(`HAMALRON.Tarot.FIELDS.symbole.${card.symbole}`),
valeurLabel: game.i18n.localize(`HAMALRON.Tarot.FIELDS.valeur.${card.valeur}`),
typeLabel: game.i18n.localize(`HAMALRON.Tarot.FIELDS.type.${card.type}`),
difficulty: difficulty,
cardValue: cardValue,
tensionBonus: tensionBonus,
totalScore: totalScore
}
)
await ChatMessage.create({
speaker: speaker,
content: content,
type: CONST.CHAT_MESSAGE_TYPES.OTHER,
})
}
/**
* Open the Tarot Deck Manager application
* @returns {HamalronTarotDeckManager}