Closed Lotendan closed 1 year ago
Nice find!
Inventory is indeed quite messy. For 1. I am not even sure this interface is really needed actually, but given that it exists I am sure it has different implementations by now. For 2. you are probably right and regarding 3. using inheritance for this is indeed a code smell. I would however not care about object creation or memory usage just yet (but it is definitely a potential memory hog).
Every item added to the player's inventory needs to be a
GameInventoryItem
type. There exists a condition inGameInventoryObject
s which allow to exchange two items from a vault, during which the item received loses its type and uses InventoryItem instead. A player could exploit this behaviour to prevent items from losing condition (for example). Indeed once turned into bareInventoryItem
s this code is no longer called. Note there are probably other places in the code where we are pushing anInventoryItem
instead of aGameInventoryItem
and we forget toGameInventoryItem.Create
.This begs some questions:
Why do the interface
IGameInventory
and all derivatives not accept anIGameInventoryItem
instead of a genericInventoryItem
object. This would effectively add a compile-time check that all items added to a player's inventory (and even a living's inventory - that would not hurt actually) are of the right type. I had a quick look in the code and actually this change would be large but wouldn't be too difficult because most of the code is articulated aroundGameInventoryItem
anyway already.What was the initial reason we splitted
InventoryItem
intoGameInventoryItem
historically? I imagine the first is the database record, and the second is the logical record and it makes sense to have a separation of their concerns.Why does the
GameInventoryItem
inherit fromInventoryItem
? Most of the time this forces a copy of theInventoryItem
object into theGameInventoryItem
, while it would probably (?) be simpler to keep a private reference to anInventoryItem
inside theGameInventoryItem
and not inherit from it (composition over inheritance).