Example #1
0
        protected override CommandQueueElement RunInternal()
        {
            using (Client.EnterPlanetExclusive(this))
            {
                HttpRequestMessage req;
                ResponseContainer  resp;

                req  = Client.RequestBuilder.GetPage(PageType.JumpGate, PlanetId);
                resp = Client.IssueRequest(req);

                if (Fleet == null)
                {
                    Fleet = FleetComposition.FromDetected(resp.GetParsed <DetectedShip>());
                }

                Dictionary <string, string> postParams = new Dictionary <string, string>();
                postParams["token"] = resp.GetParsedSingle <OgamePageInfo>().OrderToken;
                postParams["zm"]    = Destination.ToString();
                postParams.Merge(Fleet.Ships.ToDictionary(s => "ship_" + (int)s.Key, s => s.Value.ToString()));

                req  = Client.RequestBuilder.PostPage(PageType.JumpGateExecute, postParams.ToArray());
                resp = Client.IssueRequest(req);
            }

            return(null);
        }
        protected override CommandQueueElement RunInternal()
        {
            _oneWayTrip = TimeSpan.FromSeconds((ReturnTime - DateTimeOffset.Now).TotalSeconds / 2);

            using (BotDb db = new BotDb())
                using (Client.EnterPlanetExclusive(this))
                {
                    var resp = Client.IssueRequest(Client.RequestBuilder.GetPage(PageType.Fleet, PlanetId));
                    var info = resp.GetParsedSingle <OgamePageInfo>();

                    FleetComposition fleet = FleetComposition.FromDetected(resp.GetParsed <DetectedShip>());
                    if (!fleet.Ships.ContainsKey(ShipType.Recycler))
                    {
                        Logger.Instance.Log(LogLevel.Error, "Planet does not have a recycler, cannot fleetsave");
                        return(null);
                    }
                    fleet.Resources = resp.GetParsedSingle <PlanetResources>().Resources;

                    PlayerResearch research   = db.Players.Where(p => p.PlayerId == info.PlayerId).Select(p => p.Research).First();
                    int            fleetSpeed = fleet.Speed(research);

                    Coordinate      here      = info.PlanetCoord;
                    FleetSaveTarget candidate = CandidateFromSystem(db, here, fleetSpeed) ?? CandidateFromGalaxy(db, here, fleetSpeed);

                    if (candidate != null)
                    {
                        Logger.Instance.Log(LogLevel.Success, $"Best candidate for fleetsave is {candidate.Target} at speed {candidate.Speed}; one way trip {candidate.Duration}");

                        new SendFleetCommand()
                        {
                            PlanetId    = PlanetId,
                            Destination = Coordinate.Create(candidate.Target, CoordinateType.DebrisField),
                            Speed       = candidate.Speed,
                            Mission     = MissionType.Recycle,
                            Fleet       = fleet
                        }.Run();
                    }
                    else
                    {
                        Logger.Instance.Log(LogLevel.Error, $"Could not find a good candidate for fleetsave");
                    }
                }
            return(null);
        }