Add entangle effect

closes #11
This commit is contained in:
Mike Bloy 2023-03-06 23:06:51 -06:00
parent 9607e07fdc
commit 18e059a785
3 changed files with 87 additions and 0 deletions

View File

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- Confusion effect macro - Confusion effect macro
- Entangle effect macro
### Changed ### Changed

74
macros/entangle.js Normal file
View File

@ -0,0 +1,74 @@
swadeMBHelpers.runOnTargetOrSelectedTokens(main)
async function main (tokens) {
const tokenList = tokens.map(t => t.name).join(', ')
const menuOptions = {
title: 'Entangle',
defaultButton: 'Cancel',
options: {}
}
const menuData = {
inputs: [
{ type: 'header', label: 'Entangle' },
{ type: 'info', label: `Apply Entangle to ${tokenList}` },
{ type: 'radio', label: 'Not Damaging', options: ['dmg', true] },
{ type: 'radio', label: 'Damaging', options: ['dmg', false] },
{ type: 'radio', label: 'Deadly', options: ['dmg', false] },
{ type: 'checkbox', label: 'Tough', options: false }
],
buttons: [
{ label: 'Entangled', value: 'apply' },
{ label: 'Bound (raise)', value: 'raise' },
{ label: 'Cancel', value: 'cancel' }
]
}
const { buttons, inputs } = await warpgate.menu(menuData, menuOptions)
if (buttons && buttons !== 'cancel') {
const options = {
apply: (buttons === 'raise' ? 'bound' : 'entangled'),
damage: (inputs[3] ? '2d4' : (inputs[4] ? '2d6' : null)),
tough: (!!inputs[5])
}
await createEffect(tokens, options)
}
}
function getStatus (label, name) {
const effect = JSON.parse(JSON.stringify(
CONFIG.statusEffects.find(se => se.label === label)))
effect.label = name
if (!effect.flags) {
effect.flags = {}
}
effect.flags.core = { statusId: effect.id }
effect.id = name
return effect
}
async function createEffect (tokens, options) {
const effectSearch = (options.apply === 'bound' ? 'SWADE.Bound' : 'SWADE.Entangled')
const effectName = (options.apply === 'bound' ? 'Bound' : 'Entangled')
const effect = getStatus(effectSearch, effectName)
const extraIcon = 'icons/magic/nature/root-vine-barrier-wall-brown.webp'
const extraEffect = swadeMBHelpers.createEffectDocument(extraIcon, 'Entangle Modifier', 1, [])
if (options.damage) {
extraEffect.id = `${extraEffect.id} - ${options.damage} dmg`
extraEffect.label = `${extraEffect.label} - ${options.damage} dmg`
}
if (options.tough) {
extraEffect.id = `Tough ${extraEffect.id}`
extraEffect.label = `Tough ${extraEffect.label}`
}
for (const token of tokens) {
const mutateOptions = swadeMBHelpers.defaultMutationOptions('Entangle')
const mutate = { embedded: { ActiveEffect: {} } }
mutate.embedded.ActiveEffect[effect.id] = effect
if (options.damage || options.tough) {
mutate.embedded.ActiveEffect[extraEffect.id] = extraEffect
}
await warpgate.mutate(token.document, mutate, {}, mutateOptions)
}
}

File diff suppressed because one or more lines are too long