public static async Task Execute(ISession session, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); TinyIoC.TinyIoCContainer.Current.Resolve <MultiAccountManager>().ThrowIfSwitchAccountRequested(); //request map objects to referesh data. keep all fort in session var mapObjectTupe = await GetPokeStops(session).ConfigureAwait(false); var pokeStop = await GetNextPokeStop(session).ConfigureAwait(false); while (pokeStop != null) { cancellationToken.ThrowIfCancellationRequested(); // Exit this task if both catching and looting has reached its limits await CheckLimit(session).ConfigureAwait(false); var fortInfo = pokeStop.Id.StartsWith(SetMoveToTargetTask.TARGET_ID) ? SetMoveToTargetTask.FakeFortInfo(pokeStop) : await session.Client.Fort.GetFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude).ConfigureAwait(false); await WalkingToPokeStop(session, cancellationToken, pokeStop, fortInfo).ConfigureAwait(false); await DoActionAtPokeStop(session, cancellationToken, pokeStop, fortInfo).ConfigureAwait(false); try // Try to fix Error: System.NullReferenceException { bool gymAttackSucceeded = await UseGymBattleTask.Execute(session, cancellationToken, pokeStop, fortInfo).ConfigureAwait(false); if (gymAttackSucceeded && fortInfo.Type == FortType.Gym && (session.GymState.GetGymDetails(session, pokeStop).GymState.FortData.OwnedByTeam == session.Profile.PlayerData.Team || session.GymState.CapturedGymId.Equals(fortInfo.FortId)) && session.LogicSettings.GymConfig.Enable && session.LogicSettings.GymConfig.EnableGymTraining) { if (string.IsNullOrEmpty(session.GymState.TrainingGymId) || !session.GymState.TrainingGymId.Equals(fortInfo.FortId)) { session.GymState.TrainingGymId = fortInfo.FortId; session.GymState.TrainingRound = 0; } session.GymState.TrainingRound++; if (session.GymState.TrainingRound <= session.LogicSettings.GymConfig.MaxTrainingRoundsOnOneGym) { continue; } } } catch { #if DEBUG Logger.Write("catch in usenearbypokestopstask", LogLevel.Error); #endif return; } if (!await SetMoveToTargetTask.IsReachedDestination(pokeStop, session, cancellationToken).ConfigureAwait(false)) { pokeStop.CooldownCompleteTimestampMs = DateTime.UtcNow.ToUnixTime() + (pokeStop.Type == FortType.Gym ? session.LogicSettings.GymConfig.VisitTimeout : 5) * 60 * 1000; //5 minutes to cooldown session.AddForts(new List <FortData>() { pokeStop }); //replace object in memory. } await MSniperServiceTask.Execute(session, cancellationToken).ConfigureAwait(false); if (session.LogicSettings.EnableHumanWalkingSnipe) { await HumanWalkSnipeTask.Execute(session, cancellationToken, pokeStop, fortInfo).ConfigureAwait(false); } pokeStop = await GetNextPokeStop(session).ConfigureAwait(false); } }
public static async Task <FortData> GetNextPokeStop(ISession session) { var priorityTarget = await SetMoveToTargetTask.GetTarget(session).ConfigureAwait(false); if (priorityTarget != null) { return(priorityTarget); } if (session.Forts == null || session.Forts.Count == 0 || session.Forts.Count(p => p.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime()) == 0) { //TODO : A logic need to be add for handle this case? } ; var deployedPokemons = await session.Inventory.GetDeployedPokemons().ConfigureAwait(false); //NOTE : This code is killing perfomance of BOT if GYM is turn on, need to refactor to avoid this hummer call API var forts = session.Forts .Where(p => p.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime()) .Where(f => f.Type == FortType.Checkpoint || (session.LogicSettings.GymConfig.Enable && ( UseGymBattleTask.CanAttackGym(session, f, deployedPokemons) || UseGymBattleTask.CanTrainGym(session, f, deployedPokemons) || UseGymBattleTask.CanDeployToGym(session, f, deployedPokemons)))) .ToList(); if (session.LogicSettings.GymConfig.Enable && ((session.LogicSettings.GymConfig.EnableAttackGym && forts.Where(w => w.Type == FortType.Gym && UseGymBattleTask.CanAttackGym(session, w, deployedPokemons)).Count() == 0) || (session.LogicSettings.GymConfig.EnableGymTraining && forts.Where(w => w.Type == FortType.Gym && UseGymBattleTask.CanTrainGym(session, w, deployedPokemons)).Count() == 0) )) { //Logger.Write("No usable gym found. Trying to refresh list.", LogLevel.Gym, ConsoleColor.Magenta); await GetPokeStops(session).ConfigureAwait(false); } forts = forts.OrderBy( p => session.Navigation.WalkStrategy.CalculateDistance( session.Client.CurrentLatitude, session.Client.CurrentLongitude, p.Latitude, p.Longitude, session) ).ToList(); if (session.LogicSettings.UseGpxPathing) { forts = forts.Where(p => LocationUtils.CalculateDistanceInMeters(p.Latitude, p.Longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude) < 40).ToList(); } var reviveCount = (await session.Inventory.GetItems().ConfigureAwait(false)).Where(w => w.ItemId == POGOProtos.Inventory.Item.ItemId.ItemRevive || w.ItemId == POGOProtos.Inventory.Item.ItemId.ItemMaxRevive).Select(s => s.Count).Sum(); if (!session.LogicSettings.GymConfig.Enable || session.LogicSettings.GymConfig.MinRevivePotions > reviveCount /*|| session.Inventory.GetPlayerStats().FirstOrDefault().Level <= 5*/ ) { // Filter out the gyms forts = forts.Where(x => x.Type != FortType.Gym).ToList(); } else if (session.LogicSettings.GymConfig.PrioritizeGymOverPokestop) { // Prioritize gyms over pokestops var gyms = forts.Where(x => x.Type == FortType.Gym && LocationUtils.CalculateDistanceInMeters(x.Latitude, x.Longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude) < session.LogicSettings.GymConfig.MaxDistance); //.OrderBy(x => LocationUtils.CalculateDistanceInMeters(x.Latitude, x.Longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude)); if (session.LogicSettings.GymConfig.PrioritizeGymWithFreeSlot) { var freeSlots = gyms.Where(w => w.OwnedByTeam == session.Profile.PlayerData.Team && UseGymBattleTask.CanDeployToGym(session, w, deployedPokemons)); if (freeSlots.Count() > 0) { return(freeSlots.First()); } } // Return the first gym in range. if (gyms.Count() > 0) { return(gyms.FirstOrDefault()); } } return(forts.FirstOrDefault()); }
public static async Task <FortData> GetNextPokeStop(ISession session) { var priorityTarget = await SetMoveToTargetTask.GetTarget(session); if (priorityTarget != null) { return(priorityTarget); } if (session.Forts == null || session.Forts.Count == 0 || session.Forts.Count(p => p.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime()) == 0) { //TODO : A logic need to be add for handle this case? } ; var deployedPokemons = await session.Inventory.GetDeployedPokemons(); var forts = session.Forts .Where(p => p.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime()) .Where(f => f.Type == FortType.Checkpoint || UseGymBattleTask.CanAttackGym(session, f, deployedPokemons) || UseGymBattleTask.CanTrainGym(session, f, null, deployedPokemons)) .ToList(); if ((session.LogicSettings.GymConfig.EnableAttackGym && forts.Where(w => w.Type == FortType.Gym && UseGymBattleTask.CanAttackGym(session, w, deployedPokemons)).Count() == 0) || (session.LogicSettings.GymConfig.EnableGymTraining && forts.Where(w => w.Type == FortType.Gym && UseGymBattleTask.CanTrainGym(session, w, null, deployedPokemons)).Count() == 0) ) { //Logger.Write("No usable gym found. Trying to refresh list.", LogLevel.Gym, ConsoleColor.Magenta); await GetPokeStops(session); } forts = forts.OrderBy( p => session.Navigation.WalkStrategy.CalculateDistance( session.Client.CurrentLatitude, session.Client.CurrentLongitude, p.Latitude, p.Longitude, session) ).ToList(); if (session.LogicSettings.UseGpxPathing) { forts = forts.Where(p => LocationUtils.CalculateDistanceInMeters(p.Latitude, p.Longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude) < 40).ToList(); } if (!session.LogicSettings.GymConfig.Enable /*|| session.Inventory.GetPlayerStats().Result.FirstOrDefault().Level <= 5*/) { // Filter out the gyms forts = forts.Where(x => x.Type != FortType.Gym).ToList(); } else if (session.LogicSettings.GymConfig.PrioritizeGymOverPokestop) { // Prioritize gyms over pokestops var gyms = forts.Where(x => x.Type == FortType.Gym && LocationUtils.CalculateDistanceInMeters(x.Latitude, x.Longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude) < session.LogicSettings.GymConfig.MaxDistance); // Return the first gym in range. if (gyms.Count() > 0) { return(gyms.FirstOrDefault()); } } if (forts.Count == 1) { return(forts.FirstOrDefault()); } return(forts.Skip((int)DateTime.Now.Ticks % 2).FirstOrDefault()); }