diff --git a/scripts/module.js b/scripts/module.js index 0955de3..444370a 100644 --- a/scripts/module.js +++ b/scripts/module.js @@ -101,17 +101,37 @@ Hooks.on('renderSettingsConfig', (app, html, data) => { function isCriticalHit(roll) { if (!roll) return false; - // Check for Duality Roll - if (roll.constructor.name === "DualityRoll") { + // Check for Duality Roll (Class or Structure) + // DSN might pass a BaseRoll, so we check properties or terms + const isDuality = roll.constructor.name === "DualityRoll" || + (roll.dHope && roll.dFear) || + (roll.terms && roll.terms.filter(t => t.faces === 12).length === 2); + + if (isDuality) { // Exclude reaction rolls const isReaction = roll.options?.actionType === "reaction"; - if (isReaction) return false; - // Check Hope == Fear - if (!roll.dHope?.total || !roll.dFear?.total) return false; + let hopeTotal, fearTotal; - return roll.dHope.total === roll.dFear.total; + if (roll.dHope?.total !== undefined && roll.dFear?.total !== undefined) { + hopeTotal = roll.dHope.total; + fearTotal = roll.dFear.total; + } else { + // Fallback: extract from terms + const d12s = roll.terms.filter(t => t.faces === 12); + if (d12s.length >= 2) { + // Assuming standard order or just checking equality + // In Duality, Hope and Fear are the two d12s. Equality is what matters. + hopeTotal = d12s[0].total; + fearTotal = d12s[1].total; + } + } + + if (hopeTotal !== undefined && fearTotal !== undefined) { + console.log('Duality Check:', hopeTotal, fearTotal); + return hopeTotal === fearTotal; + } } // Check for standard d20 Roll (GM rolls mainly) @@ -122,8 +142,8 @@ function isCriticalHit(roll) { return false; } -// Hook into renderChatMessage to add CSS classes -Hooks.on('renderChatMessage', (message, html, data) => { +// Hook into renderChatMessageHTML (replacement for renderChatMessage) +Hooks.on('renderChatMessageHTML', (message, html, data) => { // Only proceed if we have a roll if (!message.rolls || message.rolls.length === 0) return;