private void FillReportResources(EspionageReport report, HtmlDocument document)
        {
            var resourceNode = document.DocumentNode.Descendants("ul").First(d => d.GetAttributeValue("data-type", null) == "resources");

            foreach (var node in resourceNode.Descendants("li"))
            {
                var nodeClassValue    = node.Descendants("div").First().GetAttributeValue("class", null);
                var nodeResourceValue = node.Descendants("span").First().InnerText.Replace(".", string.Empty);
                if (nodeClassValue.Contains("metal"))
                {
                    report.Metal = new Metal(nodeResourceValue);
                }
                else if (nodeClassValue.Contains("crystal"))
                {
                    report.Crystal = new Crystal(nodeResourceValue);
                }
                else if (nodeClassValue.Contains("deuterium"))
                {
                    report.Deuterium = new Deuterium(nodeResourceValue);
                }
                else if (nodeClassValue.Contains("energy"))
                {
                    report.Energy = new Energy(nodeResourceValue);
                }
            }
        }
        public void FillReportDefenses(EspionageReport report, HtmlDocument document)
        {
            var fleetNode = document.DocumentNode.Descendants("ul").First(d => d.GetAttributeValue("data-type", null) == "defense");
            var defenses  = new List <DefenseBase>();

            foreach (var node in fleetNode.Descendants("li"))
            {
                if (node.GetAttributeValue("class", null) == "detail_list_fail")
                {
                    return;
                }

                var defenseType = (DefenseType)Convert.ToInt32(node.Descendants("img")
                                                               .First(i => i.GetAttributeValue("class", null).Contains("defense"))
                                                               .GetAttributeValue("class", null)
                                                               .Replace("defense", string.Empty));
                var amount = Convert.ToInt32(node.Descendants("span")
                                             .First(i => i.GetAttributeValue("class", null) == "fright")
                                             .InnerText);

                switch (defenseType)
                {
                case DefenseType.RocketLauncher:
                    defenses.Add(new RocketLauncher(report.Target, amount, true, false));
                    break;

                case DefenseType.LightLaser:
                    defenses.Add(new LightLaser(report.Target, amount, true, false));
                    break;

                case DefenseType.HeavyLaser:
                    defenses.Add(new HeavyLaser(report.Target, amount, true, false));
                    break;

                case DefenseType.IonCannon:
                    defenses.Add(new IonCannon(report.Target, amount, true, false));
                    break;

                case DefenseType.GaussCannon:
                    defenses.Add(new GaussCannon(report.Target, amount, true, false));
                    break;

                case DefenseType.PlasmaTurret:
                    defenses.Add(new PlasmaTurret(report.Target, amount, true, false));
                    break;

                case DefenseType.SmallShield:
                    defenses.Add(new SmallShield(report.Target, amount, true, false));
                    break;

                case DefenseType.LargeShield:
                    defenses.Add(new LargeShield(report.Target, amount, true, false));
                    break;
                }
            }

            report.Defenses = defenses;
        }
        private void FillReportFleet(EspionageReport report, HtmlDocument document)
        {
            var fleetNode = document.DocumentNode.Descendants("ul").First(d => d.GetAttributeValue("data-type", null) == "ships");
            var ships     = new List <ShipBase>();

            foreach (var node in fleetNode.Descendants("li"))
            {
                if (node.GetAttributeValue("class", null) == "detail_list_fail")
                {
                    return;
                }

                var shipType = (ShipType)Convert.ToInt32(node.Descendants("img")
                                                         .First(i => i.GetAttributeValue("class", null).Contains("tech"))
                                                         .GetAttributeValue("class", null)
                                                         .Replace("tech", string.Empty));
                var amount = Convert.ToInt32(node.Descendants("span")
                                             .First(i => i.GetAttributeValue("class", null) == "fright")
                                             .InnerText);

                switch (shipType)
                {
                case ShipType.SmallCargo:
                    ships.Add(new SmallCargo(report.Target, amount, true, false));
                    break;

                case ShipType.LargeCargo:
                    ships.Add(new LargeCargo(report.Target, amount, true, false));
                    break;

                case ShipType.LightFighter:
                    ships.Add(new LightFighter(report.Target, amount, true, false));
                    break;

                case ShipType.HeavyFighter:
                    ships.Add(new HeavyFighter(report.Target, amount, true, false));
                    break;

                case ShipType.Cruiser:
                    ships.Add(new Cruiser(report.Target, amount, true, false));
                    break;

                case ShipType.Battleship:
                    ships.Add(new Battleship(report.Target, amount, true, false));
                    break;

                case ShipType.Battlecruiser:
                    ships.Add(new Battlecruiser(report.Target, amount, true, false));
                    break;

                case ShipType.Destroyer:
                    ships.Add(new Destroyer(report.Target, amount, true, false));
                    break;

                case ShipType.Deathstar:
                    ships.Add(new Deathstar(report.Target, amount, true, false));
                    break;

                case ShipType.Bomber:
                    ships.Add(new Bomber(report.Target, amount, true, false));
                    break;

                case ShipType.Recycler:
                    ships.Add(new Recycler(report.Target, amount, true, false));
                    break;

                case ShipType.EspionageProbe:
                    ships.Add(new EspionageProbe(report.Target, amount, true, false));
                    break;

                case ShipType.SolarSatellite:
                    ships.Add(new SolarSatellite(report.Target, amount, true, false));
                    break;

                case ShipType.ColonyShip:
                    ships.Add(new ColonyShip(report.Target, amount, true, false));
                    break;
                }
            }

            report.Ships = ships;
        }
        private void FillReportBuildings(EspionageReport report, HtmlDocument document)
        {
            //buildings
            var fleetNode = document.DocumentNode.Descendants("ul").First(d => d.GetAttributeValue("data-type", null) == "buildings");
            var buildings = new List <BuildingBase>();

            foreach (var node in fleetNode.Descendants("li"))
            {
                if (node.GetAttributeValue("class", null) == "detail_list_fail")
                {
                    return;
                }

                var buildingType = (BuildingType)Convert.ToInt32(node.Descendants("img")
                                                                 .First(i => i.GetAttributeValue("class", null).Contains("building"))
                                                                 .GetAttributeValue("class", null)
                                                                 .Replace("building", string.Empty));
                var level = Convert.ToInt32(node.Descendants("span")
                                            .First(i => i.GetAttributeValue("class", null) == "fright")
                                            .InnerText);

                switch (buildingType)
                {
                case BuildingType.MetalMine:
                    buildings.Add(new MetalMine(report.Target, level, true, false));
                    break;

                case BuildingType.CrystalMine:
                    buildings.Add(new CrystalMine(report.Target, level, true, false));
                    break;

                case BuildingType.DeuteriumExtractor:
                    buildings.Add(new DeuteriumExtractor(report.Target, level, true, false));
                    break;

                case BuildingType.SolarPowerPlant:
                    buildings.Add(new SolarPowerPlant(report.Target, level, true, false));
                    break;

                case BuildingType.FusionReactor:
                    buildings.Add(new FusionReactor(report.Target, level, true, false));
                    break;

                case BuildingType.MetalStorage:
                    buildings.Add(new MetalStorage(report.Target, level, true, false));
                    break;

                case BuildingType.CrystalStorage:
                    buildings.Add(new CrystalStorage(report.Target, level, true, false));
                    break;

                case BuildingType.DeuteriumTank:
                    buildings.Add(new DeuteriumTank(report.Target, level, true, false));
                    break;

                case BuildingType.RoboticsFactory:
                    buildings.Add(new RoboticsFactory(report.Target, level, true, false));
                    break;

                case BuildingType.Shipyard:
                    buildings.Add(new Shipyard(report.Target, level, true, false));
                    break;

                case BuildingType.ResearchLabolatory:
                    buildings.Add(new ResearchLabolatory(report.Target, level, true, false));
                    break;

                case BuildingType.RocketSilo:
                    buildings.Add(new RocketSilo(report.Target, level, true, false));
                    break;

                case BuildingType.NaniteFactory:
                    buildings.Add(new NaniteFactory(report.Target, level, true, false));
                    break;
                }
            }

            report.Buildings = buildings;
        }
        public override IEnumerable <DataObject> ProcessInternal(ClientBase client, ResponseContainer container)
        {
            HtmlDocument doc     = container.ResponseHtml.Value;
            HtmlNode     message = doc.DocumentNode.SelectSingleNode("//div[@class='detail_msg']");

            if (message == null)
            {
                yield break;
            }

            OGameClient oClient = (OGameClient)client;

            // Message info
            int            messageId = message.GetAttributeValue("data-msg-id", 0);
            MessageTabType tabType   = MessageTabType.FleetsEspionage;

            string   dateText = message.SelectSingleNode(".//span[contains(@class, 'msg_date')]").InnerText;
            DateTime date     = DateTime.ParseExact(dateText, "dd.MM.yyyy HH:mm:ss", oClient.ServerCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime();

            EspionageReport result = new EspionageReport
            {
                MessageId = messageId,
                TabType   = tabType,
                Sent      = new DateTimeOffset(date).Add(-oClient.Settings.ServerUtcOffset).ToOffset(oClient.Settings.ServerUtcOffset)
            };

            // Establish location
            HtmlNode locationLink = message.SelectSingleNode(".//a[contains(@href, 'page=galaxy')]");
            string   locationType = locationLink.SelectSingleNode("./figure").GetCssClasses(s => s == "moon" || s == "planet").First();

            CoordinateType coordinateType = locationType == "moon" ? CoordinateType.Moon : CoordinateType.Planet;

            result.Coordinate = Coordinate.Parse(locationLink.InnerText, coordinateType);

            // Parts
            HtmlNodeCollection            partsNodesList = message.SelectNodes(".//ul[@data-type and not(./li[@class='detail_list_fail'])]");
            Dictionary <string, HtmlNode> partsNodes     = partsNodesList.ToDictionary(s => s.GetAttributeValue("data-type", ""));

            // Parts - Resources
            HtmlNode details;

            if (partsNodes.TryGetValue("resources", out details))
            {
                HtmlNodeCollection values = details.SelectNodes(".//span[@class='res_value']");
                Debug.Assert(values.Count == 4);

                var oneThousandAdd = oClient.ServerCulture.NumberFormat.NumberGroupSeparator + "000";

                string[] vals = values.Select(s => s.InnerText
                                              .Replace("M", oneThousandAdd)
                                              .Replace("Bn", oneThousandAdd + oneThousandAdd)).ToArray();

                Resources resources = new Resources
                {
                    Metal     = int.Parse(vals[0], NumberStyles.AllowThousands | NumberStyles.Integer, oClient.ServerCulture),
                    Crystal   = int.Parse(vals[1], NumberStyles.AllowThousands | NumberStyles.Integer, oClient.ServerCulture),
                    Deuterium = int.Parse(vals[2], NumberStyles.AllowThousands | NumberStyles.Integer, oClient.ServerCulture),
                    Energy    = int.Parse(vals[3], NumberStyles.AllowThousands | NumberStyles.Integer, oClient.ServerCulture)
                };

                result.Resources = resources;
                result.Details  |= ReportDetails.Resources;
            }

            // Parts - Ships
            if (partsNodes.TryGetValue("ships", out details))
            {
                result.DetectedShips = ParseList <ShipType>(oClient, details);
                result.Details      |= ReportDetails.Ships;
            }

            // Parts - Defense
            if (partsNodes.TryGetValue("defense", out details))
            {
                result.DetectedDefence = ParseList <DefenceType>(oClient, details);
                result.Details        |= ReportDetails.Defense;
            }

            // Parts - Buildings
            if (partsNodes.TryGetValue("buildings", out details))
            {
                result.DetectedBuildings = ParseList <BuildingType>(oClient, details);
                result.Details          |= ReportDetails.Buildings;
            }

            // Parts - Research
            if (partsNodes.TryGetValue("research", out details))
            {
                result.DetectedResearch = ParseList <ResearchType>(oClient, details);
                result.Details         |= ReportDetails.Research;
            }

            // Return
            yield return(result);
        }
Exemple #6
0
 public FarmTarget(Celestial target, FarmState farmState = FarmState.Idle, EspionageReport report = null)
 {
     Celestial = target;
     State     = farmState;
     Report    = report;
 }