NPCs: uncache weapon value on weapon removal #34188
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
SUMMARY: Bugfixes "NPCs: uncache weapon value on weapon removal"
Purpose of change
Fixes #32613
The trade interface allowed you to remove an NPC's weapon without removing the cached value of the weapon. NPCs would refuse to wield other weapons until the cache was refreshed by some other event.
Describe the solution
Invalided the weapon value cache entry when a weapon is removed.
Describe alternatives you've considered
weapon should really be a class in it's own right with a private item and public setters, but that's way more work than I'm going to put into a quick bugfix. It definitely needs to be done when wielding multiple weapons is implemented.
Additional context
Tested by removing a weapon from a friendly NPC in an unpatched game and trying to make them use it, only to get rebuffed because their current weapon was better. Then I applied the patch, recompiled, and tried again, and the NPC took the weapon happily.