public override bool Attack() { bool outcome = false; /* * if(reloading && Time.time > reloadTimeStamp+reloadTime) * { * reloading = false; * ammunitionCount = ammunitionCapacity; * Debug.Log("Reloading Complete"); * * } */ if (!reloading && ammunitionCount > 0) { if (Time.time > fireTimeStamp + (1 / attributes.GetAttribute(WeaponAttributesType.FireRate).GetValue())) { ammunitionCount--; //Debug.Log("Fire " + (ammunitionCapacity - ammunitionCount) + " (Last shot at: " + fireTimeStamp); fireTimeStamp = Time.time; float interval = attributes.GetAttribute(WeaponAttributesType.SpreadAngle).GetValue() / attributes.GetAttribute(WeaponAttributesType.NumProjectiles).GetValue(); for (int i = 0; i < attributes.GetAttribute(WeaponAttributesType.NumProjectiles).GetValue(); i++) { Vector2 tempDir = equipped.GetAimRight().normalized; if (attributes.GetAttribute(WeaponAttributesType.NumProjectiles).GetValue() > 1) { tempDir = tempDir.Rotate(-attributes.GetAttribute(WeaponAttributesType.SpreadAngle).GetValue() / 2 + (interval * i)); } tempDir.Normalize(); RangedAttackPrototype attackProto = Instantiate(attack); attackProto.damage = (int)attributes.GetAttribute(WeaponAttributesType.Damage).GetValue(); attackProto.damageType = damageType; ProjectilePrototype tempProto = Instantiate(projProto); tempProto.speed = (int)attributes.GetAttribute(WeaponAttributesType.ProjectileSpeed).GetValue(); Projectile shot = new Projectile(tempProto, new RangedAttack(equipped, attackProto), tempDir); shot.Spawn(equipped.Position + new Vector2(0, attackProto.offset.y) + (attackProto.offset * tempDir.normalized)); } foreach (Companion companion in equipped.companionManager.Companions) { companion.Fire(); } //Actually fire here outcome = true; } if (ammunitionCount <= 0) { reloadTimeStamp = Time.time; reloading = true; Debug.Log("Reloading"); } } return(outcome); }
public RangedAttack(Entity entity, RangedAttackPrototype prototype) : base(entity, prototype) { numberOfProjectiles = prototype.numberOfProjectiles; spreadAngle = prototype.spreadAngle; projProto = prototype.projectilePrototype; }