Ejemplo n.º 1
0
        internal override void ExecuteOrder()
        {
            List <string> result = new List <string>();

            result.Add(string.Format("Attempting to execute order: {0}", this.ToString()));

            if (TargetPosition == CurrentShip.Position) // already at target location
            {
                result.Add("Already at target location!");
                OnMessageResult?.Invoke(this, new MessageEventArgs(result));
            }
            else if (CurrentShip.MP.Current < 1) // no remaining MP
            {
                result.Add("No remaining MP!! [[BAD CODE!! BAD!! NO BISCUT!!]]");
                OnMessageResult?.Invoke(this, new MessageEventArgs(result));
            }
            else if (!CurrentShip.Position.IsAdjacent(TargetPosition)) // invalid movement location
            {
                result.Add("Target Position is not an adjacent location!! [[BAD CODE!! BAD!! GO TO YOUR ROOM!!]]");
                OnMessageResult?.Invoke(this, new MessageEventArgs(result));
            }
            else if (Simulation.Features.Any(x => x.Position == TargetPosition && x.IsBlocking) ||
                     Simulation.Ships.Any(x => x.Position == TargetPosition && x.ID != CurrentShip.ID)) // trying to move into blocking feature or ship
            {
                result.Add("ABORT ORDER, IMMINENT COLLISION!! [[BAD CODE!! BAD!! DO THAT OUTSIDE!!]]");
                OnMessageResult?.Invoke(this, new MessageEventArgs(result));
            }
            else
            {
                CurrentShip.Position = TargetPosition;
                result.Add(string.Format("Moved to {0}", TargetPosition.ToString()));
                OnShipMoved?.Invoke(this, new ShipMovedEventArgs(CurrentShip.ID, TargetPosition, result));
            }
        }
Ejemplo n.º 2
0
        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())
                        }));
                    }
                }
            }
        }