internal override void ExecuteOrder() { List <string> result = new List <string>(); result.Add(string.Format("Attempting to execute order: {0}", this.ToString())); if (WeaponToFire.HasFiredThisRound) // has already fired { result.Add(string.Format("{0} has already fired this round!", WeaponToFire.Name)); OnMessageResult?.Invoke(this, new MessageEventArgs(result)); } else if (WeaponToFire.IsDestroyed) // weapon is destroyed { result.Add(string.Format("{0} is destroyed and cannot be fired!", WeaponToFire.Name)); OnMessageResult?.Invoke(this, new MessageEventArgs(result)); } else if (!WeaponToFire.IsLoaded) // weapon not reloaded { result.Add(string.Format("{0} will be reloaded in {1} turns", WeaponToFire.Name, WeaponToFire.Reload())); OnMessageResult?.Invoke(this, new MessageEventArgs(result)); } else if (TargetShip.HP.Current <= 0) // target is dead { result.Add("Target Already Defeated"); OnMessageResult?.Invoke(this, new MessageEventArgs(result)); } else { double distanceToTarget = CurrentShip.Position.DistanceTo(TargetShip.Position); if (distanceToTarget >= WeaponToFire.Range + 1) // target out of range { result.Add("Target Out Of Range"); OnMessageResult?.Invoke(this, new MessageEventArgs(result)); } else { WeaponToFire.Target = TargetShip; AttackResult attackResult = WeaponToFire.Fire(); result = result.Concat(attackResult.Messages).ToList <string>(); OnWeaponFired?.Invoke(this, new WeaponFiredEventArgs(CurrentShip.ID, TargetShip.ID, attackResult.IsHit, attackResult.IsCrit, WeaponToFire.FiringType, result)); if (attackResult.TargetDestroyed) { OnTargetDestroyed?.Invoke(this, new ShipEventArgs(TargetShip.ID, new List <string>() { string.Format("{0} was destroyed by this attack!", TargetShip.ToString()) })); } } } }
public void Fire(float fireDirection) { GameObject muzzleFlash = Instantiate(muzzleFlashPrefab, shotPoint.position, Quaternion.identity); for (int i = 0; i < bulletNumPerFire; i++) { Instantiate(bulletPrefab, shotPoint.position, Quaternion.FromToRotation(Vector3.up, fireDirection * Vector3.right)); } GameObject usedBullet = Instantiate(usedBulletPrefab, usedBulletShotPoint.position, Quaternion.FromToRotation(Vector3.up, -fireDirection * Vector3.right)); usedBullet.GetComponent <Rigidbody2D>().AddForce(new Vector2(-fireDirection, 4)); animator.Play("Fire"); fireSound.Play(); OnWeaponFired.Invoke(this, EventArgs.Empty); Destroy(muzzleFlash, 0.2f); }