Beispiel #1
0
 public SpaceBattle(SpaceShip a, SpaceShip b)
 {
     this.sideA      = a;
     this.sideB      = b;
     this.commands   = new Queue <BattleCommansPair>();
     this.LastUpdate = DateTime.Now;
 }
Beispiel #2
0
        public SpaceShip Clone(Player player)
        {
            SpaceShip newSpaceShip = new SpaceShip(player);

            newSpaceShip.Name               = this.Name;
            newSpaceShip.Mass               = this.Mass;
            newSpaceShip.Hull               = 100;
            newSpaceShip.Energy             = 100;
            newSpaceShip.InternalCap        = this.InternalCap;
            newSpaceShip.GunMoutings        = this.GunMoutings;
            newSpaceShip.MissilePylons      = this.MissilePylons;
            newSpaceShip.Crew               = this.Crew;
            newSpaceShip.MainThrusterAccel  = this.MainThrusterAccel;
            newSpaceShip.RetroThrusterAccel = this.RetroThrusterAccel;
            newSpaceShip.Drive              = this.Drive;
            newSpaceShip.Id        = Guid.NewGuid();
            newSpaceShip.Code      = newSpaceShip.MakeSoCode("CCC-DDDD");
            newSpaceShip.CargoBay  = new CargoBay(this.InternalCap);
            newSpaceShip.MKIIFile  = this.MKIIFile;
            newSpaceShip.Generator = new EnergyGenerator(newSpaceShip);
            newSpaceShip.Lasers    = new Laser[1];
            newSpaceShip.Lasers[0] = new Laser(this);


            return(newSpaceShip);
        }
Beispiel #3
0
        public bool ScanForTargetsAndEngage()
        {
            double    dist   = Double.MaxValue;
            SpaceShip target = null;

            var area = GameManager.Instance.StarSystemManager.GetStarSystemArea(this.SpaceShip.Coords);

            foreach (var ship in area.GetShipsInSystem())
            {
                if ((ship.Player as Pirate) == null)                   // will not attach other pirates
                {
                    double sDist = this.SpaceShip.SystemLocation.GetInSystemDistance(ship.SystemLocation);
                    if (sDist < dist)
                    {
                        dist   = sDist;
                        target = ship;
                    }
                }
            }

            //if (target != null)
            //    this.SpaceShip.EngageShip(target);

            return(false);            // target != null;
        }
Beispiel #4
0
 protected virtual void OnBattleEnded(SpaceBattle battle, SpaceShip enemy)
 {
     if (BattleEnded != null)
     {
         BattleEnded(this, battle, enemy);
     }
 }
Beispiel #5
0
        public static SpaceShip CreateRandomModel(string modelName, Player player)
        {
            var    defaultModels = SpaceShip.GetDefaultModels();
            Random rand          = new Random();
            int    modelNum      = rand.Next(0, defaultModels.Count - 1);

            return(defaultModels.Values.ElementAt(modelNum).Clone(player));
        }
Beispiel #6
0
 public void EngageShip(SpaceShip ship)
 {
     if (ship != null && this.player != null)
     {
         this.player.SpaceShip.Target = ship;
         this.player.SpaceShip.SetDestSystemLocation(ship.SystemLocation);
         GameManager.Instance.BattleManager.CreateBattle(this.player, ship);
     }
 }
Beispiel #7
0
        public int DoBattleCommand(SpaceShip ship, string command)
        {
            bool alreadyStarted    = battleStarted;
            BattleCommansPair pair = null;

            lock (commandLoker) {
                if (commands.Count == 0)
                {
                    sideTurn = SideTurnEnum.Any;
                }

                if (sideTurn == SideTurnEnum.Any)
                {
                    pair = new BattleCommansPair(++turn);

                    var message = new PlayerMessage("Battle", PlayerMessageType.Battle,
                                                    string.Format("Battle turn {0} created {1} vs {2}",
                                                                  turn, sideA.Player.Name, sideB.Player.Name));
                    sideA.Player.SendPlayerMessage(message);
                    sideB.Player.SendPlayerMessage(message);
                }
                else if (commands.Count > 0)
                {
                    pair = commands.Peek();
                }

                if (pair != null)
                {
                    if (ship == sideA && pair.A == null)
                    {
                        pair.A        = GetBattleCommand(ship, sideB, command);
                        sideTurn      = SideTurnEnum.SideB;
                        battleStarted = true;
                    }
                    else if (ship == sideB && pair.B == null)
                    {
                        pair.B        = GetBattleCommand(ship, sideA, command);
                        sideTurn      = SideTurnEnum.SideA;
                        battleStarted = true;
                    }

                    if (pair.A != null && pair.B != null)
                    {
                        sideTurn = SideTurnEnum.Any;
                    }
                }
            }

            if (!alreadyStarted && battleStarted)
            {
                sideA.ReportBattleStarted(this, sideB);
                sideB.ReportBattleStarted(this, sideA);
            }

            return(turn);
        }
