Item System Methodology

I’m trying to create an item generation system and I’m not sure how I should structure it. First I had an Item class which had every stat an equippable item (that I had implemented so far) could have, like damage for weapons, defense for gear, etc., and it worked fine, but I wasn’t sure if that was the best way to go about it since the list would get bigger and more abstract the more items I made, and each item that was generated had every single stat that other items could have so it was this long list of 0s in the inspector with only a few variables changed/useable. How it looked wasn’t really the problem, it’s more that I wasn’t sure if having each item so closely related (using the same script) was a good idea.

After that I tried something else and made the original Item class abstract, and put a few variables, like rarity, in there that other classes would inherit from. I then had classes like RangedWeapon, Melee Weapon, Accessory, etc., which would still work, but it made the code very tedious as I then have to generate the item type, then change what script it gets depending on what item it generates, so I’d end up with this long switch statement with a bunch of different lines for each item type.

I can provide examples if the above was hard to understand, but other than that if anyone has any suggestions or knows common methods game developers use then please let me know.

I can tell you how I solved that issue, maybe it’ll give you some ideas. Basically Item is just a simple class with basic properties like name, maybe requirements, etc. All of the specific properties (damage, armor, etc) are delegated into ItemBehaviour classes. Item has a collection of those classes.

So what you can do is to create class for different item behaviours like WeaponBehaviour, ArmorBehaviour, etc and then just combine instances of those behaviours to get the item you want.

So for example everything that’s related to weapon should go to WeaponBehaviour (weaponType, damage, damageType, etc). Then you just add that behaviour to your item and voila you have a weapon.

It’s very flexible because now you can have item that’s both weapon but can also give you defence, like pike (just add another behaviour to the item, for example ArmorBehaviour)