Adjust recalc_hp to avoid migrating hp levels #28692
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Looks like cumulative rounding errors in recalc_hp were causing characters using the new JSON-based STS to suddenly die.
Summary
SUMMARY: None
Purpose of change
Fixes #28680
It seems there was a latent rounding error in Character::recalc_hp(), but it was never triggered before because it was only called on character creation.
Describe the solution
Most importantly, this avoids updating hp levels if the max hp has not changed, this should prevent the bug on it's own.
Additionally, I changed the interpolation of current HP to be a bit more generous, taking the ceiling of the interpolated value instead of the (implicit) floor. In order to prevent out-of range HP values, I also clamped the value between 1 and the new max HP.
Describe alternatives you've considered
Remove STS because it's terrible.
Additional context
Introduced by #28637