From fa0b1078a1f0b30179e672b6dccd0a8d3ff89165 Mon Sep 17 00:00:00 2001 From: Eldritch-Oliver Date: Tue, 7 Oct 2025 22:22:09 -0600 Subject: [PATCH] Finish the helper in the public API and broadcast the socket event --- module/Apps/DelveDiceHUD.mjs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/module/Apps/DelveDiceHUD.mjs b/module/Apps/DelveDiceHUD.mjs index a486e4b..2bf4b32 100644 --- a/module/Apps/DelveDiceHUD.mjs +++ b/module/Apps/DelveDiceHUD.mjs @@ -264,9 +264,40 @@ export class DelveDiceHUD extends HandlebarsApplicationMixin(ApplicationV2) { game.settings.set(`ripcrypt`, `sandsOfFate`, newSands); }; + /** + * A helper method that rolls the dice required for hasty turns while delving + * and adjusts the Sands of Fate accordingly + */ static async rollForHaste() { + const shouldUpdateSands = game.settings.get(`ripcrypt`, `allowUpdateSandsSocket`); + if (shouldUpdateSands && game.users.activeGM == null) { + ui.notifications.error(localizer(`RipCrypt.notifs.error.no-active-gm`)); + return; + }; + const roll = new Roll(`1d8xo=1`); await roll.evaluate(); + + let delta = 0; + if (roll.dice[0].results[0].exploded) { + delta = -1; + if (roll.dice[0].results[1].result === 1) { + delta = -2; + }; + }; + + roll.toMessage({ flavor: `Haste Check` }); + + // Change the Sands of Fate setting if required + if (delta === 0 || !shouldUpdateSands) { return }; + if (game.user.isActiveGM) { + ui.delveDice.sandsOfFateDelta(delta); + } else { + game.socket.emit(`system.ripcrypt`, { + event: `updateSands`, + payload: { delta }, + }); + }; }; // #endregion };