Advertisement
Guest User

Untitled

a guest
Aug 16th, 2024
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. // Define the intoxication effect
  2. const intoxicationEffect = {
  3. label: "Intoxication",
  4. icon: "icons/svg/poison.svg", // Adjust this icon if needed
  5. origin: null,
  6. disabled: false,
  7. duration: { rounds: 9999, startRound: game.combat?.round, startTime: game.time.worldTime },
  8. flags: {
  9. custom: { intoxicationHookId: null }
  10. },
  11. changes: [
  12. { key: 'system.stats.ref.current', mode: CONST.ACTIVE_EFFECT_MODES.ADD, value: -2 },
  13. { key: 'system.stats.dex.current', mode: CONST.ACTIVE_EFFECT_MODES.ADD, value: -2 },
  14. { key: 'system.stats.int.current', mode: CONST.ACTIVE_EFFECT_MODES.ADD, value: -2 },
  15. // Verbal Combat reminder will be added as a chat message, not as a stat change
  16. ]
  17. };
  18.  
  19. // Function to remove the intoxication effect
  20. async function removeIntoxicationEffect(actor, effectId) {
  21. console.log(`Removing ongoing effect: ${intoxicationEffect.label}`);
  22.  
  23. await actor.deleteEmbeddedDocuments("ActiveEffect", [effectId]);
  24.  
  25. // Memory check - 25% chance they won't remember
  26. const memoryRoll = Math.random();
  27. let memoryOutcome = "You will remember everything.";
  28. if (memoryRoll < 0.25) {
  29. memoryOutcome = "You won't remember everything that happened.";
  30. }
  31.  
  32. // Inform the user
  33. ChatMessage.create({
  34. content: `${actor.name} has sobered up. ${memoryOutcome}`,
  35. speaker: ChatMessage.getSpeaker({ actor: actor })
  36. });
  37. }
  38.  
  39. // Toggle intoxication effect
  40. async function toggleIntoxicationEffect() {
  41. const token = canvas.tokens.controlled[0];
  42. if (!token) {
  43. ui.notifications.warn("Please select a token first.");
  44. return;
  45. }
  46.  
  47. const actor = token.actor;
  48.  
  49. // Check if the intoxication effect is already applied
  50. let existingEffect = actor.effects.find(e => e.label === intoxicationEffect.label);
  51.  
  52. if (existingEffect) {
  53. await removeIntoxicationEffect(actor, existingEffect.id);
  54.  
  55. // Remove the combat hook
  56. const hookId = existingEffect.flags.custom?.intoxicationHookId;
  57. if (hookId) {
  58. Hooks.off("updateCombat", hookId);
  59. console.log(`Removed combat hook with ID: ${hookId}`);
  60. }
  61. } else {
  62. console.log(`Applying ongoing effect: ${intoxicationEffect.label}`);
  63. intoxicationEffect.origin = actor.uuid; // Set the origin to the actor's UUID
  64.  
  65. // Create the effect on the actor
  66. const createdEffect = await actor.createEmbeddedDocuments("ActiveEffect", [intoxicationEffect]);
  67. const effectId = createdEffect[0].id;
  68.  
  69. // Set up a hook to handle reminders during the intoxication effect
  70. const hookId = Hooks.on("updateCombat", (combat, update, options, userId) => {
  71. const combatant = combat.combatants.find(c => c.tokenId === token.id);
  72.  
  73. // If it's the start of the token's turn
  74. if (combatant && combat.turns[combat.turn].tokenId === token.id) {
  75. console.log(`${token.name} is still intoxicated.`);
  76. // This can be used to add narrative or roleplaying cues about the intoxicated state.
  77. }
  78. });
  79.  
  80. console.log(`Created combat hook with ID: ${hookId}`);
  81.  
  82. // Store the hook ID in the effect so we can remove it later
  83. try {
  84. await actor.updateEmbeddedDocuments("ActiveEffect", [{
  85. _id: effectId,
  86. "flags.custom.intoxicationHookId": hookId
  87. }]);
  88. } catch (error) {
  89. console.error("Failed to update flag 'custom' with hookId.", error);
  90. }
  91.  
  92. // Notify about the applied effect
  93. ChatMessage.create({
  94. content: `${actor.name} is intoxicated. They suffer -2 to REF, DEX, INT and -3 to Verbal Combat actions!`,
  95. speaker: ChatMessage.getSpeaker({ actor: actor })
  96. });
  97. }
  98. }
  99.  
  100. // Run the toggle function
  101. toggleIntoxicationEffect();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement