diff --git a/module.json b/module.json index 29160b7..2733081 100644 --- a/module.json +++ b/module.json @@ -15,6 +15,7 @@ "esmodules": [ "scripts/module.js" ], + "socket": true, "packs": [ { "name": "module-docs", @@ -54,22 +55,22 @@ "label": "SWADE MB Helper Actors", "path": "packs/helper-actors", "type": "Actor", + "system": "swade", "ownership": { "PLAYER": "OBSERVER", "ASSISTANT": "OWNER" - }, - "system": "swade" + } }, { "name": "swade-mb-gear", "label": "SWADE MB Gear", "path": "packs/gear", "type": "Item", + "system": "swade", "ownership": { "PLAYER": "OBSERVER", "ASSISTANT": "OWNER" - }, - "system": "swade" + } } ], "packFolders": [ @@ -106,6 +107,10 @@ "compatibility": { "verified": "1.16.2" } + }, + { + "id": "socketlib", + "type": "module" } ], "recommends": [ diff --git a/scripts/module.js b/scripts/module.js index 9171ae8..06a19a7 100644 --- a/scripts/module.js +++ b/scripts/module.js @@ -1,6 +1,6 @@ import { api } from './api.js' -import { shapeChangeOnDismiss } from './powerEffects.js' -import { log } from './shim.js' +import { havocResult, shapeChangeOnDismiss } from './powerEffects.js' +import { log, shim } from './shim.js' const moduleName = 'swade-mb-helpers' @@ -17,6 +17,13 @@ Hooks.on('setup', api.registerFunctions) Hooks.on('ready', () => { _checkModule('warpgate') + _checkModule('socketlib') log('Initialized SWADE MB Helpers') warpgate.event.watch(warpgate.EVENT.DISMISS, shapeChangeOnDismiss) }) + +Hooks.on('socketlib.ready', () => { + const socket = socketlib.registerModule('swade-mb-helpers') + socket.register('havocResult', havocResult) + shim._socket = socket +}) diff --git a/scripts/powerEffects.js b/scripts/powerEffects.js index 96e4ca9..d683b5c 100644 --- a/scripts/powerEffects.js +++ b/scripts/powerEffects.js @@ -545,6 +545,27 @@ class EntangleEffect extends TargetedPowerEffect { } } +class HavocEffect extends TargetedPowerEffect { + get name () { + return 'Havoc' + } + + get baseDurationRounds () { + return 1 + } + + async prepResult () { + this.raise = (this.buttons === 'raise') + } + + async applyResult () { + await super.applyResult() + for (const target of this.targets) { + await havocResult(target.id, this.raise) + } + } +} + class IntangibilityEffect extends TargetedPowerEffect { get name () { return 'Intangility' @@ -1349,6 +1370,7 @@ const PowerClasses = { 'detectconceal-aracana': DetectConcealArcanaEffect, disguise: DisguiseEffect, entangle: EntangleEffect, + havoc: HavocEffect, intangibility: IntangibilityEffect, invisibility: InvisibilityEffect, 'lower trait': BoostLowerTraitEffect, @@ -1419,3 +1441,30 @@ 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 fef99b3..cb7d026 100644 --- a/scripts/shim.js +++ b/scripts/shim.js @@ -21,6 +21,10 @@ export class shim { return Actor } + static get canvas () { + return game.canvas + } + static get folders () { return game.folders } @@ -49,6 +53,12 @@ export class shim { return game.scenes } + static _socket = null + + static get socket () { + return shim._socket + } + static mergeObject (...args) { return mergeObject(...args) } @@ -114,6 +124,10 @@ export class shim { return warpgate.spawnAt(...args) } + static get warpgateUtil () { + return warpgate.util + } + static getActorFolderByPath (path) { const names = path.split('/') if (names[0] === '') {