feat: Refine Dice So Nice critical hit effect application logic and add debugging logs for DSN integration.
This commit is contained in:
parent
c8727fd7bb
commit
b7c9c0071a
1 changed files with 32 additions and 9 deletions
|
|
@ -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');
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue