75 lines
2.5 KiB
JavaScript
75 lines
2.5 KiB
JavaScript
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}` },
|
|
{ type: 'checkbox', label: 'Greater', options: false }
|
|
],
|
|
buttons: [
|
|
{ label: 'Apply', value: 'apply' },
|
|
{ label: 'Apply with Raise', value: 'raise' },
|
|
{ label: 'Cancel', value: 'cancel' }
|
|
]
|
|
}
|
|
|
|
const tokenWeapons = {}
|
|
let index = 2
|
|
for (const token of tokens) {
|
|
index += 2
|
|
tokenWeapons[token.id] = index
|
|
menuData.inputs.push({ type: 'info', label: `<h2>${token.name}</h2>` })
|
|
const weapons = token.actor.items.filter(i => i.type === 'weapon').map(
|
|
i => { return { value: i.name, html: i.name } })
|
|
weapons.unshift({ value: '', html: '<i>None</i>' })
|
|
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]]
|
|
}
|
|
const greater = (inputs[2] === 'Greater')
|
|
if (buttons && buttons !== 'cancel') {
|
|
await createEffect(tokens, tokenWeapons, buttons, greater)
|
|
}
|
|
}
|
|
|
|
async function createEffect (tokens, tokenWeapons, choice, greater) {
|
|
const baseEffect = CONFIG.statusEffects.find(se => se.label === 'SWADE.Smite')
|
|
const effectIcon = baseEffect.icon
|
|
let changeValue = (choice === 'raise' ? '+4' : '+2')
|
|
if (greater) {
|
|
changeValue = (choice === 'raise' ? '+6' : '+4')
|
|
}
|
|
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${greater ? '(greater)' : ''} (${weaponName})`
|
|
const changes = [
|
|
{
|
|
key: changeKey,
|
|
mode: foundry.CONST.ACTIVE_EFFECT_MODES.ADD,
|
|
value: changeValue,
|
|
priority: 0
|
|
}
|
|
]
|
|
const mutate = swadeMBHelpers.createMutationWithEffect(
|
|
effectIcon, effectName, 5, changes)
|
|
mutate.embedded.ActiveEffect[effectName].flags.core = { statusId: baseEffect.id }
|
|
const mutateOptions = swadeMBHelpers.defaultMutationOptions(effectName)
|
|
await warpgate.mutate(token.document, mutate, {}, mutateOptions)
|
|
}
|
|
}
|