Example #1
0
        public static async Task Execute(ISession session, FortData currentFortData, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            Logger.Write(session.Translation.GetTranslation(TranslationString.LookingForLurePokemon), LogLevel.Debug);

            var fortId = currentFortData.Id;

            var pokemonId = currentFortData.LureInfo.ActivePokemonId;

            if (session.LogicSettings.UsePokemonToNotCatchFilter &&
                session.LogicSettings.PokemonsNotToCatch.Contains(pokemonId))
            {
                session.EventDispatcher.Send(new NoticeEvent
                {
                    Message = session.Translation.GetTranslation(TranslationString.PokemonSkipped, pokemonId)
                });
            }
            else
            {
                var encounterId = currentFortData.LureInfo.EncounterId;
                var encounter   = await session.Client.Encounter.EncounterLurePokemon(encounterId, fortId);

                if (encounter.Result == DiskEncounterResponse.Types.Result.Success)
                {
                    await CatchPokemonTask.Execute(session, encounter, null, currentFortData, encounterId);
                }
                else if (encounter.Result == DiskEncounterResponse.Types.Result.PokemonInventoryFull)
                {
                    if (session.LogicSettings.TransferDuplicatePokemon)
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.InvFullTransferring)
                        });
                        await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                    }
                    else
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.InvFullTransferManually)
                        });
                    }
                }
                else
                {
                    if (encounter.Result.ToString().Contains("NotAvailable"))
                    {
                        return;
                    }
                    session.EventDispatcher.Send(new WarnEvent
                    {
                        Message =
                            session.Translation.GetTranslation(TranslationString.EncounterProblemLurePokemon,
                                                               encounter.Result)
                    });
                }
            }
        }
Example #2
0
        public static async Task <bool> CatchFromService(ISession session, CancellationToken cancellationToken, MSniperInfo2 encounterId)
        {
            cancellationToken.ThrowIfCancellationRequested();

            double lat = session.Client.CurrentLatitude;
            double lon = session.Client.CurrentLongitude;

            EncounterResponse encounter;

            try
            {
                await LocationUtils.UpdatePlayerLocationWithAltitude(session,
                                                                     new GeoCoordinate(encounterId.Latitude, encounterId.Longitude, session.Client.CurrentAltitude), 0); // Speed set to 0 for random speed.

                await Task.Delay(1000, cancellationToken);

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

                await Task.Delay(1000, cancellationToken);
            }
            catch (CaptchaException ex)
            {
                throw ex;
            }
            finally
            {
                await LocationUtils.UpdatePlayerLocationWithAltitude(session,
                                                                     new GeoCoordinate(lat, lon, session.Client.CurrentAltitude), 0); // Speed set to 0 for random speed.
            }

            if (encounter.Status == EncounterResponse.Types.Status.PokemonInventoryFull)
            {
                return(false);
            }
            PokemonData encounteredPokemon;

            // Catch if it's a WildPokemon (MSniping not allowed for Incense pokemons)
            if (encounter?.Status == EncounterResponse.Types.Status.EncounterSuccess)
            {
                encounteredPokemon = encounter.WildPokemon?.PokemonData;
            }
            else
            {
                Logger.Write($"Pokemon despawned or wrong link format!", LogLevel.Service, ConsoleColor.Gray);
                return(true);// No success to work with
            }

            var pokemon = new MapPokemon
            {
                EncounterId  = encounterId.EncounterId,
                Latitude     = encounterId.Latitude,
                Longitude    = encounterId.Longitude,
                PokemonId    = encounteredPokemon.PokemonId,
                SpawnPointId = encounterId.SpawnPointId
            };

            return(await CatchPokemonTask.Execute(session, cancellationToken, encounter, pokemon, currentFortData : null, sessionAllowTransfer : true));
        }
        public static async Task SnipePokemon(ISession session, Location snipeLocation, PokemonId pokemonId)
        {
            Tuple <double, double, double> curCoords = new Tuple <double, double, double>(session.Client.CurrentLatitude, session.Client.CurrentLongitude, session.Client.CurrentAltitude);
            await session.Client.Player.UpdatePlayerLocation(snipeLocation.Latitude, snipeLocation.Longitude, session.Settings.DefaultAltitude);

            Logger.Write($"Trying to snipe a { pokemonId } @ { snipeLocation.Latitude } : { snipeLocation.Longitude }", LogLevel.Snipe);
            var pokemons = await CatchNearbyPokemonsTask.GetNearbyPokemons(session);

            var pokemon = pokemons.Where(i => i.PokemonId == pokemonId);

            if (pokemon == null || pokemon.Count() == 0)
            {
                Logger.Write($"Unable to find { pokemonId } at location... Returning to original spot.", LogLevel.Snipe);
                await session.Client.Player.UpdatePlayerLocation(curCoords.Item1, curCoords.Item2, curCoords.Item3);

                return;
            }

            Logger.Write($"Found { pokemon.Count() } { pokemonId }'s at location. Trying to catch them ALL!", LogLevel.Snipe);
            foreach (var p in pokemon)
            {
                var encounter = session.Client.Encounter.EncounterPokemon(p.EncounterId, p.SpawnPointId).Result;
                if (encounter.Status == EncounterResponse.Types.Status.EncounterSuccess)
                {
                    await session.Client.Player.UpdatePlayerLocation(curCoords.Item1, curCoords.Item2, curCoords.Item3);

                    await CatchPokemonTask.Execute(session, encounter, p);
                }
                else if (encounter.Status == EncounterResponse.Types.Status.EncounterNotInRange)
                {
                    Logger.Write($"{pokemonId } is out of range. Moving closer....", LogLevel.Snipe);
                    await session.Client.Player.UpdatePlayerLocation(p.Latitude, p.Longitude, curCoords.Item3);

                    encounter = session.Client.Encounter.EncounterPokemon(p.EncounterId, p.SpawnPointId).Result;
                    if (encounter.Status == EncounterResponse.Types.Status.EncounterSuccess)
                    {
                        await session.Client.Player.UpdatePlayerLocation(curCoords.Item1, curCoords.Item2, curCoords.Item3);

                        await CatchPokemonTask.Execute(session, encounter, p);
                    }
                    else
                    {
                        await session.Client.Player.UpdatePlayerLocation(curCoords.Item1, curCoords.Item2, curCoords.Item3);

                        Logger.Write($"Failed to catch again ({ encounter.Status }). Moving back to original coords.", LogLevel.Snipe);
                        return;
                    }
                }
                else
                {
                    await session.Client.Player.UpdatePlayerLocation(curCoords.Item1, curCoords.Item2, curCoords.Item3);

                    Logger.Write($"Error occurred when entering encounter: { encounter.Status }.", LogLevel.Snipe);
                    return;
                }
            }
        }
        private static async Task Snipe(ISession session, IEnumerable <PokemonId> pokemonIds, double latitude,
                                        double longitude, CancellationToken cancellationToken)
        {
            var CurrentLatitude  = session.Client.CurrentLatitude;
            var CurrentLongitude = session.Client.CurrentLongitude;

            session.EventDispatcher.Send(new SnipeModeEvent {
                Active = true
            });

            await
            session.Client.Player.UpdatePlayerLocation(latitude,
                                                       longitude, session.Client.CurrentAltitude);

            session.EventDispatcher.Send(new UpdatePositionEvent
            {
                Longitude = longitude,
                Latitude  = latitude
            });

            var mapObjects       = session.Client.Map.GetMapObjects().Result;
            var catchablePokemon =
                mapObjects.MapCells.SelectMany(q => q.CatchablePokemons)
                .Where(q => pokemonIds.Contains(q.PokemonId))
                .OrderByDescending(pokemon => PokemonInfo.CalculateMaxCpMultiplier(pokemon.PokemonId))
                .ToList();

            await session.Client.Player.UpdatePlayerLocation(CurrentLatitude, CurrentLongitude,
                                                             session.Client.CurrentAltitude);

            foreach (var pokemon in catchablePokemon)
            {
                cancellationToken.ThrowIfCancellationRequested();

                EncounterResponse encounter;
                try
                {
                    await
                    session.Client.Player.UpdatePlayerLocation(latitude, longitude, session.Client.CurrentAltitude);

                    encounter =
                        session.Client.Encounter.EncounterPokemon(pokemon.EncounterId, pokemon.SpawnPointId).Result;
                }
                finally
                {
                    await
                    session.Client.Player.UpdatePlayerLocation(CurrentLatitude, CurrentLongitude,
                                                               session.Client.CurrentAltitude);
                }

                if (encounter.Status == EncounterResponse.Types.Status.EncounterSuccess)
                {
                    session.EventDispatcher.Send(new UpdatePositionEvent
                    {
                        Latitude  = CurrentLatitude,
                        Longitude = CurrentLongitude
                    });

                    await CatchPokemonTask.Execute(session, cancellationToken, encounter, pokemon);
                }
                else if (encounter.Status == EncounterResponse.Types.Status.PokemonInventoryFull)
                {
                    if (session.LogicSettings.EvolveAllPokemonAboveIv ||
                        session.LogicSettings.EvolveAllPokemonWithEnoughCandy)
                    {
                        await EvolvePokemonTask.Execute(session, cancellationToken);
                    }

                    if (session.LogicSettings.TransferDuplicatePokemon)
                    {
                        await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                    }
                    else
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.InvFullTransferManually)
                        });
                    }
                }
                else
                {
                    session.EventDispatcher.Send(new WarnEvent
                    {
                        Message =
                            session.Translation.GetTranslation(
                                TranslationString.EncounterProblem, encounter.Status)
                    });
                }

                if (
                    !Equals(catchablePokemon.ElementAtOrDefault(catchablePokemon.Count - 1),
                            pokemon))
                {
                    await Task.Delay(session.LogicSettings.DelayBetweenPokemonCatch, cancellationToken);
                }
            }

            session.EventDispatcher.Send(new SnipeModeEvent {
                Active = false
            });
            await Task.Delay(session.LogicSettings.DelayBetweenPlayerActions, cancellationToken);
        }
Example #5
0
        public static async Task Snipe(ISession session, IEnumerable <PokemonId> pokemonIds, double latitude,
                                       double longitude, CancellationToken cancellationToken)
        {
            if (LocsVisited.Contains(new PokemonLocation(latitude, longitude)))
            {
                return;
            }

            var CurrentLatitude  = session.Client.CurrentLatitude;
            var CurrentLongitude = session.Client.CurrentLongitude;
            var catchedPokemon   = false;

            session.EventDispatcher.Send(new SnipeModeEvent {
                Active = true
            });

            List <MapPokemon> catchablePokemon;

            try
            {
                await session.Client.Player.UpdatePlayerLocation(latitude, longitude, session.Client.CurrentAltitude);

                session.EventDispatcher.Send(new UpdatePositionEvent
                {
                    Longitude = longitude,
                    Latitude  = latitude
                });

                var mapObjects = session.Client.Map.GetMapObjects().Result;
                catchablePokemon =
                    mapObjects.Item1.MapCells.SelectMany(q => q.CatchablePokemons)
                    .Where(q => pokemonIds.Contains(q.PokemonId))
                    .OrderByDescending(pokemon => PokemonInfo.CalculateMaxCpMultiplier(pokemon.PokemonId))
                    .ToList();
            }
            finally
            {
                await session.Client.Player.UpdatePlayerLocation(CurrentLatitude, CurrentLongitude, session.Client.CurrentAltitude);
            }

            if (catchablePokemon.Count == 0)
            {
                // Pokemon not found but we still add to the locations visited, so we don't keep sniping
                // locations with no pokemon.
                if (!LocsVisited.Contains(new PokemonLocation(latitude, longitude)))
                {
                    LocsVisited.Add(new PokemonLocation(latitude, longitude));
                }
            }

            foreach (var pokemon in catchablePokemon)
            {
                EncounterResponse encounter;
                try
                {
                    await session.Client.Player.UpdatePlayerLocation(latitude, longitude, session.Client.CurrentAltitude);

                    encounter = session.Client.Encounter.EncounterPokemon(pokemon.EncounterId, pokemon.SpawnPointId).Result;
                }
                finally
                {
                    await session.Client.Player.UpdatePlayerLocation(CurrentLatitude, CurrentLongitude, session.Client.CurrentAltitude);
                }

                if (encounter.Status == EncounterResponse.Types.Status.EncounterSuccess)
                {
                    if (!LocsVisited.Contains(new PokemonLocation(latitude, longitude)))
                    {
                        LocsVisited.Add(new PokemonLocation(latitude, longitude));
                    }
                    //Also add exact pokemon location to LocsVisited, some times the server one differ a little.
                    if (!LocsVisited.Contains(new PokemonLocation(pokemon.Latitude, pokemon.Longitude)))
                    {
                        LocsVisited.Add(new PokemonLocation(pokemon.Latitude, pokemon.Longitude));
                    }

                    session.EventDispatcher.Send(new UpdatePositionEvent
                    {
                        Latitude  = CurrentLatitude,
                        Longitude = CurrentLongitude
                    });

                    await CatchPokemonTask.Execute(session, cancellationToken, encounter, pokemon);

                    catchedPokemon = true;
                }
                else if (encounter.Status == EncounterResponse.Types.Status.PokemonInventoryFull)
                {
                    if (session.LogicSettings.EvolveAllPokemonAboveIv ||
                        session.LogicSettings.EvolveAllPokemonWithEnoughCandy ||
                        session.LogicSettings.UseLuckyEggsWhileEvolving ||
                        session.LogicSettings.KeepPokemonsThatCanEvolve)
                    {
                        await EvolvePokemonTask.Execute(session, cancellationToken);
                    }

                    if (session.LogicSettings.TransferDuplicatePokemon)
                    {
                        await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                    }
                    else
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.InvFullTransferManually)
                        });
                    }
                }
                else
                {
                    session.EventDispatcher.Send(new WarnEvent
                    {
                        Message =
                            session.Translation.GetTranslation(
                                TranslationString.EncounterProblem, encounter.Status)
                    });
                }

                if (!Equals(catchablePokemon.ElementAtOrDefault(catchablePokemon.Count - 1), pokemon))
                {
                    await Task.Delay(session.LogicSettings.DelayBetweenPokemonCatch, cancellationToken);
                }
            }

            if (!catchedPokemon)
            {
                session.EventDispatcher.Send(new SnipeEvent
                {
                    Message = session.Translation.GetTranslation(TranslationString.NoPokemonToSnipe)
                });
            }

            _lastSnipe = DateTime.Now;

            if (catchedPokemon)
            {
                session.Stats.SnipeCount++;
                session.Stats.LastSnipeTime = _lastSnipe;
            }
            session.EventDispatcher.Send(new SnipeModeEvent {
                Active = false
            });
            await Task.Delay(session.LogicSettings.DelayBetweenPlayerActions, cancellationToken);
        }
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            TinyIoC.TinyIoCContainer.Current.Resolve <MultiAccountManager>().ThrowIfSwitchAccountRequested();
            cancellationToken.ThrowIfCancellationRequested();
            if (!session.LogicSettings.CatchPokemon || session.CatchBlockTime > DateTime.Now)
            {
                return;
            }

            Logger.Write(
                session.Translation.GetTranslation(TranslationString.LookingForIncensePokemon),
                LogLevel.Debug
                );

            var incensePokemon = await session.Client.Map.GetIncensePokemons().ConfigureAwait(false);

            if (incensePokemon.Result == GetIncensePokemonResponse.Types.Result.IncenseEncounterAvailable)
            {
                var pokemon = new MapPokemon
                {
                    EncounterId           = incensePokemon.EncounterId,
                    ExpirationTimestampMs = incensePokemon.DisappearTimestampMs,
                    Latitude     = incensePokemon.Latitude,
                    Longitude    = incensePokemon.Longitude,
                    PokemonId    = incensePokemon.PokemonId,
                    SpawnPointId = incensePokemon.EncounterLocation
                };

                //add delegate function
                OnPokemonEncounterEvent(new List <MapPokemon> {
                    pokemon
                });

                if (session.Cache.Get(CatchPokemonTask.GetEncounterCacheKey(incensePokemon.EncounterId)) != null)
                {
                    return; //pokemon been ignore before
                }
                if ((session.LogicSettings.UsePokemonToCatchLocallyListOnly && !session.LogicSettings.PokemonToCatchLocally.Pokemon.Contains(pokemon.PokemonId)) ||
                    (session.LogicSettings.UsePokemonToNotCatchFilter && session.LogicSettings.PokemonsNotToCatch.Contains(pokemon.PokemonId)))
                {
                    Logger.Write(session.Translation.GetTranslation(TranslationString.PokemonIgnoreFilter,
                                                                    session.Translation.GetPokemonTranslation(pokemon.PokemonId)));
                }
                else
                {
                    var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                           session.Client.CurrentLongitude, pokemon.Latitude, pokemon.Longitude);
                    await Task.Delay(distance > 100? 500 : 100, cancellationToken).ConfigureAwait(false);

                    var encounter =
                        await
                        session.Client.Encounter.EncounterIncensePokemon((ulong)pokemon.EncounterId,
                                                                         pokemon.SpawnPointId).ConfigureAwait(false);

                    if (encounter.Result == IncenseEncounterResponse.Types.Result.IncenseEncounterSuccess &&
                        session.LogicSettings.CatchPokemon)
                    {
                        //await CatchPokemonTask.Execute(session, cancellationToken, encounter, pokemon).ConfigureAwait(false);
                        await CatchPokemonTask.Execute(session, cancellationToken, encounter, pokemon,
                                                       currentFortData : null, sessionAllowTransfer : true).ConfigureAwait(false);
                    }
                    else if (encounter.Result == IncenseEncounterResponse.Types.Result.PokemonInventoryFull)
                    {
                        if (session.LogicSettings.TransferDuplicatePokemon || session.LogicSettings.TransferWeakPokemon)
                        {
                            session.EventDispatcher.Send(new WarnEvent
                            {
                                Message = session.Translation.GetTranslation(TranslationString.InvFullTransferring)
                            });
                            if (session.LogicSettings.TransferDuplicatePokemon)
                            {
                                await TransferDuplicatePokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                            }
                            if (session.LogicSettings.TransferWeakPokemon)
                            {
                                await TransferWeakPokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                            }
                            if (EvolvePokemonTask.IsActivated(session))
                            {
                                await EvolvePokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                            }
                        }
                        else
                        {
                            session.EventDispatcher.Send(new WarnEvent
                            {
                                Message = session.Translation.GetTranslation(TranslationString.InvFullTransferManually)
                            });
                        }
                    }
                    else
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message =
                                session.Translation.GetTranslation(TranslationString.EncounterProblem, encounter.Result)
                        });
                    }
                }
            }
        }
