Fix items spawning with fewer charges than defined in their item group entry #39620
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 "Fix items spawning with fewer charges than defined"
Purpose of change
An item spawn that looks like this
{ "item": "40x46mm_m1006", "charges": 4 }
should spawn 4 charges of the item in question, but instead would spawn between 1 and 4 charges.Per the documentation, defining charges like this should be setting the min and max charges to 4 (which it was), and then the actual spawn amount should be a random value between the min and max... which should be 4 (it wasn't).
I tracked this down to this change which effectively made it so that if the maximum charges was set (which happens both when setting the max directly or just setting the charges which sets both min and max) then the minimum number of charges would be set to 0 rather than the provided value. The system later clamps the minimum value to 1, thus resulting in a charges entry like
"charges": x
actually spawning between 1 andx
charges.Describe the solution
Wrote some unit tests to assert what I thought was happening here, confirmed that the particular scenario in question failed the test, then reverted the change and confirmed that all the tests passed.
Testing
The added unit tests.