Beispiel #8
0
 void SpaceShip_TargetReached(SectorObject sender, SystemEventArgs e)
 {
     if (State == "TARGET" || State == "BATTLE")
     {
         SpaceShip ship = this.SpaceShip.Target as SpaceShip;
         if (ship != null)
         {
             //GameManager.Instance.BattleManager.DoBattleCommand(this, ship, "F");
         }
     }
 }
Beispiel #9
0
        public static SpaceShip CreateModel(string modelName, Player player)
        {
            var defaultModels = SpaceShip.GetDefaultModels();

            if (defaultModels.ContainsKey(modelName))
            {
                SpaceShip    ship     = defaultModels[modelName].Clone(player);
                GameLocation location = player.Location;
                if (location.SystemBody != null)
                {
                    ship.Coords         = location.SystemBody.Coords;
                    ship.SystemLocation = location.SystemBody.SystemLocation;
                }
                else if (location.StarSystem != null)
                {
                    ship.Coords         = location.StarSystem.Coords;
                    ship.SystemLocation = new SystemLocation(0, 0, 0);
                    ship.SystemLocation.RandomizeInSystemCoords();
                }
                else if (location.Sector != null)
                {
                    ship.Coords         = location.Sector.Coords;
                    ship.SystemLocation = new SystemLocation(
                        Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity
                        );
                }
                else
                {
                    // this can't be possible
                    ship.Coords         = new Coords(new GalacticLocation(0, 0, 0));
                    ship.SystemLocation = new SystemLocation(
                        Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity
                        );
                }

                return(ship);
            }
            else
            {
                return(null);
            }
        }
Beispiel #10
0
        private BattleCommand GetBattleCommand(SpaceShip ship, SpaceShip target, string command)
        {
            int rangePoints = 0, hitPointsE = 0, hitPointsM = 0,
                multiplier = 0, defencePointsE = 0, defencePointsM = 0;
            var  range     = ship.SystemLocation.GetInSystemDistance(target.SystemLocation);
            bool commandOk = false;

            switch (command.ToUpper().Trim())
            {
            case "M":
                if (ship.MissileLaunchers != null)
                {
                    foreach (var missileLauncher in ship.MissileLaunchers)
                    {
                        if (missileLauncher.Activate())
                        {
                            rangePoints += GetRangePoints(missileLauncher, range);
                            hitPointsM  += missileLauncher.HitPoints;
                            multiplier++;
                            commandOk = true;
                        }
                    }
                }

                if (commandOk)
                {
                    if (ship.Player != null)
                    {
                        ship.Player.SendPlayerMessage(new PlayerMessage(
                                                          "SHIP", PlayerMessageType.Battle, string.Format("{0} missiles fired at target {1}",
                                                                                                          multiplier, target.Code)));
                    }
                    if (target.Player != null)
                    {
                        target.Player.SendPlayerMessage(new PlayerMessage(
                                                            ship.Code, PlayerMessageType.Battle,
                                                            string.Format("missile incomming! range: {0}", SystemLocation.GetDistanceDesc(range))));
                    }
                }
                else
                {
                    ship.Player.SendPlayerMessage(new PlayerMessage(
                                                      "SHIP", PlayerMessageType.BattleWarning, "Not enougf enery to fire missiles"));
                }
                break;

            case "F":
                if (ship.Lasers != null)
                {
                    foreach (var laser in ship.Lasers)
                    {
                        if (laser.Activate())
                        {
                            rangePoints += GetRangePoints(laser, range);
                            hitPointsE  += laser.HitPoints;
                            multiplier++;
                            commandOk = true;
                        }
                    }
                }

                if (commandOk)
                {
                    if (ship.Player != null)
                    {
                        ship.Player.SendPlayerMessage(new PlayerMessage(
                                                          "SHIP", PlayerMessageType.Battle, string.Format("{0} lasers fired at target {1}",
                                                                                                          multiplier, target.Code)));
                    }
                    if (target.Player != null)
                    {
                        target.Player.SendPlayerMessage(new PlayerMessage(
                                                            ship.Code, PlayerMessageType.Battle,
                                                            string.Format("laser fire! range: {0}", SystemLocation.GetDistanceDesc(range))));
                    }
                }
                else
                {
                    ship.Player.SendPlayerMessage(new PlayerMessage(
                                                      "SHIP", PlayerMessageType.BattleWarning, "Not enougf enery to fire lasers"));
                }

                break;

            case "E":
                defencePointsE += 2;                         //Todo calculate this based on spaceship and experience;
                defencePointsM += 2;                         //Todo calculate this based on spaceship and experience;
                multiplier      = 1;
                commandOk       = true;
                ship.Player.SendPlayerMessage(new PlayerMessage(
                                                  "SHIP", PlayerMessageType.Battle, "Performing evasive manouvers"));
                target.Player.SendPlayerMessage(new PlayerMessage(
                                                    ship.Code, PlayerMessageType.Battle, "target is performing evasive manouvers"));
                break;

            case "X":
                break;

            case "S":
                break;
            }

            return(new BattleCommand(command, hitPointsE, hitPointsM, rangePoints,
                                     multiplier, defencePointsE, defencePointsM));
        }
