67 lines
2.3 KiB
JavaScript
67 lines
2.3 KiB
JavaScript
/**
|
||
* Célestopol 1922 — Système FoundryVTT
|
||
*
|
||
* Célestopol 1922 est un jeu de rôle édité par Antre-Monde Éditions.
|
||
* Ce système FoundryVTT est une implémentation indépendante et n'est pas
|
||
* affilié à Antre-Monde Éditions,
|
||
* mais a été réalisé avec l'autorisation d'Antre-Monde Éditions.
|
||
*
|
||
* @author LeRatierBretonnien
|
||
* @copyright 2025–2026 LeRatierBretonnien
|
||
* @license CC BY-NC-SA 4.0 – https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||
*/
|
||
|
||
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" } },
|
||
})
|
||
}
|
||
}
|