Example #7
0
        public static async Task <bool> Snipe(ISession session, IEnumerable <PokemonId> pokemonIds, double latitude,
                                              double longitude, CancellationToken cancellationToken)
        {
            //if (LocsVisited.Contains(new PokemonLocation(latitude, longitude)))
            //    return;

            var currentLatitude  = session.Client.CurrentLatitude;
            var currentLongitude = session.Client.CurrentLongitude;
            var catchedPokemon   = false;

            session.EventDispatcher.Send(new SnipeModeEvent {
                Active = true
            });

            List <MapPokemon> catchablePokemon;
            int retry = 3;

            bool isCaptchaShow = false;

            try
            {
                do
                {
                    retry--;
                    LocationUtils.UpdatePlayerLocationWithAltitude(session, new GeoCoordinate(latitude, longitude, 10d), 0); // Set speed to 0 for random speed.
                    latitude  += 0.00000001;
                    longitude += 0.00000001;

                    session.EventDispatcher.Send(new UpdatePositionEvent
                    {
                        Longitude = longitude,
                        Latitude  = latitude
                    });
                    var mapObjects = await session.Client.Map.GetMapObjects(true);

                    catchablePokemon =
                        mapObjects.MapCells.SelectMany(q => q.CatchablePokemons)
                        .Where(q => pokemonIds.Contains(q.PokemonId))
                        .OrderByDescending(pokemon => PokemonInfo.CalculateMaxCp(pokemon.PokemonId))
                        .ToList();
                } while (catchablePokemon.Count == 0 && retry > 0);
            }
            catch (HasherException ex) { throw ex; }
            catch (CaptchaException ex)
            {
                throw ex;
            }
            catch (Exception e)
            {
                Logger.Write($"Error: {e.Message}", LogLevel.Error);
                throw e;
            }
            finally
            {
                //if(!isCaptchaShow)
                LocationUtils.UpdatePlayerLocationWithAltitude(session,
                                                               new GeoCoordinate(currentLatitude, currentLongitude, session.Client.CurrentAltitude), 0); // Set speed to 0 for random speed.
            }

            if (catchablePokemon.Count == 0)
            {
                // Pokemon not found but we still add to the locations visited, so we don't keep sniping
                // locations with no pokemon.
                if (!LocsVisited.Contains(new PokemonLocation(latitude, longitude)))
                {
                    LocsVisited.Add(new PokemonLocation(latitude, longitude));
                }

                session.EventDispatcher.Send(new SnipeEvent
                {
                    Message = session.Translation.GetTranslation(TranslationString.NoPokemonToSnipe),
                });

                session.EventDispatcher.Send(new SnipeFailedEvent
                {
                    Latitude  = latitude,
                    Longitude = longitude,
                    PokemonId = pokemonIds.FirstOrDefault()
                });

                return(false);
            }

            isCaptchaShow = false;
            foreach (var pokemon in catchablePokemon)
            {
                EncounterResponse encounter;
                try
                {
                    LocationUtils.UpdatePlayerLocationWithAltitude(session,
                                                                   new GeoCoordinate(latitude, longitude, session.Client.CurrentAltitude), 0); // Set speed to 0 for random speed.

                    encounter =
                        session.Client.Encounter.EncounterPokemon(pokemon.EncounterId, pokemon.SpawnPointId).Result;
                }
                catch (HasherException ex) { throw ex; }
                catch (CaptchaException ex)
                {
                    isCaptchaShow = true;
                    throw ex;
                }
                finally
                {
                    if (!isCaptchaShow)
                    {
                        LocationUtils.UpdatePlayerLocationWithAltitude(session,
                                                                       // Set speed to 0 for random speed.
                                                                       new GeoCoordinate(currentLatitude, currentLongitude, session.Client.CurrentAltitude), 0);
                    }
                }

                switch (encounter.Status)
                {
                case EncounterResponse.Types.Status.EncounterSuccess:
                    if (!LocsVisited.Contains(new PokemonLocation(latitude, longitude)))
                    {
                        LocsVisited.Add(new PokemonLocation(latitude, longitude));
                    }

                    //Also add exact pokemon location to LocsVisited, some times the server one differ a little.
                    if (!LocsVisited.Contains(new PokemonLocation(pokemon.Latitude, pokemon.Longitude)))
                    {
                        LocsVisited.Add(new PokemonLocation(pokemon.Latitude, pokemon.Longitude));
                    }
                    session.EventDispatcher.Send(new UpdatePositionEvent
                    {
                        Latitude  = currentLatitude,
                        Longitude = currentLongitude
                    });
                    catchedPokemon = await CatchPokemonTask.Execute(session, cancellationToken, encounter, pokemon,
                                                                    currentFortData : null, sessionAllowTransfer : true);

                    break;

                case EncounterResponse.Types.Status.PokemonInventoryFull:
                    if (session.LogicSettings.TransferDuplicatePokemon)
                    {
                        await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                    }
                    else
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.InvFullTransferManually)
                        });
                    }
                    return(false);

                default:
                    session.EventDispatcher.Send(new WarnEvent
                    {
                        Message =
                            session.Translation.GetTranslation(
                                TranslationString.EncounterProblem, encounter.Status)
                    });
                    break;
                }

                if (!Equals(catchablePokemon.ElementAtOrDefault(catchablePokemon.Count - 1), pokemon))
                {
                    await Task.Delay(session.LogicSettings.DelayBetweenPokemonCatch, cancellationToken);
                }
            }

            _lastSnipe = DateTime.Now;

            if (catchedPokemon)
            {
                session.Stats.SnipeCount++;
                session.Stats.LastSnipeTime = _lastSnipe;
            }
            session.EventDispatcher.Send(new SnipeModeEvent {
                Active = false
            });
            return(true);
            //await Task.Delay(session.LogicSettings.DelayBetweenPlayerActions, cancellationToken);
        }
        public static async Task OwnSnipe(ISession session, PokemonId targetPokemonId, double latitude,
                                          double longitude, CancellationToken cancellationToken, bool sessionAllowTransfer = true)
        {
            var currentLatitude  = session.Client.CurrentLatitude;
            var currentLongitude = session.Client.CurrentLongitude;

            session.EventDispatcher.Send(new SnipeModeEvent {
                Active = true
            });

            List <MapPokemon> catchablePokemon;

            try
            {
                await LocationUtils.UpdatePlayerLocationWithAltitude(session, new GeoCoordinate(latitude, longitude, session.Client.CurrentAltitude));

                session.EventDispatcher.Send(new UpdatePositionEvent
                {
                    Longitude = longitude,
                    Latitude  = latitude
                });

                var nearbyPokemons = await GetPokemons(session);

                catchablePokemon = nearbyPokemons.Where(p => p.PokemonId == targetPokemonId).ToList();
            }
            finally
            {
                await LocationUtils.UpdatePlayerLocationWithAltitude(session, new GeoCoordinate(currentLatitude, currentLongitude, session.Client.CurrentAltitude));
            }

            if (catchablePokemon.Count > 0)
            {
                foreach (var pokemon in catchablePokemon)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    EncounterResponse encounter;
                    try
                    {
                        await LocationUtils.UpdatePlayerLocationWithAltitude(session, new GeoCoordinate(latitude, longitude, session.Client.CurrentAltitude));

                        encounter = await session.Client.Encounter.EncounterPokemon(pokemon.EncounterId, pokemon.SpawnPointId);
                    }
                    finally
                    {
                        await LocationUtils.UpdatePlayerLocationWithAltitude(session, new GeoCoordinate(currentLatitude, currentLongitude, session.Client.CurrentAltitude));
                    }

                    switch (encounter.Status)
                    {
                    case EncounterResponse.Types.Status.EncounterSuccess:
                        session.EventDispatcher.Send(new UpdatePositionEvent
                        {
                            Latitude  = currentLatitude,
                            Longitude = currentLongitude
                        });

                        await CatchPokemonTask.Execute(session, cancellationToken, encounter, pokemon);

                        session.Stats.SnipeCount++;
                        session.Stats.LastSnipeTime = DateTime.Now;
                        break;

                    case EncounterResponse.Types.Status.PokemonInventoryFull:
                        if (session.LogicSettings.TransferDuplicatePokemon || session.LogicSettings.TransferWeakPokemon)
                        {
                            session.EventDispatcher.Send(new WarnEvent
                            {
                                Message = session.Translation.GetTranslation(TranslationString.InvFullTransferring)
                            });
                            if (session.LogicSettings.TransferDuplicatePokemon)
                            {
                                await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                            }
                            if (session.LogicSettings.TransferWeakPokemon)
                            {
                                await TransferWeakPokemonTask.Execute(session, cancellationToken);
                            }
                        }
                        else
                        {
                            session.EventDispatcher.Send(new WarnEvent
                            {
                                Message = session.Translation.GetTranslation(TranslationString.InvFullTransferManually)
                            });
                        }
                        break;

                    default:
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message =
                                session.Translation.GetTranslation(TranslationString.EncounterProblem, encounter.Status)
                        });
                        break;
                    }

                    if (!Equals(catchablePokemon.ElementAtOrDefault(catchablePokemon.Count() - 1), pokemon))
                    {
                        await Task.Delay(2000, cancellationToken);
                    }
                }
            }
            else
            {
                session.EventDispatcher.Send(new SnipeEvent
                {
                    Message = session.Translation.GetTranslation(TranslationString.NoPokemonToSnipe)
                });
            }
            await LocationUtils.UpdatePlayerLocationWithAltitude(session, new GeoCoordinate(currentLatitude, currentLongitude, session.Client.CurrentAltitude));

            session.EventDispatcher.Send(new SnipeModeEvent {
                Active = false
            });

            await Task.Delay(5000, cancellationToken);
        }
