gsimon2 / dramatic-rolls

Foundry Vtt module
GNU General Public License v3.0
7 stars 4 forks source link

Inline rolls do not activate Dramatic Rolls (Pathfinder 1e compatibility) #15

Closed SorteKanin closed 3 months ago

SorteKanin commented 3 years ago

When typing "[[1d20]]" (an "inline roll") into the chat, a natural 1 or 20 does not get the effects from Dramatic Rolls.

This is especially problematic for systems like Pathfinder 1e which uses inline rolls extensively for pretty much every roll possible from the character sheet.

It would be really nice if these rolls were acknowledged by Dramatic Rolls and would get the same effects as a "/r 1d20" command.

SorteKanin commented 3 years ago

On further investigation, this seems to be because of this:

Hooks.on('createChatMessage', (msg) => {
    let roll = msg._roll;
    const isRoller = msg.user.data._id == game.userId;
    const isPublicRoll = roll && !msg.data.whisper.length;

    if (roll && isRoller && !disableDueToNPC(msg.data.speaker)) {
        if (diceSoNiceActive) {
            pendingDiceSoNiceRolls.set(msg.id, {roll, isPublicRoll});
        } else {
            handleEffects(roll, isPublicRoll);
        }
    }
});

msg._roll is null for a message with an inline roll, since it isn't really a roll message entirely. That in turns causes this hook to fail:

Hooks.on('diceSoNiceRollComplete', (msgId) => {
    const storedInfo = pendingDiceSoNiceRolls.get(msgId); 
    const roll = storedInfo.roll;
    roll && handleEffects(roll, storedInfo.isPublicRoll);
    pendingDiceSoNiceRolls.delete(msgId);
});

Because storedInfo will be null. storedInfo.roll raises an exception.

"Dice So Nice!" uses the following hook to handle inline rolls:

Hooks.on('createChatMessage', (chatMessage) => {
    //precheck for better perf
    let hasInlineRoll = game.settings.get("dice-so-nice", "animateInlineRoll") && chatMessage.data.content.indexOf('inline-roll') !== -1;
    if ((!chatMessage.isRoll && !hasInlineRoll) || (!chatMessage.isContentVisible && !game.settings.get("dice-so-nice", "showGhostDice")) ||
        (game.view != "stream" && (!game.dice3d || game.dice3d.messageHookDisabled)) ||
        (chatMessage.getFlag("core", "RollTable") && !game.settings.get("dice-so-nice", "animateRollTable"))) {
        return;
    }
    let roll = chatMessage.isRoll ? chatMessage.roll : null;
    if (hasInlineRoll) {
        let JqInlineRolls = $($.parseHTML(chatMessage.data.content)).filter(".inline-roll.inline-result");
        if (JqInlineRolls.length == 0 && !chatMessage.isRoll) //it was a false positive
            return;
        let inlineRollList = [];
        JqInlineRolls.each((index, el) => {
            inlineRollList.push(Roll.fromJSON(unescape(el.dataset.roll)));
        });
        if (inlineRollList.length) {
            if (chatMessage.isRoll)
                inlineRollList.push(chatMessage.roll);
            let pool = PoolTerm.fromRolls(inlineRollList);
            roll = Roll.fromTerms([pool]);
        }
        else if (!chatMessage.isRoll)
            return;
    }
...

Hope that helps :)

gsimon2 commented 3 years ago

Wow, very good notes! Gives me a great start on working on this. I will add it to my to-do list and keep you updated here with the progress. Thanks for posting!

TheMathKing commented 7 months ago

Is this module abandoned? I have encountered this issue in v11 and was sad to see the module not being supported for a few years.

gsimon2 commented 3 months ago

Sorry for the long delay on this. I have a branch in flight that should add support for inline rolls. Need to do some more testing, but it seems to be working. Hopefully can release an update in a few days.

gsimon2 commented 3 months ago

This is now supported in version 2.5.0. Thanks for being patient.