swadeMBHelpers.runOnTargetOrSelectedTokens(main) async function main (tokens) { const tokenList = tokens.map(t => t.name).join(', ') const menuOptions = { title: 'Smite', defaultButton: 'Cancel', options: {} } const menuData = { inputs: [ { type: 'header', label: 'Smite' }, { type: 'info', label: `Apply Smite to ${tokenList}` } ], buttons: [ { label: 'Apply', value: 'apply' }, { label: 'Apply with Raise', value: 'raise' }, { label: 'Cancel', value: 'cancel' } ] } const tokenWeapons = {} let index = 1 for (const token of tokens) { index += 2 tokenWeapons[token.id] = index menuData.inputs.push({ type: 'info', label: `

${token.name}

` }) const weapons = token.actor.items.filter(i => i.type === 'weapon').map( i => { return { value: i.name, html: i.name } }) weapons.unshift({ value: '', html: 'None' }) menuData.inputs.push({ type: 'select', label: token.name, options: weapons }) } const { buttons, inputs } = await warpgate.menu(menuData, menuOptions) for (const tokenId in tokenWeapons) { tokenWeapons[tokenId] = inputs[tokenWeapons[tokenId]] } if (buttons && buttons !== 'cancel') { await createEffect(tokens, tokenWeapons, buttons) } } async function createEffect (tokens, tokenWeapons, choice) { const baseEffect = CONFIG.statusEffects.find(se => se.label === 'SWADE.Smite') const effectIcon = baseEffect.icon const effectId = baseEffect.id const changeValue = (choice === 'raise' ? '+4' : '+2') for (const token of tokens) { const weaponName = tokenWeapons[token.id] const weaponId = token.actor.items.getName(weaponName)?.id const changeKey = `@Weapon{${weaponName}}[system.damage]` if (!weaponId) { continue } const effectName = `${choice === 'raise' ? 'major' : 'minor'} Smite (${weaponName})` const effectData = { icon: effectIcon, id: effectId, label: effectName, duration: { rounds: 5 }, flags: { swade: { expiration: CONFIG.SWADE.CONST.STATUS_EFFECT_EXPIRATION.EndOfTurnPrompt, loseTurnOnHold: true } }, changes: [ { key: changeKey, mode: foundry.CONST.ACTIVE_EFFECT_MODES.ADD, value: changeValue, priority: 0 } ] } 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) } }