46 lines
1.4 KiB
JavaScript
46 lines
1.4 KiB
JavaScript
swadeMBHelpers.runOnTargetOrSelectedTokens(main)
|
|
|
|
async function main (tokens) {
|
|
const tokenList = tokens.map(t => t.name).join(', ')
|
|
const dialogOptions = {
|
|
title: 'Protection',
|
|
content: `Apply <em>Protection</em> to ${tokenList}`,
|
|
default: 'cancel',
|
|
buttons: [
|
|
{ label: 'Apply (+2 armor)', value: 'apply' },
|
|
{ label: 'Apply with raise (+2 toughness)', 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 baseEffect = CONFIG.statusEffects.find(se => se.label === 'SWADE.Protection')
|
|
const changes = [
|
|
{
|
|
key: 'system.stats.toughness.armor',
|
|
mode: foundry.CONST.ACTIVE_EFFECT_MODES.UPGRADE,
|
|
value: 2,
|
|
priority: 0
|
|
}
|
|
]
|
|
let effectName = 'minor Protection'
|
|
if (choice === 'raise') {
|
|
changes[0].key = 'system.stats.toughness.value'
|
|
effectName = 'major Protection'
|
|
}
|
|
for (const token of tokens) {
|
|
const mutate = swadeMBHelpers.createMutationWithEffect(
|
|
baseEffect.icon, effectName, 5, changes)
|
|
mutate.embedded.ActiveEffect[effectName].flags.core = { statusId: baseEffect.id }
|
|
const mutateOptions = swadeMBHelpers.defaultMutationOptions(effectName)
|
|
await warpgate.mutate(token.document, mutate, {}, mutateOptions)
|
|
}
|
|
}
|