javalent / initiative-tracker

TTRPG Initiative Tracker for Obsidian.md
GNU General Public License v3.0
144 stars 30 forks source link

Log only says creature was knocked unconscious if HP already at 0 when taking new damage (ALSO: log should preferably not say "Creature took X damage and was knocked unconscious" if Automatic Unconscious Status Application is disabled) #288

Open anfrimov opened 2 months ago

anfrimov commented 2 months ago

Check for existing bug reports before submitting.

Expected Behavior

Creature with HP > 0 takes damage > HP...

..when Automatic Unconscious Status Application is enabled:

..when Automatic Unconscious Status Application is disabled:

Creature with HP <= 0 takes damage > 0...

..when Automatic Unconscious Status Application is enabled:

..when Automatic Unconscious Status Application is disabled:

Current behaviour

Creature with HP > 0 takes damage > HP...

..when Automatic Unconscious Status Application is enabled:

..when Automatic Unconscious Status Application is disabled:

Creature with HP <= 0 takes damage > 0...

..when Automatic Unconscious Status Application is enabled:

..when Automatic Unconscious Status Application is disabled:

Reproduction

Example 1

  1. Enable Automatic Unconscious Status Application
  2. Start encounter with creature (set HP to 1/1)
  3. Apply 2 damage to creature
  4. Creature HP is now 0 and creature has Unconscious tag
  5. Log says "Creature took 2 damage"
  6. Apply 2 damage to creature
  7. Creature HP is still 0, but...
  8. Log says "Creature took 2 damage and was knocked unconscious"

    Example 2

  9. Disable Automatic Unconscious Status Application
  10. Start encounter with a creature which has not been assigned an HP value or whose HP is 0
  11. Apply 2 damage to creature
  12. Creature has no Unconscious tag, but...
  13. Log says "Creature took 2 damage and was knocked unconscious."

    Example 3

  14. Disable Automatic Unconscious Status Application
  15. Start encounter with a creature which has not been assigned an HP value or whose HP is 0
  16. Apply 2 damage to creature and manually apply Unconscious tag
  17. Log says "Creature took 2 damage and was knocked unconscious and took Unconscious status."

Which Operating Systems are you using?

Obsidian Version Check

Version 1.6.5 (Installer 1.4.16)

Plugin Version

13.0.12

Confirmation

Possible solution

Not a solution but a bit more info:

My use case for wanting to not see the unconscious message in the logs is that I'm using the initiative tracker as a player, thus I do not necessarily know the current or maximum HP of the enemies we face, but I would still like to track (using the log) damage dealt to each creature on every turn. However, because of the bug, the log says these creatures are knocked unconscious every time they take any damage, even though this status should not automatically be applied, and it says it twice when I add it manually.

Possible solution to part 1?:

Looking into the code (though this is not a coding language I know), it seems like change.hp is set as a variable (tracker.ts lines 512 and 1276) just the line before the check if the creature HP is <= 0. This check is thus before the function which updates creature.hp is called, I think? So it appears to be checking if the old HP is <= 0 in order to set message.unc = true rather than checking if the new HP is <=0.

Possible solution to part 2?:

Rather than having separate key:value pairs (in logger.ts and logger.types.ts) in the UpdateMessageLog type for status and unconscious (unc), perhaps it would be simpler to just have status. The simplest method would then just apply the status tag "Unconscious" when HP is <= 0 (if Auto Apply Unconscious is enabled), and the log would read "Creature took X damage and took Unconscious status." Less pretty than "was knocked unconscious" but all around functional.

With a little extra work, maybe you could add a text field to each status in the settings which would determine how the status was displayed in the log, with the default being something like "is status_name" (as most statuses, like blinded, paralyzed, etc. would work quite well this way, grammatically). "Creature takes 2 damage and is paralyzed." But that way one has the freedom, if desired, to add for example a Sleeping condition with the preferred log text "falls asleep". Unconscious could then be easily changed to "falls unconscious" or "is knocked unconscious". Invisible could be "turns invisible" or "becomes invisible", Petrified could be "is turned to stone". However people want it to appear in the log.