Beispiel #11
0
        private static Dictionary <string, SpaceShip> GetDefaultModels()
        {
            Dictionary <string, SpaceShip> defaults = new Dictionary <string, SpaceShip>();

            SpaceShip adder = new SpaceShip(null);

            adder.Name               = "Adder";
            adder.Mass               = 55;
            adder.InternalCap        = 15;
            adder.Crew               = 1;
            adder.GunMoutings        = 1;
            adder.MissilePylons      = 0;
            adder.Drive              = 2;
            adder.Cost               = 73000;
            adder.MainThrusterAccel  = 18;
            adder.RetroThrusterAccel = 8;
            adder.CargoBay           = new CargoBay(15);
            adder.Speed              = 5;
            adder.MKIIFile           = "Ship41_Sprite";

            defaults.Add("Adder", adder);


            SpaceShip anaconda = new SpaceShip(null);

            anaconda.Name               = "Anaconda";
            anaconda.Mass               = 800;
            anaconda.InternalCap        = 150;
            anaconda.Crew               = 10;
            anaconda.GunMoutings        = 2;
            anaconda.MissilePylons      = 8;
            anaconda.Drive              = 6;
            anaconda.Cost               = 1060000;
            anaconda.MainThrusterAccel  = 6;
            anaconda.RetroThrusterAccel = 3;
            anaconda.CargoBay           = new CargoBay(150);
            anaconda.Speed              = 15;
            //anaconda.ANSI16File = "Ship23_16.ans";
            anaconda.MKIIFile = "Ship23_Sprite";

            defaults.Add("Anaconda", anaconda);

            SpaceShip asp = new SpaceShip(null);

            asp.Name               = "Asp Explorer";
            asp.Mass               = 150;
            asp.InternalCap        = 30;
            asp.Crew               = 2;
            asp.GunMoutings        = 2;
            asp.MissilePylons      = 1;
            asp.Drive              = 3;
            asp.Cost               = 187000;
            asp.MainThrusterAccel  = 22;
            asp.RetroThrusterAccel = 7;
            asp.CargoBay           = new CargoBay(30);
            asp.Speed              = 20;
            //asp.ANSI16File = "Ship12_16.ans";
            asp.MKIIFile = "Ship12_Sprite";

            defaults.Add("Asp", asp);

            return(defaults);
        }
Beispiel #12
0
 public void ReportBattleEnded(SpaceBattle battle, SpaceShip enemy)
 {
     OnBattleEnded(battle, enemy);
 }
Beispiel #13
0
 void SpaceShip_BattleStarted(object sender, SpaceBattle battle, SpaceShip enemy)
 {
     this.SpaceShip.EngageShip(enemy);
 }
Beispiel #14
0
 void SpaceShip_BattleEnded(object sender, SpaceBattle battle, SpaceShip enemy)
 {
     this.State = "SEARCH";
 }