From 10bb339db94153efbfd7b1ea63e01d5732d7ee9d Mon Sep 17 00:00:00 2001 From: Pafvel <91607056+Pafvel@users.noreply.github.com> Date: Sat, 2 Mar 2024 18:06:06 +0100 Subject: [PATCH 1/2] Dragonbane support --- src/system-support/aa-dragonbane.js | 58 +++++++++++++++++++++++++++++ src/system-support/index.js | 1 + 2 files changed, 59 insertions(+) create mode 100644 src/system-support/aa-dragonbane.js diff --git a/src/system-support/aa-dragonbane.js b/src/system-support/aa-dragonbane.js new file mode 100644 index 00000000..8a49ec35 --- /dev/null +++ b/src/system-support/aa-dragonbane.js @@ -0,0 +1,58 @@ +import { trafficCop } from "../router/traffic-cop.js" +import AAHandler from "../system-handlers/workflow-data.js"; +import { getRequiredData } from "./getRequiredData.js"; + +export function systemHooks() { + Hooks.on("createChatMessage", async (msg) => { + if (msg.user.id !== game.user.id) { return }; + + // Extract the item id from the Roll Damage button. + // The item id is only available on successful spells casts and weapon attacks. + function extractItemId(content) { + try { + let itemId = $(content).find('.magic-roll').attr("data-spell-id"); + if (!itemId) { + itemId = $(content).find('.weapon-roll').attr("data-weapon-id"); + } + return itemId; + } catch (exception) { + console.log("COULD NOT GET ITEM ID") + return null; + } + } + + // Extract the target id from the Roll Damage button + // Only supports single target + function extractTargets(content) { + try { + let targetId = $(content).find('.magic-roll').attr("data-target-id"); + if (!targetId) { + targetId = $(content).find('.weapon-roll').attr("data-target-id");; + } + let target = targetId ? fromUuidSync(targetId) : null; + if (target instanceof TokenDocument) { + target = target.object; + } + return target ? [target] : null; + } catch (exception) { + console.log("COULD NOT GET ITEM ID") + return null; + } + } + + let compiledData = await getRequiredData({ + itemId: extractItemId(msg.content), + targets: extractTargets(msg.content), + actorId: msg.speaker?.actor, + tokenId: msg.speaker?.token, + workflow: msg, + }) + if (!compiledData.item) { return; } + runDragonbane(compiledData); + }); +} + +async function runDragonbane(input) { + const handler = await AAHandler.make(input); + trafficCop(handler); +} \ No newline at end of file diff --git a/src/system-support/index.js b/src/system-support/index.js index f9fdac43..48cbfbc9 100644 --- a/src/system-support/index.js +++ b/src/system-support/index.js @@ -29,3 +29,4 @@ export * as ptu from "./aa-ptu.js"; export * as lancer from "./aa-lancer.js"; export * as anarchy from "./aa-shadowrun-anarchy.js"; export * as wrathandglory from "./aa-wrath-and-glory.js"; +export * as dragonbane from "./aa-dragonbane.js"; From 6bc7da5d0d818de623b914f28820ddf714287d4e Mon Sep 17 00:00:00 2001 From: Pafvel <91607056+Pafvel@users.noreply.github.com> Date: Sat, 2 Mar 2024 18:53:56 +0100 Subject: [PATCH 2/2] Removed redundant code for targeting in Dragonbane --- src/system-support/aa-dragonbane.js | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/src/system-support/aa-dragonbane.js b/src/system-support/aa-dragonbane.js index 8a49ec35..c8b0ad9e 100644 --- a/src/system-support/aa-dragonbane.js +++ b/src/system-support/aa-dragonbane.js @@ -21,28 +21,8 @@ export function systemHooks() { } } - // Extract the target id from the Roll Damage button - // Only supports single target - function extractTargets(content) { - try { - let targetId = $(content).find('.magic-roll').attr("data-target-id"); - if (!targetId) { - targetId = $(content).find('.weapon-roll').attr("data-target-id");; - } - let target = targetId ? fromUuidSync(targetId) : null; - if (target instanceof TokenDocument) { - target = target.object; - } - return target ? [target] : null; - } catch (exception) { - console.log("COULD NOT GET ITEM ID") - return null; - } - } - let compiledData = await getRequiredData({ itemId: extractItemId(msg.content), - targets: extractTargets(msg.content), actorId: msg.speaker?.actor, tokenId: msg.speaker?.token, workflow: msg,