38 lines
1.2 KiB
JavaScript
38 lines
1.2 KiB
JavaScript
swadeMBHelpers.runOnTargetOrSelectedTokens(main)
|
|
|
|
async function main (tokens) {
|
|
const tokenList = tokens.map(t => t.name).join(', ')
|
|
const dialogOptions = {
|
|
title: 'Deflection',
|
|
content: `Apply <em>Deflection</em> to ${tokenList}`,
|
|
default: 'cancel',
|
|
buttons: [
|
|
{ label: 'Apply (melee)', value: 'melee' },
|
|
{ label: 'Apply (ranged)', value: 'ranged' },
|
|
{ label: 'Apply with raise (both)', value: 'raise' },
|
|
{ label: 'Cancel', value: 'cancel' }
|
|
]
|
|
}
|
|
|
|
const choice = await warpgate.buttonDialog(dialogOptions)
|
|
|
|
if (choice && choice !== 'cancel') {
|
|
await createEffect(tokens, choice)
|
|
}
|
|
}
|
|
|
|
async function createEffect (tokens, choice) {
|
|
const icon = 'icons/magic/defensive/shield-barrier-deflect-teal.webp'
|
|
let effectName = 'Deflection'
|
|
if (choice === 'raise') {
|
|
effectName = `${effectName} (all)`
|
|
} else {
|
|
effectName = `${effectName} (${choice})`
|
|
}
|
|
for (const token of tokens) {
|
|
const mutate = swadeMBHelpers.createMutationWithEffect(icon, effectName, 5, [])
|
|
const mutateOptions = swadeMBHelpers.defaultMutationOptions(effectName)
|
|
await warpgate.mutate(token.document, mutate, {}, mutateOptions)
|
|
}
|
|
}
|