Example #9
0
        public static async Task Execute(ISession session, FortData currentFortData,
                                         CancellationToken cancellationToken)
        {
            TinyIoC.TinyIoCContainer.Current.Resolve <MultiAccountManager>().ThrowIfSwitchAccountRequested();
            cancellationToken.ThrowIfCancellationRequested();
            if (!session.LogicSettings.CatchPokemon ||
                session.CatchBlockTime > DateTime.Now)
            {
                return;
            }

            if (session.KnownLongitudeBeforeSnipe != 0 && session.KnownLatitudeBeforeSnipe != 0 &&
                LocationUtils.CalculateDistanceInMeters(session.KnownLatitudeBeforeSnipe,
                                                        session.KnownLongitudeBeforeSnipe,
                                                        session.Client.CurrentLatitude,
                                                        session.Client.CurrentLongitude) > 1000)
            {
                Logger.Write($"ERROR - Bot stucked at snipe location({session.Client.CurrentLatitude},{session.Client.CurrentLongitude}). Teleport him back home - if you see this message please PM samuraitruong");

                session.Client.Player.SetCoordinates(session.KnownLatitudeBeforeSnipe, session.KnownLongitudeBeforeSnipe, session.Client.CurrentAltitude);
                return;
            }


            Logger.Write(session.Translation.GetTranslation(TranslationString.LookingForLurePokemon), LogLevel.Debug);

            var fortId = currentFortData.Id;

            var pokemonId = currentFortData.LureInfo.ActivePokemonId;

            if ((session.LogicSettings.UsePokemonSniperFilterOnly &&
                 !session.LogicSettings.PokemonToSnipe.Pokemon.Contains(pokemonId)) ||
                (session.LogicSettings.UsePokemonToNotCatchFilter &&
                 session.LogicSettings.PokemonsNotToCatch.Contains(pokemonId)))
            {
                session.EventDispatcher.Send(new NoticeEvent
                {
                    Message = session.Translation.GetTranslation(TranslationString.PokemonSkipped, pokemonId)
                });
            }
            else
            {
                var encounterId = currentFortData.LureInfo.EncounterId;
                if (session.Cache.Get(currentFortData.LureInfo.EncounterId.ToString()) != null)
                {
                    return; //pokemon been ignore before
                }
                var encounter = await session.Client.Encounter.EncounterLurePokemon(encounterId, fortId);

                if (encounter.Result == DiskEncounterResponse.Types.Result.Success &&
                    session.LogicSettings.CatchPokemon)
                {
                    var pokemon = new MapPokemon
                    {
                        EncounterId           = encounterId,
                        ExpirationTimestampMs = currentFortData.LureInfo.LureExpiresTimestampMs,
                        Latitude     = currentFortData.Latitude,
                        Longitude    = currentFortData.Longitude,
                        PokemonId    = currentFortData.LureInfo.ActivePokemonId,
                        SpawnPointId = currentFortData.Id
                    };

                    // Catch the Pokemon
                    await CatchPokemonTask.Execute(session, cancellationToken, encounter, pokemon,
                                                   currentFortData, sessionAllowTransfer : true);
                }
                else if (encounter.Result == DiskEncounterResponse.Types.Result.PokemonInventoryFull)
                {
                    if (session.LogicSettings.TransferDuplicatePokemon || session.LogicSettings.TransferWeakPokemon)
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.InvFullTransferring)
                        });
                        if (session.LogicSettings.TransferDuplicatePokemon)
                        {
                            await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                        }
                        if (session.LogicSettings.TransferWeakPokemon)
                        {
                            await TransferWeakPokemonTask.Execute(session, cancellationToken);
                        }
                    }
                    else
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.InvFullTransferManually)
                        });
                    }
                }
                else
                {
                    if (encounter.Result.ToString().Contains("NotAvailable"))
                    {
                        return;
                    }
                    session.EventDispatcher.Send(new WarnEvent
                    {
                        Message =
                            session.Translation.GetTranslation(TranslationString.EncounterProblemLurePokemon,
                                                               encounter.Result)
                    });
                }
            }
        }
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            Logger.Write(session.Translation.GetTranslation(TranslationString.LookingForIncensePokemon), LogLevel.Debug);

            var incensePokemon = await session.Client.Map.GetIncensePokemons();

            if (incensePokemon.Result == GetIncensePokemonResponse.Types.Result.IncenseEncounterAvailable)
            {
                var pokemon = new MapPokemon
                {
                    EncounterId           = incensePokemon.EncounterId,
                    ExpirationTimestampMs = incensePokemon.DisappearTimestampMs,
                    Latitude     = incensePokemon.Latitude,
                    Longitude    = incensePokemon.Longitude,
                    PokemonId    = incensePokemon.PokemonId,
                    SpawnPointId = incensePokemon.EncounterLocation
                };

                if (session.LogicSettings.UsePokemonToNotCatchFilter &&
                    session.LogicSettings.PokemonsNotToCatch.Contains(pokemon.PokemonId))
                {
                    Logger.Write(session.Translation.GetTranslation(TranslationString.PokemonIgnoreFilter,
                                                                    pokemon.PokemonId));
                }
                else
                {
                    var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                           session.Client.CurrentLongitude, pokemon.Latitude, pokemon.Longitude);
                    await Task.Delay(distance > 100? 3000 : 500, cancellationToken);

                    var encounter =
                        await
                        session.Client.Encounter.EncounterIncensePokemon((long)pokemon.EncounterId,
                                                                         pokemon.SpawnPointId);

                    if (encounter.Result == IncenseEncounterResponse.Types.Result.IncenseEncounterSuccess)
                    {
                        await CatchPokemonTask.Execute(session, cancellationToken, encounter, pokemon);
                    }
                    else if (encounter.Result == IncenseEncounterResponse.Types.Result.PokemonInventoryFull)
                    {
                        if (session.LogicSettings.TransferDuplicatePokemon)
                        {
                            session.EventDispatcher.Send(new WarnEvent
                            {
                                Message = session.Translation.GetTranslation(TranslationString.InvFullTransferring)
                            });
                            await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                        }
                        else
                        {
                            session.EventDispatcher.Send(new WarnEvent
                            {
                                Message = session.Translation.GetTranslation(TranslationString.InvFullTransferManually)
                            });
                        }
                    }
                    else
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message =
                                session.Translation.GetTranslation(TranslationString.EncounterProblem, encounter.Result)
                        });
                    }
                }
            }
        }
Example #11
0
        public static async Task Execute(ISession session)
        {
            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;

                foreach (var location in session.LogicSettings.PokemonToSnipe.Locations)
                {
                    session.EventDispatcher.Send(new SnipeScanEvent()
                    {
                        Bounds = location
                    });

                    var scanResult = SnipeScanForPokemon(location);

                    var pokemonIds =
                        session.LogicSettings.PokemonToSnipe.Pokemon.Select(
                            q => Enum.Parse(typeof(PokemonId), q) as PokemonId? ?? PokemonId.Missingno).Select(q => (int)q);


                    var locationsToSnipe = scanResult.pokemon == null ? new List <PokemonLocation>() : scanResult.pokemon.Where(q =>
                                                                                                                                pokemonIds.Contains(q.pokemonId) &&
                                                                                                                                !locsVisited.Contains(q) &&
                                                                                                                                q.expiration_time < currentTimestamp &&
                                                                                                                                q.is_alive).ToList();

                    if (locationsToSnipe.Any())
                    {
                        foreach (var pokemonLocation in locationsToSnipe)
                        {
                            locsVisited.Add(pokemonLocation);

                            var currentLatitude  = session.Client.CurrentLatitude;
                            var currentLongitude = session.Client.CurrentLongitude;

                            await
                            session.Client.Player.UpdatePlayerLocation(pokemonLocation.latitude,
                                                                       pokemonLocation.longitude, session.Client.CurrentAltitude);

                            session.EventDispatcher.Send(new UpdatePositionEvent()
                            {
                                Longitude = pokemonLocation.longitude,
                                Latitude  = pokemonLocation.latitude
                            });

                            var mapObjects       = session.Client.Map.GetMapObjects().Result;
                            var catchablePokemon =
                                mapObjects.MapCells.SelectMany(q => q.CatchablePokemons)
                                .Where(q => pokemonIds.Contains((int)q.PokemonId))
                                .ToList();

                            await session.Client.Player.UpdatePlayerLocation(currentLatitude, currentLongitude,
                                                                             session.Client.CurrentAltitude);

                            foreach (var pokemon in catchablePokemon)
                            {
                                await session.Client.Player.UpdatePlayerLocation(pokemonLocation.latitude, pokemonLocation.longitude, session.Client.CurrentAltitude);

                                var encounter = session.Client.Encounter.EncounterPokemon(pokemon.EncounterId, pokemon.SpawnPointId).Result;

                                await session.Client.Player.UpdatePlayerLocation(currentLatitude, currentLongitude, session.Client.CurrentAltitude);

                                if (encounter.Status == EncounterResponse.Types.Status.EncounterSuccess)
                                {
                                    session.EventDispatcher.Send(new UpdatePositionEvent()
                                    {
                                        Latitude  = currentLatitude,
                                        Longitude = currentLongitude
                                    });

                                    await CatchPokemonTask.Execute(session, encounter, pokemon);
                                }
                                else if (encounter.Status == EncounterResponse.Types.Status.PokemonInventoryFull)
                                {
                                    session.EventDispatcher.Send(new WarnEvent
                                    {
                                        Message =
                                            session.Translation.GetTranslation(
                                                Common.TranslationString.InvFullTransferManually)
                                    });
                                }
                                else
                                {
                                    session.EventDispatcher.Send(new WarnEvent
                                    {
                                        Message =
                                            session.Translation.GetTranslation(
                                                Common.TranslationString.EncounterProblem, encounter.Status)
                                    });
                                }

                                if (
                                    !Equals(catchablePokemon.ElementAtOrDefault(catchablePokemon.Count() - 1),
                                            pokemon))
                                {
                                    await Task.Delay(session.LogicSettings.DelayBetweenPokemonCatch);
                                }
                            }

                            await Task.Delay(session.LogicSettings.DelayBetweenPlayerActions);
                        }
                    }
                    else
                    {
                        session.EventDispatcher.Send(new NoticeEvent()
                        {
                            Message = session.Translation.GetTranslation(Common.TranslationString.NoPokemonToSnipe)
                        });
                    }
                }
            }
        }
        private static async Task snipe(ISession session, IEnumerable <PokemonId> pokemonIds, double latitude, double longitude, CancellationToken cancellationToken)
        {
            var currentLatitude  = session.Client.CurrentLatitude;
            var currentLongitude = session.Client.CurrentLongitude;

            await
            session.Client.Player.UpdatePlayerLocation(latitude,
                                                       longitude, session.Client.CurrentAltitude);

            session.EventDispatcher.Send(new UpdatePositionEvent()
            {
                Longitude = longitude,
                Latitude  = latitude
            });

            var mapObjects       = session.Client.Map.GetMapObjects().Result;
            var catchablePokemon =
                mapObjects.MapCells.SelectMany(q => q.CatchablePokemons)
                .Where(q => pokemonIds.Contains(q.PokemonId))
                .ToList();

            await session.Client.Player.UpdatePlayerLocation(currentLatitude, currentLongitude,
                                                             session.Client.CurrentAltitude);

            foreach (var pokemon in catchablePokemon)
            {
                cancellationToken.ThrowIfCancellationRequested();

                await session.Client.Player.UpdatePlayerLocation(latitude, longitude, session.Client.CurrentAltitude);

                var encounter = session.Client.Encounter.EncounterPokemon(pokemon.EncounterId, pokemon.SpawnPointId).Result;

                await session.Client.Player.UpdatePlayerLocation(currentLatitude, currentLongitude, session.Client.CurrentAltitude);

                if (encounter.Status == EncounterResponse.Types.Status.EncounterSuccess)
                {
                    session.EventDispatcher.Send(new UpdatePositionEvent()
                    {
                        Latitude  = currentLatitude,
                        Longitude = currentLongitude
                    });

                    await CatchPokemonTask.Execute(session, encounter, pokemon);
                }
                else if (encounter.Status == EncounterResponse.Types.Status.PokemonInventoryFull)
                {
                    session.EventDispatcher.Send(new WarnEvent
                    {
                        Message =
                            session.Translation.GetTranslation(
                                Common.TranslationString.InvFullTransferManually)
                    });
                }
                else
                {
                    session.EventDispatcher.Send(new WarnEvent
                    {
                        Message =
                            session.Translation.GetTranslation(
                                Common.TranslationString.EncounterProblem, encounter.Status)
                    });
                }

                if (
                    !Equals(catchablePokemon.ElementAtOrDefault(catchablePokemon.Count() - 1),
                            pokemon))
                {
                    await Task.Delay(session.LogicSettings.DelayBetweenPokemonCatch, cancellationToken);
                }
            }

            await Task.Delay(session.LogicSettings.DelayBetweenPlayerActions, cancellationToken);
        }
Example #13
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            Logger.Write(session.Translation.GetTranslation(TranslationString.LookingForPokemon), LogLevel.Debug);

            var pokemons = await GetNearbyPokemons(session);

            foreach (var pokemon in pokemons)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var pokeBallsCount = await session.Inventory.GetItemAmountByType(ItemId.ItemPokeBall);

                var greatBallsCount = await session.Inventory.GetItemAmountByType(ItemId.ItemGreatBall);

                var ultraBallsCount = await session.Inventory.GetItemAmountByType(ItemId.ItemUltraBall);

                var masterBallsCount = await session.Inventory.GetItemAmountByType(ItemId.ItemMasterBall);


                if ((pokeBallsCount + greatBallsCount + ultraBallsCount) < GlobalSettings.irCritical_Ball_Lowest)
                {
                    GlobalSettings.blCriticalBall = true;
                }
                if ((pokeBallsCount + greatBallsCount + ultraBallsCount) > GlobalSettings.irCritical_Ball_Upper)
                {
                    GlobalSettings.blCriticalBall = false;
                }

                if (pokeBallsCount + greatBallsCount + ultraBallsCount + masterBallsCount == 0)
                {
                    Logger.Write(session.Translation.GetTranslation(TranslationString.ZeroPokeballInv));
                    return;
                }

                if (session.LogicSettings.UsePokemonToNotCatchFilter &&
                    session.LogicSettings.PokemonsNotToCatch.Contains(pokemon.PokemonId))
                {
                    Logger.Write(session.Translation.GetTranslation(TranslationString.PokemonSkipped, pokemon.PokemonId));
                    continue;
                }

                var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                       session.Client.CurrentLongitude, pokemon.Latitude, pokemon.Longitude);
                await Task.Delay(distance > 100? 3000 : 500, cancellationToken);

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

                if (encounter.Status == EncounterResponse.Types.Status.EncounterSuccess)
                {
                    await CatchPokemonTask.Execute(session, cancellationToken, encounter, pokemon);
                }
                else if (encounter.Status == EncounterResponse.Types.Status.PokemonInventoryFull)
                {
                    if (session.LogicSettings.TransferDuplicatePokemon)
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.InvFullTransferring)
                        });
                        await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                    }
                    else
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.InvFullTransferManually)
                        });
                    }
                }
                else
                {
                    session.EventDispatcher.Send(new WarnEvent
                    {
                        Message =
                            session.Translation.GetTranslation(TranslationString.EncounterProblem, encounter.Status)
                    });
                }

                // If pokemon is not last pokemon in list, create delay between catches, else keep moving.
                if (!Equals(pokemons.ElementAtOrDefault(pokemons.Count() - 1), pokemon))
                {
                    await Task.Delay(session.LogicSettings.DelayBetweenPokemonCatch, cancellationToken);
                }
            }
        }
Example #14
0
        public static async Task <bool> SnipeUnverifiedPokemon(ISession session, MSniperInfo2 sniperInfo, CancellationToken cancellationToken)
        {
            var latitude  = sniperInfo.Latitude;
            var longitude = sniperInfo.Longitude;

            var originalLatitude  = session.Client.CurrentLatitude;
            var originalLongitude = session.Client.CurrentLongitude;

            var catchedPokemon = false;

            session.EventDispatcher.Send(new SnipeModeEvent {
                Active = true
            });

            MapPokemon catchablePokemon;
            int        retry = 3;

            bool useWalk = session.LogicSettings.EnableHumanWalkingSnipe;

            try
            {
                var distance = LocationUtils.CalculateDistanceInMeters(new GeoCoordinate(session.Client.CurrentLatitude, session.Client.CurrentLongitude), new GeoCoordinate(latitude, longitude));

                if (useWalk)
                {
                    Logger.Write($"Walking to snipe target. Distance: {distance}", LogLevel.Info);

                    await session.Navigation.Move(
                        new MapLocation(latitude, longitude, 0),
                        async() =>
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        await ActionsWhenTravelToSnipeTarget(session, cancellationToken, new MapLocation(latitude, longitude, 0), session.LogicSettings.HumanWalkingSnipeCatchPokemonWhileWalking, session.LogicSettings.HumanWalkingSnipeSpinWhileWalking).ConfigureAwait(false);
                    },
                        session,
                        cancellationToken,
                        session.LogicSettings.HumanWalkingSnipeAllowSpeedUp?session.LogicSettings.HumanWalkingSnipeMaxSpeedUpSpeed : 200
                        ).ConfigureAwait(false);
                }
                else
                {
                    Logger.Write($"Jumping to snipe target. Distance: {distance}", LogLevel.Info);

                    await LocationUtils.UpdatePlayerLocationWithAltitude(session, new GeoCoordinate(latitude, longitude, 10d), 0).ConfigureAwait(false); // Set speed to 0 for random speed.

                    session.EventDispatcher.Send(new UpdatePositionEvent
                    {
                        Latitude  = latitude,
                        Longitude = longitude
                    });
                }

                try
                {
                    do
                    {
                        retry--;

                        var mapObjects = await session.Client.Map.GetMapObjects(true, false).ConfigureAwait(false);

                        catchablePokemon =
                            mapObjects.MapCells.SelectMany(q => q.CatchablePokemons)
                            .Where(q => sniperInfo.PokemonId == (short)q.PokemonId)
                            .OrderByDescending(pokemon => PokemonInfo.CalculateMaxCp(pokemon.PokemonId))
                            .FirstOrDefault();
                    } while (catchablePokemon == null && retry > 0);
                }
                catch (HasherException ex) { throw ex; }
                catch (CaptchaException ex)
                {
                    throw ex;
                }
                catch (Exception e)
                {
                    Logger.Write($"Error: {e.Message}", LogLevel.Error);
                    throw e;
                }

                if (catchablePokemon == null)
                {
                    session.EventDispatcher.Send(new SnipeEvent
                    {
                        Message = session.Translation.GetTranslation(TranslationString.NoPokemonToSnipe),
                    });

                    session.EventDispatcher.Send(new SnipeFailedEvent
                    {
                        Latitude    = latitude,
                        Longitude   = longitude,
                        PokemonId   = (PokemonId)sniperInfo.PokemonId,
                        EncounterId = sniperInfo.EncounterId
                    });

                    return(false);
                }

                if (catchablePokemon != null)
                {
                    EncounterResponse encounter;
                    try
                    {
                        await LocationUtils.UpdatePlayerLocationWithAltitude(session,
                                                                             new GeoCoordinate(catchablePokemon.Latitude, catchablePokemon.Longitude, session.Client.CurrentAltitude), 0).ConfigureAwait(false); // Set speed to 0 for random speed.

                        encounter =
                            await session.Client.Encounter.EncounterPokemon(catchablePokemon.EncounterId, catchablePokemon.SpawnPointId).ConfigureAwait(false);
                    }
                    catch (HasherException ex) { throw ex; }
                    catch (CaptchaException ex)
                    {
                        throw ex;
                    }

                    switch (encounter.Status)
                    {
                    case EncounterResponse.Types.Status.EncounterSuccess:
                        catchedPokemon = await CatchPokemonTask.Execute(session, cancellationToken, encounter, catchablePokemon,
                                                                        currentFortData : null, sessionAllowTransfer : true).ConfigureAwait(false);

                        break;

                    case EncounterResponse.Types.Status.PokemonInventoryFull:
                        if (session.LogicSettings.TransferDuplicatePokemon)
                        {
                            await TransferDuplicatePokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                        }
                        else
                        {
                            session.EventDispatcher.Send(new WarnEvent
                            {
                                Message = session.Translation.GetTranslation(TranslationString.InvFullTransferManually)
                            });
                        }
                        return(false);

                    default:
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message =
                                session.Translation.GetTranslation(
                                    TranslationString.EncounterProblem, encounter.Status)
                        });
                        break;
                    }

                    await Task.Delay(session.LogicSettings.DelayBetweenPokemonCatch, cancellationToken).ConfigureAwait(false);
                }

                if (catchedPokemon)
                {
                    session.Stats.SnipeCount++;
                }
                session.EventDispatcher.Send(new SnipeModeEvent {
                    Active = false
                });
                return(true);
            }
            finally
            {
                if (useWalk)
                {
                    Logger.Write($"Walking back to original location.", LogLevel.Info);

                    await session.Navigation.Move(
                        new MapLocation(originalLatitude, originalLongitude, 0),
                        async() =>
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        await ActionsWhenTravelToSnipeTarget(session, cancellationToken, new MapLocation(latitude, longitude, 0), session.LogicSettings.HumanWalkingSnipeCatchPokemonWhileWalking, session.LogicSettings.HumanWalkingSnipeSpinWhileWalking).ConfigureAwait(false);
                    },
                        session,
                        cancellationToken,
                        session.LogicSettings.HumanWalkingSnipeAllowSpeedUp?session.LogicSettings.HumanWalkingSnipeMaxSpeedUpSpeed : 200
                        ).ConfigureAwait(false);
                }
                else
                {
                    Logger.Write($"Jumping back to original location.", LogLevel.Info);

                    await LocationUtils.UpdatePlayerLocationWithAltitude(session, new GeoCoordinate(originalLatitude, originalLongitude), 0).ConfigureAwait(false); // Set speed to 0 for random speed.

                    session.EventDispatcher.Send(new UpdatePositionEvent
                    {
                        Latitude  = originalLatitude,
                        Longitude = originalLongitude
                    });

                    await session.Client.Map.GetMapObjects(true).ConfigureAwait(false);
                }
            }
        }
Example #15
0
        public static async Task <bool> SnipeUnverifiedPokemon(ISession session, MSniperInfo2 sniperInfo, CancellationToken cancellationToken)
        {
            var latitude         = sniperInfo.Latitude;
            var longitude        = sniperInfo.Longitude;
            var currentLatitude  = session.Client.CurrentLatitude;
            var currentLongitude = session.Client.CurrentLongitude;

            var catchedPokemon = false;

            session.EventDispatcher.Send(new SnipeModeEvent {
                Active = true
            });

            MapPokemon catchablePokemon;
            int        retry = 3;

            bool isCaptchaShow = false;

            try
            {
                do
                {
                    retry--;
                    await LocationUtils.UpdatePlayerLocationWithAltitude(session, new GeoCoordinate(latitude, longitude, 10d), 0).ConfigureAwait(false); // Set speed to 0 for random speed.

                    latitude  += 0.00000001;
                    longitude += 0.00000001;

                    session.EventDispatcher.Send(new UpdatePositionEvent
                    {
                        Longitude = longitude,
                        Latitude  = latitude
                    });
                    var mapObjects = await session.Client.Map.GetMapObjects(true, false).ConfigureAwait(false);

                    catchablePokemon =
                        mapObjects.MapCells.SelectMany(q => q.CatchablePokemons)
                        .Where(q => sniperInfo.PokemonId == (short)q.PokemonId)
                        .OrderByDescending(pokemon => PokemonInfo.CalculateMaxCp(pokemon.PokemonId))
                        .FirstOrDefault();
                } while (catchablePokemon != null && retry > 0);
            }
            catch (HasherException ex) { throw ex; }
            catch (CaptchaException ex)
            {
                throw ex;
            }
            catch (Exception e)
            {
                Logger.Write($"Error: {e.Message}", LogLevel.Error);
                throw e;
            }
            finally
            {
                await LocationUtils.UpdatePlayerLocationWithAltitude(session,
                                                                     new GeoCoordinate(currentLatitude, currentLongitude, session.Client.CurrentAltitude), 0).ConfigureAwait(false); // Set speed to 0 for random speed.
            }

            if (catchablePokemon == null)
            {
                session.EventDispatcher.Send(new SnipeEvent
                {
                    Message = session.Translation.GetTranslation(TranslationString.NoPokemonToSnipe),
                });

                session.EventDispatcher.Send(new SnipeFailedEvent
                {
                    Latitude    = latitude,
                    Longitude   = longitude,
                    PokemonId   = (PokemonId)sniperInfo.PokemonId,
                    EncounterId = sniperInfo.EncounterId
                });

                return(false);
            }

            isCaptchaShow = false;
            if (catchablePokemon != null)
            {
                EncounterResponse encounter;
                try
                {
                    await LocationUtils.UpdatePlayerLocationWithAltitude(session,
                                                                         new GeoCoordinate(catchablePokemon.Latitude, catchablePokemon.Longitude, session.Client.CurrentAltitude), 0).ConfigureAwait(false); // Set speed to 0 for random speed.

                    encounter =
                        await session.Client.Encounter.EncounterPokemon(catchablePokemon.EncounterId, catchablePokemon.SpawnPointId).ConfigureAwait(false);
                }
                catch (HasherException ex) { throw ex; }
                catch (CaptchaException ex)
                {
                    isCaptchaShow = true;
                    throw ex;
                }
                finally
                {
                    if (!isCaptchaShow)
                    {
                        await LocationUtils.UpdatePlayerLocationWithAltitude(session,
                                                                             // Set speed to 0 for random speed.
                                                                             new GeoCoordinate(currentLatitude, currentLongitude, session.Client.CurrentAltitude), 0).ConfigureAwait(false);
                    }
                }

                switch (encounter.Status)
                {
                case EncounterResponse.Types.Status.EncounterSuccess:
                    session.EventDispatcher.Send(new UpdatePositionEvent
                    {
                        Latitude  = currentLatitude,
                        Longitude = currentLongitude
                    });
                    catchedPokemon = await CatchPokemonTask.Execute(session, cancellationToken, encounter, catchablePokemon,
                                                                    currentFortData : null, sessionAllowTransfer : true).ConfigureAwait(false);

                    break;

                case EncounterResponse.Types.Status.PokemonInventoryFull:
                    if (session.LogicSettings.TransferDuplicatePokemon)
                    {
                        await TransferDuplicatePokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                    }
                    else
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.InvFullTransferManually)
                        });
                    }
                    return(false);

                default:
                    session.EventDispatcher.Send(new WarnEvent
                    {
                        Message =
                            session.Translation.GetTranslation(
                                TranslationString.EncounterProblem, encounter.Status)
                    });
                    break;
                }

                await Task.Delay(session.LogicSettings.DelayBetweenPokemonCatch, cancellationToken).ConfigureAwait(false);
            }

            if (catchedPokemon)
            {
                session.Stats.SnipeCount++;
            }
            session.EventDispatcher.Send(new SnipeModeEvent {
                Active = false
            });
            return(true);
            //await Task.Delay(session.LogicSettings.DelayBetweenPlayerActions, cancellationToken).ConfigureAwait(false);
        }
Example #16
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken,
                                         PokemonId priority = PokemonId.Missingno, bool sessionAllowTransfer = true)
        {
            cancellationToken.ThrowIfCancellationRequested();
            if (!session.LogicSettings.CatchPokemon)
            {
                return;
            }

            if (session.Stats.CatchThresholdExceeds(session))
            {
                if (session.LogicSettings.AllowMultipleBot &&
                    session.LogicSettings.MultipleBotConfig.SwitchOnCatchLimit)
                {
                    throw new ActiveSwitchByRuleException()
                          {
                              MatchedRule  = SwitchRules.CatchLimitReached,
                              ReachedValue = session.LogicSettings.CatchPokemonLimit
                          };
                }

                return;
            }


            Logger.Write(session.Translation.GetTranslation(TranslationString.LookingForPokemon), LogLevel.Debug);

            var nearbyPokemons = await GetNearbyPokemons(session);

            var priorityPokemon         = nearbyPokemons.Where(p => p.PokemonId == priority).FirstOrDefault();
            var pokemons                = nearbyPokemons.Where(p => p.PokemonId != priority).ToList();
            EncounterResponse encounter = null;

            //if that is snipe pokemon and inventories if full, execute transfer to get more room for pokemon
            if (priorityPokemon != null)
            {
                pokemons.Insert(0, priorityPokemon);
                encounter = await session.Client.Encounter
                            .EncounterPokemon(priorityPokemon.EncounterId, priorityPokemon.SpawnPointId);

                if (encounter.Status == EncounterResponse.Types.Status.PokemonInventoryFull)
                {
                    await TransferWeakPokemonTask.Execute(session, cancellationToken);

                    await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                }
            }

            foreach (var pokemon in pokemons)
            {
                await MSniperServiceTask.Execute(session, cancellationToken);

                cancellationToken.ThrowIfCancellationRequested();
                string pokemonUniqueKey = $"{pokemon.EncounterId}";

                if (session.Cache.GetCacheItem(pokemonUniqueKey) != null)
                {
                    continue; //this pokemon has been skipped because not meet with catch criteria before.
                }

                var allitems = await session.Inventory.GetItems();

                var pokeBallsCount   = allitems.FirstOrDefault(i => i.ItemId == ItemId.ItemPokeBall)?.Count;
                var greatBallsCount  = allitems.FirstOrDefault(i => i.ItemId == ItemId.ItemGreatBall)?.Count;
                var ultraBallsCount  = allitems.FirstOrDefault(i => i.ItemId == ItemId.ItemUltraBall)?.Count;
                var masterBallsCount = allitems.FirstOrDefault(i => i.ItemId == ItemId.ItemMasterBall)?.Count;
                masterBallsCount =
                    masterBallsCount == null
                        ? 0
                        : masterBallsCount; //return null ATM. need this code to logic check work

                if (pokeBallsCount + greatBallsCount + ultraBallsCount + masterBallsCount <
                    session.LogicSettings.PokeballsToKeepForSnipe && session.CatchBlockTime < DateTime.Now)
                {
                    session.CatchBlockTime = DateTime.Now.AddMinutes(session.LogicSettings.OutOfBallCatchBlockTime);
                    Logger.Write(session.Translation.GetTranslation(TranslationString.CatchPokemonDisable,
                                                                    session.LogicSettings.OutOfBallCatchBlockTime, session.LogicSettings.PokeballsToKeepForSnipe));
                    return;
                }

                if (session.CatchBlockTime > DateTime.Now)
                {
                    return;
                }

                if ((session.LogicSettings.UsePokemonSniperFilterOnly &&
                     !session.LogicSettings.PokemonToSnipe.Pokemon.Contains(pokemon.PokemonId)) ||
                    (session.LogicSettings.UsePokemonToNotCatchFilter &&
                     session.LogicSettings.PokemonsNotToCatch.Contains(pokemon.PokemonId)))
                {
                    Logger.Write(session.Translation.GetTranslation(TranslationString.PokemonSkipped,
                                                                    session.Translation.GetPokemonTranslation(pokemon.PokemonId)));
                    continue;
                }

                var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                       session.Client.CurrentLongitude, pokemon.Latitude, pokemon.Longitude);
                await Task.Delay(distance > 100? 500 : 100, cancellationToken);

                //to avoid duplicated encounter when snipe priority pokemon

                if (encounter == null || encounter.Status != EncounterResponse.Types.Status.EncounterSuccess)
                {
                    encounter =
                        await session.Client.Encounter.EncounterPokemon(pokemon.EncounterId, pokemon.SpawnPointId);
                }

                if (encounter.Status == EncounterResponse.Types.Status.EncounterSuccess &&
                    session.LogicSettings.CatchPokemon)
                {
                    // Catch the Pokemon
                    await CatchPokemonTask.Execute(session, cancellationToken, encounter, pokemon,
                                                   currentFortData : null, sessionAllowTransfer : sessionAllowTransfer);
                }
                else if (encounter.Status == EncounterResponse.Types.Status.PokemonInventoryFull)
                {
                    if (session.LogicSettings.TransferDuplicatePokemon || session.LogicSettings.TransferWeakPokemon)
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.InvFullTransferring)
                        });
                        if (session.LogicSettings.TransferDuplicatePokemon)
                        {
                            await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                        }
                        if (session.LogicSettings.TransferWeakPokemon)
                        {
                            await TransferWeakPokemonTask.Execute(session, cancellationToken);
                        }
                    }
                    else
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.InvFullTransferManually)
                        });
                    }
                }
                else
                {
                    session.EventDispatcher.Send(new WarnEvent
                    {
                        Message =
                            session.Translation.GetTranslation(TranslationString.EncounterProblem, encounter.Status)
                    });
                }
                encounter = null;
                // If pokemon is not last pokemon in list, create delay between catches, else keep moving.
                if (!Equals(pokemons.ElementAtOrDefault(pokemons.Count() - 1), pokemon))
                {
                    await Task.Delay(session.LogicSettings.DelayBetweenPokemonCatch, cancellationToken);
                }
            }
        }
