Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Define the intoxication effect
- const intoxicationEffect = {
- label: "Intoxication",
- icon: "icons/svg/poison.svg", // Adjust this icon if needed
- origin: null,
- disabled: false,
- duration: { rounds: 9999, startRound: game.combat?.round, startTime: game.time.worldTime },
- flags: {
- custom: { intoxicationHookId: null }
- },
- changes: [
- { key: 'system.stats.ref.current', mode: CONST.ACTIVE_EFFECT_MODES.ADD, value: -2 },
- { key: 'system.stats.dex.current', mode: CONST.ACTIVE_EFFECT_MODES.ADD, value: -2 },
- { key: 'system.stats.int.current', mode: CONST.ACTIVE_EFFECT_MODES.ADD, value: -2 },
- // Verbal Combat reminder will be added as a chat message, not as a stat change
- ]
- };
- // Function to remove the intoxication effect
- async function removeIntoxicationEffect(actor, effectId) {
- console.log(`Removing ongoing effect: ${intoxicationEffect.label}`);
- await actor.deleteEmbeddedDocuments("ActiveEffect", [effectId]);
- // Memory check - 25% chance they won't remember
- const memoryRoll = Math.random();
- let memoryOutcome = "You will remember everything.";
- if (memoryRoll < 0.25) {
- memoryOutcome = "You won't remember everything that happened.";
- }
- // Inform the user
- ChatMessage.create({
- content: `${actor.name} has sobered up. ${memoryOutcome}`,
- speaker: ChatMessage.getSpeaker({ actor: actor })
- });
- }
- // Toggle intoxication effect
- async function toggleIntoxicationEffect() {
- const token = canvas.tokens.controlled[0];
- if (!token) {
- ui.notifications.warn("Please select a token first.");
- return;
- }
- const actor = token.actor;
- // Check if the intoxication effect is already applied
- let existingEffect = actor.effects.find(e => e.label === intoxicationEffect.label);
- if (existingEffect) {
- await removeIntoxicationEffect(actor, existingEffect.id);
- // Remove the combat hook
- const hookId = existingEffect.flags.custom?.intoxicationHookId;
- if (hookId) {
- Hooks.off("updateCombat", hookId);
- console.log(`Removed combat hook with ID: ${hookId}`);
- }
- } else {
- console.log(`Applying ongoing effect: ${intoxicationEffect.label}`);
- intoxicationEffect.origin = actor.uuid; // Set the origin to the actor's UUID
- // Create the effect on the actor
- const createdEffect = await actor.createEmbeddedDocuments("ActiveEffect", [intoxicationEffect]);
- const effectId = createdEffect[0].id;
- // Set up a hook to handle reminders during the intoxication 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 intoxicated.`);
- // This can be used to add narrative or roleplaying cues about the intoxicated 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.intoxicationHookId": hookId
- }]);
- } catch (error) {
- console.error("Failed to update flag 'custom' with hookId.", error);
- }
- // Notify about the applied effect
- ChatMessage.create({
- content: `${actor.name} is intoxicated. They suffer -2 to REF, DEX, INT and -3 to Verbal Combat actions!`,
- speaker: ChatMessage.getSpeaker({ actor: actor })
- });
- }
- }
- // Run the toggle function
- toggleIntoxicationEffect();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement