From 9eb7f4c5ea8c74b170c11c1ca8f29528b934cdb8 Mon Sep 17 00:00:00 2001 From: Mike Bloy Date: Sat, 18 Nov 2023 23:58:09 -0600 Subject: [PATCH] updated havoc --- scripts/module.js | 3 +-- scripts/powerEffects.js | 51 ++++++++++++++++++----------------------- scripts/shim.js | 4 ++++ 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/scripts/module.js b/scripts/module.js index 0498760..852a4cc 100644 --- a/scripts/module.js +++ b/scripts/module.js @@ -1,6 +1,6 @@ import { api } from './api.js' import { requestTokenRoll } from './helpers.js' -import { havocResult, shapeChangeOnDismiss } from './powerEffects.js' +import { shapeChangeOnDismiss } from './powerEffects.js' import { log, shim } from './shim.js' const moduleName = 'swade-mb-helpers' @@ -25,7 +25,6 @@ Hooks.on('ready', () => { Hooks.on('socketlib.ready', () => { const socket = socketlib.registerModule('swade-mb-helpers') - socket.register('havocResult', havocResult) socket.register('requestTokenRoll', requestTokenRoll) shim._socket = socket }) diff --git a/scripts/powerEffects.js b/scripts/powerEffects.js index d683b5c..9765507 100644 --- a/scripts/powerEffects.js +++ b/scripts/powerEffects.js @@ -1,4 +1,5 @@ import { CONST, log, shim } from './shim.js' +import { requestRollFromTokens } from './helpers.js' class PowerEffect { constructor (token, targets) { @@ -556,13 +557,32 @@ class HavocEffect extends TargetedPowerEffect { async prepResult () { this.raise = (this.buttons === 'raise') + this.effectDocs.unshift(shim.getStatus('SWADE.Distr', 'Distracted')) } async applyResult () { await super.applyResult() - for (const target of this.targets) { - await havocResult(target.id, this.raise) + await shim.wait(1000) + + const resistMods = function (token) { + const mods = [] + if (token.actor.effects.find(e => e.name === 'Flying')) { + mods.push({ label: 'Flying', value: -2 }) + } + return mods } + + const options = { + title: 'Resisting Havoc!', + flavour: 'Havoc!', + mods: [], + modCallback: resistMods + } + if (this.raise) { + options.mods.push({ label: 'vs. Raise', value: -2 }) + } + + await requestRollFromTokens(this.targets, 'attribute', 'strength', options) } } @@ -1441,30 +1461,3 @@ export async function shapeChangeOnDismiss (data) { await token.update(update) } } - -export async function havocResult (tokenId, isRaise) { - const token = shim.canvas.tokens.get(tokenId) - if (!token) { - log('Unable to find token with id ', tokenId) - return - } - const owner = shim.warpgateUtil.firstOwner(token.document) - if (owner !== shim.user) { - shim.socket.executeAsUser(havocResult, owner.id, tokenId, isRaise) - return - } - const effect = shim.getStatus('SWADE.Distr', 'Distracted') - await shim.applyActiveEffects(token, [effect]) - log(`apply ${effect.label} to ${token.document.name}, raise: ${isRaise}`) - const opts = { - flavour: 'Resist Havoc', - additionalMods: [] - } - if (isRaise) { - opts.additionalMods.push({ label: 'vs. Raise', value: -2 }) - } - if (token.actor.effects.find(e => e.name === 'Flying')) { - opts.additionalMods.push({ label: 'Flying', value: -2 }) - } - token.actor.rollAttribute('strength', opts) -} diff --git a/scripts/shim.js b/scripts/shim.js index f5b2aee..f8beeb1 100644 --- a/scripts/shim.js +++ b/scripts/shim.js @@ -116,6 +116,10 @@ export class shim { await warpgate.mutate(token.document, mutation, {}, mutateOptions) } + static wait (ms) { + return warpgate.wait(ms) + } + static warpgateMenu (menuData, menuOptions) { return warpgate.menu(menuData, menuOptions) }