parent
2111746643
commit
c8a153d514
@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
|
||||
- Confusion effect macro
|
||||
|
||||
## 0.9.0
|
||||
|
||||
|
||||
62
macros/confusion.js
Normal file
62
macros/confusion.js
Normal file
@ -0,0 +1,62 @@
|
||||
swadeMBHelpers.runOnTargetOrSelectedTokens(main)
|
||||
|
||||
async function main (tokens) {
|
||||
const tokenList = tokens.map(t => t.name).join(', ')
|
||||
const menuOptions = {
|
||||
title: 'Confusion',
|
||||
defaultButton: 'Cancel',
|
||||
options: {}
|
||||
}
|
||||
|
||||
const menuData = {
|
||||
inputs: [
|
||||
{ type: 'header', label: 'Confusion' },
|
||||
{ type: 'info', label: `Apply Confusion to ${tokenList}` },
|
||||
{ type: 'checkbox', label: 'Greater (adds shaken)', options: false }
|
||||
],
|
||||
buttons: [
|
||||
{ label: 'Distracted', value: 'distracted' },
|
||||
{ label: 'Vulnerable', value: 'vulnerable' },
|
||||
{ label: 'Raise (both)', value: 'raise' },
|
||||
{ label: 'Cancel', value: 'cancel' }
|
||||
]
|
||||
}
|
||||
|
||||
const { buttons, inputs } = await warpgate.menu(menuData, menuOptions)
|
||||
const greater = (inputs[2] === 'Greater (adds shaken)')
|
||||
if (buttons && buttons !== 'cancel') {
|
||||
await createEffect(tokens, buttons, greater)
|
||||
}
|
||||
}
|
||||
|
||||
function getStatus (label, name) {
|
||||
const effect = JSON.parse(JSON.stringify(
|
||||
CONFIG.statusEffects.find(se => se.label === label)))
|
||||
effect.label = name
|
||||
effect.flags.core = { statusId: effect.id }
|
||||
effect.id = name
|
||||
return effect
|
||||
}
|
||||
|
||||
async function createEffect (tokens, choice, greater) {
|
||||
const effects = []
|
||||
if (choice === 'distracted' || choice === 'raise') {
|
||||
effects.push(getStatus('SWADE.Distr', 'Distracted'))
|
||||
}
|
||||
if (choice === 'vulnerable' || choice === 'raise') {
|
||||
effects.push(getStatus('SWADE.Vuln', 'Vulnerable'))
|
||||
}
|
||||
if (greater) {
|
||||
effects.push(getStatus('SWADE.Shaken', 'Shaken'))
|
||||
}
|
||||
for (const token of tokens) {
|
||||
const mutateOptions = swadeMBHelpers.defaultMutationOptions('Confusion')
|
||||
const mutate = {
|
||||
embedded: { ActiveEffect: {} }
|
||||
}
|
||||
for (const effect of effects) {
|
||||
mutate.embedded.ActiveEffect[effect.id] = effect
|
||||
}
|
||||
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