Register

Effective Tray

An Add-on Module for Foundry Virtual Tabletop

Author: alakshana Project Source: Project URL Versions 12 - 12 (Verified 12) Last Updated 5 days, 3 hours ago

Effective Tray (for Dungeons & Dragons Fifth Edition)

A module for dnd5e on foundryvtt that allows the effects and damage trays to be used more effectively.

Effects Tray

Allows users to use the effect tray as much or as little as wanted by the GM, up to and including transferal to targets they do not own. User ability to transfer effects to and from any target is on by default.

Damage Tray

Allows users to use the damage tray for selected tokens that they own, and for targeted tokens (either that they own, or ones they don't own with a setting). User ability to use the damage tray is on by default, but unless the relevant setting is selected, they cannot damage targets.

Settings

Additional Features

Compatibility
  • This module is NOT compatible with Midi Quality of Life Improvements (midi-qol), and I have no plans to support it.

  • This module may or may not be compatible with Ready Set Roll for D&D5e. If it is compatible, it is a happy accident, and I make no promises of continued support.
  • Otherwise, this module should be compatible with most others.
API

Now includes three helper functions exposed in the global scope under effectiv, effectiv.applyEffect, effectiv.applyDamage and effective.partitionTargets. These functions have not been heavily tested and are included now in the hopes that, if someone wants to use them, they will also test them for issues.

applyEffect, a helper function to allow users to apply effects. It allows users to apply effects via macro (or other module), and can take a variety of types of data when doing so, allowing effect data to be passed as the full ActiveEffect document, an effect Uuid, or an object (note that passing it as an object will not interact with refreshing duration or deleting effects of same origin, as determined by module setting, because creating an effect from an object will have its own unique origin). Similarly, this function allows target data to be passed as an array of Uuids, a single Uuid, an array of Tokens, or a Set, as game.user.targets.

This helper also allows the use of the other things the effects tray does, primarily flagging effects with spellLevel, or any other arbitrary flags (via effectData), and making an effect dependent on a concentration effect (so it will be deleted when the concentration effect is). If concentration is used, because it passed as an ID, you must also pass the Uuid or Actor document of the actor the concentration effect is on.

/**
 * Helper function to allow for macros or other applications to apply effects to owned and unowned targets.
 * @param {string|object|ActiveEffect5e} effect            The effect to apply.
 * @param {Set|Token5e[]|string[]|string} targets          Targeted tokens.
 * @param {object} [options]
 * @param {object} [options.effectData]                    A generic data object, which typically handles the level the originating spell was cast at, 
 *                                                         if it originated from a spell, if any. Use flags like { "flags.dnd5e.spellLevel": 1 }.
 * @param {string} [options.concentration]                 The ID (not Uuid) of the concentration effect this effect is dependent on, if any.
 * @param {string|Actor5e} [options.caster]                The Uuid or Actor5e document of the actor that cast the spell that requires concentration, if any.
 */
async function applyEffect(
  effect, 
  targets, 
  { effectData: null, concentration: null, caster: null } = {}
)
 
/* in use...*/
effectiv.applyEffect(
  effect, 
  targets, 
  { effectData: null, concentration: null, caster: null } = {}
)
 

applyDamage, helper function to allow users to apply damage. This function has been tested not at all and is included as a courtesy. Personally I find the way damage information must be structured to respect resistances, etc is too much of a mess to test this even a single time, but if someone really wants to do this over a socket but didn't write their own socket handler for it...here you go. Full, extensive documentation of the array that must be created is in scripts/api.mjs, copied directly from dnd5e, with the exception that socket transmission requires the sets to be arrays. Unlike applyEffect, this applies no damage via the requesting client, and so is basically only meant for damaging unowned targets. Users wishing to apply damage to owned targets should simply use the system's Actor#applyDamage. See README on the repo for full documentation.

/**
 * Helper function to allow for macros or other applications to apply damage via socket request.
 * @param {Array} damage Array of damage objects; see above.
 * @param {Array} opts   Object of options (which may inlude arrays); see above.
 * @param {string} id    Uuid of the target.
 */
async function applyDamage(damage = [], opts = {}, id)
 
/* in use...*/
effectiv.applyDamage(damage = [], opts = {}, id)
 

partitionTargets, a function similar to foundry's Array#partition but specifically designed to handle game.user.targets, a set, or an array of tokens. It sorts them into two arrays, the first array containing tokens that the user owns, and the second array containing those token's document.uuids. This can be useful for determining what information needs to be sent over sockets. I have no idea why anyone would use this function, but here it is.

/**
 * Sort tokens into owned and unowned categories.
 * @param {Set|array} targets The set or array of tokens to be sorted.
 * @returns {Array}           An Array of length two, the elements of which are the partitioned pieces of the original.
 */
function partitionTargets(targets)
/* in use...*/
effectiv.partitionTargets(targets)
Hooks

Now includes two hooks, effectiv.preApplyEffect and effectiv.applyEffect. The former allows the data of the first parameter to be modified and explicitly returning false will prevent the effect from being applied. The later passes the same information in its final state upon application.

These hooks have not been extensively tested.

/**
 * Hook called before the effect is completed and applied.
 * @param {Actor5e} actor                The actor to create the effect on.
 * @param {ActiveEffect5e} effect        The effect to create.
 * @param {object} [options]             Additional data that may be included with the effect.
 * @param {object} [options.effectData]            A generic data object that contains spellLevel in a `dnd5e` scoped flag, and whatever else.
 * @param {ActiveEffect5e} [options.concentration] The concentration effect on which `effect` is dependent, if it requires concentration.
 */
Hooks.call("effectiv.preApplyEffect", effectData, actor, concentration);
/**
 * Hook called before the effect is completed and applied. Same as above except for effectData.
 * @param {Actor5e} actor                The actor to create the effect on.
 * @param {ActiveEffect5e} effect        The effect to create.
 * @param {object} [options]             Additional data that may be included with the effect.
 * @param {object} [options.effectData]            The packaged effect immediately before application.
 * @param {ActiveEffect5e} [options.concentration] The concentration effect on which `effect` is dependent, if it requires concentration.
 */
Hooks.callAll("effectiv.applyEffect", effectData, actor, concentration);

Technical Details

Scope: Replaces the effects tray in chat messages with a similar one that allows all users, not just GMs or the chat message's creator, to apply active effects to tokens they control (and have selected) by looping over all messages in the "dnd5e.renderChatMessage" hook. Extends the system's damage application element class to allow users who are not GMs to use the damage tray. Additionally, transmits target target and change data via sockets to allow an active GM client to apply effects (or damage) to a non GM user's targets.

License: MIT License.

Additional Info: Thanks to Zhell for help with adding actors to a set and lots of other stuff (and for the github action), and to Flix for much encouragement. Thanks also to ChaosOS for help with sockets, and DrentalBot for help with suppressing the system's context menu.

Some code has been adapted from dnd5e, particularly the extension of the tray custom html elements, and unifying module and system logic for collapsing or expanding trays.

Supported Game Systems

  1. Dungeons & Dragons Fifth Edition

    Latest Version: Version 4.1.1 Last Updated 5 days ago

Categories

Available Versions

  1. Version 4.1.1

    5 days, 3 hours ago
    Foundry Version 12 - 12 (Verified 12) Manifest URL Read Notes
  2. Version 4.1.0

    1 week, 1 day ago
    Foundry Version 12 - 12 (Verified 12) Manifest URL Read Notes
  3. Version 4.0.11

    2 weeks, 3 days ago
    Foundry Version 12 - 12 (Verified 12) Manifest URL Read Notes
  4. Version 4.0.10

    2 weeks, 5 days ago
    Foundry Version 12 - 12 (Verified 12) Manifest URL Read Notes
  5. Version 4.0.8

    3 weeks, 5 days ago
    Foundry Version 12 - 12 (Verified 12) Manifest URL Read Notes
  6. Version 4.0.7

    4 weeks ago
    Foundry Version 12 - 12 (Verified 12) Manifest URL Read Notes
  7. Version 4.0.6

    1 month, 1 week ago
    Foundry Version 12 - 12 (Verified 12) Manifest URL Read Notes
  8. Version 4.0.5

    1 month, 2 weeks ago
    Foundry Version 12 - 12 (Verified 12) Manifest URL Read Notes
  9. Version 4.0.4

    2 months ago
    Foundry Version 12 - 12 (Verified 12) Manifest URL Read Notes
  10. Version 4.0.3

    2 months ago
    Foundry Version 12 - 12 (Verified 12) Manifest URL Read Notes
  11. Version 3.3.0

    2 months, 1 week ago
    Foundry Version 11 - 12 (Verified 12) Manifest URL Read Notes
  12. Version 1.2.11

    2 months, 2 weeks ago
    Foundry Version 11 - 12 (Verified 12) Manifest URL Read Notes
  13. Version 1.2.9

    2 months, 3 weeks ago
    Foundry Version 11 - 12 (Verified 12) Manifest URL Read Notes
  14. Version 1.2.8

    4 months ago
    Foundry Version 11 - 12 (Verified 12) Manifest URL Read Notes
  15. Version 1.2.7

    4 months, 1 week ago
    Foundry Version 11 - 12 (Verified 12) Manifest URL Read Notes
  16. Version 1.2.6

    5 months, 2 weeks ago
    Foundry Version 11 - 11 (Verified 11) Manifest URL Read Notes
  17. Version 1.2.5

    5 months, 2 weeks ago
    Foundry Version 11 - 11 (Verified 11) Manifest URL Read Notes
  18. Version 1.2.4

    5 months, 3 weeks ago
    Foundry Version 11 - 11 (Verified 11) Manifest URL Read Notes
  19. Version 1.2.3

    5 months, 3 weeks ago
    Foundry Version 11 - 11 (Verified 11) Manifest URL Read Notes
  20. Version 1.2.2

    5 months, 3 weeks ago
    Foundry Version 11 - 11 (Verified 11) Manifest URL Read Notes
  21. Version 1.1.20

    6 months ago
    Foundry Version 11 - 11 (Verified 11) Manifest URL Read Notes
  22. Version 1.1.19

    6 months ago
    Foundry Version 11 - 11 (Verified 11) Manifest URL Read Notes
  23. Version 1.1.18

    6 months ago
    Foundry Version 11 - 11 (Verified 11) Manifest URL Read Notes
  24. Version 1.1.17

    6 months, 1 week ago
    Foundry Version 11 - 11 (Verified 11) Manifest URL Read Notes
  25. Version 1.1.16

    6 months, 1 week ago
    Foundry Version 11 - 11 (Verified 11) Manifest URL Read Notes
  26. Version 1.1.15

    6 months, 1 week ago
    Foundry Version 11 - 11 (Verified 11) Manifest URL Read Notes
  27. Version 1.1.14

    6 months, 2 weeks ago
    Foundry Version 11 - 11 (Verified 11) Manifest URL Read Notes
  28. Version 1.1.13

    6 months, 2 weeks ago
    Foundry Version 11 - 11 (Verified 11) Manifest URL Read Notes
  29. Version 1.1.12

    7 months, 1 week ago
    Foundry Version 11 - 11 (Verified 11) Manifest URL Read Notes
  30. Version 1.1.11

    7 months, 1 week ago
    Foundry Version 11 - 11 (Verified 11) Manifest URL Read Notes
  31. Version 1.1.10

    7 months, 1 week ago
    Foundry Version 11 - 11 (Verified 11) Manifest URL Read Notes
  32. Version 1.1.9

    7 months, 1 week ago
    Foundry Version 11 - 11 (Verified 11) Manifest URL Read Notes
  33. Version 1.1.7

    7 months, 1 week ago
    Foundry Version 11 - 11 (Verified 11) Manifest URL Read Notes
  34. Version 1.1.6

    7 months, 1 week ago
    Foundry Version 11 - 11 (Verified 11) Manifest URL Read Notes
  35. Version 1.1.5

    7 months, 1 week ago
    Foundry Version 11 - 11 (Verified 11) Manifest URL Read Notes
  36. Version 1.1.4

    7 months, 2 weeks ago
    Foundry Version 11 - 11 (Verified 11) Manifest URL Read Notes
  37. Version 1.1.3

    7 months, 3 weeks ago
    Foundry Version 11 - 11 (Verified 11) Manifest URL Read Notes
  38. Version 1.1.2

    7 months, 3 weeks ago
    Foundry Version 11 - 11 (Verified 11) Manifest URL Read Notes
  39. Version 1.1.1

    8 months ago
    Foundry Version 11 - 11 (Verified 11) Manifest URL Read Notes
  40. Version 1.1.0

    8 months ago
    Foundry Version 11 - 11 (Verified 11) Manifest URL Read Notes
  41. Version 1.0.3

    8 months, 2 weeks ago
    Foundry Version 11 - 11 (Verified 11) Manifest URL Read Notes
  42. Version 1.0.2

    8 months, 2 weeks ago
    Foundry Version 11 - 11 (Verified 11) Manifest URL Read Notes