kiliki
kiliki

Reputation: 377

Game Dev - Abstract skill/talent system implementation

Reposted from gamedev stackexchange (original) as it's pretty dead over there:

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.

Upvotes: 0

Views: 1427

Answers (1)

mikera
mikera

Reputation: 106371

You can do this by creating a set of "composable" skill objects that you can hook into the right parts of your code.

Something like:

ninjaAttackSkill = new ModifiedAttack(originalAttack, 
       new ConditionalHit(behindTargetCondition, new InstantKillHit()));

The attack skill objects can then have a method signature something like:

public SomeResult attack(Thing attacker, Thing target);

Which you can then override for each of your composable skill objects.

I used a technique similar to this in my little Roguelike game Tyrant - basically there was a "Script" object that you could subclass to implement all kind of scripted functionality.

Upvotes: 1

Related Questions