Пример #1
0
        private static int CommandSpawnUnit(List <string> arg)
        {
            if (arg == null || arg.Count < 1)
            {
                Debug.WriteLine("%WARNING%Usage: \"spawn-unit <xml name>\"");
                return(1);
            }

            SpaceShipUnit newUnit = new SpaceShipUnit();

            for (int i = 0; i < 7; i++)
            {
                SpaceShip newShip = SpaceShip.FromXml(ResourceManager.Get <XmlResource>(arg[0]), null);
                newShip.Location = new Vector2(0, 0);
                newShip.Faction  = 2;
                newShip.Hitbox   = new Hitbox(newShip.Texture.Texture.width);
                newUnit.Add(newShip);
            }
            newUnit.UiImage = ResourceManager.Get <TextureResource>(@"thumbnail\barb");
            GameManager.Add(newUnit);

            return(0);
        }
Пример #2
0
        public static SpaceShipHardpoint FromXml(XmlResource Xml, SpaceShipHardpoint DstObject)
        {
            if (Xml == null)
            {
                throw new ArgumentNullException("Xml");
            }
            SpaceShipHardpoint Result = DstObject;

            if (DstObject == null)
            {
                Result = new SpaceShipHardpoint();
            }
            Result = SpaceShip.FromXml(Xml, Result) as SpaceShipHardpoint;

            XmlNode obj = Xml.Xml.LastChild;

            string             baseName   = GetXmlText(obj, "Base", string.Empty);
            SpaceShipHardpoint baseObject = Result;

            if (!string.IsNullOrEmpty(baseName))
            {
                try
                {
                    baseObject = SpaceShipHardpoint.FromXml(ResourceManager.Get <XmlResource>(baseName), null);
                }
                catch (KeyNotFoundException e)
                {
                    baseObject = Result;
                    Console.WriteLine("XML Error: Failed to locate XML base " + baseName);
                }
            }

            string[] offsetRaw = GetXmlText(obj, "Offset", "0,0").Split(',');
            Result.Offset  = new Vector2(float.Parse(offsetRaw[0]), float.Parse(offsetRaw[1]));
            Result.Texture = ResourceManager.Get <TextureResource>(GetXmlText(obj, "Texture", baseObject.Texture.Name));
            return(Result);
        }
Пример #3
0
        private static List <SpaceObject> GetXmlNested(XmlNode Parent, string Name, List <SpaceObject> Default)
        {
            if (Parent.HasChildNodes)
            {
                XmlNodeList children = Parent.ChildNodes;
                foreach (XmlNode node in children)
                {
                    if (node.Name.ToUpperInvariant() == Name.ToUpperInvariant())
                    {
                        List <SpaceObject> result = new List <SpaceObject>();
                        if (node.ChildNodes.Count > 0)
                        {
                            children = node.ChildNodes;
                            foreach (XmlNode childNode in children)
                            {
                                if (childNode.Name.ToUpperInvariant() == "spaceship".ToUpperInvariant())
                                {
                                    SpaceShip child = SpaceShip.FromXml(new XmlResource()
                                    {
                                        Xml = new XmlDocument()
                                        {
                                            InnerXml = childNode.OuterXml
                                        }
                                    }, null);
                                    result.Add(child);
                                }
                            }
                        }

                        return(result);
                    }
                }
            }

            return(Default);
        }
Пример #4
0
        public static SpaceShip FromXml(XmlResource Xml, SpaceShip DstObject)
        {
            if (Xml == null)
            {
                throw new ArgumentNullException("Xml");
            }
            SpaceShip Result = DstObject;

            if (DstObject == null)
            {
                Result = new SpaceShip();
            }
            Result = SpaceObject.FromXml(Xml, Result) as SpaceShip;

            XmlNode obj = Xml.Xml.LastChild;

            string    baseName   = GetXmlText(obj, "Base", string.Empty);
            SpaceShip baseObject = Result;

            if (!string.IsNullOrEmpty(baseName))
            {
                try
                {
                    baseObject = SpaceShip.FromXml(ResourceManager.Get <XmlResource>(baseName), null);
                }
                catch (KeyNotFoundException e)
                {
                    baseObject = Result;
                    Console.WriteLine("XML Error: Failed to locate XML base " + baseName);
                }
            }

            Result.Hull                    = GetXmlValue(obj, "Hull", baseObject.Hull);
            Result.Shield                  = GetXmlValue(obj, "Shield", baseObject.Shield);
            Result.MaxHull                 = GetXmlValue(obj, "MaxHull", baseObject.MaxHull);
            Result.MaxShield               = GetXmlValue(obj, "MaxShield", baseObject.MaxShield);
            Result.ShieldRegen             = GetXmlValue(obj, "ShieldRegen", baseObject.ShieldRegen);
            Result.MaxThrust               = GetXmlValue(obj, "MaxThrust", baseObject.MaxThrust);
            Result.TurnSpeed               = GetXmlValue(obj, "TurnSpeed", baseObject.TurnSpeed);
            Result.RateOfFire              = GetXmlValue(obj, "RateOfFire", baseObject.RateOfFire);
            Result.ShieldRebootProbability = (int)GetXmlValue(obj, "ShieldRebootProbability", baseObject.ShieldRebootProbability);
            Result.Texture                 = ResourceManager.Get <TextureResource>(GetXmlText(obj, "Texture", baseObject.Texture.Name));
            //Result.Hitbox = Hitbox.Automatic(Result.Texture, (int)Math.Max(2, Result.Scale * Result.Texture.Texture.height / 8));

            List <SpaceObject> hardpoints = GetXmlNested(obj, "Hardpoints", null);

            if (hardpoints != null && hardpoints.Count > 0)
            {
                Result.Hardpoints = new List <SpaceShipHardpoint>();
                foreach (SpaceObject o in hardpoints)
                {
                    SpaceShipHardpoint hp = o as SpaceShipHardpoint;
                    if (hp != null)
                    {
                        hp.Parent = Result;
                        hp.Depth += Result.Depth;
                        hp.Scale *= Result.Scale;
                        Result.Hardpoints.Add(hp);
                    }
                }
                Debug.WriteLine("Loaded hardpoints");
            }

            return(Result);
        }