Module unit.TimeToDie

Handles Time to Die of units.

Functions

Unit:UpdateTtd (self) Updates the Time To Die (TTD) history for a unit.
Unit:TimeToX (self, percentage) Calculates the estimated time to reach a certain health percentage for the unit based on historical data.
Unit:SpecialTtdPercentage (self, npcID) Returns a special Time To Die (TTD) percentage for specific NPCs.
Unit:Ttd (self) Returns the estimated Time To Die (TTD) for the unit, considering special TTD percentages for specific NPCs.
Unit:TimeToDie (self) Alias for `Unit:Ttd()`.
Unit:BossTimeToDie (self) Returns the estimated Time To Die (TTD) for the unit if it's a boss or a dummy unit.
Unit:TimeToDieIsNotValid (self) Checks if the calculated Time To Die (TTD) for the unit is considered invalid.
Unit:BossTimeToDieIsNotValid (self) Checks if the calculated Time To Die (TTD) for a boss or dummy unit is considered invalid.
API.GetFightRemains (enemies, bossOnly) Calculates the maximum estimated time until any relevant enemy in the current fight dies.
API.GetBossFightRemains () Calculates the maximum estimated time until any boss in the current fight dies.
API.BossFightRemainsIsNotValid () Checks if the calculated `BossFightRemains` is considered invalid.


Functions

Unit:UpdateTtd (self)
Updates the Time To Die (TTD) history for a unit. This function records the unit's current health and the current time if the unit is hostile and its health is below 100. It maintains a history of up to 50 samples for calculation.

Parameters:

  • self Unit The unit object.
Unit:TimeToX (self, percentage)
Calculates the estimated time to reach a certain health percentage for the unit based on historical data. It uses linear regression on the recorded health samples to predict the time.

Parameters:

  • self Unit The unit object.
  • percentage number The target health percentage (e.g., 0 for 0% HP).

Returns:

    number The estimated time in seconds, or a specific code indicating an invalid state: * `11111`: Invalid unit (no GUID). * `9999`: Negative time (the target percentage has already been passed). * `8888`: Not enough samples (less than 4) to perform a reliable calculation. * `7777`: No DPS (health is not decreasing, or the calculation results in an extremely long time). * `6666`: The unit is a dummy. * `25`: The unit is a hostile player.
Unit:SpecialTtdPercentage (self, npcID)
Returns a special Time To Die (TTD) percentage for specific NPCs. This is used for mechanics where a boss might become immune or untargetable at a certain health threshold.

Parameters:

  • self Unit The unit object.
  • npcID number The NPC ID of the unit.

Returns:

    number The special TTD percentage for the given NPC ID, or 0 if no special percentage is defined.
Unit:Ttd (self)
Returns the estimated Time To Die (TTD) for the unit, considering special TTD percentages for specific NPCs. This function calls `Unit:TimeToX` with the percentage returned by `Unit:SpecialTtdPercentage`.

Parameters:

  • self Unit The unit object.

Returns:

    number The estimated time in seconds, or a specific code (see `Unit:TimeToX` for codes).
Unit:TimeToDie (self)
Alias for `Unit:Ttd()`. Returns the estimated Time To Die (TTD) for the unit, considering special TTD percentages for specific NPCs.

Parameters:

  • self Unit The unit object.

Returns:

    number The estimated time in seconds, or a specific code (see `Unit:TimeToX` for codes).
Unit:BossTimeToDie (self)
Returns the estimated Time To Die (TTD) for the unit if it's a boss or a dummy unit.

Parameters:

  • self Unit The unit object.

Returns:

    number The estimated time in seconds if the unit is a boss or dummy, otherwise `11111`.
Unit:TimeToDieIsNotValid (self)
Checks if the calculated Time To Die (TTD) for the unit is considered invalid. A TTD is invalid if it's greater than or equal to `7777` (which indicates no DPS or insufficient data).

Parameters:

  • self Unit The unit object.

Returns:

    boolean True if TTD is invalid, false otherwise.
Unit:BossTimeToDieIsNotValid (self)
Checks if the calculated Time To Die (TTD) for a boss or dummy unit is considered invalid.

Parameters:

  • self Unit The unit object.

Returns:

    boolean True if TTD is invalid for a boss/dummy, false otherwise.
API.GetFightRemains (enemies, bossOnly)
Calculates the maximum estimated time until any relevant enemy in the current fight dies. It prioritizes boss units if they exist or if `bossOnly` is true. Otherwise, it checks provided `enemies`.

Parameters:

  • enemies table|nil An optional table of enemy units to consider. If nil, it only checks current target if `bossOnly` is false.
  • bossOnly boolean|nil If true, only considers boss units.

Returns:

    number The maximum estimated time to die among relevant enemies, or `11111` if no valid enemies are found.
API.GetBossFightRemains ()
Calculates the maximum estimated time until any boss in the current fight dies. This is a convenience function that calls `API.GetFightRemains` with `bossOnly` set to true.

Returns:

    number The maximum estimated time to die among boss units, or `11111` if no valid bosses are found.
API.BossFightRemainsIsNotValid ()
Checks if the calculated `BossFightRemains` is considered invalid. A `BossFightRemains` value is invalid if it's greater than or equal to `7777`.

Returns:

    boolean True if `BossFightRemains` is invalid, false otherwise.
generated by LDoc 1.5.0 Last updated 2025-08-07 15:27:51