feat: Enhance Duality Roll critical hit detection for varied roll structures and migrate to the renderChatMessageHTML hook.

This commit is contained in:
CPTN Cosmo 2026-02-10 03:35:52 +01:00
parent e57d889a21
commit c7589a55ab
No known key found for this signature in database

View file

@ -101,17 +101,37 @@ Hooks.on('renderSettingsConfig', (app, html, data) => {
function isCriticalHit(roll) { function isCriticalHit(roll) {
if (!roll) return false; if (!roll) return false;
// Check for Duality Roll // Check for Duality Roll (Class or Structure)
if (roll.constructor.name === "DualityRoll") { // 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 // Exclude reaction rolls
const isReaction = roll.options?.actionType === "reaction"; const isReaction = roll.options?.actionType === "reaction";
if (isReaction) return false; if (isReaction) return false;
// Check Hope == Fear let hopeTotal, fearTotal;
if (!roll.dHope?.total || !roll.dFear?.total) return false;
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) // Check for standard d20 Roll (GM rolls mainly)
@ -122,8 +142,8 @@ function isCriticalHit(roll) {
return false; return false;
} }
// Hook into renderChatMessage to add CSS classes // Hook into renderChatMessageHTML (replacement for renderChatMessage)
Hooks.on('renderChatMessage', (message, html, data) => { Hooks.on('renderChatMessageHTML', (message, html, data) => {
// Only proceed if we have a roll // Only proceed if we have a roll
if (!message.rolls || message.rolls.length === 0) return; if (!message.rolls || message.rolls.length === 0) return;