Fix to pollution by stat modifications in newcharacter. #64296
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.
Summary
Bugfixes "Fixes the situation where stat mods affect the displayed effects of your base stats."
Purpose of change
Fixes #64280
Describe the solution
avatar::reset_stats() is accumulating stat mods each passthrough because character::reset_bonuses() is never called on the object. reset_stats() should never be called without first resetting bonuses as it can reapply additional bonuses without clearing the last ones. Ideally character::reset() should be used in these situations? Regardless, I find that no mod bonuses should affect the displayed effects of your base stats, hence I've placed reset_bonuses() after reset_stats() so it only displays the effect of your base stats, though it could still be polluted by other means as I've not investigated the functions that calculate the bonuses that are affected by the stats.
Describe alternatives you've considered
Calling reset() instead of reset_stats() or extracting the calculations used to determine stat effects and calculate the bonuses in-place instead of relying on the avatar object.
Testing
Tested #64280, while also including the mutation "compound eyes" as that mutation will continually mod perception by 2 while equipped in the same manner as StatsThroughSkills or the BMI rework.
Additional context
This could likely need some refactoring later. Since this fix is closer to the core issue than #64270 , maybe the fixes from there can be removed safely. If there are other places in code that calls reset_stats() haphazardly it could cause issues in other places.