Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Define the blinded effect
- const blindedEffect = {
- label: "Blinded",
- icon: "icons/svg/blind.svg", // Adjust this icon if needed
- origin: null,
- disabled: false,
- duration: { rounds: 9999, startRound: game.combat?.round, startTime: game.time.worldTime },
- flags: {
- custom: { blindedHookId: null }
- },
- changes: [
- { key: 'system.skills.ref.brawling.value', mode: CONST.ACTIVE_EFFECT_MODES.ADD, value: -3 },
- { key: 'system.skills.ref.melee.value', mode: CONST.ACTIVE_EFFECT_MODES.ADD, value: -3 },
- { key: 'system.skills.ref.smallblades.value', mode: CONST.ACTIVE_EFFECT_MODES.ADD, value: -3 },
- { key: 'system.skills.ref.staffspear.value', mode: CONST.ACTIVE_EFFECT_MODES.ADD, value: -3 },
- { key: 'system.skills.ref.swordsmanship.value', mode: CONST.ACTIVE_EFFECT_MODES.ADD, value: -3 },
- { key: 'system.skills.dex.archery.value', mode: CONST.ACTIVE_EFFECT_MODES.ADD, value: -3 },
- { key: 'system.skills.dex.crossbow.value', mode: CONST.ACTIVE_EFFECT_MODES.ADD, value: -3 },
- { key: 'system.skills.will.spellcast.value', mode: CONST.ACTIVE_EFFECT_MODES.ADD, value: -3 },
- { key: 'system.skills.will.resistmagic.value', mode: CONST.ACTIVE_EFFECT_MODES.ADD, value: -3 },
- { key: 'system.skills.ref.dodge.value', mode: CONST.ACTIVE_EFFECT_MODES.ADD, value: -3 },
- { key: 'system.skills.int.awareness.value', mode: CONST.ACTIVE_EFFECT_MODES.ADD, value: -5 }
- ]
- };
- // Function to remove the blinded effect
- async function removeBlindedEffect(actor, effectId) {
- console.log(`Removing ongoing effect: ${blindedEffect.label}`);
- await actor.deleteEmbeddedDocuments("ActiveEffect", [effectId]);
- // Inform the user
- ChatMessage.create({
- content: `${actor.name} is no longer blinded.`,
- speaker: ChatMessage.getSpeaker({ actor: actor })
- });
- }
- // Toggle blinded effect
- async function toggleBlindedEffect() {
- const token = canvas.tokens.controlled[0];
- if (!token) {
- ui.notifications.warn("Please select a token first.");
- return;
- }
- const actor = token.actor;
- // Check if the blinded effect is already applied
- let existingEffect = actor.effects.find(e => e.label === blindedEffect.label);
- if (existingEffect) {
- await removeBlindedEffect(actor, existingEffect.id);
- // Remove the combat hook
- const hookId = existingEffect.flags.custom?.blindedHookId;
- if (hookId) {
- Hooks.off("updateCombat", hookId);
- console.log(`Removed combat hook with ID: ${hookId}`);
- }
- } else {
- console.log(`Applying ongoing effect: ${blindedEffect.label}`);
- blindedEffect.origin = actor.uuid; // Set the origin to the actor's UUID
- // Create the effect on the actor
- const createdEffect = await actor.createEmbeddedDocuments("ActiveEffect", [blindedEffect]);
- const effectId = createdEffect[0].id;
- // Set up a hook to handle reminders during the blinded effect
- const hookId = Hooks.on("updateCombat", (combat, update, options, userId) => {
- const combatant = combat.combatants.find(c => c.tokenId === token.id);
- // If it's the start of the token's turn
- if (combatant && combat.turns[combat.turn].tokenId === token.id) {
- console.log(`${token.name} is still blinded.`);
- // This can be used to add narrative or roleplaying cues about the blinded state.
- }
- });
- console.log(`Created combat hook with ID: ${hookId}`);
- // Store the hook ID in the effect so we can remove it later
- try {
- await actor.updateEmbeddedDocuments("ActiveEffect", [{
- _id: effectId,
- "flags.custom.blindedHookId": hookId
- }]);
- } catch (error) {
- console.error("Failed to update flag 'custom' with hookId.", error);
- }
- // Notify about the applied effect
- ChatMessage.create({
- content: `${actor.name} is blinded and suffers penalties to several skills.`,
- speaker: ChatMessage.getSpeaker({ actor: actor })
- });
- }
- }
- // Run the toggle function
- toggleBlindedEffect();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement