Author Topic: [Bug v1.04] Health/Mana regen goes negative  (Read 1401 times)

peewee_RotA

  • Sr. Member
  • Posts: 260
  • Karma: +8/-0
    • View Profile
[Bug v1.04] Health/Mana regen goes negative
« on: May 09, 2014, 11:47:01 AM »
There is a long time bug that people have been reporting, but has yet to be pin pointed. It seems to come and go intermittently. That is the health regen going into the negative bug. Sometimes players will somehow lose mana or health instead of slowly gain it back. Although there was a similar bug, this one is unique and I found the cause.

It's complicated so here are the parts:

  • Health and Mana regen values are only calculated at character creation and leveling. When either action happens, the value is calculated by multiplying the unmodified base stat (constitution/magic) by the player's level + 5. This calculation is assigned to the active stat's for HealthRegen and ManaRegen. (keep this in mind)
  • On a save, all active stats are written to the character save file. When a player reloads their character, their active stats are reloaded, meaning that the health and mana regen values are not recalculated. They are simply loaded from the last play.
  • Any magical effects are removed before a save happens. This includes level loading and level ending. As well as sleeping.
  • When a magical effect improves mana or health regeneration, it adds a value to the existing active stat. After the magical effect is removed, the bonus is subtracted from the existing active stat .

Now that all that setup is understood, here's how to cause the glitch.

Right before leveling, use a magical effect to improve health regeneration. This will ADD to the value. While the effect is active, gain a level. This will OVERWRITE the health regeneration value. Now exit the level (or allow the effect to wear off). The original bonus will be subtracted from the new overwritten value. The next time that the player saves, this erroneous value will be written to the save file because it is the active stat.

The next time that the player gains a level, these values will be overwritten. If the player does not have any sort of regeneration bonus, the values will return to normal. This is what makes the problem so hard to track.

Now, only players with really low con or magic should ever notice the glitch. It's hard to stack bonuses high enough to make regen go into the negatives. However, a citizen has a 150 (25 * (lvl1 + 5)) regen for both values at start. Plenty of items do over 150 in improvement. So it IS possible.

I'm creating a solution for this in peewee's Fork, but it will not be compatible to vanilla since I have custom code to generate class advantages. I'll post a link to it for reference once it is ready.

peewee_RotA

  • Sr. Member
  • Posts: 260
  • Karma: +8/-0
    • View Profile
Re: [Bug v1.04] Health/Mana regen goes negative
« Reply #1 on: May 09, 2014, 01:20:33 PM »
Here's the latest commit to fix the issue.

https://github.com/cabbruzzese/AmuletsArmor/commit/fe9642e69506d6378a99256549f3ed10864918be


This moves the calculations into their own functions and compares the old regen values against the current to find the bonus, then applies the bonus to the new values.