56 lines
1.6 KiB
JavaScript
56 lines
1.6 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 effectData = {
|
|
icon,
|
|
id: effectName,
|
|
label: effectName,
|
|
duration: { rounds: 5 },
|
|
flags: {
|
|
swade: {
|
|
expiration: CONFIG.SWADE.CONST.STATUS_EFFECT_EXPIRATION.EndOfTurnPrompt,
|
|
loseTurnOnHold: true
|
|
}
|
|
}
|
|
}
|
|
const mutate = { embedded: { ActiveEffect: { } } }
|
|
mutate.embedded.ActiveEffect[effectName] = effectData
|
|
const mutateOptions = {
|
|
comparisonKeys: { ActiveEffect: 'label' },
|
|
name: effectName,
|
|
permanent: true,
|
|
description: effectName
|
|
}
|
|
await warpgate.mutate(token.document, mutate, {}, mutateOptions)
|
|
}
|
|
}
|