87 lines
2.5 KiB
JavaScript
87 lines
2.5 KiB
JavaScript
import { moduleName } from './globals.js'
|
|
import { PowerEffect } from './basePowers.js'
|
|
|
|
class BurrowEffect extends PowerEffect {
|
|
get name () { return 'Burrow' }
|
|
get duration () { return 5 }
|
|
get icon () { return 'icons/magic/earth/projectile-stone-landslide.webp' }
|
|
get hasAdditionalRecipients () { return true }
|
|
get additionalRecipientCost () { return 1 }
|
|
get basePowerPoints () { return 1 }
|
|
get isTargeted () { return true }
|
|
get modifiers () {
|
|
const mods = super.modifiers
|
|
mods.push(
|
|
{ name: 'Power',
|
|
id: 'power',
|
|
value: 1,
|
|
epic: false,
|
|
effect: false,
|
|
})
|
|
return mods
|
|
}
|
|
get effectName () {
|
|
return `${this.name} ${this.data.mods.has('power') ? '[Power] ' : ''}` +
|
|
`(${this.data.raise ? 'full' : 'half'} pace)`
|
|
}
|
|
}
|
|
|
|
const PowerClasses = {
|
|
burrow: BurrowEffect
|
|
}
|
|
|
|
/* ---------------------------------------------------------------- */
|
|
|
|
export async function powerEffectManagementHook(effect, data, userId) {
|
|
if (game.user.id !== userId) {
|
|
return
|
|
}
|
|
const maintId = effect.getFlag(moduleName, 'maintainingId')
|
|
if (!maintId) {
|
|
return
|
|
}
|
|
const mutateOptions = {
|
|
permanent: true,
|
|
comparisonKeys: {
|
|
ActiveEffect: 'id'
|
|
}
|
|
}
|
|
const targetIds = effect.getFlag(moduleName, 'targetIds') || []
|
|
for (const targetId of targetIds) {
|
|
const mutation = {
|
|
embedded: { ActiveEffect: {} }
|
|
}
|
|
const target = canvas.tokens.get(targetId)
|
|
if (!target) {
|
|
continue
|
|
}
|
|
const effects = target.actor.effects.filter(
|
|
e => e.getFlag(moduleName, 'maintId') === maintId)
|
|
for (const effect of effects) {
|
|
mutation.embedded.ActiveEffect[effect.id] = warpgate.CONST.DELETE
|
|
}
|
|
mutateOptions.description = `${effect.parent.name} is no longer ${effect.name} on ${target.name}`
|
|
await warpgate.mutate(target.document, mutation, {}, mutateOptions)
|
|
}
|
|
}
|
|
|
|
export async function powers (options = {}) {
|
|
const token = 'token' in options ? options.token : null
|
|
if (token === undefined || token === null) {
|
|
ui.notifications.error('Please select one token to be the caster')
|
|
return
|
|
}
|
|
|
|
const targets = 'targets' in options ? Array.from(options.targets) : []
|
|
const item = 'item' in options ? options.item : null
|
|
const swid = options?.name || item?.system.swid || null
|
|
|
|
if (swid in PowerClasses) {
|
|
const runner = new PowerClasses[swid](token, targets)
|
|
runner.powerEffect()
|
|
return
|
|
}
|
|
ui.notifications.error(`No power effect found for ${name}`)
|
|
}
|
|
|