RPG inventory HowTo

I'm in the midst of designing an RPG more specifically the inventory portion. I'm not quite sure how I should design the system and how to create the items. Should I make a separate class for every item or should I create some sort of type system and value system? I am programming this in objective-c for the iPhone using cocos2d as an engine.

Good question, shadowgate. I've gone both ways in my games, and I've tried mixes of the systems as well.

The disadvantages and advantages of each depend on your specific situation and your game.

If you want the user to be able to create new items, edit existing ones, or expect to have external editing tools, you'll probably be forced to create a single Item class, and define all the behaviors using various flags and values set on instances of items.

If your items have a lot of diversity in their actions- where you expect to have each unique item have a block of code associated with it, the one-class-per-item approach might be easier.

People who are really gung-ho about object oriented development and overengineering systems usually favor the separate class per item, cause you can have nice deep inheritance hierarchies: Item > PickupableItem > Food > CookedFood > Bacon. Sometimes this can save you some coding, since a lot of non-specific details can be inherited. I find it a bit overkill though.

If you're expecting a lot of similar items, you'll probably do pretty well just with an itemType flag and a few values to control what happens with each type of item.

Especially for an iOS game, you'll want to do whatever's simpler in your solution. Scott and I have found that hardcoding game specifics is a big time saver over writing our own loading systems. No one other than us will touch the code anyway, and it's easier to be expressive in code than in a flatfile.

awesome. Thank you for the quick response. I will hopefully start that tonight or tomorrow. First I need a saving function using NSCoder. I think I might take the object-orientated path since I think better that way because I first learned programming through java.

Why not let every item be a dictionary of features where each feature deals with some kind of aspect of items e.g. their use as; weapon, key, food, carrying properties like weight/size/"does it float on water" ... etc. Each feature could be implement by one or more classes.

This avoids having a single big inheritance graph where a item -> weapon -> sword can't have features of item -> food - making it impossible to e.g. create edible swords.