Hi guys,
So I’m making an RPG and consumable items all extend the abstract “Item” class.
But here’s the thing, depending on the potion or whatever, it can do different things. There are two ways I can see of implementing this:
-
Implement a healing potion class and then have custom variables in there for weak, mid and strong healing. (then I do another class for Mana potions, separate class for defense potions, etc).
-
Have one class for all consumable items and then an enum for the item type. If Item is weak potion, heal this much, else if item is defense potion, bolster defense, etc.
I feel the second option is messier in code while the first would result in more scripts in the item scripts folder.
One class is better IMHO since Unity do not support serialization of arrays of different types. It’s like you can’t have an array of items containing items of different class serialized correctly.
Also you may to want to make different behaviours for every item type - DropItemBehaviour, ShopItemBehaviour, InventoryItemBehaviour and activate them as apporiate.
In one class class you can directly or by id refernce an action to perform and/or character attribute(s) to perform action on instead of making enum and then switch.
Ah, that could be bad for me. Due to how I set up my inventory, I already have separate arrays for each item type so as to allow for easy implementation of item tabs. At the same time though there is an array for items/skills that all extend the “Item” class which serves as an action bar, and that will break upon load if not serialized correctly.
Just to be sure, even if all the items extend the Item class (and are thus technically “Items”), they will still not serialize correctly, is that right?
Then I suggest you test those cases before you continue