diff --git a/scripts/cm-functions.js b/scripts/cm-functions.js index 517f1f7..5b536e1 100644 --- a/scripts/cm-functions.js +++ b/scripts/cm-functions.js @@ -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); +} \ No newline at end of file diff --git a/scripts/cm.js b/scripts/cm.js index fb56f8d..81c3234 100644 --- a/scripts/cm.js +++ b/scripts/cm.js @@ -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) { @@ -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!",