Finish the helper in the public API and broadcast the socket event
This commit is contained in:
parent
78d02400d0
commit
fa0b1078a1
1 changed files with 31 additions and 0 deletions
|
|
@ -264,9 +264,40 @@ export class DelveDiceHUD extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||||
game.settings.set(`ripcrypt`, `sandsOfFate`, newSands);
|
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() {
|
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`);
|
const roll = new Roll(`1d8xo=1`);
|
||||||
await roll.evaluate();
|
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
|
// #endregion
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue