Skip to content

Commit

Permalink
Merge pull request NecronomiconCoding#1454 from Ilses/master
Browse files Browse the repository at this point in the history
Fix MinPokeballsToSnipe and MinPokeballsWhileSnipe
  • Loading branch information
NecronomiconCoding authored Jul 30, 2016
2 parents b9f746c + 4df6a80 commit 157cda2
Showing 1 changed file with 57 additions and 51 deletions.
108 changes: 57 additions & 51 deletions PoGo.NecroBot.Logic/Tasks/SnipePokemonTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,75 +213,81 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
if (lastSnipe.AddMilliseconds(session.LogicSettings.MinDelayBetweenSnipes) > DateTime.Now)
return;

if (session.LogicSettings.PokemonToSnipe != null)
if (await CheckPokeballsToSnipe(session.LogicSettings.MinPokeballsToSnipe, session, cancellationToken))
{
DateTime st = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
TimeSpan t = (DateTime.Now.ToUniversalTime() - st);
var currentTimestamp = t.TotalMilliseconds;
if (session.LogicSettings.PokemonToSnipe != null)
{
DateTime st = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
TimeSpan t = (DateTime.Now.ToUniversalTime() - st);
var currentTimestamp = t.TotalMilliseconds;

var pokemonIds = session.LogicSettings.PokemonToSnipe.Pokemon;
var pokemonIds = session.LogicSettings.PokemonToSnipe.Pokemon;

if (session.LogicSettings.UseSnipeLocationServer)
{
var locationsToSnipe = snipeLocations == null ? new List<SniperInfo>() : snipeLocations.Where(q =>
(!session.LogicSettings.UseTransferIVForSnipe || (
(q.iv == 0 && !session.LogicSettings.SnipeIgnoreUnknownIV) ||
(q.iv >= session.Inventory.GetPokemonTransferFilter(q.id).KeepMinIvPercentage)
)) &&
!locsVisited.Contains(new PokemonLocation(q.latitude, q.longitude))
&& !(q.timeStamp != default(DateTime) &&
q.timeStamp > new DateTime(2016) && // make absolutely sure that the server sent a correct datetime
q.timeStamp < DateTime.Now) && (q.id == PokemonId.Missingno || pokemonIds.Contains(q.id))).ToList();

if (locationsToSnipe.Any())
if (session.LogicSettings.UseSnipeLocationServer)
{
lastSnipe = DateTime.Now;
foreach (var location in locationsToSnipe)
var locationsToSnipe = snipeLocations == null ? new List<SniperInfo>() : snipeLocations.Where(q =>
(!session.LogicSettings.UseTransferIVForSnipe || (
(q.iv == 0 && !session.LogicSettings.SnipeIgnoreUnknownIV) ||
(q.iv >= session.Inventory.GetPokemonTransferFilter(q.id).KeepMinIvPercentage)
)) &&
!locsVisited.Contains(new PokemonLocation(q.latitude, q.longitude))
&& !(q.timeStamp != default(DateTime) &&
q.timeStamp > new DateTime(2016) && // make absolutely sure that the server sent a correct datetime
q.timeStamp < DateTime.Now) && (q.id == PokemonId.Missingno || pokemonIds.Contains(q.id))).ToList();

if (locationsToSnipe.Any())
{
session.EventDispatcher.Send(new SnipeScanEvent() { Bounds = new Location(location.latitude, location.longitude), PokemonId = location.id, iv = location.iv });
lastSnipe = DateTime.Now;
foreach (var location in locationsToSnipe)
{
session.EventDispatcher.Send(new SnipeScanEvent() { Bounds = new Location(location.latitude, location.longitude), PokemonId = location.id, iv = location.iv });

await snipe(session, pokemonIds, location.latitude, location.longitude, cancellationToken);
locsVisited.Add(new PokemonLocation(location.latitude, location.longitude));
if (!await CheckPokeballsToSnipe(session.LogicSettings.MinPokeballsWhileSnipe + 1, session, cancellationToken))
return;

await snipe(session, pokemonIds, location.latitude, location.longitude, cancellationToken);
locsVisited.Add(new PokemonLocation(location.latitude, location.longitude));
}
}
}
}
else if (await CheckPokeballsToSnipe(session.LogicSettings.MinPokeballsToSnipe, session, cancellationToken))
{
foreach (var location in session.LogicSettings.PokemonToSnipe.Locations)
else
{
session.EventDispatcher.Send(new SnipeScanEvent() { Bounds = location, PokemonId = PokemonId.Missingno });
foreach (var location in session.LogicSettings.PokemonToSnipe.Locations)
{
session.EventDispatcher.Send(new SnipeScanEvent() { Bounds = location, PokemonId = PokemonId.Missingno });

var scanResult = SnipeScanForPokemon(location);
var scanResult = SnipeScanForPokemon(location);

var locationsToSnipe = new List<PokemonLocation>();
if (scanResult.pokemon != null)
{
var filteredPokemon = scanResult.pokemon.Where(q => pokemonIds.Contains((PokemonId)q.pokemonId));
var notVisitedPokemon = filteredPokemon.Where(q => !locsVisited.Contains(q));
var notExpiredPokemon = notVisitedPokemon.Where(q => q.expiration_time < currentTimestamp);
var locationsToSnipe = new List<PokemonLocation>();
if (scanResult.pokemon != null)
{
var filteredPokemon = scanResult.pokemon.Where(q => pokemonIds.Contains((PokemonId)q.pokemonId));
var notVisitedPokemon = filteredPokemon.Where(q => !locsVisited.Contains(q));
var notExpiredPokemon = notVisitedPokemon.Where(q => q.expiration_time < currentTimestamp);

locationsToSnipe.AddRange(notExpiredPokemon);
}
locationsToSnipe.AddRange(notExpiredPokemon);
}

if (locationsToSnipe.Any())
{
lastSnipe = DateTime.Now;
foreach (var pokemonLocation in locationsToSnipe)
if (locationsToSnipe.Any())
{
if (!await CheckPokeballsToSnipe(session.LogicSettings.MinPokeballsWhileSnipe + 1, session, cancellationToken))
return;
lastSnipe = DateTime.Now;
foreach (var pokemonLocation in locationsToSnipe)
{
if (!await CheckPokeballsToSnipe(session.LogicSettings.MinPokeballsWhileSnipe + 1, session, cancellationToken))
return;

locsVisited.Add(pokemonLocation);
locsVisited.Add(pokemonLocation);

await snipe(session, pokemonIds, pokemonLocation.latitude, pokemonLocation.longitude, cancellationToken);
await snipe(session, pokemonIds, pokemonLocation.latitude, pokemonLocation.longitude, cancellationToken);
}
}
}
else
{
session.EventDispatcher.Send(new NoticeEvent()
else
{
Message = session.Translation.GetTranslation(Common.TranslationString.NoPokemonToSnipe)
});
session.EventDispatcher.Send(new NoticeEvent()
{
Message = session.Translation.GetTranslation(Common.TranslationString.NoPokemonToSnipe)
});
}
}
}
}
Expand Down

0 comments on commit 157cda2

Please sign in to comment.