I've been making small 2D games for about 3 years now (XNA and more recently LWJGL/Slick2D). My latest idea would involve some form of "talent tree" system in a real time game.

I've been wracking my brain but can't think of a structure to hold a talent. Something like

"Your melee attack is an instant kill if behind the target"

I'd like to come up with an abstract object rather than putting random conditionals into other methods. I've solved some relatively complex problems before but I don't even know where to begin with this one.

Any help would be appreciated - Java, pseudocode or general concepts are all great.


1 Answer 1


"Your melee attack is an instant kill if behind target"

The talent system basically consists of a set of rules which need to validate to true before some effect takes place. You could treat the rules like as follows:

// Some abstract rule
class IRule {
  virtual bool validate() = 0;
class BehindTargetRule : public IRule {}
class IsAttackMeleeRule : public IRule {}

Then you have some code which validates each rule and if each rule is true, you trigger specific effects like:

// Some abstract effect
class IEffect {
  virtual void apply() = 0;
class SetDamageToHealthOfTarget : public IEffect {}

You could package these up in something like the following:

struct Talent {
  std::vector<IRule*> rules;
  std::vector<IEffect>* effects;

This allows you to mix/match bits and pieces of talents with one another to give varying talent choices which are similar or have the same rules but different effects based on the type of player, etc.

Now somehow you'd need to interface this with your combat system. Since combat often needs to take into account things like buffs/debuffs, armor depreciation, armor mitigation and so forth, you'd need to interweave those calculations with the effects that the rules trigger if they all validate.



You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .