A weapon can be used as melee or range weapon, it can be thrown, toss, fired, shoot, cast (a projectile) or use to slash, bash, stab . How do I apply these to entity-system? my first approach is to create an enum class of WeaponType, a melee or range.
public enum WeaponType { MELEE, RANGE } public interface Weapon { void use(); } Then I've create a weapon component and add weapon type data, to determine its type. For melee a weapon, it needs to have a method that handles different kind of "attack motion" like slash, bash, stab. For range weapon, it needs to have a container, factory and a method that handles different kinds of "projectile motion" like shoot, fire, throw, toss etc.. Now the problem is how could I create a method for different kinds of projectile motion, remember I am specifically using Ashley ECS framework
public class WeaponComponent implements Component { public Weapon weapon; public WeaponType type; // if weapon type is melee, use the below data public Container container // holds the created projectile public Factory factory // creates a different kinds of projectile object } // or create seperately??? public class MeleeWeaponComponent implements Component { ... different kinds of method also like slash, bash, stab } public class RangeWeaponComponent implements Component { ... Factory and Container ... different kinds of projectile motion? } In this idea, I can use abstract or interface but I think abstraction or is not recommended.
[Combined data suggestion] by @Ryanwhite and me
- Blue line is area of effect angle covered
- Green line is distance covered
- Red point is the target point
public class WeaponComponent implements Component { public Ray ray // to handle collisions public float aoe; // 0.5 for melee, more than 0.5 for other weapon public float aoeAngleCovered; public float aoeAngle public Ammo[] // 0 for melee, 1 or more for other weapon } 