How to handle inventory in 2d game, via xml, no game objects (inheritance? interface?)
Hello all,
I have a system which I have cobbled together off various tutorials and some intuitively hacking stuff together. This is for a 2D rpg, largely UI based game. However I want there to be lot that players can do with items in the game, such as equip, use, repair, upgrade, break up for components, buy/sell etc.
I have an xml database of items which are constructed from properties in a BaseItem class and put in a BaseItem dictionary, no problem.
Gameplay wise, there is no need for these items to 'exist' in the scene - only that the game knows whether or not the player has them in their playerInventory List, and that there is a sprite for them to appear in the inventory. So the inventory doesn't really contain the items, but just scans the playerInventory and builds itself accordingly. Again, all fine.
However, I can't help but think I am missing a trick on how to manage the properties of these items. My xml document has lots of fields such as 'ConsumeEffect' and 'EquipBonus' which clearly don't apply to every item in the game. So I leave these blank.
I know that I could create child classes of BaseItem, for weapons/consumables etc. but is there any point? Apart from the benefit of streamlining the sprawling xml document into a few more concise ones with fewer variables, and then having a separate dictionary for each, is there any good reason I should do this? (As I write this, I'm thinking about functions only within the class, but struggling to think of a useful example.)
I've also been reading about inheritance, but this seems to me to be an entirely different model to what I'm proposing, and am I right in thinking that it would require Game Objects or scriptable objects? And would that effectively mean creating an object for each item in the game? If so, I definitely don't want to go down that route.
I'd be curious to hear collective thoughts - I imagine there will be differences of opinion, but I want to hear them before I go much further this way.
When you have unused vars in a class, you are wasting memory. Inheritance isn't commonly understand as an Unity thing. It would be the way to go here. Just google c# polymorphism or c# inheritance.
Your answer
Follow this Question
Related Questions
Zelda-like inventory system 0 Answers
Inventory and item class design 0 Answers
Classifying item types without inheritance 0 Answers
Object reference not set to an instance of an object 1 Answer
Harcoding items vs using a JSON database 0 Answers