diff --git a/fvtt-hamalron.mjs b/fvtt-hamalron.mjs
index fda3618..2c0e7ba 100644
--- a/fvtt-hamalron.mjs
+++ b/fvtt-hamalron.mjs
@@ -237,9 +237,11 @@ function addChatTools() {
game.system.api.openActionComplexe()
})
}
- addBtn("fas fa-dice", "Épreuve", "Lancer une épreuve standard", () => {
- const actor = game.user?.character || game.actors?.find(a => a.type === "personnage")
- if (actor) actor.system?.roll?.("stat", { name: "Épreuve", value: 0 })
+ addBtn("fas fa-cards", "Épreuve", "Lancer une épreuve (choisir une carte)", async () => {
+ const actor = game.user?.character || game.actors?.find(a => a.type === "personnage" && a.testUserPermission(game.user, "OWNER"))
+ if (!actor) { ui.notifications.warn("Aucun personnage trouvé"); return }
+ const { default: HamalronTirageTarot } = await import("./module/documents/tirage-tarot.mjs")
+ await HamalronTirageTarot.promptEpreuve(actor)
})
controls.parentNode.insertBefore(tools, controls)
diff --git a/module/documents/tirage-tarot.mjs b/module/documents/tirage-tarot.mjs
index 5b35123..425334f 100644
--- a/module/documents/tirage-tarot.mjs
+++ b/module/documents/tirage-tarot.mjs
@@ -90,6 +90,138 @@ export default class HamalronTirageTarot extends Roll {
ui.notifications.info(`Le Mat ! Toutes vos cartes ont été défaussées et vous recevez 7 nouvelles cartes. Le deck a été mélangé.`)
}
+ // Carte de symbole par défaut pour les épreuves sans compétence
+ static async promptEpreuve(actor) {
+ const tarotCards = actor.items.filter(i => i.type === "tarot")
+ if (tarotCards.length === 0) {
+ ui.notifications.warn(game.i18n.localize("HAMALRON.Notifications.noTarotCards"))
+ return
+ }
+
+ const cardData = tarotCards.map(c => ({
+ id: c.id,
+ name: c.name,
+ img: c.img,
+ valeur: c.system.valeur,
+ symbole: c.system.symbole,
+ type: c.system.type,
+ valeurNumerique: HamalronTirageTarot.#vNumerique(c.system.valeur),
+ }))
+
+ const content = `
+
+
+
+
+
`
+
+ const result = await foundry.applications.api.DialogV2.wait({
+ window: { title: game.i18n.localize("HAMALRON.Label.titleStandard") },
+ classes: ["fvtt-hamalron"],
+ position: { width: 420 },
+ content,
+ buttons: [{ action: "roll", label: game.i18n.localize("HAMALRON.Roll.roll"), default: true, callback: (e, btn) => {
+ const selected = btn.form.querySelector('.tarot-card-select.selected')
+ if (!selected) return null
+ return {
+ cardId: selected.dataset.cardId,
+ cardValue: Number(selected.dataset.cardValue) || 0,
+ difficulty: Number(btn.form.querySelector('.difficulty-select-epreuve')?.value || 3),
+ }
+ }}, { action: "cancel", label: game.i18n.localize("HAMALRON.Roll.cancel") }],
+ rejectClose: false,
+ render: () => {
+ $(document).off(".epreuve")
+ $(document).on("click.epreuve", ".tarot-card-select", function () {
+ $(".tarot-card-select").removeClass("selected")
+ $(this).addClass("selected")
+ const val = Number($(this).data("cardValue")) || 0
+ $("#card-value-display").text(`+ ${val}`)
+ $("#total-value").text(String(val))
+ })
+ $(document).on("change.epreuve", ".difficulty-select-epreuve", function () {
+ $("#target-score").text($(this).val())
+ })
+ },
+ })
+
+ if (!result) return
+
+ const cardItem = actor.items.get(result.cardId)
+ const isSuccess = result.cardValue >= result.difficulty
+
+ // Card used: move to discard
+ const deckModule = await import("../applications/tarot-deck-manager.mjs")
+ const DM = deckModule.default
+ if (DM._instance) {
+ DM._instance.addToDiscard({
+ id: cardItem.id, name: cardItem.name, img: cardItem.img,
+ symbole: cardItem.system.symbole, valeur: cardItem.system.valeur,
+ type: cardItem.system.type,
+ })
+ await DM._instance.saveDeckState()
+ }
+ if (cardItem) await actor.deleteEmbeddedDocuments("Item", [cardItem.id])
+
+ // Draw replacement
+ if (DM._instance?.deck?.length > 0) {
+ const drawn = DM._instance.drawCards(1)
+ if (drawn.length > 0) {
+ const orig = await HamalronUtils.findTarotItem(drawn[0])
+ if (orig) await actor.createEmbeddedDocuments("Item", [orig.toObject()])
+ }
+ await DM._instance.saveDeckState()
+ }
+
+ ChatMessage.create({
+ user: game.user.id,
+ speaker: ChatMessage.getSpeaker({ actor }),
+ content: `
+
${game.i18n.localize("HAMALRON.Label.titleStandard")}
+
${cardItem?.name}: ${result.cardValue}
+
${game.i18n.localize("HAMALRON.Label.difficulty")}: ${result.difficulty}
+
+ ${isSuccess ? game.i18n.localize("HAMALRON.Label.success") : game.i18n.localize("HAMALRON.Label.failure")}
+
+
`,
+ style: CONST.CHAT_MESSAGE_STYLES.OTHER,
+ })
+ }
+
+ static #vNumerique(valeur) {
+ return SYSTEM.TAROT_VALEURS[valeur]?.value ?? (Number.parseInt(valeur) || 0)
+ }
+
static async prompt(options = {}) {
let formula = `3D6 + 0D6KH - 0D6KH + ${options?.rollItem?.value}`