From 39e5fcebcacc1e1f1d0ecdae7ddd3de9a774df26 Mon Sep 17 00:00:00 2001 From: Truong Nguyen Date: Sat, 31 Dec 2016 13:27:34 +1100 Subject: [PATCH 1/2] Not calling api to refresh pokedex anytime --- PoGo.NecroBot.Logic/Inventory.cs | 5 ++-- .../Tasks/MSniperServiceTask.cs | 24 ++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/PoGo.NecroBot.Logic/Inventory.cs b/PoGo.NecroBot.Logic/Inventory.cs index c10590d41..7fdb57f39 100644 --- a/PoGo.NecroBot.Logic/Inventory.cs +++ b/PoGo.NecroBot.Logic/Inventory.cs @@ -47,6 +47,7 @@ public Inventory(Client client, ILogicSettings logicSettings) { //Console.WriteLine("################# INVENTORY UPDATE ######################"); _cachedInventory = refreshedInventoryData; + _lastRefresh = DateTime.Now; }; } @@ -430,8 +431,8 @@ public async Task UseIncenseConstantly() public async Task> GetPokeDexItems() { - List PokeDex = new List(); - var inventory = await _client.Inventory.GetInventory(); + //List PokeDex = new List(); + var inventory = await GetCachedInventory(); return (from items in inventory.InventoryDelta.InventoryItems where items.InventoryItemData?.PokedexEntry != null diff --git a/PoGo.NecroBot.Logic/Tasks/MSniperServiceTask.cs b/PoGo.NecroBot.Logic/Tasks/MSniperServiceTask.cs index 1d42d1f49..7c7fd3074 100644 --- a/PoGo.NecroBot.Logic/Tasks/MSniperServiceTask.cs +++ b/PoGo.NecroBot.Logic/Tasks/MSniperServiceTask.cs @@ -28,7 +28,7 @@ namespace PoGo.NecroBot.Logic.Tasks public static class MSniperServiceTask { #region Variables - + private const int SNIPE_SAFE_TIME = 120; public static List LocationQueue = new List(); public static List VisitedEncounterIds = new List(); private static List autoSnipePokemons = new List(); @@ -305,6 +305,7 @@ public static async Task CatchFromService(ISession session, CancellationTo double lat = session.Client.CurrentLatitude; double lon = session.Client.CurrentLongitude; + bool captchaShowed = false; EncounterResponse encounter; try { @@ -315,7 +316,6 @@ await LocationUtils.UpdatePlayerLocationWithAltitude(session, encounter = await session.Client.Encounter.EncounterPokemon(encounterId.EncounterId, encounterId.SpawnPointId); - await Task.Delay(1000, cancellationToken); } catch (CaptchaException ex) { @@ -323,10 +323,12 @@ await LocationUtils.UpdatePlayerLocationWithAltitude(session, } catch(Exception ex) { + captchaShowed = true; return false; } finally { + if(!captchaShowed) await LocationUtils.UpdatePlayerLocationWithAltitude(session, new GeoCoordinate(lat, lon, session.Client.CurrentAltitude), 0); // Speed set to 0 for random speed. } @@ -346,7 +348,8 @@ await LocationUtils.UpdatePlayerLocationWithAltitude(session, else { Logger.Write($"Pokemon despawned or wrong link format!", LogLevel.Service, ConsoleColor.Gray); - return true;// No success to work with + return false; + //return await CatchWithSnipe(session, encounterId, cancellationToken);// No success to work with } var pokemon = new MapPokemon @@ -395,11 +398,10 @@ public static async Task AddSnipeItem(ISession session, MSniperInfo2 item, bool { item.AddedTime = DateTime.Now; //just keep pokemon in last 2 min - autoSnipePokemons.RemoveAll(x => x.AddedTime.AddMinutes(2) < DateTime.Now);// || (x.ExpiredTime > 0 && x.ExpiredTime < DateTime.Now.ToUnixTime())); + autoSnipePokemons.RemoveAll(x => x.AddedTime.AddSeconds(SNIPE_SAFE_TIME) < DateTime.Now);// || (x.ExpiredTime > 0 && x.ExpiredTime < DateTime.Now.ToUnixTime())); pokedexSnipePokemons.RemoveAll(x => x.AddedTime.AddMinutes(2) < DateTime.Now); if (OutOffBallBlock > DateTime.Now || - autoSnipePokemons.Exists(x => x.EncounterId == item.EncounterId && item.EncounterId > 0) || (item.EncounterId > 0 && session.Cache[item.EncounterId.ToString()] != null) || (session.LogicSettings.SnipeIgnoreUnknownIv && item.Iv == 0 && !byPassValidation) ) return; @@ -491,7 +493,7 @@ public static async Task Execute(ISession session, CancellationToken cancellatio { if ((!File.Exists(pth) && autoSnipePokemons.Count == 0) || OutOffBallBlock > DateTime.Now) { - autoSnipePokemons.Clear(); + //autoSnipePokemons.Clear(); return; } @@ -530,8 +532,12 @@ public static async Task Execute(ISession session, CancellationToken cancellatio } else { - autoSnipePokemons.RemoveAll(x => x.AddedTime.AddMinutes(2) < DateTime.Now);// || ( x.ExpiredTime >0 && x.ExpiredTime < DateTime.Now.ToUnixTime())); - autoSnipePokemons.OrderByDescending(x => x.PokemonId).ThenByDescending(x => x.AddedTime); + autoSnipePokemons.RemoveAll(x => x.AddedTime.AddSeconds(SNIPE_SAFE_TIME) < DateTime.Now);// || ( x.ExpiredTime >0 && x.ExpiredTime < DateTime.Now.ToUnixTime())); + autoSnipePokemons.OrderByDescending(x=> PokemonGradeHelper.GetPokemonGrade((PokemonId) x.PokemonId)) + .ThenByDescending(x=>x.Iv) + .ThenByDescending(x => x.PokemonId) + .ThenByDescending(x => x.AddedTime); + var batch = autoSnipePokemons.Take(5); //mSniperLocation2.AddRange(autoSnipePokemons.Take(10)); //autoSnipePokemons.Clear(); @@ -560,6 +566,8 @@ public static async Task Execute(ISession session, CancellationToken cancellatio break; } + if (location.AddedTime.AddSeconds(SNIPE_SAFE_TIME) < DateTime.Now) continue; + //If bot already catch the same pokemon, and very close this location. string uniqueCacheKey = $"{session.Settings.PtcUsername}{session.Settings.GoogleUsername}{Math.Round(location.Latitude, 6)}{location.PokemonId}{Math.Round(location.Longitude, 6)}"; if (session.Cache.Get(uniqueCacheKey) != null) continue; From 3b1cd6e2f87abc9bf8faf925bb08a6f4f88437e0 Mon Sep 17 00:00:00 2001 From: Truong Nguyen Date: Sat, 31 Dec 2016 13:37:47 +1100 Subject: [PATCH 2/2] Not calling api to refresh pokedex anytime --- PoGo.NecroBot.Logic/Tasks/MSniperServiceTask.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PoGo.NecroBot.Logic/Tasks/MSniperServiceTask.cs b/PoGo.NecroBot.Logic/Tasks/MSniperServiceTask.cs index 7c7fd3074..9e9ddfc2a 100644 --- a/PoGo.NecroBot.Logic/Tasks/MSniperServiceTask.cs +++ b/PoGo.NecroBot.Logic/Tasks/MSniperServiceTask.cs @@ -28,7 +28,7 @@ namespace PoGo.NecroBot.Logic.Tasks public static class MSniperServiceTask { #region Variables - private const int SNIPE_SAFE_TIME = 120; + private const int SNIPE_SAFE_TIME = 180; public static List LocationQueue = new List(); public static List VisitedEncounterIds = new List(); private static List autoSnipePokemons = new List(); @@ -538,7 +538,7 @@ public static async Task Execute(ISession session, CancellationToken cancellatio .ThenByDescending(x => x.PokemonId) .ThenByDescending(x => x.AddedTime); - var batch = autoSnipePokemons.Take(5); + var batch = autoSnipePokemons.Take(10); //mSniperLocation2.AddRange(autoSnipePokemons.Take(10)); //autoSnipePokemons.Clear(); if (batch!= null && batch.Count()>0)