From 557cb6e5468c2df7bffbef5da9ba8fc27be9e7e2 Mon Sep 17 00:00:00 2001 From: Mike Bloy Date: Mon, 10 Jun 2024 16:49:22 -0500 Subject: [PATCH] macro to add effects to powers --- macros/addEffectToPowers.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 macros/addEffectToPowers.js diff --git a/macros/addEffectToPowers.js b/macros/addEffectToPowers.js new file mode 100644 index 0000000..7ab37f7 --- /dev/null +++ b/macros/addEffectToPowers.js @@ -0,0 +1,28 @@ +const tokens = canvas.tokens.controlled; +const actors = tokens.map((t) => t.actor); +const EFFECT_OBJECT = { + name: 'Effect', + type: 'macro', + dice: null, + resourcesUsed: null, + modifier: '', + override: '', + uuid: 'Compendium.swade-mb-helpers.helper-macros.Macro.AjuA11hQ48UJNwlH', + macroActor: 'self', + isHeavyWeapon: false, +}; +for (const actor of actors) { + const updates = []; + for (const power of actor.items.filter((i) => i.type === 'power')) { + if (Object.values(power.system.actions.additional).find((action) => action.name === 'Effect')) { + continue; + } + const _id = power.id; + const additional = foundry.utils.deepClone(power.system.actions.additional); + additional[foundry.utils.randomID(8)] = foundry.utils.deepClone(EFFECT_OBJECT); + updates.push({ _id, 'system.actions.additional': additional }); + } + if (updates.length > 0) { + actor.updateEmbeddedDocuments('Item', updates); + } +}