I’m gonna implement battle mechanics of heroes of might and magic 3, basically it is just a standard turn based game where each unit has its own specific skills, like one might have lifesteal when attacks, one can charge and attack and gain hit bonus based on tile he moved before attacking, one might have something in defense and uses it when he takes damage etc.
So the main problem is code architecture, I have BattleController class where I want to send signal to this unit, attack to this other unit. I also have Unit class which represents units, and because of the unit variety I also have a scriptableobject called UnitConfig class where I can store unit specific information on derived classes like
public abstract class UnitConfig : ScriptableObject
{
// bunch of parameters
int attackPower, defensePower, hitPoints;
// every unit shares the same logic which is taking damage, attacking, and if available defensing with skills
public virtual Attack(Unit attacker, Unit attacked)
{
atacked.TakeDamage(attacker.attackPower);
}
public virtual TakeDamage(Unit attacker, Unit attacked)
{
// bla bla bla
}
// bunch of other codes
}
public class GuardianUnit : UnitConfig
{
public override Attack()
{
// this unit has special attack ability
// override standard attack method and instead use special attack
}
}
So there is some issues, first UnitConfig does a lot of things which I don’t like to, instead what it should do is just store info about specific unit’s special ability, then I can use it whenever it is possible to use, in Unit class, not in the UnitConfig file,
I have something like this in my mind:
BattleController sends Attack Command which stores info about attacker and attacked unit
Then before Units apply that command, they look for any special ability in any point (maybe it is just a defense ability or attacking one), then apply with that special ability.
For visualization: BattleController —> Attack Command (which also contains attacker and attacked unit) —> Units (which involved in command) —> UnitConfig (To see which special ability do units have for that command)
How can I develop a flexible architecture based on this problem, what would be your suggestions?