Files
vtt_work/wg-greyknights/scripts/macros/gk-glow-toggle.js
T

34 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// GK Aegis Glow Toggle (module)
(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 aegisArm = actor.items.find(i => ["armour","armor"].includes(i.type) && /Aegis/.test(i.name));
if (!aegisArm) return ui.notifications.warn("Nie znaleziono Aegis armour na postaci.");
const eff = aegisArm.effects.find(e => e.name?.toLowerCase().startsWith("aegis warding runes"));
if (!eff) return ui.notifications.warn("Nie znaleziono efektu toggle na Aegis armour.");
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.` }); }
})();