private void OnMouseDown() { int scores = negative ? -containScores : containScores; OnTargetDestroyed?.Invoke(scores); Destroy(gameObject); }
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()) })); } } } }