Files
fvtt-celestopol/module/documents/combat.mjs

54 lines
1.9 KiB
JavaScript

const SYSTEM_ID = "fvtt-celestopol"
export default class CelestopolCombat extends Combat {
/** @override — Initiative déterministe, message stylé maison */
async rollInitiative(ids, { updateTurn = true } = {}) {
ids = typeof ids === "string" ? [ids] : ids
const combatants = ids.map(id => this.combatants.get(id)).filter(Boolean)
if (!combatants.length) return this
const updates = []
for (const combatant of combatants) {
const actor = combatant.actor
if (!actor) continue
const value = actor.system.initiative ?? 0
updates.push({ _id: combatant.id, initiative: value })
await CelestopolCombat._postInitiativeMessage(combatant, actor, value)
}
if (updates.length) await this.updateEmbeddedDocuments("Combatant", updates)
if (updateTurn && this.turn !== null) await this.update({ turn: this.turn })
return this
}
static async _postInitiativeMessage(combatant, actor, value) {
const sys = actor.system
let detail
if (actor.type === "character") {
const mob = sys.stats?.corps?.mobilite?.value ?? 0
const insp = sys.stats?.coeur?.inspiration?.value ?? 0
detail = `4 + ${mob} (${game.i18n.localize("CELESTOPOL.Skill.mobilite")}) + ${insp} (${game.i18n.localize("CELESTOPOL.Skill.inspiration")})`
} else {
const corps = sys.stats?.corps?.res ?? value
detail = `${game.i18n.localize("CELESTOPOL.Stat.corps")} : ${corps}`
}
const content = await renderTemplate(
`systems/${SYSTEM_ID}/templates/chat-initiative.hbs`,
{
actorName: combatant.name ?? actor.name,
actorImg: actor.img,
value,
detail,
}
)
await ChatMessage.create({
speaker: ChatMessage.getSpeaker({ actor }),
content,
style: CONST.CHAT_MESSAGE_STYLES.OTHER,
flags: { [SYSTEM_ID]: { type: "initiative" } },
})
}
}