import { SYSTEM } from "../config/system.mjs" export default class HamalronResistanceRecovery { static SYMBOLE_LABELS = { coupe: "Coupe", epee: "Épée", denier: "Denier", baton: "Bâton", } static async prompt(actor) { const resistances = actor.system.resistances const recovery = actor.system.resistanceRecovery || {} const today = new Date().toISOString().split("T")[0] const todayNum = Number(new Date().toISOString().split("T")[0].replace(/-/g, "")) const symInfos = Object.entries(SYSTEM.TAROT_SYMBOLES).map(([key, val]) => { const r = resistances[key] const lastDate = recovery[key] const lastNum = lastDate ? Number(lastDate.replace(/-/g, "")) : 0 const canRecover = key === "epee" ? true : (lastNum < todayNum) const isDenierCoupe = key === "denier" || key === "coupe" return { id: key, label: val.label, value: r?.value ?? 0, max: r?.max ?? 0, canRecover, isDenierCoupe, lastRecovery: lastDate || "-", } }) const content = HamalronResistanceRecovery.#renderContent(actor, symInfos) const result = await foundry.applications.api.DialogV2.wait({ window: { title: game.i18n.localize("HAMALRON.Recovery.Title") }, classes: ["fvtt-hamalron"], position: { width: 480 }, content, buttons: [ { action: "close", label: game.i18n.localize("Cancel"), default: true, }, ], actions: { recoverTest: async (event, button, dialog) => { const btn = event.currentTarget const symbole = btn.dataset.symbole if (!symbole) return const rollItem = { name: HamalronResistanceRecovery.SYMBOLE_LABELS[symbole] || symbole, value: 0 } await HamalronResistanceRecovery.#doRecoveryTest(actor, symbole, rollItem) HamalronResistanceRecovery.prompt(actor) }, adjustResistance: async (event, button, dialog) => { const btn = event.currentTarget const symbole = btn.dataset.symbole const delta = Number(btn.dataset.delta) || 0 if (!symbole) return const resistance = actor.system.resistances[symbole] if (!resistance) return const newValue = Math.max(0, Math.min(resistance.max, (resistance.value || 0) + delta)) await actor.update({ [`system.resistances.${symbole}.value`]: newValue }) HamalronResistanceRecovery.prompt(actor) }, }, rejectClose: false, }) } static #renderContent(actor, symInfos) { const today = new Date().toISOString().split("T")[0] let html = `
${game.i18n.format("HAMALRON.Recovery.Today", { date: today })}
` html += `