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.