Hooks - League-of-Fabulous-Developers/FoundryVTT-Fabula-Ultima GitHub Wiki

System Hooks

The following are the hooks that module developers can use to register callbacks within the lifecycle of the system. They can be found within the constant FUHooks.

Damage Pipeline

The following hooks accept a callback that accepts a DamagePipelineContext object and returns a Boolean to know whether subsequent callbacks should be invoked.

/**
 * @property {Number} affinity The index of the affinity
 * @property {String} affinityMessage The localized affinity message to use
 * @property {FU.damageTypes} damageType
 * @property {Number} amount The base amount before bonuses or modifiers are applied
 * @property {Map<String, Number>} bonuses Increments
 * @property {Map<String, Number>} modifiers Multipliers
 * @property {String} breakdown
 * @extends PipelineContext
 */
  • DAMAGE_PIPELINE_PRE_CALCULATE: Used for modifying the bonuses/modifiers before the result of a damage calculation is applied onto an actor.
  • DAMAGE_PIPELINE_POST_CALCULATE: Used for directly modifying the result of a damage calculation is applied onto an actor. This should be used only when modifying the former is unfeasable.

Legacy Hooks

The following hooks are still supported by a translation step. We recommend you migrate from them onto the newer ones as they have been marked for deprecation.

  • projectfu.damage.beforeApply

    • (data: BeforeApplyHookData) => void
    • baseDamageInfo, extraDamageInfo, and clickModifiers will be the primary data to modify to affect damage
    • baseDamageInfo is the basic data that comes from the damage entry
    • extraDamageInfo is the data that comes from the damage customizer dialog
    • clickModifiers are keyboard modifiers that are applied when clicking on the UI
    • even if the call path triggering the hook may not have used optional data, you can inject/modify values as if they had
    • sourceUuid is useful to find the damage source. This could be the uuid of an item belonging to an actor or the uuid of an actor itself
      • e.g. fromUuidSync(data.sourceUuid)
  • projectfu.damage.applyTarget

    • (data: ApplyTargetHookData) => void
    • refer to the above projectfu.damage.beforeApply for comments on the same fields
    • actor is the target of the damage (should have named it accordingly >.>)
    • overrides values attempt to bypass parts of damage calculation
    • overrides.affinity should override the affinity calculations in the damage formula and should also affect the messages shown
    • overrides.total simply replaces the end result value of damage dealt

PrepareData

  • projectfu.actor.dataPrepared

    • (actor: FUActor) => void
  • projectfu.item.dataPrepared

    • (item: FUItem) => void

Rolls

  • studyRoll
    • (actor: FUActor, journalEntry: JournalEntry) => void
    • Callback after a study roll is completed

Typedefs

Nullability may not be accurately captured here

/**
 * @typedef BeforeApplyHookData
 * @prop {Event | null} event  // <- a regular HTML event
 * @prop {FUActor[]} targets
 * @prop {string | null} sourceUuid
 * @prop {string | null} sourceName
 * @prop {BaseDamageInfo} baseDamageInfo
 * @prop {ExtraDamageInfo} extraDamageInfo
 * @prop {ClickModifiers | null} clickModifiers
 */
 
/**
 * @typedef ApplyTargetHookData
 * @prop {FUActor} target
 * @prop {string | null} sourceUuid
 * @prop {string | null} sourceName
 * @prop {DamageType} damageType
 * @prop {number} total
 * @prop {ClickModifiers | null} clickModifiers
 * @prop {ExtraDamageInfo} extraDamageInfo
 * @prop {ApplyTargetOverrides} overrides
 */
 
/**
 * @typedef {"untyped" | "physical" | "air" | "bolt" | "dark" | "earth" | "fire" | "ice" | "light" | "poison"} DamageType
 */

 /**
 * @typedef BaseDamageInfo
 * @prop {number} total
 * @prop {DamageType} type
 * @prop {number} modifierTotal
 */

/**
 * @typedef ExtraDamageInfo
 * @prop {DamageType} damageType
 * @prop {number} damageBonus
 * @prop {number} extraDamage
 * @prop {DamageType} extraDamageType
 * @prop {boolean} hrZero
 * @prop {boolean} ignoreVulnerable
 * @prop {boolean} ignoreResistance
 * @prop {boolean} ignoreImmunities
 * @prop {boolean} ignoreAbsorption
 * @prop {FUActor[]} targets
 */

 /**
 * @typedef ClickModifiers
 * @prop {boolean} alt
 * @prop {boolean} ctrl
 * @prop {boolean} shift
 */
 
/**
 * @typedef ApplyTargetOverrides
 * @prop {number | null} affinity
 * @prop {number | null} total
 */