5
\$\begingroup\$

Pretty new to the whole game development scene, but I have experience in other branches of programming. Anyway, I was wondering what methods are used to implement a skill structure. I imagine a skill in itself would a class. I'm using actionscript 3 for this project btw.

public class Skill
{
    public var power:int;
    public var delay:int;
    public var cooldown:int;

    public function Skill(user:Mob, target:Mob) 
    {

    }       
}

Each skill would extend the Skill class and add it's own functionality.

public class Tackle extends Skill
{       
    public function Tackle(user:Mob, target:Mob) 
    {
        super(user, target);
        executeAttack();
    }

    private function executeAttack():void 
    {
        //multiply user.strength with power etc
        //play attack animation
    }
}

This where I get stuck. How do I termine which mobs has which skills? And which skill will they later be able to retrieve (by reaching a certain level etc). How does the player actually execute the skill and how is it determine if it hits. It's all very new to me so I have no idea where to begin. Any links would also be appreciated. Thanks in advance.

\$\endgroup\$

3 Answers 3

5
\$\begingroup\$

There's a lot of different directions you could go with this. What kind of game are you making, and what does type Mob represent? It sounds like you need to separate your concerns more.

How do I termine which mobs has which skills?

If each skill is its own class, and each skill extends the Skill class, then that leads me to think you should have a Vector.<Skill> field in the Mob class.

Assuming you need to instantiate the skill for purposes of state management (like cooldowns and other things), then this Vector. would contain objects which are-a Skill. To search for a specific skill, it could be useful to give Skill a property called Name which is overridden by subclasses of Skill. Then you can search through a mob's Vector. looking at the name of each skill until you find the one you're looking for.

A more robust solution would be to analyze your gameplay such that you don't even need to subclass Skill, and you could create entirely new skills by setting the properties of the skill class accordingly.

And which skill will they later be able to retrieve (by reaching a certain level etc).

This is a larger architecture question.

How does the player actually execute the skill

Presumably, the player is a Mob, and there's a keyboard mapping such that Attack gets called. Why do you have a separate function, executeAttack defined in the Tackle class?

and how is it determine if it hits.

This is something you need to decide. Read up on collision detection for checking if a point intersects a region on the screen, or find a D&D rulebook and look at how the Difficult Class system works.


It sounds like you're biting off more than you can chew. Try breaking this game down into something simpler. Build individual aspects of it into smaller games, then as you learn more you will be able to assemble the bits and pieces you've learned on the way into something bigger.

\$\endgroup\$
4
  • \$\begingroup\$ Thanks for your response. The mob class is just a general class which every interactive object in the game world will extend. I'm using actionscript which doesn't natively support vectors, but I get the idea! \$\endgroup\$
    – omgnoseat
    Commented Feb 26, 2011 at 20:33
  • 1
    \$\begingroup\$ AS2 or AS3? If you're using AS3 check here: help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/… Adobe recently added this class to Flex 4 in order to make operations on a container of elements of all the same type more efficient. You should definitely use it if you're able. \$\endgroup\$ Commented Feb 26, 2011 at 21:27
  • \$\begingroup\$ Oh nice, didn't realise this! thanks :) Another thing I was wondering, how should I call the attack class to execute it? Should the class be static so I could just call it like "sampleattack.execute" or should I make it a regeular class and initialize it as followed: "var attack:sampleattack = new sampleattack()". Not sure whats appropiate in this case. \$\endgroup\$
    – omgnoseat
    Commented Feb 26, 2011 at 22:48
  • \$\begingroup\$ If you want to maintain state inside of your SampleAttack class for cooldowns or other things on a per mob instance, then that requires a SampleAttack instance for each mob. If you don't need to track state, or if you are tracking with another field in the mob class, when you can use the static method route. But then you have no type safety. You could provide a GetInstance method for each attack and treat them as singletons. It really depends on your game. \$\endgroup\$ Commented Feb 26, 2011 at 23:37
2
\$\begingroup\$

Language and words are extremely important in programming. And your "situation" is the result of their misuse in abstracting classes. You need to determine which of the two are happening here. Reading 1: Mobs have Skills i.e. TacklingSkill etc. and when a target approaches it, the mob uses a Skill of choice? Reading 2: Actions like Tackle take place between two Mobs when they interact, collide etc.

Solution: I think you know what you want. Just rethink the names and your structure will derive itself from it. Use simple, straightforward and descriptive words. Do not mix concepts (i.e. actions with what creates them or what they result in or what is required for them).

