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); }
public int GetSpeed(PlayerResearch research) { return(GetSpeed(((Dictionary <ResearchType, int>)research)[_speedResearch])); }
public Player() { Research = new PlayerResearch(); }
public int Speed(PlayerResearch research) { return(Ships.Keys.Min(s => ((Ship)s).GetSpeed(research))); }