示例#1
0
        public async Task CatchAllNearbyPokemon(Client client)
        {
            var mapObjects = await client.Map.GetMapObjects();

            var pokemonList = mapObjects.Item1.MapCells.SelectMany(i => i.CatchablePokemons).ToList();

            _logger.Write($"Found {pokemonList.Count()} nearby pokemon", LogLevel.INFO);

            foreach (var pokemon in pokemonList)
            {
                var distance = Navigation.CalculateDistanceInMeters(client.CurrentLatitude, client.CurrentLongitude,
                                                                    pokemon.Latitude, pokemon.Longitude);

                if (distance <= _settings.Settings.PlayerMaxTravelInMeters)
                {
                    if (_settings.Settings.UpdateLocation)
                    {
                        await
                        _walkingHandler.Walking(client, pokemon.Latitude, pokemon.Longitude,
                                                _settings.Settings.PlayerWalkingSpeed, null);
                    }

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

                    _logger.Write(
                        $"Starting encounter with pokemon: {pokemon.PokemonId}. " +
                        $"Probability: {Math.Round(encounter.CaptureProbability.CaptureProbability_.First(), 2, MidpointRounding.AwayFromZero)}.",
                        LogLevel.INFO);

                    await Task.Delay(2000);
                    await CatchEncounter(encounter, pokemon, client);
                }
            }

            await Task.Delay(_settings.Settings.DelayBetweenActions);
        }
示例#2
0
        public async Task FarmPokestops(Client client)
        {
            var mapObjects = await client.Map.GetMapObjects();

            IEnumerable <FortData> pokeStops =
                mapObjects.Item1.MapCells.SelectMany(i => i.Forts)
                .Where(i =>
                       i.Type.Equals(FortType.Checkpoint) &&
                       i.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime());

            _logger.Write("Sorting pokestops per distance", LogLevel.DEBUG);

            List <PokestopPoco> pokeStopsPoco = PokestopDistanceSorter.SortByDistance(pokeStops, client.CurrentLatitude,
                                                                                      client.CurrentLongitude, _settings.Settings.PlayerMaxTravelInMeters);

            var pokestopsCount = pokeStopsPoco.Count;

            OnPokestopFound?.Invoke(pokestopsCount);
            _logger.Write($"Found {pokestopsCount} pokestops nearby", LogLevel.INFO);

            foreach (var pokeStop in pokeStopsPoco)
            {
                if (_settings.Settings.UpdateLocation)
                {
                    _logger.Write($"Walking to location [LAT: {pokeStop.Latitude} | LON: {pokeStop.Longitude}]",
                                  LogLevel.INFO);

                    await _walkingHandler.Walking(client, pokeStop.Latitude, pokeStop.Longitude,
                                                  _settings.Settings.PlayerWalkingSpeed, () => _catchPokemonHandler.CatchAllNearbyPokemon(client));
                }

                var fortInfo = await client.Fort.GetFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude);

                await Task.Delay(2000);

                _logger.Write($"Spinning pokestop: {fortInfo.Name}", LogLevel.INFO);
                var fortSearch = await client.Fort.SearchFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude);

                if (fortSearch.Result == FortSearchResponse.Types.Result.Success)
                {
                    if (fortSearch.ExperienceAwarded == 0)
                    {
                        _logger.Write("[Softban] No exp on pokestop.", LogLevel.ERROR);
                    }
                    else
                    {
                        _logger.Write($"Reward: {fortSearch.ExperienceAwarded}xp", LogLevel.INFO);
                        OnExperienceAwarded?.Invoke(fortSearch.ExperienceAwarded);
                    }

                    foreach (var r in fortSearch.ItemsAwarded.GroupBy(x => x.ItemId))
                    {
                        _logger.Write($"Reward: {r.Count()}x {r.Key} ", LogLevel.INFO);
                    }
                }
                else if (fortSearch.Result == FortSearchResponse.Types.Result.InCooldownPeriod)
                {
                    _logger.Write($"Pokestop in cooldown: {fortSearch.CooldownCompleteTimestampMs}", LogLevel.WARN);
                }
                else if (fortSearch.Result == FortSearchResponse.Types.Result.InventoryFull)
                {
                    _logger.Write("Inventory full", LogLevel.WARN);
                }
                else if (fortSearch.Result == FortSearchResponse.Types.Result.OutOfRange)
                {
                    _logger.Write("Pokestop to far away", LogLevel.WARN);
                }

                OnPokestopVisited?.Invoke();

                await Task.Delay(1000);
            }
        }