swadeMBHelpers.runOnTargetOrSelectedTokens(main) async function main (tokens) { const tokenList = tokens.map(t => t.name).join(', ') const dialogOptions = { title: 'Protection', content: `Apply Protection 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 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) } }