Zakarik / foundry-mm3

5 stars 3 forks source link

Damage automation not functioning (v1.30.9) #68

Open WildBillLives opened 1 month ago

WildBillLives commented 1 month ago

fvtt-Actor-decathalon-(uri-andropov)-UEUIHYNsmU6G9yNv.json

[^Example charcter where this issue occurs]

In my M&M3 game the damage automation is not working: I am running Foundry v11.315, M&M3 system v1.30.9

When a PC actor hits a target & I press the "Toughness Roll" button on the chat card I get the following error message:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'v3')
    at rollVs (common.mjs:2188:73)
common.mjs:2188

Notes: Sometimes it will say "reading 'v2', sometimes 'v1', and sometimes 'v3'. If I click the "Toughness Roll" button multiple times, sometimes it will eventually roll the save after 6-10 attempts, but it does not apply any injuries to the actor, but will apply effects (like Dazed, Incapacitated, etc) to the token. Also, when an NPC successfully hits a PC actor there is no 'Toughness Roll" button to click on the chat card.

I should add it does this with no extra modules loaded, so its not module-related...

DeviousHearts commented 2 weeks ago

I found an issue with this as well. A freind of mine (A genius coder by the name of Ethaks) had to write a world script. the issue was the ownership was not officially recognized by the system, I believe he said.

I installed the World Scripter module and put this macro in the World Scripter compendium and it solved the issue for me.

// Fix Toughness Roll Buttons
async function runStuff() {
    const commons = await import("/systems/mutants-and-masterminds-3e/module/helpers/common.mjs");

    Hooks.on("renderChatMessage", async (message, html, data) => {
        html.find("button.btnRoll").click(async (ev) => {
            ev.stopPropagation();
            const target = $(ev.currentTarget);
            const tgt = target.data("target");
            const savetype = target.data("savetype");
            const vs = target.data("vs");
            const dataAtk = target.data("datk");
            const dataStr = target.data("dstr");
            const typeAtk = target.data("type");
            const hasAlt = ev.altKey;

            const token = canvas.scene.tokens.find((token) => token.id === tgt);

            if (token.actor.ownership[game.user.id] === 3 || token.actor.ownership.default === 3) return;
            if (!token.actor.isOwner)
                return ui.notifications.error(`You do not have owner permissions for ${token.actor.name}`);

            const tokenData = token.actor.system;
            const saveScore = tokenData.defense[savetype].total;
            const name = `${game.i18n.localize(CONFIG.MM3.defenses[savetype])}`;

            commons.rollVs(
                token.actor,
                name,
                saveScore,
                vs,
                { typeAtk: typeAtk, atk: dataAtk, str: dataStr, tkn: token },
                { alt: hasAlt },
            );
        });
    });
}
runStuff();