Пример #1
0
        public override IEnumerable <DataObject> ProcessInternal(ClientBase client, ResponseContainer container)
        {
            HtmlDocument       doc         = container.ResponseHtml.Value;
            HtmlNodeCollection imageFields = doc.DocumentNode.SelectNodes("//div[starts-with(@id, 'fleet')]");

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

            FleetSlotCount count = new FleetSlotCount();
            HtmlNode       slots = doc.DocumentNode.SelectSingleNode("//div[@id='content']//div[@class='fleetStatus']/span[@class='fleetSlots']");

            count.Current = int.Parse(slots.SelectSingleNode("./span[@class='current']").InnerText);
            count.Max     = int.Parse(slots.SelectSingleNode("./span[@class='all']").InnerText);

            yield return(count);

            foreach (HtmlNode node in imageFields)
            {
                string idText = node.GetAttributeValue("id", null);
                int    id     = int.Parse(FleetIdRegex.Match(idText).Groups[1].Value, NumberStyles.AllowThousands | NumberStyles.Integer, client.ServerCulture);

                FleetMissionDetails missionDetails = FleetUtilityParser.ParseFleetMissionDetails(node);
                HtmlNode            fleetInfo      = node.SelectSingleNode(".//span[@class='starStreak']");
                FleetComposition    composition    = FleetUtilityParser.ParseFleetInfoTable((OGameClient)client, fleetInfo);

                FleetEndpointInfo endpointOrigin      = ParseEndpoint(node.SelectSingleNode("./span[@class='originData']"));
                FleetEndpointInfo endpointDestination = ParseEndpoint(node.SelectSingleNode("./span[@class='destinationData']"));

                yield return(new FleetInfo
                {
                    Id = id,
                    ArrivalTime = missionDetails.ArrivalTime,
                    IsReturning = missionDetails.IsReturn,
                    MissionType = missionDetails.Mission,
                    Origin = endpointOrigin,
                    Destination = endpointDestination,
                    Composition = composition
                });
            }
        }
Пример #2
0
        public override IEnumerable <DataObject> ProcessInternal(ClientBase client, ResponseContainer container)
        {
            HtmlDocument       doc         = container.ResponseHtml.Value;
            HtmlNodeCollection imageFields = doc.DocumentNode.SelectNodes("//tr[contains(@class, 'eventFleet') and @data-mission-type]");

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

            foreach (HtmlNode node in imageFields)
            {
                FleetMissionDetails missionDetails = FleetUtilityParser.ParseFleetMissionDetails(node);
                EventInfo           info           = new EventInfo()
                {
                    ArrivalTime = missionDetails.ArrivalTime,
                    IsReturning = missionDetails.IsReturn,
                    MissionType = missionDetails.Mission
                };

                string idText = node.GetAttributeValue("id", "0");
                if (idText.Length > 9)
                {
                    info.Id = int.Parse(idText.Substring(9, idText.Length - 9));
                }
                else
                {
                    info.Id = info.ArrivalTime.Hour * 3600 + info.ArrivalTime.Minute * 60 + info.ArrivalTime.Millisecond;
                }

                string @class = node.ChildNodes[1].GetAttributeValue("class", string.Empty);
                if (@class.Contains("friendly"))
                {
                    info.Type = EventType.Own;
                }
                else if (@class.Contains("hostile"))
                {
                    info.Type = EventType.Hostile;
                }
                else
                {
                    throw new ApplicationException($"Fleet is neither own nor hostile: {@class}");
                }

                // crashes on missle attack, need to get the html to parse correctly
                string detailsHtml = WebUtility.HtmlDecode(node.SelectSingleNode("./td[contains(@class, 'icon_movement')]")?.ChildNodes[1].GetAttributeValue("title", string.Empty));
                if (detailsHtml != null)
                {
                    HtmlDocument fleetComposition = new HtmlDocument();
                    fleetComposition.LoadHtml(detailsHtml);
                    info.Composition = FleetUtilityParser.ParseFleetInfoTable((OGameClient)client, fleetComposition.DocumentNode);
                }

                string playerOther = node.SelectSingleNode("./td[@class='sendMail']/a")?.GetAttributeValue("title", string.Empty) ?? string.Empty;

                info.Origin = new FleetEndpointInfo()
                {
                    Coordinate   = Coordinate.Parse(node.SelectSingleNode("./td[@class='coordsOrigin']").InnerText.Trim(trims), CoordinateType.Planet),
                    EndpointName = node.SelectSingleNode("./td[@class='originFleet']").InnerText.Trim(trims),
                    Playername   = info.Type == EventType.Own ? "" : playerOther
                };

                info.Destination = new FleetEndpointInfo()
                {
                    Coordinate   = Coordinate.Parse(node.SelectSingleNode("./td[@class='destCoords']").InnerText.Trim(trims), CoordinateType.Planet),
                    EndpointName = node.SelectSingleNode("./td[@class='destFleet']").InnerText.Trim(trims),
                    Playername   = info.Type == EventType.Own ? playerOther : ""
                };

                yield return(info);
            }
        }