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 forts = session.Forts.Where(p => p.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime()).ToList(); 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.GymAllowed /*|| session.Inventory.GetPlayerStats().Result.FirstOrDefault().Level <= 5*/) { // Filter out the gyms forts = forts.Where(x => x.Type != FortType.Gym).ToList(); } else if (session.LogicSettings.GymPrioritizeOverPokestop) { // 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.GymMaxDistance); // 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()); }
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) { //non pokestop . should we init or return nul? } ; var pokeStopes = session.Forts.Where(p => p.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime()).ToList(); pokeStopes = pokeStopes.OrderBy( p => session.Navigation.WalkStrategy.CalculateDistance( session.Client.CurrentLatitude, session.Client.CurrentLongitude, p.Latitude, p.Longitude, session) ).ToList(); if (session.LogicSettings.UseGpxPathing) { pokeStopes = pokeStopes.Where(p => LocationUtils.CalculateDistanceInMeters(p.Latitude, p.Longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude) < 40).ToList(); } if (pokeStopes.Count == 1) { return(pokeStopes.FirstOrDefault()); } if (session.LogicSettings.GymAllowed) { var gyms = pokeStopes.Where(x => x.Type == FortType.Gym && LocationUtils.CalculateDistanceInMeters(x.Latitude, x.Longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude) < session.LogicSettings.GymMaxDistance && x.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime()); if (gyms.Count() > 0) { return(gyms.FirstOrDefault()); } } return(pokeStopes.Skip((int)DateTime.Now.Ticks % 2).FirstOrDefault()); }
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? } ; //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(x => x.Id != string.Empty).ToList(); 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) { // Filter out the gyms forts = forts.Where(p => p.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime()) .Where(x => x.Type == FortType.Gym).ToList(); } 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 = new List <FortData>(); foreach (var gym in gyms) { if (gym.OwnedByTeam == session.Profile.PlayerData.Team) { var task = await session.Client.Fort.GymGetInfo(gym.Id, gym.Latitude, gym.Longitude).ConfigureAwait(false); if (task.Result == GymGetInfoResponse.Types.Result.Success) { if (task.GymStatusAndDefenders.GymDefender.Count() < UseGymBattleTask.MaxPlayers) { freeSlots.Add(gym); } } } } if (freeSlots.Count() > 0) { return(freeSlots.FirstOrDefault()); } } // 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 = session.Inventory.GetDeployedPokemons(); //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); } 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 = session.Inventory.GetItems().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, ref deployedPokemons) || UseGymBattleTask.CanTrainGym(session, f, null, ref deployedPokemons)) .ToList(); if ((session.LogicSettings.GymConfig.EnableAttackGym && forts.Where(w => w.Type == FortType.Gym && UseGymBattleTask.CanAttackGym(session, w, ref deployedPokemons)).Count() == 0) || (session.LogicSettings.GymConfig.EnableGymTraining && forts.Where(w => w.Type == FortType.Gym && UseGymBattleTask.CanTrainGym(session, w, null, ref 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()); }