Example #17
0
        public static async Task Execute(ISession session, FortData currentFortData, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            if (!session.LogicSettings.CatchPokemon ||
                session.CatchBlockTime > DateTime.Now)
            {
                return;
            }

            Logger.Write(session.Translation.GetTranslation(TranslationString.LookingForLurePokemon), LogLevel.Debug);

            var fortId = currentFortData.Id;

            var pokemonId = currentFortData.LureInfo.ActivePokemonId;

            if ((session.LogicSettings.UsePokemonSniperFilterOnly && !session.LogicSettings.PokemonToSnipe.Pokemon.Contains(pokemonId)) ||
                (session.LogicSettings.UsePokemonToNotCatchFilter && session.LogicSettings.PokemonsNotToCatch.Contains(pokemonId)))
            {
                session.EventDispatcher.Send(new NoticeEvent
                {
                    Message = session.Translation.GetTranslation(TranslationString.PokemonSkipped, pokemonId)
                });
            }
            else
            {
                var encounterId = currentFortData.LureInfo.EncounterId;
                if (session.Cache.Get(currentFortData.LureInfo.EncounterId.ToString()) != null)
                {
                    return;                                                                             //pokemon been ignore before
                }
                var encounter = await session.Client.Encounter.EncounterLurePokemon(encounterId, fortId);

                if (encounter.Result == DiskEncounterResponse.Types.Result.Success && session.LogicSettings.CatchPokemon)
                {
                    var pokemon = new MapPokemon
                    {
                        EncounterId           = encounterId,
                        ExpirationTimestampMs = currentFortData.LureInfo.LureExpiresTimestampMs,
                        Latitude     = currentFortData.Latitude,
                        Longitude    = currentFortData.Longitude,
                        PokemonId    = currentFortData.LureInfo.ActivePokemonId,
                        SpawnPointId = currentFortData.Id
                    };

                    // Catch the Pokemon
                    await CatchPokemonTask.Execute(session, cancellationToken, encounter, pokemon,
                                                   currentFortData, sessionAllowTransfer : true);
                }
                else if (encounter.Result == DiskEncounterResponse.Types.Result.PokemonInventoryFull)
                {
                    if (session.LogicSettings.TransferDuplicatePokemon || session.LogicSettings.TransferWeakPokemon)
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.InvFullTransferring)
                        });
                        if (session.LogicSettings.TransferDuplicatePokemon)
                        {
                            await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                        }
                        if (session.LogicSettings.TransferWeakPokemon)
                        {
                            await TransferWeakPokemonTask.Execute(session, cancellationToken);
                        }
                    }
                    else
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.InvFullTransferManually)
                        });
                    }
                }
                else
                {
                    if (encounter.Result.ToString().Contains("NotAvailable"))
                    {
                        return;
                    }
                    session.EventDispatcher.Send(new WarnEvent
                    {
                        Message =
                            session.Translation.GetTranslation(TranslationString.EncounterProblemLurePokemon,
                                                               encounter.Result)
                    });
                }
            }
        }
        public static async Task Execute(ISession session, CancellationToken cancellationToken, PokemonId priority = PokemonId.Missingno)
        {
            cancellationToken.ThrowIfCancellationRequested();
            if (!session.LogicSettings.CatchPokemon)
            {
                return;
            }

            Logger.Write(session.Translation.GetTranslation(TranslationString.LookingForPokemon), LogLevel.Debug);

            var nearbyPokemons = await GetNearbyPokemons(session);

            var pokemons = nearbyPokemons.Where(p => p.PokemonId == priority).ToList();

            pokemons.AddRange(nearbyPokemons.Where(p => p.PokemonId != priority).ToList());

            foreach (var pokemon in pokemons)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var allitems = await session.Inventory.GetItems();

                var pokeBallsCount   = allitems.FirstOrDefault(i => i.ItemId == ItemId.ItemPokeBall)?.Count;
                var greatBallsCount  = allitems.FirstOrDefault(i => i.ItemId == ItemId.ItemGreatBall)?.Count;
                var ultraBallsCount  = allitems.FirstOrDefault(i => i.ItemId == ItemId.ItemUltraBall)?.Count;
                var masterBallsCount = allitems.FirstOrDefault(i => i.ItemId == ItemId.ItemMasterBall)?.Count;

                /*
                 * var pokeBallsCount = await session.Inventory.GetItemAmountByType(ItemId.ItemPokeBall);
                 * var greatBallsCount = await session.Inventory.GetItemAmountByType(ItemId.ItemGreatBall);
                 * var ultraBallsCount = await session.Inventory.GetItemAmountByType(ItemId.ItemUltraBall);
                 * var masterBallsCount = await session.Inventory.GetItemAmountByType(ItemId.ItemMasterBall);
                 */

                if (pokeBallsCount + greatBallsCount + ultraBallsCount + masterBallsCount == 0)
                {
                    Logger.Write(session.Translation.GetTranslation(TranslationString.ZeroPokeballInv));
                    return;
                }

                if ((session.LogicSettings.UsePokemonSniperFilterOnly && !session.LogicSettings.PokemonToSnipe.Pokemon.Contains(pokemon.PokemonId)) ||
                    (session.LogicSettings.UsePokemonToNotCatchFilter && session.LogicSettings.PokemonsNotToCatch.Contains(pokemon.PokemonId)))
                {
                    Logger.Write(session.Translation.GetTranslation(TranslationString.PokemonSkipped, session.Translation.GetPokemonTranslation(pokemon.PokemonId)));
                    continue;
                }

                var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                       session.Client.CurrentLongitude, pokemon.Latitude, pokemon.Longitude);
                await Task.Delay(distance > 100? 500 : 100, cancellationToken);

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

                if (encounter.Status == EncounterResponse.Types.Status.EncounterSuccess && session.LogicSettings.CatchPokemon)
                {
                    await CatchPokemonTask.Execute(session, cancellationToken, encounter, pokemon);
                }
                else if (encounter.Status == EncounterResponse.Types.Status.PokemonInventoryFull)
                {
                    if (session.LogicSettings.TransferDuplicatePokemon || session.LogicSettings.TransferWeakPokemon)
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.InvFullTransferring)
                        });
                        if (session.LogicSettings.TransferDuplicatePokemon)
                        {
                            await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                        }
                        if (session.LogicSettings.TransferWeakPokemon)
                        {
                            await TransferWeakPokemonTask.Execute(session, cancellationToken);
                        }
                    }
                    else
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.InvFullTransferManually)
                        });
                    }
                }
                else
                {
                    session.EventDispatcher.Send(new WarnEvent
                    {
                        Message =
                            session.Translation.GetTranslation(TranslationString.EncounterProblem, encounter.Status)
                    });
                }

                // If pokemon is not last pokemon in list, create delay between catches, else keep moving.
                if (!Equals(pokemons.ElementAtOrDefault(pokemons.Count() - 1), pokemon))
                {
                    await Task.Delay(session.LogicSettings.DelayBetweenPokemonCatch, cancellationToken);
                }
            }
        }
Example #19
0
        public static async Task <bool> CatchFromService(ISession session,
                                                         CancellationToken cancellationToken, MSniperInfo2 encounterId)
        {
            cancellationToken.ThrowIfCancellationRequested();

            double lat = session.Client.CurrentLatitude;
            double lon = session.Client.CurrentLongitude;

            bool captchaShowed = false;
            EncounterResponse encounter;

            try
            {
                // Speed set to 0 for random speed.
                await LocationUtils.UpdatePlayerLocationWithAltitude(
                    session,
                    new GeoCoordinate(encounterId.Latitude, encounterId.Longitude, session.Client.CurrentAltitude),
                    0
                    );

                await Task.Delay(1000, cancellationToken);

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

#if DEBUG
                if (encounter != null && encounter.Status != EncounterResponse.Types.Status.EncounterSuccess)
                {
                    Debug.WriteLine($"{encounter}");

                    Logger.Write($"{encounter}");
                }
#endif
            }
            catch (CaptchaException ex)
            {
                captchaShowed = true;
                throw ex;
            }
            catch (Exception)
            {
                return(false);
            }
            finally
            {
                if (!captchaShowed)
                {
                    //TODO - What if udpate location failed
                    // Speed set to 0 for random speed.
                    var response = await LocationUtils.UpdatePlayerLocationWithAltitude(
                        session,
                        new GeoCoordinate(lat, lon, session.Client.CurrentAltitude),
                        0
                        );
                }
                else
                {
                    session.Client.Player.SetCoordinates(lat, lon, session.Client.CurrentAltitude); //only reset d
                }
            }

            if (encounter.Status == EncounterResponse.Types.Status.PokemonInventoryFull)
            {
                Logger.Write("Pokemon bag full, snipe cancel");
                await TransferDuplicatePokemonTask.Execute(session, cancellationToken);

                return(false);
            }
            PokemonData encounteredPokemon;

            // Catch if it's a WildPokemon (MSniping not allowed for Incense pokemons)
            if (encounter?.Status == EncounterResponse.Types.Status.EncounterSuccess)
            {
                encounteredPokemon = encounter.WildPokemon?.PokemonData;
            }
            else
            {
                Logger.Write($"Pokemon despawned or wrong link format!", LogLevel.Service, ConsoleColor.Gray);
                return(false);
                //return await CatchWithSnipe(session, encounterId, cancellationToken);// No success to work with
            }

            var pokemon = new MapPokemon
            {
                EncounterId  = encounterId.EncounterId,
                Latitude     = encounterId.Latitude,
                Longitude    = encounterId.Longitude,
                PokemonId    = encounteredPokemon.PokemonId,
                SpawnPointId = encounterId.SpawnPointId
            };

            return(await CatchPokemonTask.Execute(
                       session, cancellationToken, encounter, pokemon, currentFortData : null, sessionAllowTransfer : true
                       ));
        }
Example #20
0
        public static async Task <bool> CatchFromService(ISession session,
                                                         CancellationToken cancellationToken, MSniperInfo2 encounterId)
        {
            cancellationToken.ThrowIfCancellationRequested();
            double originalLat = session.Client.CurrentLatitude;
            double originalLng = session.Client.CurrentLongitude;

            EncounterResponse encounter;

            try
            {
                // Speed set to 0 for random speed.
                LocationUtils.UpdatePlayerLocationWithAltitude(
                    session,
                    new GeoCoordinate(encounterId.Latitude, encounterId.Longitude, session.Client.CurrentAltitude),
                    0
                    );


                await session.Client.Misc.RandomAPICall();

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

                if (encounter != null && encounter.Status != EncounterResponse.Types.Status.EncounterSuccess)
                {
                    Logger.Debug($"{encounter}");
                }
                //pokemon has expired, send event to remove it.
                if (encounter != null && (encounter.Status == EncounterResponse.Types.Status.EncounterClosed ||
                                          encounter.Status == EncounterResponse.Types.Status.EncounterNotFound))
                {
                    session.EventDispatcher.Send(new SnipePokemonUpdateEvent(encounterId.EncounterId.ToString(), false, null));
                }
            }
            catch (CaptchaException ex)
            {
                throw ex;
            }
            catch (Exception)
            {
                return(false);
            }
            finally
            {
                session.Client.Player.SetCoordinates(originalLat, originalLng, session.Client.CurrentAltitude); //only reset d
            }

            if (encounter.Status == EncounterResponse.Types.Status.PokemonInventoryFull)
            {
                Logger.Write("Pokemon bag full, snipe cancel");
                await TransferDuplicatePokemonTask.Execute(session, cancellationToken);

                return(false);
            }

            if (encounter.Status == EncounterResponse.Types.Status.EncounterClosed)
            {
                Logger.Write("This pokemon has been expired");
                return(true);
            }
            PokemonData encounteredPokemon;

            // Catch if it's a WildPokemon (MSniping not allowed for Incense pokemons)
            if (encounter?.Status == EncounterResponse.Types.Status.EncounterSuccess)
            {
                encounteredPokemon = encounter.WildPokemon?.PokemonData;
            }
            else
            {
                Logger.Write($"Pokemon despawned or wrong link format!", LogLevel.Service, ConsoleColor.Gray);
                return(false);
                //return await CatchWithSnipe(session, encounterId, cancellationToken);// No success to work with
            }

            var pokemon = new MapPokemon
            {
                EncounterId  = encounterId.EncounterId,
                Latitude     = encounterId.Latitude,
                Longitude    = encounterId.Longitude,
                PokemonId    = encounteredPokemon.PokemonId,
                SpawnPointId = encounterId.SpawnPointId
            };

            return(await CatchPokemonTask.Execute(
                       session, cancellationToken, encounter, pokemon, currentFortData : null, sessionAllowTransfer : true
                       ));
        }
