I am creating a item system including inventory, crafting and collecting resources. Some of myy core objects are:
-
class ResourceNode, which players can destroy to obtain Items
-
For example, destroy CrystalNode to obtain Crystals
-
Right now, the when destroyed, the Node drops specific Items on the ground which can be collected
-
-
DataTable which contains all existing items, has many properties like Name, Description, Icon. Each item also has a Class reference to it’s Item class
-
InventoryComponent, which contains Structs with (Item, Quantity), based on the Items DataTable
Everything up to this point is working fine and I am quite happy with my setup, but I am wondering how would I cope with the possibility (almost certainty) that many items will have different functionalities, for example:
-
If you have a Weapon Item type in the inventory, the weapon gets automatically equipped and you can use it
-
If you have Potion item type in inventory, you can use it’s effect by pressing some (Use) button
-
Etc., you get the point
-
Another question is, if I destroy the CrystalNode, the Crystal Item should not drop from it, right? Should it be more like a “CrystalDrop” class, that is there only for the dropped items? As the specific drop is there only to be collected and has really nothing to do with the specific item / its functionality.
I wonder, where should this “decide what this item is and then work some more logic” functionality should be defined / implemented". I really would not want a big old switch statement like case Item.Type == ItemType::Weapon {EquipmentComponent.EquipWeapon(Item)}
or something like that.
I also hate having multiple, possibly empty properties inside the ItemDataTable which would indicate the effects of the item (for example having isPotion and HealthRestorationValue properties for each and every item).
I was thinking about having a UseEffect
inside the ItemClass, that could be called when clicking the item from inventory, but then again, I would have to first instantiate the item, which might be unnecessary in this case? Or should I just go with that?
TLDR: What is the best practice for a good ITEM SYSTEM containing many items types, utilizing DataTables. Items can be used, equipped, crafted etc. From the game design perspective.
Any general or specific ideas, solutions are hugely welcome!