This commit is contained in:
@@ -39,6 +39,7 @@ import {
|
||||
} from "./module/applications/_module.mjs"
|
||||
|
||||
const DAMAGE_APPLICATION_FLAG = "damageApplication"
|
||||
const MOON_EFFECT_FLAG = "moonEffectApplied"
|
||||
const FACTION_ASPECT_STATE_SETTING = "factionAspectState"
|
||||
const PREGENS_IMPORTED_SETTING = "pregensImported"
|
||||
const WELCOME_SCENE_IMPORTED_SETTING = "welcomeSceneImported"
|
||||
@@ -173,6 +174,9 @@ Hooks.once("ready", async () => {
|
||||
if (foundry.utils.hasProperty(changed, `flags.${SYSTEM_ID}.${DAMAGE_APPLICATION_FLAG}`)) {
|
||||
_updateRenderedChatMessageState(message)
|
||||
}
|
||||
if (foundry.utils.hasProperty(changed, `flags.${SYSTEM_ID}.${MOON_EFFECT_FLAG}`)) {
|
||||
_updateRenderedMoonEffectState(message)
|
||||
}
|
||||
})
|
||||
_activateExistingChatCards()
|
||||
|
||||
@@ -548,8 +552,9 @@ function _activateExistingChatCards() {
|
||||
document.querySelectorAll(".message[data-message-id]").forEach(messageEl => {
|
||||
const messageId = messageEl.dataset.messageId
|
||||
const message = game.messages.get(messageId)
|
||||
const root = messageEl.querySelector(".celestopol.chat-roll")
|
||||
if (!message || !root) return
|
||||
if (!message) return
|
||||
const root = messageEl.querySelector(".celestopol.chat-roll, .celestopol-roll.moon-standalone-card")
|
||||
if (!root) return
|
||||
_activateChatCardListeners(message, root)
|
||||
})
|
||||
}
|
||||
@@ -559,12 +564,19 @@ function _activateChatCardListeners(message, html) {
|
||||
if (!root) return
|
||||
|
||||
_renderWeaponDamageState(message, root)
|
||||
_renderMoonEffectState(message, root)
|
||||
|
||||
root.querySelectorAll('[data-action="apply-weapon-damage"]').forEach(button => {
|
||||
if (button.dataset.bound === "true") return
|
||||
button.dataset.bound = "true"
|
||||
button.addEventListener("click", event => _onApplyWeaponDamageClick(event, message))
|
||||
})
|
||||
|
||||
root.querySelectorAll('[data-action="apply-moon-effect"]').forEach(button => {
|
||||
if (button.dataset.bound === "true") return
|
||||
button.dataset.bound = "true"
|
||||
button.addEventListener("click", event => _onApplyMoonEffectClick(event, message))
|
||||
})
|
||||
}
|
||||
|
||||
async function _onApplyWeaponDamageClick(event, message) {
|
||||
@@ -746,6 +758,126 @@ async function _applyWeaponDamage({ actorId, actorUuid = null, incomingWounds, c
|
||||
return { actorName: actor.name, appliedWounds, armorProtection }
|
||||
}
|
||||
|
||||
/* ─── Dé de la Lune — contreparties ─────────────────────────────────────── */
|
||||
|
||||
function _getMoonEffectState(message) {
|
||||
return message?.getFlag(SYSTEM_ID, MOON_EFFECT_FLAG) ?? null
|
||||
}
|
||||
|
||||
function _renderMoonEffectState(message, root) {
|
||||
const state = _getMoonEffectState(message)
|
||||
const actionsDiv = root.querySelector(".moon-effect-actions")
|
||||
if (!actionsDiv) return
|
||||
|
||||
if (!state?.applied) return
|
||||
|
||||
const NEGATIVE_EFFECTS = new Set(["lose-anomaly", "gain-spleen", "lose-destin"])
|
||||
|
||||
// Désactiver tous les boutons et afficher le statut
|
||||
actionsDiv.querySelectorAll(".moon-effect-btn").forEach(btn => { btn.disabled = true })
|
||||
|
||||
let statusEl = actionsDiv.querySelector(".moon-effect-applied-status")
|
||||
if (!statusEl) {
|
||||
statusEl = document.createElement("span")
|
||||
actionsDiv.append(statusEl)
|
||||
}
|
||||
statusEl.className = "moon-effect-applied-status" + (NEGATIVE_EFFECTS.has(state.effect) ? " is-negative" : "")
|
||||
statusEl.textContent = state.effectLabel
|
||||
? game.i18n.format("CELESTOPOL.Moon.effectApplied", { label: state.effectLabel })
|
||||
: game.i18n.localize("CELESTOPOL.Moon.effectApplied")
|
||||
}
|
||||
|
||||
function _updateRenderedMoonEffectState(message) {
|
||||
const msgEl = document.querySelector(`.message[data-message-id="${message.id}"]`)
|
||||
if (!msgEl) return
|
||||
const root = msgEl.querySelector(".celestopol.chat-roll, .celestopol-roll.moon-standalone-card")
|
||||
if (!root) return
|
||||
_renderMoonEffectState(message, root)
|
||||
}
|
||||
|
||||
async function _onApplyMoonEffectClick(event, message) {
|
||||
event.preventDefault()
|
||||
const state = _getMoonEffectState(message)
|
||||
if (state?.applied) return
|
||||
|
||||
const button = event.currentTarget
|
||||
const effect = button.dataset.effect
|
||||
const actionsDiv = button.closest(".moon-effect-actions")
|
||||
const actorId = actionsDiv?.dataset.moonActorId ?? ""
|
||||
const actorUuid = actionsDiv?.dataset.moonActorUuid ?? ""
|
||||
|
||||
// Désactiver immédiatement pour éviter les double-clics
|
||||
actionsDiv?.querySelectorAll(".moon-effect-btn").forEach(btn => { btn.disabled = true })
|
||||
|
||||
const actor = await CelestopolRoll.resolveActor({ actorId, actorUuid })
|
||||
if (!actor) {
|
||||
ui.notifications.warn(game.i18n.localize("CELESTOPOL.Moon.actorNotFound"))
|
||||
actionsDiv?.querySelectorAll(".moon-effect-btn").forEach(btn => { btn.disabled = false })
|
||||
return
|
||||
}
|
||||
|
||||
const effectLabel = await _applyMoonEffect(actor, effect)
|
||||
if (effectLabel === null) {
|
||||
actionsDiv?.querySelectorAll(".moon-effect-btn").forEach(btn => { btn.disabled = false })
|
||||
return
|
||||
}
|
||||
|
||||
await message.setFlag(SYSTEM_ID, MOON_EFFECT_FLAG, { applied: true, effect, effectLabel })
|
||||
}
|
||||
|
||||
async function _applyMoonEffect(actor, effect) {
|
||||
const i18n = key => game.i18n.localize(`CELESTOPOL.Moon.${key}`)
|
||||
const anomaly = actor.items.find(i => i.type === "anomaly")
|
||||
|
||||
switch (effect) {
|
||||
case "regain-anomaly": {
|
||||
if (!anomaly) { ui.notifications.warn(i18n("noAnomaly")); return null }
|
||||
const max = anomaly.system?.level ?? 0
|
||||
const cur = anomaly.system?.usesRemaining ?? 0
|
||||
if (cur >= max) { ui.notifications.warn(i18n("anomalyFull")); return null }
|
||||
await anomaly.update({ "system.usesRemaining": Math.min(max, cur + 1) })
|
||||
ui.notifications.info(game.i18n.format("CELESTOPOL.Moon.effectApplied", { label: i18n("effectRegainAnomaly") }))
|
||||
return i18n("effectRegainAnomaly")
|
||||
}
|
||||
case "lose-spleen": {
|
||||
const cur = actor.system?.spleen?.lvl ?? 0
|
||||
if (cur <= 0) { ui.notifications.warn(i18n("spleenEmpty")); return null }
|
||||
await actor.update({ "system.spleen.lvl": Math.max(0, cur - 1) })
|
||||
ui.notifications.info(game.i18n.format("CELESTOPOL.Moon.effectApplied", { label: i18n("effectLoseSpleen") }))
|
||||
return i18n("effectLoseSpleen")
|
||||
}
|
||||
case "gain-destin": {
|
||||
const cur = actor.system?.destin?.lvl ?? 0
|
||||
await actor.update({ "system.destin.lvl": Math.min(8, cur + 2) })
|
||||
ui.notifications.info(game.i18n.format("CELESTOPOL.Moon.effectApplied", { label: i18n("effectGainDestin") }))
|
||||
return i18n("effectGainDestin")
|
||||
}
|
||||
case "lose-destin": {
|
||||
const cur = actor.system?.destin?.lvl ?? 0
|
||||
await actor.update({ "system.destin.lvl": Math.max(0, cur - 2) })
|
||||
ui.notifications.info(game.i18n.format("CELESTOPOL.Moon.effectApplied", { label: i18n("effectLoseDestin") }))
|
||||
return i18n("effectLoseDestin")
|
||||
}
|
||||
case "lose-anomaly": {
|
||||
if (!anomaly) { ui.notifications.warn(i18n("noAnomaly")); return null }
|
||||
const cur = anomaly.system?.usesRemaining ?? 0
|
||||
if (cur <= 0) { ui.notifications.warn(i18n("anomalyEmpty")); return null }
|
||||
await anomaly.update({ "system.usesRemaining": Math.max(0, cur - 1) })
|
||||
ui.notifications.info(game.i18n.format("CELESTOPOL.Moon.effectApplied", { label: i18n("effectLoseAnomaly") }))
|
||||
return i18n("effectLoseAnomaly")
|
||||
}
|
||||
case "gain-spleen": {
|
||||
const cur = actor.system?.spleen?.lvl ?? 0
|
||||
if (cur >= 8) { ui.notifications.warn(i18n("spleenFull")); return null }
|
||||
await actor.update({ "system.spleen.lvl": Math.min(8, cur + 1) })
|
||||
ui.notifications.info(game.i18n.format("CELESTOPOL.Moon.effectApplied", { label: i18n("effectGainSpleen") }))
|
||||
return i18n("effectGainSpleen")
|
||||
}
|
||||
default:
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
function _getDefaultFactionAspectState() {
|
||||
return {
|
||||
pointsMax: 8,
|
||||
|
||||
Reference in New Issue
Block a user