63 lines
1.8 KiB
JavaScript
63 lines
1.8 KiB
JavaScript
swadeMBHelpers.runOnTargetOrSelectedTokens(main)
|
|
|
|
async function main (tokens) {
|
|
const tokenList = tokens.map(t => t.name).join(', ')
|
|
const menuOptions = {
|
|
title: 'Confusion',
|
|
defaultButton: 'Cancel',
|
|
options: {}
|
|
}
|
|
|
|
const menuData = {
|
|
inputs: [
|
|
{ type: 'header', label: 'Confusion' },
|
|
{ type: 'info', label: `Apply Confusion to ${tokenList}` },
|
|
{ type: 'checkbox', label: 'Greater (adds shaken)', options: false }
|
|
],
|
|
buttons: [
|
|
{ label: 'Distracted', value: 'distracted' },
|
|
{ label: 'Vulnerable', value: 'vulnerable' },
|
|
{ label: 'Raise (both)', value: 'raise' },
|
|
{ label: 'Cancel', value: 'cancel' }
|
|
]
|
|
}
|
|
|
|
const { buttons, inputs } = await warpgate.menu(menuData, menuOptions)
|
|
const greater = (inputs[2] === 'Greater (adds shaken)')
|
|
if (buttons && buttons !== 'cancel') {
|
|
await createEffect(tokens, buttons, greater)
|
|
}
|
|
}
|
|
|
|
function getStatus (label, name) {
|
|
const effect = JSON.parse(JSON.stringify(
|
|
CONFIG.statusEffects.find(se => se.label === label)))
|
|
effect.label = name
|
|
effect.flags.core = { statusId: effect.id }
|
|
effect.id = name
|
|
return effect
|
|
}
|
|
|
|
async function createEffect (tokens, choice, greater) {
|
|
const effects = []
|
|
if (choice === 'distracted' || choice === 'raise') {
|
|
effects.push(getStatus('SWADE.Distr', 'Distracted'))
|
|
}
|
|
if (choice === 'vulnerable' || choice === 'raise') {
|
|
effects.push(getStatus('SWADE.Vuln', 'Vulnerable'))
|
|
}
|
|
if (greater) {
|
|
effects.push(getStatus('SWADE.Shaken', 'Shaken'))
|
|
}
|
|
for (const token of tokens) {
|
|
const mutateOptions = swadeMBHelpers.defaultMutationOptions('Confusion')
|
|
const mutate = {
|
|
embedded: { ActiveEffect: {} }
|
|
}
|
|
for (const effect of effects) {
|
|
mutate.embedded.ActiveEffect[effect.id] = effect
|
|
}
|
|
await warpgate.mutate(token.document, mutate, {}, mutateOptions)
|
|
}
|
|
}
|