Jump to content
  • Advertisement
Sign in to follow this  
dhartles

Question about 'Item System' Implementation

This topic is 5033 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here is the situation. I'm implementing my 'Item System' in an RPG, and want to bounce some ideas off you guys(ladies). Currently I have an ArrayList (using C#) as a 'Container' as a private member on my Player class. (Eventually this Container will be moved to a separate class). Anyways, right now when the player object 'adds' an item to their container I'm adding a string value representing the name of the type of Item i.e (Health Potion). Then when a user 'uses' the item, I create an object from my Health Potion class, run the animation sequence, apply the coded effects to the target object, dispose of the item object, and remove the string value from the container Array List. This seemed a little more 'memory friendly' than creating a Health Potion object when the user added it to their container. In trying to think down the road I didn't want 99 Health Potion objects created and sitting in the player object's container array list (as all of these would contain the animation bmp's, effect code, etc.). I though 99 string values of 'Health Potion' would be a little better. Or better yet, one string value of 'Health Potion' and another int value representing the count of that item type '99'. Then when/if the user ever 'used' an item, then I would create the object, use it, and dispose of it almost instantly, and decrement the int value representing the item count in the container array list (and remove the string name value of the count was at one). Thoughts/Ideas/Comments? Thanks, Dave

Share this post


Link to post
Share on other sites
Advertisement
Wouldn't it be easier to add the number of that item type to the item class, and maybe have a maximum limit for that stack? That way you have 1 representation of the object, and you don't have to create a new object to use it. Also, you might want to consider using hash maps (if C# has them that is, I know Java does), that way you can look up the item faster.

If you have a maximum capacity for the 'stack', you may need another way to look up the next item of that type (maybe put it in the item class too).

If you plan on limiting the number of items, I suggest you make multiple 'bags', like in World Of Warcraft; that way you only have small lists to check, rather than a list with an unlimited capacity.

If you don't want to add any restrictions to the number of items to be carried, then a hash map would be perfect for this.

Share this post


Link to post
Share on other sites
Thx Gorax,

I think you're right about adding the item count to the class and carrying it with the object. I think I am going to place count restrictions on the items. In just the past few minutes I was in the middle of changing my implementation to the 'bags' type architecture you mentioned below, when I saw you're reply. I'm pretty sure the C# ArraryList doesn't have a hashmap method already defined, but it does have a binary search (which will probaly be fast enough for me).

Thx again,
Dave

Share this post


Link to post
Share on other sites
Java doesn't have a hash map method for it's ArrayList class either, it's a completely seperate storage class. Since you're going to be using bags, it doesn't matter, but you should check them out if you ever plan on making a database. ;)

Share this post


Link to post
Share on other sites
What I always do, is separate the data out into instance classes (which contain information pertinent to each particular item) and archetype classes (which contain information that is shared across all instances of any particular item). Each instance contains a reference to the relevant archetype. That way, you use minimal memory but you still have all the information right there.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!