Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am trying to program Fantasy Flights boardgame "Descent - Journeys in the Dark", but I have hit a wall when dealing with implementing abilities, which are a crucial part of the game.

Abilities are used alot of different places, but are similar most of the time.

For a hero an ability could be: At the start of his turn, Varikas the Dead recovers 1 fatigue

I have written monsters with abilities like this: Damage 2/Command

Equipment/Treasures look like this: When(TakingDamage):Exhaust&CancelDamage:2, When(MakingAttack(Type=Magic)):Gain:Surge 1 and When(Equipped(State=StartOfTurn))):Discard&Hero.Healt=Hero.HealthMax&Hero.Fatigue=Hero.FatigueMax

My idea is to maybe have some ability factory that will build an ability by reading the string formats, but I do not know how to implement them as a whole, and I am therefor turning to you.

Do any of you have any experience doing stuff like this, maybe when making D&D, Magic the Gathering, or maybe Descent?

Kind Regards Thediabloman

share|improve this question
add comment

1 Answer

I've somewhat-implemented a solution to a similar problem to this when attempting to make a digital version of a card game, similar to Magic The Gathering. I'm also reusing a similar model to this as I attempt to implement a D&D simulator, for player Feats.

The way I handled it was to create a series of "hooks", which were points in gameplay where an ability could potentially take effect. For example, there was a hook at the start of a player's turn, before and after they drew a card, before and after they started their attack phase, etc.

I then implemented an "AbilityComponent" abstract class, which simply consisted of a single virtual function for each of those hooks. An implemented subclass would then implement the hooks appropriate to it.

From there, I created an "Ability" class which was little more than a collection of AbilityComponents, and some utility functions for managing them.

When the game ran, at each hook-point, all active effects would have their implementation of that hook called.

Following this model, you could theoretically build a string parser that, for each command, separates the command into Condition, Action, and Parameter, i.e. {Condition}:{Action1}({Parameter1},{Parameter2})&{Action2}({Parameter1}); etc.

From there, just map each parsed action string to an instance of its related Ability class, and pass through the parameters.

share|improve this answer
    
+1 - Agreed, the Strategy pattern is the way to go here. –  Clockwork-Muse Dec 8 '11 at 22:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.