Skip to content

Commit

Permalink
Merge pull request #722 from Flightless-Birb/dnd5e-v4
Browse files Browse the repository at this point in the history
dnd5e v4 compatibility
  • Loading branch information
otigon authored Oct 6, 2024
2 parents b0fd5c3 + 0a0c5bc commit 5079d88
Showing 1 changed file with 47 additions and 22 deletions.
69 changes: 47 additions & 22 deletions src/system-support/aa-dnd5e.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,54 @@ export function systemHooks() {
} else if (game.modules.get("wire")?.active) {
// WIRE handles triggering AA
} else {
Hooks.on("dnd5e.preRollAttack", async (item, options) => {
let spellLevel = options.spellLevel ?? void 0;
Hooks.once("dnd5e.rollAttack", async (item, roll) => {
criticalCheck(roll, item);
let playOnDamage = game.settings.get('autoanimations', 'playonDamageCore')
if (item.hasAreaTarget || (item.hasDamage && playOnDamage)) { return; }
attack(await getRequiredData({item, actor: item.actor, workflow: item, rollAttackHook: {item, roll}, spellLevel}))
})
})
Hooks.on("dnd5e.rollDamage", async (item, roll) => {
let playOnDamage = game.settings.get('autoanimations', 'playonDamageCore')
if (item.hasAreaTarget || (item.hasAttack && !playOnDamage)) { return; }
damage(await getRequiredData({item, actor: item.actor, workflow: item, rollDamageHook: {item, roll}, spellLevel: roll?.data?.item?.level ?? void 0}))
})
Hooks.on('dnd5e.useItem', async (item, config, options) => {
if (item?.hasAreaTarget || item.hasAttack || item.hasDamage) { return; }
useItem(await getRequiredData({item, actor: item.actor, workflow: item, useItemHook: {item, config, options}, spellLevel: options?.flags?.dnd5e?.use?.spellLevel || void 0}))
})
Hooks.on("dnd5e.rollAttackV2", async (rolls, data) => {
const roll = rolls[0];
const activity = data.subject;
const playOnDamage = game.settings.get('autoanimations', 'playonDamageCore');
if (["circle", "cone", "cube", "cylinder", "line", "sphere", "square", "wall"].includes(activity?.target?.template?.type) || (activity?.damage?.parts?.length && activity?.type != "heal" && playOnDamage)) { return; }
const item = activity?.parent?.parent;
const ammoItem = item?.parent?.items?.get(data?.ammoUpdate?.id) ?? null;
const overrideNames = activity?.name && !["heal", "summon"].includes(activity?.name?.trim()?.toLowerCase()) ? [activity.name] : [];
criticalCheck(roll, item);
attack(await getRequiredData({item: item, actor: item.parent, workflow: item, rollAttackHook: {item, roll}, spellLevel: roll?.data?.item?.level ?? void 0, ammoItem, overrideNames}));
});
Hooks.on("dnd5e.rollDamageV2", async (rolls, data) => {
const roll = rolls[0];
const activity = data.subject;
const playOnDamage = game.settings.get('autoanimations', 'playonDamageCore');
if (["circle", "cone", "cube", "cylinder", "line", "sphere", "square", "wall"].includes(activity?.target?.template?.type) || (activity?.type == "attack" && !playOnDamage)) { return; }
const item = activity?.parent?.parent;
const overrideNames = activity?.name && !["heal", "summon"].includes(activity?.name?.trim()?.toLowerCase()) ? [activity.name] : [];
damage(await getRequiredData({item, actor: item.parent, workflow: item, rollDamageHook: {item, roll}, spellLevel: roll?.data?.item?.level ?? void 0, overrideNames}));
});
Hooks.on('dnd5e.postUseActivity', async (activity, usageConfig, results) => {
if (["circle", "cone", "cube", "cylinder", "line", "sphere", "square", "wall"].includes(activity?.target?.template?.type) || activity?.type == "attack" || (activity?.damage?.parts?.length && activity?.type != "heal")) { return; }
const config = usageConfig;
const options = results;
const item = activity?.parent?.parent;
const overrideNames = activity?.name && !["heal", "summon"].includes(activity?.name?.trim()?.toLowerCase()) ? [activity.name] : [];
useItem(await getRequiredData({item, actor: item.parent, workflow: item, useItemHook: {item, config, options}, spellLevel: options?.flags?.dnd5e?.use?.spellLevel || void 0, overrideNames}));
});
}
Hooks.on("dnd5e.preCreateActivityTemplate", async (activity, templateData) => {
templateData.flags.autoanimations = {
itemData: {
parent: activity?.parent?.parent?.parent,
actor: activity?.parent?.parent?.parent,
name: activity?.parent?.parent?.name,
type: activity?.parent?.parent?.type,
system: activity?.parent?.parent?.system,
flags: activity?.parent?.parent?.flags
}
}
});
Hooks.on("createMeasuredTemplate", async (template, data, userId) => {
if (userId !== game.user.id) { return };
templateAnimation(await getRequiredData({itemUuid: template.flags?.dnd5e?.origin, templateData: template, workflow: template, isTemplate: true}))
})
const activity = await fromUuid(template.flags?.dnd5e?.origin);
const item = activity ? activity?.parent?.parent : template?.flags?.autoanimations?.itemData;
const overrideNames = activity?.name && !["heal", "summon"].includes(activity?.name?.trim()?.toLowerCase()) ? [activity.name] : [];
templateAnimation(await getRequiredData({item, templateData: template, workflow: template, isTemplate: true, overrideNames}));
});
/*
Hooks.on("createMeasuredTemplate", async (template, data, userId) => {
if (userId !== game.user.id) { return };
Expand Down Expand Up @@ -76,7 +101,7 @@ async function useItem(input) {
}

async function attack(input) {
checkAmmo(input)
//checkAmmo(input)
checkReach(input)
debug("Attack rolled, checking for animations");
const handler = await AAHandler.make(input)
Expand All @@ -85,7 +110,7 @@ async function attack(input) {
}

async function damage(input) {
checkAmmo(input)
//checkAmmo(input)
checkReach(input)
debug("Damage rolled, checking for animations")
const handler = await AAHandler.make(input)
Expand Down

0 comments on commit 5079d88

Please sign in to comment.