45 lines
1.5 KiB
JavaScript
45 lines
1.5 KiB
JavaScript
swadeMBHelpers.runOnTargetOrSelectedTokens(main)
|
|
|
|
async function main (tokens) {
|
|
const tokenList = tokens.map(t => t.name).join(', ')
|
|
const menuOptions = {
|
|
title: 'Invisibility',
|
|
defaultButton: 'Cancel',
|
|
options: {}
|
|
}
|
|
|
|
const menuData = {
|
|
inputs: [
|
|
{ type: 'header', label: 'Invisibility' },
|
|
{ type: 'info', label: `Apply Invisibility to ${tokenList}` },
|
|
{ type: 'checkbox', label: 'Duration', options: false }
|
|
],
|
|
buttons: [
|
|
{ label: 'Apply', value: 'apply' },
|
|
{ label: 'Raise', value: 'raise' },
|
|
{ label: 'Cancel', value: 'cancel' }
|
|
]
|
|
}
|
|
|
|
const { buttons, inputs } = await warpgate.menu(menuData, menuOptions)
|
|
if (buttons && buttons !== 'cancel') {
|
|
const options = {
|
|
raise: (buttons === 'raise'),
|
|
duration: (!!inputs[2])
|
|
}
|
|
await createEffect(tokens, options)
|
|
}
|
|
}
|
|
|
|
async function createEffect (tokens, options) {
|
|
const effectName = `${options.raise ? 'major' : 'minor'} Invisibility`
|
|
const baseEffect = CONFIG.statusEffects.find(se => se.label === 'EFFECT.StatusInvisible')
|
|
const duration = (options.duration ? 5 * 6 * 60 : 5)
|
|
for (const token of tokens) {
|
|
const mutate = swadeMBHelpers.createMutationWithEffect(baseEffect.icon, effectName, duration, [])
|
|
mutate.embedded.ActiveEffect[effectName].flags.core = { statusId: baseEffect.id }
|
|
const mutateOptions = swadeMBHelpers.defaultMutationOptions('Invisibility')
|
|
await warpgate.mutate(token.document, mutate, {}, mutateOptions)
|
|
}
|
|
}
|