public string Inject(OgamePageInfo info, string body, ResponseContainer response, string host, int port)
        {
            if (!response.RequestMessage.RequestUri.PathAndQuery.Contains("page=eventList"))
            {
                return(body);
            }

            var events = response.GetParsed <EventInfo>();


            var totalAttack    = TotalFor(events.Where(ei => ei.IsReturning && ei.MissionType == MissionType.Attack));
            var totalTransport = TotalFor(events.Where(ei => !ei.IsReturning && (ei.MissionType == MissionType.Transport || ei.MissionType == MissionType.Deployment)));

            StringBuilder repl = new StringBuilder();


            string wrapper = "<tr class='eventFleet'><td colspan=11>Total cargo from {0}: <span class='textBeefy friendly'>{1}</span></td></tr>";

            if (totalAttack.Total > 0)
            {
                repl.Append(string.Format(wrapper, "attacks", totalAttack));
            }
            if (totalTransport.Total > 0)
            {
                repl.Append(string.Format(wrapper, "transport", totalTransport));
            }

            if (repl.Length > 0)
            {
                body = body.Replace(@"<tbody>", $@"<tbody>{repl.ToString()}");
            }

            return(body);
        }
예제 #2
0
        protected override CommandQueueElement RunInternal()
        {
            using (Client.EnterPlanetExclusive(this))
            {
                // Make the initial request to get a token
                HttpRequestMessage req = Client.RequestBuilder.GetPage(PageType.Resources, PlanetId);
                ResponseContainer  res = AssistedIssue(req);

                OgamePageInfo info  = res.GetParsedSingle <OgamePageInfo>();
                string        token = info.OrderToken;

                // validate resources
                int currentBuildingLevel = res.GetParsed <DetectedBuilding>()
                                           .Where(b => b.Building == BuildingToBuild)
                                           .Select(b => b.Level)
                                           .FirstOrDefault();

                PlanetResources resources = res.GetParsedSingle <PlanetResources>();

                Resources cost = Building.Get(BuildingToBuild).Cost.ForLevel(currentBuildingLevel + 1);
                DetectedOngoingConstruction underConstruction = res.GetParsedSingle <DetectedOngoingConstruction>(false);

                if (underConstruction != null)
                {
                    Logger.Instance.Log(LogLevel.Debug, $"Building {underConstruction.Building} already under construction on planet {info.PlanetName}, will finish at {underConstruction.FinishingAt}");
                    return(Reschedule(underConstruction.FinishingAt));
                }
                else if (cost.Metal > resources.Resources.Metal || cost.Crystal > resources.Resources.Crystal || cost.Deuterium > resources.Resources.Deuterium)
                {
                    double maxTimeToGetEnoughResources = new double[] {
                        (cost.Metal - resources.Resources.Metal) / (resources.ProductionPerHour.Metal / 3600.0),
                        (cost.Crystal - resources.Resources.Crystal) / (resources.ProductionPerHour.Deuterium / 3600.0),
                        (cost.Deuterium - resources.Resources.Deuterium) / (resources.ProductionPerHour.Deuterium / 3600.0)
                    }.Max();
                    Logger.Instance.Log(LogLevel.Debug, $"Not enough resources! It would cost {cost} to build {BuildingToBuild} level {currentBuildingLevel + 1}, planet {info.PlanetName} only has {resources.Resources}; will have enough in {maxTimeToGetEnoughResources} seconds");
                    return(Reschedule(DateTimeOffset.Now.AddSeconds(maxTimeToGetEnoughResources)));
                }


                HttpRequestMessage buildReq = Client.RequestBuilder.GetBuildBuildingRequest(BuildingToBuild, token);
                AssistedIssue(buildReq);

                return(null);
            }
        }
예제 #3
0
        private void WaitForProbes()
        {
            Progress = "Waiting for probes";
            Thread.Sleep(5000 + _sleepTime.Next(2000));

            IEnumerable <FleetInfo> probes;

            do
            {
                HttpRequestMessage req  = RequestBuilder.GetPage(PageType.FleetMovement);
                ResponseContainer  resp = Client.IssueRequest(req);

                probes = resp.GetParsed <FleetInfo>().Where(fi => fi.MissionType == MissionType.Espionage && !fi.IsReturning);
                if (probes.Any())
                {
                    Thread.Sleep(3000 + _sleepTime.Next(2000));
                }
            } while (probes.Any());
        }