Proper item system design

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!

1 Like

hi @KarelOtruba

You seem to have a decent grasp on what you want. Theres no right or wrong ways. Its all down to your requirements.

But as you asked this is my take on inventory:

inventory is basically storage, an array. So while it might be advantagous to have some interactivity like potion use, or item equip from inside the inventory. I would keep it simple as possible.

As far as auto using items, i would have equipment slots like most games do.

so say you have 2 weapon slots, if one is empty when picking up a weapon, put it in the slot, otherwise the inventory. Same with potions. This helps keep things easier to manage and not over complicate. Then you can assign keys or action to those slots as you wish that then access the items inner workings.

So you want someway of identifying what an item is and does and a way of communicating its actions without having to spawn the item. OR spawn the item in your hand and let the actor object handle its workings. which might be easier as the first option is kinda duplicating work.

As far as the node, you could have a spawner that spawns the node after x time after its destroyed (if its renewable of not then just place them).
Inside the actual crystalnode actor handle dropping of crystals depeding on an event or interaction with the player. Once the node is empty then destroy the actor and no more crystals can be gotten as it was the crystalnode actor handling the drops.