Add initiative rolls

This commit is contained in:
2026-03-18 16:51:10 +01:00
parent 000bf348a6
commit b2befe039e
30 changed files with 512 additions and 144 deletions

36
module/combat.mjs Normal file
View File

@@ -0,0 +1,36 @@
import { rollInitiativeCheck } from "./rolls.mjs"
/**
* Custom Combat class for Oath Hammer.
* Initiative = opposed Leadership check (DV=0).
* The number of successes becomes the combatant's initiative score.
*/
export default class OathHammerCombat extends Combat {
/**
* Override Foundry's rollInitiative to use Leadership skill checks.
* For characters: Leadership (Fate) opposed check, successes = score.
* For NPCs: Fate rank + initiative bonus pool.
*
* @param {string|string[]} ids Combatant IDs to roll for
* @param {object} options
*/
async rollInitiative(ids, { formula = null, updateTurn = true, messageOptions = {} } = {}) {
const combatantIds = typeof ids === "string" ? [ids] : ids
const updates = []
for (const id of combatantIds) {
const combatant = this.combatants.get(id)
if (!combatant?.isOwner) continue
const actor = combatant.actor
if (!actor) continue
const { successes } = await rollInitiativeCheck(actor)
updates.push({ _id: id, initiative: successes })
}
if (!updates.length) return this
await this.updateEmbeddedDocuments("Combatant", updates)
if (updateTurn && this.turn !== null) await this.update({ turn: 0 })
return this
}
}