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 };