Wrong requirement when trying to equip and level too low#512
Open
hydrozoa-yt wants to merge 1 commit intoluna-rs:masterfrom
Open
Wrong requirement when trying to equip and level too low#512hydrozoa-yt wants to merge 1 commit intoluna-rs:masterfrom
hydrozoa-yt wants to merge 1 commit intoluna-rs:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Proposed changes
Currently, when trying to equip anything and the level is too low, it will say "You need an Attack level of x to equip this". This happens for example for mirror shield and rune boots, even though they don't have an attack requirement.
This happens due to the way EquipmentDefinition is loaded. When loaded using Gson#fromJson the objects are instantiated using reflection, and so the constructor of EquipmentDefinition.Requirement is never ran. This causes the level field to never be instantiated, as this happens in the constructor. This field determines the behavior of the Requirement, so this bug is critical for equipment working properly.
This PR fixes the bug by removing final from the level field, allowing it to be instantiated in a different method, and forcibly running this method after loading. I've also added it to the unused constructor, should the way Requirements are loaded change in the future.
Pull Request type
Further comments
A different fix to this could be to use the streaming api in gson to load the json file. This would be a bit more verbose than the Gson#fromJson solution, but would allow "normal" instantiation of the objects, and keep the level field final.