feat: Refine Dice So Nice critical hit effect application logic and add debugging logs for DSN integration.

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

View file

@ -46,6 +46,13 @@ Hooks.once('init', () => {
}, },
default: 'default' 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 // 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 // Hook into DiceSoNice to trigger effects
Hooks.on('diceSoNiceRollStart', (messageId, context) => { Hooks.on('diceSoNiceRollStart', (messageId, context) => {
console.log('DSN Hook Fired', messageId, context);
const roll = context.roll; const roll = context.roll;
if (!roll) return; if (!roll) return;
if (isCriticalHit(roll)) { if (isCriticalHit(roll)) {
console.log('DSN: Critical Hit Detected');
const effect = game.settings.get('dh-immersive-crits', 'dsnCritEffect'); const effect = game.settings.get('dh-immersive-crits', 'dsnCritEffect');
console.log('DSN Effect Setting:', effect);
if (effect && effect !== 'none') { 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 // Check if roll.dice exists and has elements
if (roll.dice && roll.dice.length > 0) { if (roll.dice && roll.dice.length > 0) {
roll.dice.forEach(die => { roll.dice.forEach(die => applyEffect(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 };
});
} else { } else {
// Determine if we need to iterate terms for Duality Rolls // Determine if we need to iterate terms for Duality Rolls
console.log('No roll.dice found. Checking terms:', roll.terms);
if (roll.terms) { if (roll.terms) {
roll.terms.forEach(term => { roll.terms.forEach(term => {
if (term.faces) { // It's a die if (term.faces) { // It's a die
if (!term.options) term.options = {}; applyEffect(term);
term.options.sfx = { id: effect === 'default' ? 'stars' : effect };
} }
}); });
} }
} }
} }
} else {
console.log('DSN: Not a Critical Hit');
} }
}); });