Skip to content
This repository has been archived by the owner on Jul 30, 2020. It is now read-only.

Commit

Permalink
Merge pull request #454 from Necrobot-Private/feature/snipe_enhanceme…
Browse files Browse the repository at this point in the history
…nt_misc

Critical fix getpokedex entry from cache instead of all api
  • Loading branch information
samuraitruong authored Dec 31, 2016
2 parents 3c3b79e + 3b1cd6e commit d00ebe2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
5 changes: 3 additions & 2 deletions PoGo.NecroBot.Logic/Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public Inventory(Client client, ILogicSettings logicSettings)
{
//Console.WriteLine("################# INVENTORY UPDATE ######################");
_cachedInventory = refreshedInventoryData;
_lastRefresh = DateTime.Now;
};
}

Expand Down Expand Up @@ -430,8 +431,8 @@ public async Task<UseIncenseResponse> UseIncenseConstantly()

public async Task<List<InventoryItem>> GetPokeDexItems()
{
List<InventoryItem> PokeDex = new List<InventoryItem>();
var inventory = await _client.Inventory.GetInventory();
//List<InventoryItem> PokeDex = new List<InventoryItem>();
var inventory = await GetCachedInventory();

return (from items in inventory.InventoryDelta.InventoryItems
where items.InventoryItemData?.PokedexEntry != null
Expand Down
26 changes: 17 additions & 9 deletions PoGo.NecroBot.Logic/Tasks/MSniperServiceTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace PoGo.NecroBot.Logic.Tasks
public static class MSniperServiceTask
{
#region Variables

private const int SNIPE_SAFE_TIME = 180;
public static List<EncounterInfo> LocationQueue = new List<EncounterInfo>();
public static List<string> VisitedEncounterIds = new List<string>();
private static List<MSniperInfo2> autoSnipePokemons = new List<MSniperInfo2>();
Expand Down Expand Up @@ -305,6 +305,7 @@ public static async Task<bool> CatchFromService(ISession session, CancellationTo
double lat = session.Client.CurrentLatitude;
double lon = session.Client.CurrentLongitude;

bool captchaShowed = false;
EncounterResponse encounter;
try
{
Expand All @@ -315,18 +316,19 @@ await LocationUtils.UpdatePlayerLocationWithAltitude(session,

encounter = await session.Client.Encounter.EncounterPokemon(encounterId.EncounterId, encounterId.SpawnPointId);

await Task.Delay(1000, cancellationToken);
}
catch (CaptchaException ex)
{
throw ex;
}
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.
}
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -530,9 +532,13 @@ 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);
var batch = autoSnipePokemons.Take(5);
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(10);
//mSniperLocation2.AddRange(autoSnipePokemons.Take(10));
//autoSnipePokemons.Clear();
if (batch!= null && batch.Count()>0)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d00ebe2

Please sign in to comment.