示例#1
0
        public EnemyShip Clone()
        {
            var s = new EnemyShip();

            s.Name    = Name;
            s.Glyph   = Glyph;
            s.Color   = Color;
            s.Shields = Shields;
            foreach (var comp in Components)
            {
                s.Components.Add(comp.Clone());
            }
            return(s);
        }
示例#2
0
        static EnemyShip()
        {
            // load enemy ship designs
            var designsData = JsonConvert.DeserializeObject <IDictionary <string, IEnumerable <string> > >(File.ReadAllText("EnemyShips.json"));
            var library     = new List <EnemyShip>();

            foreach (var designData in designsData)
            {
                var design = new EnemyShip();
                design.Name  = designData.Key;
                design.Glyph = design.Name[0].ToString().ToUpper()[0];
                foreach (var compName in designData.Value)
                {
                    var comp = Component.Get(compName).Clone();
                    design.Components.Add(comp);
                }
                design.Shields = design.MaxShields;
                library.Add(design);
            }
            Library = library;
        }
示例#3
0
        private bool Build(EnemyShip design)
        {
            // find sector to place ship in
            var places = new List <dynamic>();
            var sys    = StarSystem;
            var x      = X;
            var y      = Y;

            for (int dx = -1; dx <= 1; dx++)
            {
                for (int dy = -1; dy <= 1; dy++)
                {
                    if (sys.SpaceObjects.AreCoordsInBounds(x + dx, y + dy) && sys.SpaceObjects[x + dx, y + dy] == null)
                    {
                        places.Add(new { X = x + dx, Y = y + dy });
                    }
                }
            }
            if (!places.Any())
            {
                return(false);                // nowhere to put the ship
            }
            var coords = places.PickRandom();

            // create the ship and place it
            var ship = design.Clone();

            if (PlayerShip.Instance.StarSystem == StarSystem)
            {
                Log.Add("An enemy shipyard builds a " + ship.Name + "!", Color.Red);
            }
            Savings -= ship.Cost;
            StarSystem.PlaceSpaceObject(ship, coords.X, coords.Y, 0);
            Galaxy.Current.RefreshEnemyCounts();
            return(true);
        }
示例#4
0
        public override void Attack()
        {
            var fired = new List <Component>();

            // first targeting priority: shipyards
            // find weapons to fire
            bool didstuff = false;

            do
            {
                didstuff = false;
                foreach (var comp in Components.Where(c => c.WeaponInfo != null && c.WeaponInfo.Wait <= 0))
                {
                    var sys = FindSpaceObjectsInRange <EnemyShipyard>(comp.WeaponInfo.Range).Where(sy => sy.IsRevealed);
                    if (sys.Any())
                    {
                        // find closest
                        EnemyShipyard target = null;
                        var           dist   = int.MaxValue;
                        foreach (var sy in sys)
                        {
                            var nd = Utilities.Distance(X, Y, sy.X, sy.Y);
                            if (nd < dist)
                            {
                                target = sy;
                                dist   = nd;
                            }
                        }

                        // fire!
                        Log.Add("Firing " + comp + " at the Jraenar shipyard!");
                        fired.Add(comp);
                        target.TakeDamage(comp.WeaponInfo.Damage);
                        comp.WeaponInfo.Wait += comp.WeaponInfo.ReloadRate;
                        didstuff              = true;
                    }
                }
            } while (didstuff);

            // second targeting priority: enemy ships
            // find weapons to fire
            do
            {
                didstuff = false;
                foreach (var comp in Components.Where(c => c.WeaponInfo != null && !fired.Contains(c) && c.WeaponInfo.Wait <= 0))
                {
                    var ships = FindSpaceObjectsInRange <EnemyShip>(comp.WeaponInfo.Range);
                    if (ships.Any())
                    {
                        // find closest
                        EnemyShip target = null;
                        var       dist   = int.MaxValue;
                        foreach (var sy in ships)
                        {
                            var nd = Utilities.Distance(X, Y, sy.X, sy.Y);
                            if (nd < dist)
                            {
                                target = sy;
                                dist   = nd;
                            }
                        }

                        // fire!
                        Log.Add("Firing " + comp + " at the " + target + "!");
                        if (target.RollEvasionOrPD(comp.WeaponInfo.IsMissile))
                        {
                            if (comp.WeaponInfo.IsMissile)
                            {
                                Log.Add("It was shot down!", Color.Yellow);
                            }
                            else
                            {
                                Log.Add("We missed!", Color.Yellow);
                            }
                        }
                        else
                        {
                            target.TakeDamage(comp.WeaponInfo.Damage);
                        }
                        comp.WeaponInfo.Wait += comp.WeaponInfo.ReloadRate;
                        didstuff              = true;
                    }
                }
            } while (didstuff);
        }