mirror of
https://github.com/migatu/vtt_work.git
synced 2026-07-14 13:34:42 +00:00
60 lines
2.2 KiB
JavaScript
60 lines
2.2 KiB
JavaScript
// Aegis: toggle warding + token glow (Foundry v13) — with canvas refresh
|
|
(async () => {
|
|
const tok = canvas.tokens.controlled[0] ?? null;
|
|
const actor = tok?.actor ?? game.user.character;
|
|
const token = tok ?? canvas.tokens.placeables.find(t => t.actor?.id === actor?.id);
|
|
if (!actor || !token) return ui.notifications.warn("Wybierz token lub przypisz postać do użytkownika.");
|
|
|
|
const aegis = actor.items.find(i => i.name.includes("Aegis (Psychic Hood)"));
|
|
if (!aegis) return ui.notifications.warn("Nie znaleziono itemu Aegis na postaci.");
|
|
const eff = aegis.effects.find(e => e.name?.startsWith("Warding Runes Engaged"));
|
|
if (!eff) return ui.notifications.warn("Nie znaleziono efektu toggle w Aegis.");
|
|
|
|
const wasDisabled = eff.disabled ?? true;
|
|
await eff.update({ disabled: !wasDisabled });
|
|
|
|
const FLAG_SCOPE = "wng-gk";
|
|
const FLAG_KEY = "prevLight";
|
|
|
|
const setGlowOn = async () => {
|
|
const prev = token.document.getFlag(FLAG_SCOPE, FLAG_KEY);
|
|
if (!prev) await token.document.setFlag(FLAG_SCOPE, FLAG_KEY, foundry.utils.deepClone(token.document.light));
|
|
await token.document.update({
|
|
light: {
|
|
color: "#66ccff",
|
|
coloration: 2,
|
|
alpha: 0.7,
|
|
dim: 16,
|
|
bright: 0,
|
|
angle: 360,
|
|
luminosity: 0.5,
|
|
attenuation: 0.35,
|
|
saturation: 0,
|
|
contrast: 0,
|
|
shadows: 0,
|
|
animation: { type: "pulse", speed: 3, intensity: 4, reverse: false }
|
|
}
|
|
});
|
|
await canvas.perception.update({ lighting: { refresh: true } });
|
|
};
|
|
|
|
const setGlowOff = async () => {
|
|
const prev = token.document.getFlag(FLAG_SCOPE, FLAG_KEY);
|
|
if (prev) {
|
|
await token.document.update({ light: prev });
|
|
await token.document.unsetFlag(FLAG_SCOPE, FLAG_KEY);
|
|
} else {
|
|
await token.document.update({ light: { dim: 0, bright: 0, color: null } });
|
|
}
|
|
await canvas.perception.update({ lighting: { refresh: true } });
|
|
};
|
|
|
|
if (wasDisabled) {
|
|
await setGlowOn();
|
|
ChatMessage.create({ content: `<b>Aegis:</b> Warding Runes <span style="color:#66ccff">ENGAGED</span>. (Akcja)` });
|
|
} else {
|
|
await setGlowOff();
|
|
ChatMessage.create({ content: `<b>Aegis:</b> Warding Runes DISENGAGED.` });
|
|
}
|
|
})();
|