ENhance actor sheet with roll messages
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
export let RollHandler = null
|
||||
|
||||
Hooks.once('tokenActionHudCoreApiReady', async (coreModule) => {
|
||||
RollHandler = class RollHandler extends coreModule.api.RollHandler {
|
||||
|
||||
/** @override */
|
||||
async handleActionClick(event, encodedValue) {
|
||||
const [actionTypeId, actionId] = encodedValue.split(this.delimiter ?? '|')
|
||||
|
||||
if (this.actor) {
|
||||
await this.#handleAction(event, this.actor, this.token, actionTypeId, actionId)
|
||||
return
|
||||
}
|
||||
|
||||
const knownTypes = ['character', 'creature']
|
||||
for (const token of canvas.tokens.controlled.filter(t => knownTypes.includes(t.actor?.type))) {
|
||||
await this.#handleAction(event, token.actor, token, actionTypeId, actionId)
|
||||
}
|
||||
}
|
||||
|
||||
/** @override */
|
||||
async handleActionHover(event, encodedValue) {}
|
||||
|
||||
/** @override */
|
||||
async handleGroupClick(event, group) {}
|
||||
|
||||
async #handleAction(event, actor, token, actionTypeId, actionId) {
|
||||
switch (actionTypeId) {
|
||||
case 'attribute':
|
||||
await actor.rollAttribute(actionId)
|
||||
break
|
||||
case 'hp':
|
||||
await this.#handleHP(actor, actionId)
|
||||
break
|
||||
case 'flow':
|
||||
await this.#handleFlow(actor, actionId)
|
||||
break
|
||||
case 'weapon':
|
||||
await this.#handleWeapon(actor, actionId)
|
||||
break
|
||||
case 'condition':
|
||||
await actor.toggleStatusEffect(actionId)
|
||||
break
|
||||
case 'ability':
|
||||
await actor.useAbility(actionId)
|
||||
break
|
||||
case 'kit':
|
||||
await actor.useKit(actionId)
|
||||
break
|
||||
case 'utility':
|
||||
await this.#handleUtility(actor, token, actionId)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
async #handleHP(actor, actionId) {
|
||||
if (actionId === 'display') return
|
||||
const hp = actor.system.hp
|
||||
if (!hp) return
|
||||
const newValue = actionId === 'add' ? hp.value + 1 : hp.value - 1
|
||||
if (newValue < 0 || newValue > hp.max) return
|
||||
await actor.update({ 'system.hp.value': newValue })
|
||||
}
|
||||
|
||||
async #handleFlow(actor, actionId) {
|
||||
if (actionId === 'display') return
|
||||
const fp = actor.system.flowPoints
|
||||
if (fp === undefined) return
|
||||
const newValue = actionId === 'add' ? fp.value + 1 : Math.max(0, fp.value - 1)
|
||||
await actor.update({ 'system.flowPoints.value': newValue })
|
||||
}
|
||||
|
||||
async #handleWeapon(actor, actionId) {
|
||||
const weapon = actor.items.get(actionId)
|
||||
if (!weapon) return
|
||||
await actor.rollWeapon(weapon)
|
||||
}
|
||||
|
||||
async #handleUtility(actor, token, actionId) {
|
||||
switch (actionId) {
|
||||
case 'longRest':
|
||||
await actor.longRest()
|
||||
break
|
||||
case 'endTurn':
|
||||
if (game.combat?.current?.tokenId === token?.id) {
|
||||
await game.combat.nextTurn()
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user