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 For Worn Enchanted Armor"
Purpose of change
Enchanted armor was broken when applying/removing traits. Also I have a desire to use the enchantment system for non magical armor. So to work towards more usability I've fixed some of the oddities.
The core issue is that when you trigger on_item_wear or on_item_takeoff you are still wearing the item that provides the traits so all of the recalculating that should happen gets done while you still have the traits
Easiest way to recreate this is try to put on an enchanted item that when worn gives Huge. Your Strength will keep scaling infinitely.
Describe the solution
This PR does the following
Adds a vector for "mutations to add" and "mutations to remove" to the character object
In on_item_takeoff and on_item_wear it just adds the relevant mutations to the relevant vectors doesn't do the calcs there
Split all the repeated post calcs into their own function enchantment_wear_change
In update body when the characters cached enchantments are recalced then the removed and added mutations are applied as well as the calls from enchantment_wear_change
In the loop it also tests if you still have the mutation and if so doesn't run all the removal stuff. This would be for the situation where you have two items giving the same trait
Needed to do some overloading of mutations_from_wearing so that you can specify your removing an item and further down the call stack ignore traits from items. This is because when doing the check for "hey did the player already have one of these mutations before putting on this item YOU ARE STILL WEARING THE ITEM SO IT SEES ITSELF"
I've also added a new flag for items called "MUNDANE" it's for items with enchantments that shouldn't glow pink in the menu because they aren't magic.
I've also added a rule so that if an item changes your size (makes you huge for example it doesn't push off the item that did it). This is for 2 reasons:
Describe alternatives you've considered
Not spending hours going down this rabbit hole because of an off hand comment on discord.
Testing
Tested with a pair of earings jsoned to have:
and a firebelt with:
glass jaw is great because its easy to test if your hp pool has updated on wearing and not wearing the item.
Additional context