Skip to content

Temporary HP Damage Bug #93

@adambennett

Description

@adambennett

Description

I believe I discovered a bug with the Temporary HP implementation. In the base game code, there are several damage calculation steps that are not being applied when the creature has Temporary HP.

For example, I noticed this issue while playing a run where I had the relics Tungsten Rod and Blue Candle. With these two relics in play, I expect to receive 0 damage and lose 0 HP when I play a Curse card. Blue Candle allows Curses to be played for the cost of 1 HP, while Tungsten Rod should reduce any HP damage by 1, resulting in the expected result of 0 damage.

However, when I had Temporary HP active this was not the behavior, and instead I lost 1 TempHP whenever I played a Curse. Whenever I play a Curse without any TempHP, I do indeed receive 0 damage as expected.

I believe this is a bug in the StS-Lib code, as I was able to reproduce the same behavior in a vanilla run with no mods active aside from BaseMod and StS-Lib (although I did modify StS-Lib slightly to allow me to gain TempHP via the BaseMod console).

Steps to Reproduce

  1. Compile a version of StS-Lib that allows you to gain TempHP somehow. Originally I tested by adding a temporary card to the game which gave the player TempHP, but later also did further testing using a custom BaseMod console command.
  2. Start the game with only BaseMod and the modified StS-Lib mod active.
  3. Start a fresh run with any character.
  4. Get through Neow and enter the first combat.
  5. Run the following BaseMod commands:
    • hand discard all
    • hand add Strike_R
    • hand add AscendersBane
    • power Strength -2 (note: apply to yourself)
    • relic add Boot
    • relic add Blue_Candle
    • relic add TungstenRod
  6. Apply TempHP to both the player and enemy via your chosen method.
  7. Play a copy of Ascender's Bane. Note the player will lose 1 TempHP.
  8. Attack the enemy with your Strike. Note the enemy will only take 4 damage, rather than the expected 5.

Reproduced with Mods

  • BaseMod (v5.52.3)
  • StS-Lib (v2.10.1)

Notes

I believe this is caused by the way the PlayerDamage and MonsterDamage patches are applied. The logic for these patches is applied directly after the decrementBlock() function is called, but there are several damage calculation steps that occur after this point.

To fix the issue, I reorganized the patch code slightly by applying 2 locator classes instead. The first bit of logic should still run after decrementBlock(), but the actual damage ignore step should be performed after all other damage calculation checks.

There is almost certainly cleaner and better ways to fix this issue, but this code does appear to work correctly so I will raise a pull request and allow the repository maintainers determine how to proceed.

Please let me know if you have any questions!

Videos

Bug Demo: https://youtu.be/sno7SQy8cy4

Fix Demo: https://youtu.be/HYLHHmMCIvM

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions