Skip to content

Commit

Permalink
Updated roll detection
Browse files Browse the repository at this point in the history
Roll detection type code
Added setting to allow hidden rolls
  • Loading branch information
Yosoy-Ed authored Apr 19, 2024
1 parent c561967 commit d92f27c
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 3 deletions.
46 changes: 46 additions & 0 deletions scripts/cm-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,49 @@ export function criticalmessage(d20dices, userwhorolled) {
}
});
}

export function detectroll(chatMessage) {

// If the current user is not the one who rolled the dice, do nothing
if (chatMessage.user._id !== game.user._id) {
return;
}

let rolltype = 0; // 0-Public, 1-Blind , 2-PrivateGM, 3-Self

// If the roll is not public it is whisper
if (chatMessage.whisper.length !== 0) {

let whisperdto = chatMessage.whisper;
let gmids = game.users.contents.filter(user => user.isGM).map(gm => gm.id);

// The roll is blind
if (chatMessage.blind) {
rolltype = 1; // Blind Roll
} else {
//The roll was whispered to the GM
if(whisperdto.length === gmids.length){

const a1fus = whisperdto.sort().join('');
const a2fus = gmids.sort().join('');

if (a1fus === a2fus){
rolltype = 2; //Private GM
}
}
//The roll was whispered to himself
if (chatMessage.whisper[0] === chatMessage.user._id && chatMessage.whisper.length === 1) {
rolltype = 3; // selfRoll
}
}
}

if (rolltype !== 0 && !game.settings.get('critic-message', 'allowhiddenrolls')) {
return;
}

let d20dices = chatMessage.rolls[0].dice;
let userwhorolled = chatMessage.user.name;
verifyimgfolders();
criticalmessage(d20dices, userwhorolled);
}
60 changes: 57 additions & 3 deletions scripts/cm.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Updatetxtarraysn1, Updatetxtarraysn20, ResetButton, ResetButton1, ResetButtonAll } from './cm-classes.js';
import { verifyimgfolders, criticalmessage } from './cm-functions.js';
import { verifyimgfolders, criticalmessage, detectroll } from './cm-functions.js';


/************************************************** CHAT DICE HOOKS ***********/
/************************************************** CHAT DICE HOOKS ***********
// If dice so nice is not active
Hooks.on("createChatMessage", (chatMessage) => {
if (!game.modules.get("dice-so-nice")?.active) {
Expand Down Expand Up @@ -33,9 +33,63 @@ Hooks.on('diceSoNiceRollComplete', (data) => {
}
});
/* **************************** INIT SETTINGS ************************************ */
/************************************************** CHAT DICE HOOKS ***********/
// If dice so nice is not active
Hooks.on("createChatMessage", (chatMessage) => {

if (game.modules.get("dice-so-nice")?.active){ //If dice so nice is active but the roll is blind and ghost dice is not enabled
if(!game.settings.get("dice-so-nice", "showGhostDice") && chatMessage.blind && !game.settings.get('critic-message', 'disablemodule') && chatMessage.isRoll){

detectroll(chatMessage);
}
}

if (!game.modules.get("dice-so-nice")?.active && !game.settings.get('critic-message', 'disablemodule') && chatMessage.isRoll ) {

detectroll(chatMessage);
}

});

// If dice so nice is active wait for animation to finish
Hooks.on('diceSoNiceRollComplete', (data) => {

let chatMessage = game.messages.get(data);

if (game.settings.get('critic-message', 'disablemodule') || (chatMessage.blind && !game.settings.get("dice-so-nice", "showGhostDice"))) {// if the roll is blind it was registered like dice so nice is not installed and evaluated before
return;
}

detectroll(chatMessage);
});
/****************************************************************************** */

/***************************** INIT SETTINGS ************************************ */
Hooks.once('init', function () {

//Option to stop detecting Natural dices
game.settings.register('critic-message', 'disablemodule', {
name: 'disable module',
hint: 'While this is enabled, critical messages will not be shown',
scope: 'world',
config: true,
type: Boolean,
default: false,
restricted: true
});

//Avoid showing data if not selected
game.settings.register('critic-message', 'allowhiddenrolls', {
name: 'Allow to show message on hidden rolls',
hint: 'MESSAGES WILL APPEAR ONLY WITH PUBLIC ROLLS.',
scope: 'world',
config: true,
type: Boolean,
default: true,
restricted: true
});

// RESET ALL SETTINGS TO DEFAULT
game.settings.registerMenu('critic-message', 'reset-all-button', {
name: "WARNING: Reset All defaults requires reload!",
Expand Down

0 comments on commit d92f27c

Please sign in to comment.