コード例 #1
0
ファイル: LcogIO.cs プロジェクト: sal1n/lcog-client
        /// <summary>
        /// Loads game data.
        /// </summary>
        /// <param name="fileName">File name.</param>
        public static void LoadGameData(string fileName)
        {
            Client.Instance.Map = new Map();
            Client.Instance.Components = new Components();

            XmlDocument xml = LcogIO.LoadXml(fileName);

            XmlNode gameNode = xml.SelectSingleNode("/game");
            Client.Instance.GameName = gameNode.Attributes["name"].Value;

            XmlNode mapNode = xml.SelectSingleNode("//map");
            Client.Instance.Map.Name = mapNode.Attributes["name"].Value;
            Client.Instance.Map.Size = int.Parse(mapNode.Attributes["extremes"].Value);

            foreach (XmlNode node in xml.SelectNodes("//planet"))
            {
                Planet planet = new Planet();
                planet.Image = global::LcogClient.Properties.Resources.planet;
                planet.ID = int.Parse(node.Attributes["id"].Value);
                planet.Name = node.Attributes["name"].Value;
                planet.X = int.Parse(node.Attributes["x"].Value);
                planet.Y = int.Parse(node.Attributes["y"].Value);
                Client.Instance.Map.Add(planet);
            }

            foreach (XmlNode node in xml.SelectNodes("//component"))
            {
                Component component = new Component();
                component.Name = node.Attributes["name"].Value;
                component.Description = node.Attributes["desc"].Value;
                component.Cost = int.Parse(node.Attributes["cost"].Value);
                component.Size = int.Parse(node.Attributes["size"].Value);
               foreach (XmlNode n in node.SelectNodes("tech"))
                {
                    Technology tech = new Technology();
                    tech.Level = int.Parse(n.Attributes["level"].Value);
                    tech.Name = n.Attributes["name"].Value;
                    component.Tech.Add(tech);
                }
                Client.Instance.Components.Add(component);
            }
        }
コード例 #2
0
ファイル: LcogIO.cs プロジェクト: sal1n/lcog-client
        /// <summary>
        /// Loads a turn report.
        /// </summary>
        /// <param name="fileName">File name.</param>
        public static void LoadReport(string fileName)
        {
            Client.Instance.Player = new Player();
            Client.Instance.Factions = new Factions();
            //Client.Instance.Selected = null;
            //Client.Instance.Target = null;

            XmlDocument xml = LcogIO.LoadXml(fileName);

            Client.Instance.Player.ID = int.Parse(xml.DocumentElement.Attributes["id"].Value);
            Client.Instance.Player.Turn = int.Parse(xml.DocumentElement.Attributes["turn"].Value);
            Client.Instance.Player.Password = xml.DocumentElement.Attributes["password"].Value;
            Client.Instance.Player.Energy = int.Parse(xml.DocumentElement.Attributes["energy"].Value);

            foreach (XmlNode node in xml.SelectNodes("//message"))
            {
                Message message = new Message();
                message.Type = node.Attributes["type"].Value;
                message.From = node.Attributes["from"].Value;
                message.Body = node.InnerText;
                Client.Instance.Player.Messages.Add(message);
            }

            Client.Instance.Player.Tech.Researching = xml.SelectSingleNode("//technology").Attributes["researching"].Value;
            Client.Instance.Player.Tech.CurrentResearch = int.Parse(xml.SelectSingleNode("//technology").Attributes["current_research"].Value);
            foreach (XmlNode node in xml.SelectNodes("//tech"))
            {
                Technology tech = new Technology();
                tech.Level = int.Parse(node.Attributes["level"].Value);
                tech.Name = node.Attributes["name"].Value;
                try
                {
                    tech.Research = int.Parse(node.Attributes["research"].Value);
                }
                catch
                {
                    tech.Research = 0;
                }
                Client.Instance.Player.Tech.Add(tech);
            }

            foreach (XmlNode node in xml.SelectNodes("//faction"))
            {
                Faction faction = new Faction();
                faction.ID = int.Parse(node.Attributes["id"].Value);
                faction.Name = node.Attributes["name"].Value;
                faction.Planets = int.Parse(node.Attributes["planets"].Value);
                faction.Score = int.Parse(node.Attributes["score"].Value);
                faction.Ships = int.Parse(node.Attributes["ships"].Value);
                faction.Mass = int.Parse(node.Attributes["shipmass"].Value);

                if (node.Attributes["diplomacy"] != null)
                {
                    faction.Relations = node.Attributes["diplomacy"].Value;
                }
                else
                {
                    faction.Relations = "Neutral";
                }
                Client.Instance.Factions.Add(faction);

                // assign faction to player
                if (faction.ID == Client.Instance.Player.ID)
                {
                    Client.Instance.Player.Faction = faction;
                }
            }

            foreach (XmlNode node in xml.SelectNodes("//planet"))
            {
                // just get the planet reference from the map
                Planet planet = Client.Instance.Map.GetPlanetByID(int.Parse(node.Attributes["id"].Value));
                if (node.Attributes["energy"] != null)
                {
                    planet.Energy = int.Parse(node.Attributes["energy"].Value);
                }
                if (node.Attributes["factionId"] != null)
                {
                    planet.Faction = Client.Instance.Factions.GetFactionByID(int.Parse(node.Attributes["factionId"].Value));
                }
                if (planet.Faction == Client.Instance.Player.Faction)
                {
                    Client.Instance.Player.Planets.Add(planet);
                }

                foreach (XmlNode component in node.SelectNodes("slot"))
                {
                    planet.Components.Add(Client.Instance.Components.GetComponentByName(component.InnerText));
                }
            }

            foreach (XmlNode node in xml.SelectNodes("//ship"))
            {
                Ship ship = new Ship();
                ship.Image = global::LcogClient.Properties.Resources.ship;
                ship.ID = int.Parse(node.Attributes["id"].Value);
                ship.X = int.Parse(node.Attributes["x"].Value);
                ship.Y = int.Parse(node.Attributes["y"].Value);

                if (node.Attributes["damage"] != null)
                {
                    ship.Damage = int.Parse(node.Attributes["damage"].Value);
                }

                ship.Faction = Client.Instance.Factions.GetFactionByID(int.Parse(node.Attributes["factionId"].Value));
                ship.Name = node.Attributes["name"].Value;

                string wp = node.Attributes["waypoint"].Value;
                if (wp.Length > 1)
                {
                    int x = int.Parse(wp.Substring(0, wp.IndexOf(',')));
                    int y = int.Parse(wp.Substring(wp.IndexOf(',') + 1));
                    ship.Waypoint = new Point(x, y);
                }
                else
                {
                    ship.Waypoint = ship.Location;
                }

                ship.HullClass = node.Attributes["class"].Value;
                ship.Hull = int.Parse(node.Attributes["hull"].Value);

                //ship.Image = LcogIO.GetHullImage(ship.Hull.Name);

                ship.Mass = int.Parse(node.Attributes["mass"].Value);

                foreach (XmlNode component in node.SelectNodes("slot"))
                {
                    ship.Components.Add(Client.Instance.Components.GetComponentByName(component.InnerText));
                }

                if (ship.Faction == Client.Instance.Player.Faction)
                {
                    ship.MaxMove = int.Parse(node.Attributes["maxmove"].Value);
                    Client.Instance.Player.Ships.Add(ship);
                }
                Client.Instance.Map.Add(ship);
            }
        }