Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shillelagh improvement #33

Open
dstein766 opened this issue Oct 20, 2022 · 0 comments
Open

Shillelagh improvement #33

dstein766 opened this issue Oct 20, 2022 · 0 comments

Comments

@dstein766
Copy link

The Shillelagh macro v10.0.13 has two issues:

  1. It assumes the caster is WIS-based rather than using the actual spellcasting attribute.
  2. It does not set the "Magical" property on the empowered weapon.

This code fixes both of those issues. (It saves the pre-existing set of properties before forcibly setting Magical to true. Upon revert to normal, all the original props will be restored. So if the weapon was Magical pre-spell, it will remain Magical post-spell.)

const version = "10.0.13";
try {
    const lastArg = args[args.length - 1];
    let weapons = actor.items.filter(i => i.type === `weapon` && ["club","quarterstaff"].includes(i.system.baseItem));
    let weapon_content = ``;
    for (let weapon of weapons) {
        weapon_content += `<option value=${weapon.id}>${weapon.name}</option>`;
    }
    if (args[0] === "on") {
        let content = `
    <div class="form-group">
    <label>Weapons : </label>
    <select name="weapons">
        ${weapon_content}
    </select>
    </div>`;

        new Dialog({
            title: "Choose a club or quarterstaff",
            content,
            buttons:
            {
                Ok:
                {
                    label: `Ok`,
                    callback: (html) => {
                        let itemId = html.find('[name=weapons]')[0].value;
                        let weaponItem = actor.items.get(itemId);
                        let copy_item = duplicate(weaponItem.toObject(false));
                        DAE.setFlag(actor, `shillelagh`, {
                            id : itemId,
                            damage : copy_item.system.damage.parts[0][0],   
			    props: copy_item.system.properties 
                        });
                        let damage = copy_item.system.damage.parts[0][0];
                        var newdamage = damage.replace(/1d(4|6)/g,"1d8");
                        copy_item.system.damage.parts[0][0] = newdamage;
                        copy_item.system.ability = actor.system.attributes.spellcasting;
			copy_item.system.properties["mgc"] = true;
                        actor.updateEmbeddedDocuments("Item", [copy_item]);
                        ChatMessage.create({content: copy_item.name + " is empowered"});
                    }
                },
                Cancel:
                {
                    label: `Cancel`
                }
            }
        }).render(true);
    }

    if (args[0] === "off") {
        let flag = DAE.getFlag(actor, `shillelagh`);
        let weaponItem = actor.items.get(flag.id);
        let copy_item = duplicate(weaponItem.toObject(false));
        copy_item.system.damage.parts[0][0] = flag.damage;
        copy_item.system.properties = flag.props;
        copy_item.system.ability = "";
        await actor.updateEmbeddedDocuments("Item", [copy_item]);
        DAE.unsetFlag(actor, `shillelagh`);
        ChatMessage.create({content: copy_item.name + " returns to normal"});
    }
} catch (err)  {
    console.error(`Shillelagh ${version}`, err);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant