Game Development Community

Ability design

by Ryan Strandberg · in Torque 2D Beginner · 10/23/2014 (10:01 am) · 4 replies

I'm working on a project rpg like action game that has a lot of different character abilities(read: attacks, spells, heals, and such). So I'm just wondering if there is a preferred way of doing this, or even an optimal way.

Currently I'm creating a main ability behavior that handles input from the player or AI controller. This behavior creates different behaviors to judge different condition(such as target health, your health, target range). It also creates different behaviors to handle the individual activated portions(such as deal damage to target or buffing the target) and passive portions(such as increasing a character stat while they have the ability loaded in). I've been doing this to save time having to code the same parts of an ability over and over.

This means the same character can have a different instance of the same behavior for each ability, which quickly adds up. This has been working on a small scale, but I'm wondering if having this many behaviors will be a problem later. I mean I'm pretty close to where I want my game scale to be and it runs fine on the hunk of junk that I call my laptop, but I'd still be interested to know if there is a better way of doing this.

Also, I'm wondering if there is an easier way to create an instance of a behavior with a behavior onAdd(). I'm currently using a funky string variable setup to get it to work now. Basically, I have strings in the main ability behavior called Conditions/Passives/Actives. Each string has TAB separated sections for each behavior to create/add when this behavior is added to an Object. The first word in the field is a BehaviorTemplate name and the rest are its variables. So it'd be something like:

%conditions = "rangeCondition 10" TAB "healthPercentCondition 0 25" TAB "targetTypeCondition friendly self";

%x = getFieldCount(%conditions);
for(%y = 0; %y != %x; %y++) {
%field = getField(%conditions, %y);

%template = getWord(%field, 0);
%instance = %template.createInstance();

%values = removeWord(%field, 0);

%instance.setVariables(%values);

%this.owner.addBehavior(%instance);
}

the new behaviors would know what to do with %values, or they would echo an error if they were sent the wrong things.

Sorry for the long post. Just don't want to spend my time doing something that's just going to cause a problem.
Thanks in advance for any help you might have.

--Edit--

Opps actually solved it right after I finished typing it. I think I just need to think through the possess I was using.

I'm just going to create a single instance of the sub behaviors if they doesn't already exist when the ability is added. then pass the values to the instance when it tests the conditions, activates, or whatever. Might even just add the instance to the scene instead of an individual object too.

#1
10/23/2014 (5:06 pm)
Paper and pencil - seriously. When you start designing really complex systems it really helps to "map it all out" so you can wrap your head around it.

I cheated; I made a tool to skim tables from the d20 Modern rtf files and convert them to torquescript arrays for me - vastly cut down on manually typing in data (still have to do a little clean-up) and all I have to do is write code to handle the data.

You could cheat a little too - using Excel (or another spreadsheet tool) to lay it all out and then exporting it to torquescript. As a general rule, text editors aren't the easiest way to visualize these sorts of systems.
#2
10/24/2014 (4:17 am)
Thanks Richard, I know I've kinda skimped on planning entirely with this project. It started off as just trying to learn the torque 2d engine, but once I actually saw some gameplay I couldn't help but add to it. Now its the code is a jumbled mess as I didn't really have any idea where I was going with it.

Does anyone know of a good tutorial for project planning? or have any tips?
#3
10/24/2014 (5:52 am)
Oh, it's one of those projects....

So, here's some advice from a book called Hard Code: "Don't sell the prototype." Your code is a steaming pile of awesome functionality - it works, but it's jumbled and confusing. That's fine, but don't keep it. Now that you see how to do the things you will need to do, you can use this project as a reference and rebuild it with better planning. In fact, it's entirely acceptable to make a new project just to try out each major feature. It's not like you get charged per project. Don't be afraid to experiment!

There are a million books on planning software projects. Software Engineering for Game Developers is not bad, and walks you through some decent practices using a sample project. Note that the method in this book is not the only way - there are so many project planning methodologies out there that it is amazing anyone can choose one to get to planning....
#4
10/24/2014 (3:30 pm)
Thanks Richard, I'll take a look through some of those books on amazon.