add protection macro
This commit is contained in:
parent
1aa3cae1f5
commit
310ea55f21
62
macros/protection.js
Normal file
62
macros/protection.js
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
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 !== '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 effectData = {
|
||||||
|
icon: baseEffect.icon,
|
||||||
|
id: effectName,
|
||||||
|
label: effectName,
|
||||||
|
duration: baseEffect.duration,
|
||||||
|
flags: {
|
||||||
|
swade: {
|
||||||
|
expiration: CONFIG.SWADE.CONST.STATUS_EFFECT_EXPIRATION.EndOfTurnPrompt,
|
||||||
|
loseTurnOnHold: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
changes
|
||||||
|
}
|
||||||
|
const mutate = { embedded: { ActiveEffect: { } } }
|
||||||
|
mutate.embedded.ActiveEffect[effectName] = effectData
|
||||||
|
const mutateOptions = {
|
||||||
|
comparisonKeys: { ActiveEffect: 'label' },
|
||||||
|
name: effectName,
|
||||||
|
permanent: true,
|
||||||
|
description: baseEffect.label
|
||||||
|
}
|
||||||
|
await warpgate.mutate(token.document, mutate, {}, mutateOptions)
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user