Dungeon: Fix wrong item removal by using equals-based matching#2771
Dungeon: Fix wrong item removal by using equals-based matching#2771Shruti39 wants to merge 7 commits intoDungeon-CampusMinden:masterfrom
Conversation
…ased removal logic with instance-first and equals-based item matching. This ensures health potions with different heal amounts are removed correctly. Fixes Dungeon-CampusMinden#2698.
Co-authored-by: Niklas Schumann <68606032+Flamtky@users.noreply.github.com>
| @@ -330,28 +328,32 @@ public Optional<Item> get(int index) { | |||
| * inventory. | |||
| */ | |||
There was a problem hiding this comment.
This Javadoc now needs to be updated.
Co-authored-by: Niklas Schumann <68606032+Flamtky@users.noreply.github.com>
I agree that start items should be represented as an ordered collection that allows duplicates (e.g. Item[] or List), since the amount is known upfront. I can take this issue and prepare a PR that:
Let me know if Item[] is preferred over List. |
Co-authored-by: Niklas Schumann <68606032+Flamtky@users.noreply.github.com>
We will use lists. I have already opened a PR for this change => #2779. This will allow us to focus on resolving issue #2698 in this PR. |
Fixes #2698
This PR fixes a bug where InventoryComponent.removeOne removed the wrong
item when multiple items of the same class but different attributes
(e.g. health potions with different heal amounts) were present.
Changes:
to equals-based matching
based on heal_amount
Other InventoryComponent methods already rely on equals(Item) and
therefore benefit automatically from the corrected equality semantics.
Class-based query methods were intentionally left unchanged.