Example #21
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken,
                                         PokemonId priority = PokemonId.Missingno, bool sessionAllowTransfer = true)
        {
            var manager = TinyIoCContainer.Current.Resolve <MultiAccountManager>();

            manager.ThrowIfSwitchAccountRequested();
            cancellationToken.ThrowIfCancellationRequested();

            if (!session.LogicSettings.CatchPokemon)
            {
                return;
            }

            var totalBalls = (await session.Inventory.GetItems().ConfigureAwait(false)).Where(x => x.ItemId == ItemId.ItemPokeBall || x.ItemId == ItemId.ItemGreatBall || x.ItemId == ItemId.ItemUltraBall).Sum(x => x.Count);

            if (session.SaveBallForByPassCatchFlee && totalBalls < 130)
            {
                return;
            }

            if (session.Stats.CatchThresholdExceeds(session))
            {
                if (manager.AllowMultipleBot() &&
                    session.LogicSettings.MultipleBotConfig.SwitchOnCatchLimit &&
                    manager.AllowSwitch()
                    )
                {
                    throw new ActiveSwitchByRuleException()
                          {
                              MatchedRule  = SwitchRules.CatchLimitReached,
                              ReachedValue = session.LogicSettings.CatchPokemonLimit
                          };
                }

                return;
            }

            Logger.Write(session.Translation.GetTranslation(TranslationString.LookingForPokemon), LogLevel.Debug);

            var nearbyPokemons = await GetNearbyPokemons(session).ConfigureAwait(false);

            Logger.Write($"There are {nearbyPokemons.Count()} pokemon nearby.", LogLevel.Debug);

            if (nearbyPokemons == null)
            {
                return;
            }

            var priorityPokemon = nearbyPokemons.Where(p => p.PokemonId == priority).FirstOrDefault();
            var pokemons        = nearbyPokemons.Where(p => p.PokemonId != priority).ToList();

            //add pokemons to map
            OnPokemonEncounterEvent(pokemons.ToList());

            EncounterResponse encounter = null;

            //if that is snipe pokemon and inventories if full, execute transfer to get more room for pokemon
            if (priorityPokemon != null)
            {
                pokemons.Insert(0, priorityPokemon);
                await LocationUtils.UpdatePlayerLocationWithAltitude(session,
                                                                     new GeoCoordinate(priorityPokemon.Latitude, priorityPokemon.Longitude, session.Client.CurrentAltitude), 0).ConfigureAwait(false); // Set speed to 0 for random speed.

                encounter = await session.Client.Encounter
                            .EncounterPokemon(priorityPokemon.EncounterId, priorityPokemon.SpawnPointId).ConfigureAwait(false);

                if (encounter.Status == EncounterResponse.Types.Status.PokemonInventoryFull)
                {
                    if (session.LogicSettings.TransferDuplicatePokemon)
                    {
                        await TransferDuplicatePokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                    }

                    if (session.LogicSettings.TransferWeakPokemon)
                    {
                        await TransferWeakPokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                    }

                    if (session.LogicSettings.EvolveAllPokemonAboveIv ||
                        session.LogicSettings.EvolveAllPokemonWithEnoughCandy ||
                        session.LogicSettings.UseLuckyEggsWhileEvolving ||
                        session.LogicSettings.KeepPokemonsThatCanEvolve)
                    {
                        await EvolvePokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                    }
                }
            }

            var allitems = await session.Inventory.GetItems().ConfigureAwait(false);

            var pokeBallsCount   = allitems.FirstOrDefault(i => i.ItemId == ItemId.ItemPokeBall)?.Count;
            var greatBallsCount  = allitems.FirstOrDefault(i => i.ItemId == ItemId.ItemGreatBall)?.Count;
            var ultraBallsCount  = allitems.FirstOrDefault(i => i.ItemId == ItemId.ItemUltraBall)?.Count;
            var masterBallsCount = allitems.FirstOrDefault(i => i.ItemId == ItemId.ItemMasterBall)?.Count;

            masterBallsCount = masterBallsCount ?? 0; //return null ATM. need this code to logic check work
            var PokeBalls = pokeBallsCount + greatBallsCount + ultraBallsCount + masterBallsCount;

            if (0 < pokemons.Count && PokeBalls >= session.LogicSettings.PokeballsToKeepForSnipe) // Don't display if not enough Pokeballs - TheWizrad1328
            {
                Logger.Write($"Catching {pokemons.Count} Pokemon Nearby...", LogLevel.Info);
            }

            foreach (var pokemon in pokemons)
            {
                await MSniperServiceTask.Execute(session, cancellationToken).ConfigureAwait(false);

                /*
                 * if (LocationUtils.CalculateDistanceInMeters(pokemon.Latitude, pokemon.Longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude) > session.Client.GlobalSettings.MapSettings.EncounterRangeMeters)
                 * {
                 *  Logger.Debug($"THIS POKEMON IS TOO FAR, {pokemon.Latitude}, {pokemon.Longitude}");
                 *  continue;
                 * }
                 */

                cancellationToken.ThrowIfCancellationRequested();
                TinyIoC.TinyIoCContainer.Current.Resolve <MultiAccountManager>().ThrowIfSwitchAccountRequested();

                if (session.Cache.GetCacheItem(CatchPokemonTask.GetEncounterCacheKey(pokemon.EncounterId)) != null)
                {
                    continue; //this pokemon has been skipped because not meet with catch criteria before.
                }

                if (PokeBalls < session.LogicSettings.PokeballsToKeepForSnipe && session.CatchBlockTime < DateTime.Now)
                {
                    session.CatchBlockTime = DateTime.Now.AddMinutes(session.LogicSettings.OutOfBallCatchBlockTime);
                    Logger.Write(session.Translation.GetTranslation(TranslationString.CatchPokemonDisable,
                                                                    session.LogicSettings.OutOfBallCatchBlockTime, session.LogicSettings.PokeballsToKeepForSnipe));
                    return;
                }

                if (session.CatchBlockTime > DateTime.Now)
                {
                    return;
                }

                if ((session.LogicSettings.UsePokemonToCatchLocallyListOnly &&
                     !session.LogicSettings.PokemonToCatchLocally.Pokemon.Contains(pokemon.PokemonId)) ||
                    (session.LogicSettings.UsePokemonToNotCatchFilter &&
                     session.LogicSettings.PokemonsNotToCatch.Contains(pokemon.PokemonId)))
                {
                    Logger.Write(session.Translation.GetTranslation(TranslationString.PokemonSkipped,
                                                                    session.Translation.GetPokemonTranslation(pokemon.PokemonId)));
                    continue;
                }

                /*
                 * var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                 *  session.Client.CurrentLongitude, pokemon.Latitude, pokemon.Longitude);
                 * await Task.Delay(distance > 100 ? 500 : 100, cancellationToken).ConfigureAwait(false);
                 */

                //to avoid duplicated encounter when snipe priority pokemon

                if (encounter == null || encounter.Status != EncounterResponse.Types.Status.EncounterSuccess)
                {
                    await LocationUtils.UpdatePlayerLocationWithAltitude(session,
                                                                         new GeoCoordinate(pokemon.Latitude, pokemon.Longitude, session.Client.CurrentAltitude), 0).ConfigureAwait(false); // Set speed to 0 for random speed.

                    encounter =
                        await session.Client.Encounter.EncounterPokemon(pokemon.EncounterId, pokemon.SpawnPointId).ConfigureAwait(false);
                }

                if (encounter.Status == EncounterResponse.Types.Status.EncounterSuccess &&
                    session.LogicSettings.CatchPokemon)
                {
                    // Catch the Pokemon
                    await CatchPokemonTask.Execute(session, cancellationToken, encounter, pokemon,
                                                   currentFortData : null, sessionAllowTransfer : sessionAllowTransfer).ConfigureAwait(false);
                }
                else if (encounter.Status == EncounterResponse.Types.Status.PokemonInventoryFull)
                {
                    if (session.LogicSettings.TransferDuplicatePokemon || session.LogicSettings.TransferWeakPokemon)
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.InvFullTransferring)
                        });
                        if (session.LogicSettings.TransferDuplicatePokemon)
                        {
                            await TransferDuplicatePokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                        }
                        if (session.LogicSettings.TransferWeakPokemon)
                        {
                            await TransferWeakPokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                        }
                        if (session.LogicSettings.EvolveAllPokemonAboveIv ||
                            session.LogicSettings.EvolveAllPokemonWithEnoughCandy ||
                            session.LogicSettings.UseLuckyEggsWhileEvolving ||
                            session.LogicSettings.KeepPokemonsThatCanEvolve)
                        {
                            await EvolvePokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                        }
                    }
                    else
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.InvFullTransferManually)
                        });
                    }
                }
                else
                {
                    session.EventDispatcher.Send(new WarnEvent
                    {
                        Message =
                            session.Translation.GetTranslation(TranslationString.EncounterProblem, encounter.Status)
                    });
                }
                encounter = null;
                // If pokemon is not last pokemon in list, create delay between catches, else keep moving.
                if (!Equals(pokemons.ElementAtOrDefault(pokemons.Count() - 1), pokemon))
                {
                    await Task.Delay(session.LogicSettings.DelayBetweenPokemonCatch, cancellationToken).ConfigureAwait(false);
                }
            }
        }