Foundry VTT/P2FE

From Omnia
Revision as of 02:38, 27 August 2024 by Kenneth (talk | contribs) (Created page with "== Macros == === Raise Shield === <pre> game.pf2e.actions.raiseAShield({ actors: [token?.actor ?? actor ?? game.user.character].filter((actor) => actor) }) </pre> === Scouting === <pre> const actors = game.user.getActiveTokens().flatMap((t) => t.actor ?? []); if (actors.length === 0) { return ui.notifications.error("PF2E.ErrorMessage.NoTokenSelected", { localize: true }); } const ITEM_UUID = "Compendium.pf2e.other-effects.Item.EMqGwUi3VMhCjTlF"; // Effect: Scout...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Macros

Raise Shield

game.pf2e.actions.raiseAShield({ actors: [token?.actor ?? actor ?? game.user.character].filter((actor) => actor) })

Scouting

const actors = game.user.getActiveTokens().flatMap((t) => t.actor ?? []);
if (actors.length === 0) {
    return ui.notifications.error("PF2E.ErrorMessage.NoTokenSelected", { localize: true });
}

const ITEM_UUID = "Compendium.pf2e.other-effects.Item.EMqGwUi3VMhCjTlF"; // Effect: Scouting
const item = await fromUuid(ITEM_UUID);
if (item?.type === "condition") {
    for (const actor of actors) {
        actor.toggleCondition(item.slug);
    }
} else if (item?.type === "effect") {
    const source = item.toObject();
    source.flags = mergeObject(source.flags ?? {}, { core: { sourceId: ITEM_UUID } });

    for (const actor of actors) {
        const existing = actor.itemTypes.effect.find((e) => e.flags.core?.sourceId === ITEM_UUID);
        if (existing) {
            await existing.delete();
        } else {
            await actor.createEmbeddedDocuments("Item", [source]);
        }
    }
} else {
    ui.notifications.error(game.i18n.format("PF2E.ErrorMessage.ItemNotFoundByUUID", { uuid: ITEM_UUID }));
}