\$\endgroup\$
1
\$\begingroup\$

There should be two layers - logical and presentational. Power etc. belongs to the logical level while the animation belongs to the presentation layer.

Skill constructor doesn't need mob and target. Remove them. Also, skill shouldn't be executed on creation.

There are probablu should be different types of skills - permanent passive skills ( masteries), temporary spells (bonus auras), active non-targeted spells (Frost Nova), active directional spells (Fireball), active targeted spells (Mana Drain). Each skill type has a slightly different invokation methods.

There is also a hard architectural problem of Classes / Types, Objects / Instances (and type objects). DefenceAura is a type of skill and has Duration, but the CastedDefenceAura is an instance of skill and has TimeLeft. There can also be PlayerSkill classes which the player acquired and can level. Normally OOP languages only have two "type layers" - classes and objects. But for skills we need slightly more. I designed a system where there are three types of spell classes: Spell (the one described in the rule book) which can be given to a player (at certain skill leven) as a PlayerSpell (has level and cooldown) and CastedSpell (flying in some direction)

The skill system may look something like this:

Skills

 public class Skill { 
     public var Name:string;
     public var MaxLevel:int;

     public function GiveToPlayer(player:Mob, level:int) : PlayerSkill {}
 }

 public class PermanentPassiveSkill extends Skill { } //Regeneration

 public class SkillWithCooldown {
     public var Cooldown:float;
 }

 public class DurationalSkill extends SkillWithCooldown { //Chilling Armor
     public var Duration:float;
 }

 public class SelfTargetedSkill extends SkillWithCooldown { } //Heal, Frost Nova

 public class DirectionalSkill extends SkillWithCooldown { } //Acid spray, normal and ranged physical attacks

 public class PointedSkill extends SkillWithCooldown { } //Firewall, Meteor

 public class TargetedSkill extends SkillWithCooldown { } //Mana drain

Player skills

 public class PlayerSkill { 
     public var Skill:Skill;
     public var Player:Mob;
     public var Level:int;
 }

 public class PlayerSkillWithCooldown {
     public var CooldownLeft:float;
 }

 public class SelfTargetedPlayerSkill extends PlayerSkillWithCooldown {
     public function Activate() : CastedSkill { }
 }

 public class DurationalPlayerSkill extends SelfTargetedPlayerSkill {
     public function Activate() : CastedDurationalSkill { }
 }

 public class DirectionalPlayerSkill extends PlayerSkillWithCooldown  {
     public function Activate(direction:Vector) : CastedDirectionalSkill { }
 }

 public class PointedPlayerSkill extends PlayerSkillWithCooldown  {
     public function Activate(target:Point) : CastedPointedSkill { }
 }

 public class TargetedPlayerSkill extends PlayerSkillWithCooldown  {
     public function Activate(target:Mob) : CastedTargetedSkill { }
 }

Casted skills

 public class CastedSkill {
     public var PlayerSkill:PlayerSkill;
 }

 public class CastedDurationalSkill extends CastedSkill {
     public var TimeLeft:float;
 }

 public class CastedDirectionalSkill extends CastedSkill {
     public var Direction:Vector;
 }

 public class CastedPointedSkill extends CastedSkill {
     public var Target:Point;
 }

 public class CastedTargetedSkill extends CastedSkill {
     public var Target:Mob;
 }

Animations

 public class PlayerSkillAnimation { //Casting/attack animation
     public var PlayerSkill:PlayerSkill;
 }

 public class CastedSkillAnimation { //Projectiles animation
     public var CastedSkill:CastedSkill;
 }

Concrete skill implementations

 public class Fireball extends DirectionalSkill {
    public var DamagePerLevel:float;

    public function GiveToPlayer(player:Mob, level:int) : PlayerFireball {
        return new PlayerFireball(self, player, DamagePerLevel * level)
    }
 }

 public class PlayerFireball extends DirectionalPlayerSkill {
    public var Damage:float;

    public function PlayerFireball(skill:Skill, player:Mob, level:int) {
        super(skill, player)
    }

    public function Activate(direction:Vector) : CastedFireball {
        return new CastedFireball(this, direction);
    }
 }

 public class CastedFireball extends CastedDirectionalSkill { }

It may look very complicated, but such skill system can bring clarity to the chaos of the skill code.

\$\endgroup\$

You must log in to answer this question.

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