Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added hook to influence dice rolls #265

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion apps/savingthrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,11 +465,13 @@ export class SavingThrow {
if (update.roll) {
let tooltip = '';
if (update.roll instanceof Roll) {
await this.asyncHooksCallAll('tokenBarInfluenceRoll', this, message, update);

msgtoken.roll = update.roll.toJSON();
msgtoken.total = update.roll.total;
msgtoken.reveal = update.reveal || reveal;
tooltip = await update.roll.getTooltip();

Hooks.callAll('tokenBarUpdateRoll', this, message, update.id, msgtoken.roll);
}

Expand Down Expand Up @@ -683,6 +685,17 @@ export class SavingThrow {
e.returnValue = false;
}
}

// Note: this is a straight extract from midiQoL
// https://gitlab.com/tposney/midi-qol/-/blob/master/src/module/utils.ts#L3167
static async asyncHooksCallAll(hook, ...args) {
if (!Hooks._hooks.hasOwnProperty(hook)) return true;
const fns = new Array(...Hooks._hooks[hook]);
for (let fn of fns) {
await Hooks._call(hook, fn, args);
}
return true;
}
}

/*
Expand Down