Jump to content

View more

Image of the Day

Working on an auto spawn system. #gamedev #indiedev #screenshotsaturday https://t.co/Mm2kfekz7b
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

Item system - design patterns

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 vincero   Members   


Posted 10 November 2012 - 04:35 AM


I want to design an easily extensible item system for my game where I don't need to modify existing code much. I want to add items with new effects on the fly.

Traits my items have in common:

A name,
a description,
an npc sell price,
if it can be equipped,
required level,
if it is usable in battle,
if it is usable outside of battle,
a cooldown

So I can encapsulate this already into a class. But now there are item effects.

heals x health points,
heals x mana points,
removes debuff x,
adds buff x,
gives x stat points on equipping,
has x% chance to create some other effect when equipped,

And those can be combined like: heals x health and mana points. The first four are examples for effects a usable item can have while the last two are examples for effects equipable items can have.

The idea behind it is that I have this structure in a database as well and I can add a new item with a new effect combination in my database, my code reads this then and builds it together into a new fancy item, without me having to modify much. The only time I need to modify my code is when I add new effects obviously.

How would you put this together in design pattern(s)? I am writing my game in a language which has support for OO obviously.

#2 Scourage   Members   


Posted 10 November 2012 - 08:26 AM

I'd recommend an effect class that the item class has a pointer to. The effect class is the base class for all the different kinds of desired effects. You could have a list of effects in the item class instead of a single pointer to chain effects together, but that might complicate things. Either way, separate the effect from the item and make the interface for enabling the effect generic so it can be enabled in a consistent manner.



Halfway down the trail to Hell...

#3 kalixxx   Members   


Posted 10 November 2012 - 10:23 AM

makeing one myself and as far as iv seen you will need an item object with a list of effects of each one.
the effects are generic and you dont even have to name them or make them all in advance thats the work of you item creator.

now the effects need nothing unless you adress them BUT you can make new effect any time you need.

#4 MaxDZ8   Members   


Posted 12 November 2012 - 02:01 AM

Are you interested in generating them on the fly (I mean, randomly) or you're going to make the objects one by one (by a human)? Or perhaps use them as templates?
I worked on an RPG-oriented game system years ago with a friend for his MUD. I don't remember much but in the end we had to classify all the possible effects in advance to resolve cross-dependancies when generating.
So for example, if an object dealt fire damage, it couldn't roll a ice damage enchant (he decided fire would negate ice).
Similarly, we had to merge damage bonus such as +30%, +20% ends up being +50% and not (130*120=+56%).
Stacking was surprisingly involved as we needed to figure out if similar effect would stack linearly (+), negate each other, not stack, or combine by (*).

Besides generation, game play was relatively straightforward, we designed a set of signals/callbacks/events to be broadcast to each object. They took care of implementing the per-object requisite testing, checking against various conditions etc.
I have to admit the way we made combat work was pretty ugly. I'd probably make it nicer nowadays but at the time I was really unsatisfied by it, magic such as "regen" or anything else enabling lasting effects went through several holes in the design.

Edited by Krohm, 12 November 2012 - 02:06 AM.

Previously "Krohm"

#5 wqking   Members   


Posted 12 November 2012 - 02:25 AM

Separate item system and effect system, don't mix them up.

The effect system manages a collection of effects.
Each effect has a unique ID (the ID can be either string or integer, whatever), and implement an interface, e.g IEffect.
IEffect has a function, something like, void perform(Item * item);
When you add new effect, just implement IEffect and add the interface to effect system.

The item system manages a collection of items.
The items can be read from database, or added by code.
An item holds a collection of effect IDs.
When you want to do the effect, just ask the effect system with the effect ID, and the call IEffect::perform with the given item.

With this design, your item only knows an effect ID. It doesn't care what's the effect, or how effect works.

Edited by wqking, 12 November 2012 - 02:27 AM.

cpgf library -- free C++ open source library for reflection, serialization, script binding, callbacks, and meta data for OpenGL Box2D, SFML and Irrlicht.
v1.5.5 was released. Now supports tween and timeline for ease animation.

#6 freeworld   Members   


Posted 13 November 2012 - 11:49 AM

When I was messing around with a magic the gathering clone I used a sortve hardcover + scripted solution. I boiled everything down to; cost - what is needed to use the ability. Target - what kind of objects can it effect. Effect - what the ability does.

Effects were hardcover as a series of functions. Ie DealDamage(target&, amountOfDamage). I had a separate functions that would validate cost, target, etc.

If every thing passed another function would parse the effect and pass its parameters and the desired target to the abilities corresponding function which would apply the actual effect.
[ dev journal ]
[ current projects' videos ]
[ Zolo Project ]
I'm not mean, I just like to get to the point.

#7 LordRhys   Members   


Posted 16 November 2012 - 10:28 AM

You could use a combination of what was mentioned above with EffectID but enumerate them with names like what is used in most common games now like Borderlands, and Diablo, etc.. where your Items have names like Fiery Vampiric Longsword of Flight. Then you have 3 effects Fiery, Vampiric, and Flight, which can fall into 3 different categories that have various levels like say: Hot, Flame, Fiery, Inferno, Hellfire for example and then you can have an exclusion list so you couldn't have a Fiery Blizzard Mace, etc...

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.