add deflection macro, fix close button behavior for all macros
This commit is contained in:
parent
310ea55f21
commit
38a60f8671
@ -57,7 +57,7 @@ async function main (tokens) {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
const { buttons, inputs } = await warpgate.menu(menuData, menuOptions)
|
const { buttons, inputs } = await warpgate.menu(menuData, menuOptions)
|
||||||
if (buttons !== 'cancel') {
|
if (buttons && buttons !== 'cancel') {
|
||||||
const options = {
|
const options = {
|
||||||
action: buttons,
|
action: buttons,
|
||||||
name: inputs[2],
|
name: inputs[2],
|
||||||
|
|||||||
55
macros/deflection.js
Normal file
55
macros/deflection.js
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -15,7 +15,7 @@ async function main (tokens) {
|
|||||||
|
|
||||||
const choice = await warpgate.buttonDialog(dialogOptions)
|
const choice = await warpgate.buttonDialog(dialogOptions)
|
||||||
|
|
||||||
if (choice !== 'cancel') {
|
if (choice && choice !== 'cancel') {
|
||||||
await createEffect(tokens, choice)
|
await createEffect(tokens, choice)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,7 +36,7 @@ async function main (tokens) {
|
|||||||
tokenWeapons[tokenId] = inputs[tokenWeapons[tokenId]]
|
tokenWeapons[tokenId] = inputs[tokenWeapons[tokenId]]
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buttons !== 'cancel') {
|
if (buttons && buttons !== 'cancel') {
|
||||||
await createEffect(tokens, tokenWeapons, buttons)
|
await createEffect(tokens, tokenWeapons, buttons)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user