From b7c9c0071ac497cc5fa6c5d61f93e8b18f448f68 Mon Sep 17 00:00:00 2001 From: CPTN Cosmo Date: Tue, 10 Feb 2026 03:47:35 +0100 Subject: [PATCH] feat: Refine Dice So Nice critical hit effect application logic and add debugging logs for DSN integration. --- scripts/module.js | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/scripts/module.js b/scripts/module.js index 0ac0954..9e7aca6 100644 --- a/scripts/module.js +++ b/scripts/module.js @@ -46,6 +46,13 @@ Hooks.once('init', () => { }, default: 'default' }); + + // Check if DSN is ready and log effects + Hooks.once('diceSoNiceReady', (dice3d) => { + console.log('DSN Ready. Helper:', dice3d); + const sfxModes = dice3d.getSFXModes(); + console.log('DSN SFX Modes:', sfxModes); + }); }); // Hook to handle conditional settings in the UI @@ -199,35 +206,51 @@ Hooks.on('renderChatMessageHTML', (message, html, data) => { } }); -// Hook into DiceSoNice to trigger effects // Hook into DiceSoNice to trigger effects Hooks.on('diceSoNiceRollStart', (messageId, context) => { + console.log('DSN Hook Fired', messageId, context); const roll = context.roll; if (!roll) return; if (isCriticalHit(roll)) { + console.log('DSN: Critical Hit Detected'); const effect = game.settings.get('dh-immersive-crits', 'dsnCritEffect'); + console.log('DSN Effect Setting:', effect); + if (effect && effect !== 'none') { + const effectName = effect === 'default' ? 'Stars' : capitalize(effect); + console.log('DSN Applying Effect Name:', effectName); + + // Function to apply effect to a die/term + const applyEffect = (term) => { + if (!term.options) term.options = {}; + // Try both id (for presets) and specialEffect (for classes) to be safe, + // based on different DSN versions/styles. + // 'Stars', 'Fire', etc are likely registered system effects. + term.options.sfx = { + id: effectName, + specialEffect: effectName + }; + console.log('Applied sfx to term:', term, term.options.sfx); + }; + // Check if roll.dice exists and has elements if (roll.dice && roll.dice.length > 0) { - roll.dice.forEach(die => { - if (!die.options) die.options = {}; - // Use new DSN v4 API: sfx property - // Effect ID should likely be lowercase - die.options.sfx = { id: effect === 'default' ? 'stars' : effect }; - }); + roll.dice.forEach(die => applyEffect(die)); } else { // Determine if we need to iterate terms for Duality Rolls + console.log('No roll.dice found. Checking terms:', roll.terms); if (roll.terms) { roll.terms.forEach(term => { if (term.faces) { // It's a die - if (!term.options) term.options = {}; - term.options.sfx = { id: effect === 'default' ? 'stars' : effect }; + applyEffect(term); } }); } } } + } else { + console.log('DSN: Not a Critical Hit'); } });