Add initiative rolls
This commit is contained in:
@@ -6,7 +6,7 @@ import OathHammerSpellDialog from "../spell-dialog.mjs"
|
||||
import OathHammerMiracleDialog from "../miracle-dialog.mjs"
|
||||
import OathHammerDefenseDialog from "../defense-dialog.mjs"
|
||||
import OathHammerArmorDialog from "../armor-dialog.mjs"
|
||||
import { rollSkillCheck, rollWeaponAttack, rollWeaponDamage, rollSpellCast, rollMiracleCast, rollArmorSave, rollWeaponDefense } from "../../rolls.mjs"
|
||||
import { rollSkillCheck, rollWeaponAttack, rollWeaponDamage, rollSpellCast, rollMiracleCast, rollArmorSave, rollWeaponDefense, rollInitiativeCheck } from "../../rolls.mjs"
|
||||
|
||||
export default class OathHammerCharacterSheet extends OathHammerActorSheet {
|
||||
/** @override */
|
||||
@@ -25,6 +25,7 @@ export default class OathHammerCharacterSheet extends OathHammerActorSheet {
|
||||
createMiracle: OathHammerCharacterSheet.#onCreateMiracle,
|
||||
createEquipment: OathHammerCharacterSheet.#onCreateEquipment,
|
||||
createTrait: OathHammerCharacterSheet.#onCreateTrait,
|
||||
createOath: OathHammerCharacterSheet.#onCreateOath,
|
||||
rollSkill: OathHammerCharacterSheet.#onRollSkill,
|
||||
attackWeapon: OathHammerCharacterSheet.#onAttackWeapon,
|
||||
defendWeapon: OathHammerCharacterSheet.#onDefendWeapon,
|
||||
@@ -33,6 +34,7 @@ export default class OathHammerCharacterSheet extends OathHammerActorSheet {
|
||||
castMiracle: OathHammerCharacterSheet.#onCastMiracle,
|
||||
rollArmorSave: OathHammerCharacterSheet.#onRollArmorSave,
|
||||
resetMiracleBlocked: OathHammerCharacterSheet.#onResetMiracleBlocked,
|
||||
rollInitiative: OathHammerCharacterSheet.#onRollInitiative,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -96,15 +98,18 @@ export default class OathHammerCharacterSheet extends OathHammerActorSheet {
|
||||
_typeLabel: typeKey ? game.i18n.localize(typeKey) : a.system.traitType,
|
||||
_usageLabel: isPassive
|
||||
? game.i18n.localize("OATHHAMMER.UsagePeriod.None")
|
||||
: `${a.system.maxUses > 0 ? a.system.maxUses + " / " : ""}${game.i18n.localize(periodKey)}`
|
||||
: `${a.system.maxUses > 0 ? a.system.maxUses + " / " : ""}${game.i18n.localize(periodKey)}`,
|
||||
_descTooltip: _stripHtml(a.system.description)
|
||||
}
|
||||
})
|
||||
context.oaths = doc.itemTypes.oath.map(o => {
|
||||
const typeEntry = SYSTEM.OATH_TYPES[o.system.oathType]
|
||||
const parts = [o.system.tenet, o.system.boon, o.system.bane].filter(Boolean)
|
||||
return {
|
||||
id: o.id, uuid: o.uuid, img: o.img, name: o.name, system: o.system,
|
||||
_typeLabel: typeEntry ? game.i18n.localize(typeEntry.label) : o.system.oathType,
|
||||
_violated: o.system.violated
|
||||
_violated: o.system.violated,
|
||||
_descTooltip: _stripHtml(parts.join(" "))
|
||||
}
|
||||
})
|
||||
context.enrichedBackground = await foundry.applications.ux.TextEditor.implementation.enrichHTML(doc.system.background ?? "", { async: true })
|
||||
@@ -160,6 +165,7 @@ export default class OathHammerCharacterSheet extends OathHammerActorSheet {
|
||||
id: w.id, uuid: w.uuid, img: w.img, name: w.name, system: w.system,
|
||||
_groupLabel: groupKey ? game.i18n.localize(groupKey) : w.system.proficiencyGroup,
|
||||
_traitsTooltip: traitsLabel || null,
|
||||
_descTooltip: _stripHtml(w.system.description),
|
||||
_isMagic: w.system.isMagic
|
||||
}
|
||||
})
|
||||
@@ -173,6 +179,7 @@ export default class OathHammerCharacterSheet extends OathHammerActorSheet {
|
||||
id: a.id, uuid: a.uuid, img: a.img, name: a.name, system: a.system,
|
||||
_typeLabel: typeKey ? game.i18n.localize(typeKey) : a.system.armorType,
|
||||
_traitsTooltip: traitsLabel || null,
|
||||
_descTooltip: _stripHtml(a.system.description),
|
||||
_isMagic: a.system.isMagic
|
||||
}
|
||||
})
|
||||
@@ -181,16 +188,31 @@ export default class OathHammerCharacterSheet extends OathHammerActorSheet {
|
||||
context.slotsMax = 10 + (doc.system.attributes.might.rank * 2)
|
||||
context.slotsUsed = doc.items.reduce((sum, item) => sum + (item.system.slots ?? 0), 0)
|
||||
context.slotsOver = context.slotsUsed > context.slotsMax
|
||||
// Show current initiative score if actor is in an active combat
|
||||
const combatant = game.combat?.combatants.find(c => c.actor?.id === doc.id)
|
||||
context.combatantInitiative = combatant?.initiative ?? null
|
||||
break
|
||||
case "magic":
|
||||
context.tab = context.tabs.magic
|
||||
context.spells = doc.itemTypes.spell
|
||||
context.miracles = doc.itemTypes.miracle
|
||||
context.spells = doc.itemTypes.spell.map(s => ({
|
||||
id: s.id, uuid: s.uuid, img: s.img, name: s.name, system: s.system,
|
||||
_descTooltip: _stripHtml(s.system.effect)
|
||||
}))
|
||||
context.miracles = doc.itemTypes.miracle.map(m => ({
|
||||
id: m.id, uuid: m.uuid, img: m.img, name: m.name, system: m.system,
|
||||
_descTooltip: _stripHtml(m.system.effect)
|
||||
}))
|
||||
break
|
||||
case "equipment":
|
||||
context.tab = context.tabs.equipment
|
||||
context.equipment = doc.itemTypes.equipment
|
||||
context.magicItems = doc.itemTypes["magic-item"]
|
||||
context.equipment = doc.itemTypes.equipment.map(e => ({
|
||||
id: e.id, uuid: e.uuid, img: e.img, name: e.name, system: e.system,
|
||||
_descTooltip: _stripHtml(e.system.description)
|
||||
}))
|
||||
context.magicItems = doc.itemTypes["magic-item"].map(m => ({
|
||||
id: m.id, uuid: m.uuid, img: m.img, name: m.name, system: m.system,
|
||||
_descTooltip: _stripHtml(m.system.description)
|
||||
}))
|
||||
context.slotsMax = 10 + (doc.system.attributes.might.rank * 2)
|
||||
context.slotsUsed = doc.items.reduce((sum, item) => sum + (item.system.slots ?? 0), 0)
|
||||
context.slotsOver = context.slotsUsed > context.slotsMax
|
||||
@@ -263,6 +285,10 @@ export default class OathHammerCharacterSheet extends OathHammerActorSheet {
|
||||
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("OATHHAMMER.NewItem.Trait"), type: "trait" }])
|
||||
}
|
||||
|
||||
static #onCreateOath(event, target) {
|
||||
this.document.createEmbeddedDocuments("Item", [{ name: game.i18n.localize("OATHHAMMER.NewItem.Oath"), type: "oath" }])
|
||||
}
|
||||
|
||||
static async #onRollSkill(event, target) {
|
||||
const skillKey = target.dataset.skill
|
||||
if (!skillKey) return
|
||||
@@ -338,4 +364,23 @@ export default class OathHammerCharacterSheet extends OathHammerActorSheet {
|
||||
if (!opts) return
|
||||
await rollArmorSave(this.document, armor, opts)
|
||||
}
|
||||
|
||||
static async #onRollInitiative() {
|
||||
const actor = this.document
|
||||
const combatant = game.combat?.combatants.find(c => c.actor?.id === actor.id)
|
||||
if (combatant) {
|
||||
// Delegate to OathHammerCombat.rollInitiative — posts to chat and updates tracker
|
||||
await game.combat.rollInitiative([combatant.id])
|
||||
} else {
|
||||
// Not in combat — roll for display only
|
||||
await rollInitiativeCheck(actor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Strip HTML tags and collapse whitespace for use in data-tooltip attributes. */
|
||||
function _stripHtml(html, maxLen = 300) {
|
||||
if (!html) return ""
|
||||
const text = html.replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim()
|
||||
return text.length > maxLen ? text.slice(0, maxLen - 1) + "…" : text
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user