Example #1
0
        public async Task CatchPokemon(EncounterResponse encounter, MapPokemon pokemon)
        {
            CatchPokemonResponse caughtPokemonResponse;
            var attempts = 0;
            do
            {
                var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault();

                var pokeball = GetPokeball(encounter);
                if (pokeball == ItemId.ItemUnknown)
                    return;
                var isLowProbability = probability.HasValue && probability.Value < 0.35;
                var isHighCp = encounter != null && encounter.WildPokemon?.PokemonData?.Cp > 400;
                var isHighPerfection = PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData) >=
                                       _logicSettings.KeepMinIvPercentage;

                if ((isLowProbability && isHighCp) || isHighPerfection)
                    UseBerry(pokemon.EncounterId, pokemon.SpawnPointId);

                //var distance = LocationUtils.CalculateDistanceInMeters(_navigation.CurrentLatitude,
                //    _navigation.CurrentLongitude, pokemon.Latitude, pokemon.Longitude);

                caughtPokemonResponse =
                    await _apiEncounter.CatchPokemon(pokemon.EncounterId, pokemon.SpawnPointId, pokeball);
                logger.Info($"[{caughtPokemonResponse.Status} - {attempts}] {pokemon.PokemonId} encountered. {PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData)}% perfect. {encounter?.WildPokemon?.PokemonData?.Cp} CP. Probabilty: {probability}");
                attempts++;
            } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed ||
                     caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);
            //if (caughtPokemonResponse.Status != CatchPokemonResponse.Types.CatchStatus.CatchSuccess)
            //    logger.Info($"Dude. I tried. I'm sorry, but {pokemon.PokemonId} left. Reason: {caughtPokemonResponse.Status}");
        }
Example #2
0
        private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon)
        {
            CatchPokemonResponse caughtPokemonResponse;
            do
            {
                var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault();
                if ((probability.HasValue && probability.Value < 0.35 && encounter.WildPokemon?.PokemonData?.Cp > 400) ||
                    CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData) >=
                    _clientSettings.KeepMinIVPercentage)
                {
                    //Throw berry is we can
                    await UseBerry(pokemon.EncounterId, pokemon.SpawnpointId);
                }

                var pokeball = await GetBestBall(encounter?.WildPokemon);
                var distance = Navigation.DistanceBetween2Coordinates(_client.CurrentLat, _client.CurrentLng,
                    pokemon.Latitude, pokemon.Longitude);
                caughtPokemonResponse =
                    await
                        _client.CatchPokemon(pokemon.EncounterId, pokemon.SpawnpointId, pokemon.Latitude,
                            pokemon.Longitude, pokeball);
                Logger.Write(
                    caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess
                        ? $"{pokemon.PokemonId} ({encounter?.WildPokemon?.PokemonData?.Cp} CP) ({Math.Round(CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData)).ToString("0.00")}% perfection) | Chance: {encounter?.CaptureProbability.CaptureProbability_.First()} | {Math.Round(distance)}m distance | with {pokeball} "
                        : $"{pokemon.PokemonId} ({encounter?.WildPokemon?.PokemonData?.Cp} CP) Chance: {Math.Round(Convert.ToDouble(encounter?.CaptureProbability?.CaptureProbability_.First()))} | {Math.Round(distance)}m distance {caughtPokemonResponse.Status} | with {pokeball}",
                    LogLevel.Caught);
                await DisplayPlayerLevelInTitle(true);
                await Task.Delay(2000);
            } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed ||
                     caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);
        }
Example #3
0
        public void CreateStarterPokemons(Geopoint playerLocation)
        {
            var poke1 = new MapPokemon()
            {
                PokemonId = PokemonId.Bulbasaur,
                Latitude  = playerLocation.Position.Latitude + 0.0005,
                Longitude = playerLocation.Position.Longitude + 0.0005
            };
            var poke2 = new MapPokemon()
            {
                PokemonId = PokemonId.Charmander,
                Latitude  = playerLocation.Position.Latitude - 0.0005,
                Longitude = playerLocation.Position.Longitude + 0.0005
            };
            var poke3 = new MapPokemon()
            {
                PokemonId = PokemonId.Squirtle,
                Latitude  = playerLocation.Position.Latitude - 0.0005,
                Longitude = playerLocation.Position.Longitude - 0.0005
            };

            CatchablePokemons.Add(new MapPokemonWrapper(poke1));
            CatchablePokemons.Add(new MapPokemonWrapper(poke2));
            CatchablePokemons.Add(new MapPokemonWrapper(poke3));
            RaisePropertyChanged(nameof(CatchablePokemons));
        }
Example #4
0
 public static string GetDespawnString(MapPokemon pokemon)
 {
     var despawnSeconds = (pokemon.ExpirationTimestampMs - DateTime.UtcNow.ToUnixTime()) / 1000;
     var despawnMinutes = despawnSeconds / 60;
     despawnSeconds = despawnSeconds % 60;
     return $", despawn in {despawnMinutes} minutes { despawnSeconds} seconds";
 }
Example #5
0
 void infoObservable_HandleNewPokemonLocation(MapPokemon mapPokemon)
 {
     Invoke(new MethodInvoker(() =>
     {
         if (!_pokemonMarks.ContainsKey(mapPokemon.SpawnPointId))
         {
             GMarkerGoogle pokemonMarker;
             Bitmap pokebitMap = PokeImgManager.GetPokemonMediumImage(mapPokemon.PokemonId);
             if (pokebitMap != null)
             {
                 var ImageSize = new System.Drawing.Size(pokebitMap.Width, pokebitMap.Height);
                 pokemonMarker = new GMarkerGoogle(new PointLatLng(mapPokemon.Latitude, mapPokemon.Longitude), pokebitMap)
                 {
                     Offset = new System.Drawing.Point(-ImageSize.Width / 2, -ImageSize.Height / 2)
                 };
             }
             else
             {
                 pokemonMarker = new GMarkerGoogle(new PointLatLng(mapPokemon.Latitude, mapPokemon.Longitude), GMarkerGoogleType.green_small);
             }
             var expriationTime = StringUtils.TimeMStoString(mapPokemon.ExpirationTimestampMs, "mm:ss");
             Logger.Debug("nExpires in: " + expriationTime);
             var address = LocationUtils.FindAddress(mapPokemon.Latitude, mapPokemon.Longitude);
             pokemonMarker.ToolTipText  = th.TS("{0}\nExpires in: {1}\n{2}\n{3},{4}", new object[] { mapPokemon.PokemonId, expriationTime, address, mapPokemon.Latitude, mapPokemon.Longitude });
             pokemonMarker.ToolTip.Font = new Font("Arial", 12, GraphicsUnit.Pixel);
             pokemonMarker.ToolTipMode  = MarkerTooltipMode.OnMouseOver;
             _pokemonMarks.Add(mapPokemon.SpawnPointId, pokemonMarker);
             _pokemonOverlay.Markers.Add(pokemonMarker);
         }
     }));
 }
        private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon)
        {
            CatchPokemonResponse caughtPokemonResponse;

            do
            {
                var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault();
                if ((probability.HasValue && probability.Value < 0.35 && encounter.WildPokemon?.PokemonData?.Cp > 400) ||
                    CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData) >=
                    _clientSettings.KeepMinIVPercentage)
                {
                    //Throw berry is we can
                    await UseBerry(pokemon.EncounterId, pokemon.SpawnpointId);
                }

                var pokeball = await GetBestBall(encounter?.WildPokemon);

                var distance = Navigation.DistanceBetween2Coordinates(_client.CurrentLat, _client.CurrentLng,
                                                                      pokemon.Latitude, pokemon.Longitude);
                caughtPokemonResponse =
                    await
                    _client.CatchPokemon(pokemon.EncounterId, pokemon.SpawnpointId, pokemon.Latitude,
                                         pokemon.Longitude, pokeball);

                Logger.Write(
                    caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess
                        ? $"{pokemon.PokemonId} ({encounter?.WildPokemon?.PokemonData?.Cp} CP) ({Math.Round(CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData)).ToString("0.00")}% perfection) | Chance: {encounter?.CaptureProbability.CaptureProbability_.First()} | {Math.Round(distance)}m distance | with {pokeball} "
                        : $"{pokemon.PokemonId} ({encounter?.WildPokemon?.PokemonData?.Cp} CP) Chance: {Math.Round(Convert.ToDouble(encounter?.CaptureProbability?.CaptureProbability_.First()))} | {Math.Round(distance)}m distance {caughtPokemonResponse.Status} | with {pokeball}",
                    LogLevel.Caught);
                await DisplayPlayerLevelInTitle(true);

                await Task.Delay(2000);
            } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed ||
                     caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);
        }
Example #7
0
        private void PushRemovePokemon(ISession session, MapPokemon mapPokemon)
        {
            var botReceiver = BotsCollection.FirstOrDefault(x => x.Session == session);
            var nMapObj     = new NewMapObject("pm_rm", mapPokemon.PokemonId.ToString(), mapPokemon.Latitude, mapPokemon.Longitude, mapPokemon.EncounterId.ToString());

            botReceiver?.MarkersQueue.Enqueue(nMapObj);
        }
Example #8
0
        public async Task<CatchPokemonResponse> CatchPokemon(EncounterResponse encounter, MapPokemon pokemon)
        {
            CatchPokemonResponse caughtPokemonResponse;
            var attempts = 0;
            //var r = new Random((int)DateTime.Now.Ticks);
            //var waitTime = r.Next(100, 3000);
            do
            {
                var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault();

                var pokeball = GetPokeball(encounter);
                if (pokeball == ItemId.ItemUnknown)
                    return new CatchPokemonResponse();
                var isLowProbability = probability.HasValue && probability.Value < 0.35;
                var isHighCp = encounter != null && encounter.WildPokemon?.PokemonData?.Cp > 400;
                var isHighPerfection = PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData) >= _logicSettings.KeepMinIvPercentage;

                if ((isLowProbability && isHighCp) || isHighPerfection)
                    UseBerry(pokemon.EncounterId, pokemon.SpawnPointId);

                //var distance = LocationUtils.CalculateDistanceInMeters(_navigation.CurrentLatitude,
                //    _navigation.CurrentLongitude, pokemon.Latitude, pokemon.Longitude);

                //lock (lockObject)
                //    Thread.Sleep(waitTime);
                caughtPokemonResponse =
                    await _apiEncounter.CatchPokemon(pokemon.EncounterId, pokemon.SpawnPointId, pokeball);
                logger.Info($"[{caughtPokemonResponse.Status} - {attempts}] {pokemon.PokemonId} {Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData), 1)}% perfect. {encounter?.WildPokemon?.PokemonData?.Cp} CP. Probabilty: {Math.Round((double)probability * 100, 1)} with ball: {pokeball}");
                attempts++;
            } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed ||
                     caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);
            return caughtPokemonResponse;
        }
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            Logger.Write(session.Translation.GetTranslation(Common.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 = (PokemonId)incensePokemon.PokemonId,
                    SpawnPointId = incensePokemon.EncounterLocation
                };

                if (session.LogicSettings.UsePokemonToNotCatchFilter &&
                    session.LogicSettings.PokemonsNotToCatch.Contains(pokemon.PokemonId))
                {
                    Logger.Write(session.Translation.GetTranslation(Common.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);

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

                    if (encounter.Result == IncenseEncounterResponse.Types.Result.IncenseEncounterSuccess)
                    {
                        await CatchPokemonTask.Execute(session, encounter, pokemon);
                    }
                    else if (encounter.Result == IncenseEncounterResponse.Types.Result.PokemonInventoryFull)
                    {
                        if (session.LogicSettings.TransferDuplicatePokemon)
                        {
                            session.EventDispatcher.Send(new WarnEvent { Message = session.Translation.GetTranslation(Common.TranslationString.InvFullTransferring) });
                            await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                        }
                        else
                            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.Result) });
                    }
                }
            }
        }
        public static async Task Execute(Context ctx, StateMachine machine)
        {
            Logger.Write("Looking for incense pokemon..", LogLevel.Debug);


            var incensePokemon = await ctx.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 = (PokemonId) incensePokemon.PokemonTypeId,
                    SpawnPointId = incensePokemon.EncounterLocation
                };

                if (ctx.LogicSettings.UsePokemonToNotCatchFilter &&
                    ctx.LogicSettings.PokemonsNotToCatch.Contains(pokemon.PokemonId))
                {
                    Logger.Write("Skipped " + pokemon.PokemonId);
                }
                else
                {
                    var distance = LocationUtils.CalculateDistanceInMeters(ctx.Client.CurrentLatitude,
                        ctx.Client.CurrentLongitude, pokemon.Latitude, pokemon.Longitude);
                    await Task.Delay(distance > 100 ? 3000 : 500);

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

                    if (encounter.Result == IncenseEncounterResponse.Types.Result.IncenseEncounterSuccess)
                    {
                        await CatchPokemonTask.Execute(ctx, machine, encounter, pokemon);
                    }
                    else if (encounter.Result == IncenseEncounterResponse.Types.Result.PokemonInventoryFull)
                    {
                        if (ctx.LogicClient.Settings.TransferDuplicatePokemon)
                        {
                            machine.Fire(new WarnEvent {Message = "PokemonInventory is Full.Transferring pokemons..."});
                            await TransferDuplicatePokemonTask.Execute(ctx, machine);
                        }
                        else
                            machine.Fire(new WarnEvent
                            {
                                Message =
                                    "PokemonInventory is Full.Please Transfer pokemon manually or set TransferDuplicatePokemon to true in settings..."
                            });
                    }
                    else
                    {
                        machine.Fire(new WarnEvent {Message = $"Encounter problem: {encounter.Result}"});
                    }
                }
            }
        }
Example #11
0
 public MapPokemonWrapper(MapPokemon mapPokemon)
 {
     _mapPokemon = mapPokemon;
     Geoposition =
         new Geopoint(new BasicGeoposition {
         Latitude = _mapPokemon.Latitude, Longitude = _mapPokemon.Longitude
     });
 }
Example #12
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));
        }
Example #13
0
        public void Update(IMapPokemon update)
        {
            _mapPokemon = ((MapPokemonWrapper)update)._mapPokemon;

            OnPropertyChanged(nameof(PokemonId));
            OnPropertyChanged(nameof(EncounterId));
            OnPropertyChanged(nameof(SpawnpointId));
            OnPropertyChanged(nameof(Geoposition));
        }
Example #14
0
        private async Task <MethodResult <EncounterResponse> > EncounterPokemon(MapPokemon mapPokemon)
        {
            if (mapPokemon.EncounterId == 0 || mapPokemon.ExpirationTimestampMs >= DateTime.UtcNow.ToUnixTime())
            {
                LogCaller(new LoggerEventArgs("Encounter expired....", LoggerTypes.Warning));
                return(new MethodResult <EncounterResponse>());
            }

            var response = await _client.ClientSession.RpcClient.SendRemoteProcedureCallAsync(new Request {
                RequestType    = RequestType.Encounter,
                RequestMessage = new EncounterMessage {
                    EncounterId     = mapPokemon.EncounterId,
                    PlayerLatitude  = _client.ClientSession.Player.Latitude,
                    PlayerLongitude = _client.ClientSession.Player.Longitude,
                    SpawnPointId    = mapPokemon.SpawnPointId
                }.ToByteString()
            });

            EncounterResponse eResponse = null;

            try
            {
                eResponse = EncounterResponse.Parser.ParseFrom(response);
            }
            catch (Exception)
            {
                LogCaller(new LoggerEventArgs("Encounter expired....", LoggerTypes.Warning));
                return(new MethodResult <EncounterResponse>());
            }

            if (eResponse.Status == EncounterResponse.Types.Status.PokemonInventoryFull)
            {
                LogCaller(new LoggerEventArgs("Encounter failed. Pokemon inventory full", LoggerTypes.Warning));

                return(new MethodResult <EncounterResponse> {
                    Message = "Encounter failed. Pokemon inventory full"
                });
            }
            if (eResponse.Status == EncounterResponse.Types.Status.EncounterAlreadyHappened)
            {
            }
            if (eResponse.Status != EncounterResponse.Types.Status.EncounterSuccess)
            {
                LogCaller(new LoggerEventArgs(String.Format("Encounter failed with response {0}", eResponse.Status), LoggerTypes.Warning));

                return(new MethodResult <EncounterResponse> {
                    Message = "Encounter failed"
                });
            }

            return(new MethodResult <EncounterResponse> {
                Data = eResponse,
                Success = true,
                Message = "Success"
            });
        }
Example #15
0
        public static string GetName(this MapPokemon Pokemon)
        {
            try
            {
                return(Pokemon.PokemonId.ToString());
            }
            catch { }

            return(null);
        }
Example #16
0
        private static string MakeTooltip(MapPokemon Pokemon)
        {
            var Result = string.Format("{0} - #{1}{2}", Pokemon.GetName(), Pokemon.GetID(), Environment.NewLine);

            Result += string.Format("Latitude: {0}. {3}Longitude: {1}. {2}", Pokemon.Latitude, Pokemon.Longitude, Environment.NewLine, Environment.NewLine);

            Result += string.Format("Expiration date: {0}.", (Pokemon.ExpirationTimestampMs > 0) ? Origin.AddMilliseconds(Pokemon.ExpirationTimestampMs).ToLocalTime().ToShortTimeString() : "Never");

            return(Result);
        }
Example #17
0
 public PokemonModel(MapPokemon mapPokemon)
 {
     Name        = mapPokemon.PokemonId.ToString();
     Id          = mapPokemon.PokemonId + "";
     Latitude    = mapPokemon.Latitude.ToString(CultureInfo.InvariantCulture);
     Longitude   = mapPokemon.Longitude.ToString(CultureInfo.InvariantCulture);
     EncounterId = mapPokemon.EncounterId.ToString();
     SpawnId     = mapPokemon.SpawnPointId;
     Expires     = mapPokemon.ExpirationTimestampMs.ToString();
 }
Example #18
0
        public static int GetID(this MapPokemon Pokemon)
        {
            try
            {
                return((int)Pokemon.PokemonId);
            }
            catch { }

            return(-1);
        }
Example #19
0
 public PokemonCacheItem(MapPokemon pokemon)
 {
     SpawnPointId          = pokemon.SpawnPointId;
     EncounterId           = pokemon.EncounterId;
     PokemonId             = pokemon.PokemonId;
     ExpirationTimestampMs = pokemon.ExpirationTimestampMs;
     Latitude       = pokemon.Latitude;
     Longitude      = pokemon.Longitude;
     BaseMapPokemon = pokemon;
     Caught         = false;
 }
Example #20
0
        private void PushRemovePokemon(ISession session, MapPokemon mapPokemon)
        {
            if (!_openedSessions.ContainsKey(session))
            {
                return;
            }
            var tBot    = _openedSessions[session];
            var nMapObj = new NewMapObject("pm_rm", mapPokemon.PokemonId.ToString(), mapPokemon.Latitude, mapPokemon.Longitude, mapPokemon.EncounterId.ToString());

            tBot.MarkersQueue.Enqueue(nMapObj);
        }
Example #21
0
        public SpawnedPokemon(MapPokemon mapPokemon, string instanceName) : this(instanceName)
        {
            this.PokemonID    = mapPokemon.PokemonId;
            this.EncounterID  = mapPokemon.EncounterId.ToString();
            this.SpawnPointID = mapPokemon.SpawnPointId;

            this.Latitude  = mapPokemon.Latitude;
            this.Longitude = mapPokemon.Longitude;

            DateTime utcStart = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
            this.Despawn = utcStart.AddMilliseconds(mapPokemon.ExpirationTimestampMs).ToLocalTime();
        }
        public MapPokemonViewModel(MapPokemon pokemon, SessionViewModel session, Settings settings, PlayerViewModel player, MapViewModel map)
            : base(pokemon.PokemonId, pokemon.EncounterId, settings)
        {
            this.session = session;
            this.player  = player;
            this.map     = map;

            EncounterId           = pokemon.EncounterId;
            ExpirationTimestampMs = pokemon.ExpirationTimestampMs;
            SpawnPointId          = pokemon.SpawnPointId;
            Position = new Position2DViewModel(pokemon.Latitude, pokemon.Longitude);
        }
Example #23
0
        public void Update(IMapPokemon update)
        {
            var incense = (IncensePokemon)update;

            _incensePokemon = incense._incensePokemon;
            Geoposition     = incense.Geoposition;

            OnPropertyChanged(nameof(PokemonId));
            OnPropertyChanged(nameof(EncounterId));
            OnPropertyChanged(nameof(SpawnpointId));
            OnPropertyChanged(nameof(Geoposition));
        }
Example #24
0
 public static Image GetImage(string name, PokemonData pokemon = null, MapPokemon _pokemon = null)
 {
     if (pokemon != null)
     {
         return(GetPokemonImage(pokemon));
     }
     if (_pokemon != null)
     {
         return(GetPokemonImage(_pokemon));
     }
     return((Image)Properties.Resources.ResourceManager.GetObject(name));
 }
Example #25
0
        public static GMarkerGoogle GetMarker(this MapPokemon Pokemon)
        {
            var Position = new GMap.NET.PointLatLng(Pokemon.Latitude, Pokemon.Longitude);

            var Result = new GMarkerGoogle(Position, (Bitmap)Bitmap.FromFile(string.Format("icons/{0}.png", Pokemon.GetID())));

            //Result.Size = new Size(Settings.POKEMON_IMAGE_SIZE, Settings.POKEMON_IMAGE_SIZE);

            Result.ToolTipText = MakeTooltip(Pokemon);

            return(Result);
        }
Example #26
0
        private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon, Client client)
        {
            CatchPokemonResponse caughtPokemonResponse;

            do
            {
                if (encounter?.CaptureProbability.CaptureProbability_.First() < 0.40)
                {
                    _logger.Write("Using berry", LogLevel.INFO);
                    await _pokemonItems.UseBerry(pokemon.EncounterId, pokemon.SpawnPointId, client);
                }

                var pokeball = await _pokemonItems.GetBestBall(encounter?.WildPokemon, client.Inventory);

                await Task.Delay(1000);

                caughtPokemonResponse =
                    await client.Encounter.CatchPokemon(pokemon.EncounterId, pokemon.SpawnPointId, pokeball);

                await Task.Delay(500);
            } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed ||
                     caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);

            if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess)
            {
                var wildPokemon = encounter?.WildPokemon.PokemonData;
                if (wildPokemon != null)
                {
                    OnCatch?.Invoke(wildPokemon);
                    OnExperienceAwarded?.Invoke(caughtPokemonResponse.CaptureAward.Xp.Sum(x => x));

                    var iv = wildPokemon.IndividualAttack + wildPokemon.IndividualDefense +
                             wildPokemon.IndividualStamina;

                    _logger.Write($"Gotcha! {pokemon.PokemonId} - CP: {wildPokemon.Cp}, " +
                                  $"IV {iv}", LogLevel.SUCC);

                    if (_settings.Settings.QuickTransfer)
                    {
                        if (_pokemonHelper.ShouldTranferPokemon(wildPokemon, _settings.Settings.IvPercentageDiscart,
                                                                _settings.Settings.KeepMinCp, _settings.Settings.IvOverCp))
                        {
                            await _transferPokemonHandler.TransferPokemon(client, wildPokemon, true);
                        }
                    }
                }
                else
                {
                    _logger.Write($"Caught status: {caughtPokemonResponse.Status}", LogLevel.WARN);
                }
            }
        }
Example #27
0
        private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon)
        {
            CatchPokemonResponse caughtPokemonResponse;

            do
            {
                var bestBerry = await GetBestBerry(encounter?.WildPokemon);

                var inventoryBerries = await _inventory.GetItems();

                var berries     = inventoryBerries.Where(p => (ItemId)p.Item_ == bestBerry).FirstOrDefault();;
                var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault();
                if (bestBerry != AllEnum.ItemId.ItemUnknown && probability.HasValue && probability.Value < 0.35)
                {
                    var useRaspberry = await _client.UseCaptureItem(pokemon.EncounterId, bestBerry, pokemon.SpawnpointId);

                    Logger.Normal($"(BERRY) {bestBerry} used, remaining: {berries.Count}");
                    await RandomHelper.RandomDelay(500, 1000);
                }

                var bestPokeball = await GetBestBall(encounter?.WildPokemon);

                if (bestPokeball == MiscEnums.Item.ITEM_UNKNOWN)
                {
                    Logger.Normal($"(POKEBATTLE) You don't own any Pokeballs :( - We missed a {pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp}");
                    return;
                }

                var distance = Navigation.DistanceBetween2Coordinates(_client.CurrentLat, _client.CurrentLng, pokemon.Latitude, pokemon.Longitude);
                caughtPokemonResponse = await _client.CatchPokemon(pokemon.EncounterId, pokemon.SpawnpointId, pokemon.Latitude, pokemon.Longitude, bestPokeball);

                if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess)
                {
                    foreach (int xp in caughtPokemonResponse.Scores.Xp)
                    {
                        _stats.addExperience(xp);
                    }
                    _stats.increasePokemons();
                    var profile = await _client.GetProfile();

                    _stats.getStardust(profile.Profile.Currency.ToArray()[1].Amount);
                }
                _stats.updateConsoleTitle(_inventory);
                Logger.Normal(ConsoleColor.Yellow,
                              caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess
                    ? $"(POKEBATTLE) We caught a {pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp} ({CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData).ToString("0.00")}% perfect) and CaptureProbability: {encounter?.CaptureProbability.CaptureProbability_.First()}, used {bestPokeball} and received XP {caughtPokemonResponse.Scores.Xp.Sum()}"
                    : $"(POKEBATTLE) {pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp} CaptureProbability: {encounter?.CaptureProbability.CaptureProbability_.First()} {caughtPokemonResponse.Status} while using a {bestPokeball}.."
                              );
                await RandomHelper.RandomDelay(1750, 2250);
            }while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);
        }
Example #28
0
        internal bool AddPokemon(MapPokemon Pokemon)
        {
            try
            {
                Pokemons.Add(Pokemon.EncounterId, Pokemon);

                Storage.Insert(Pokemon);

                return(!Blacklist.Contains(Pokemon.GetID()));
            }
            catch { }

            return(false);
        }
        public static async Task Execute()
        {
            if (!Logic._client.Settings.CatchIncensePokemon)
            {
                return;
            }

            var incensePokemon = await Logic._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 (Logic._client.Settings.UsePokemonDoNotCatchList &&
                    Logic._client.Settings.PokemonsToNotCatch.Contains(pokemon.PokemonId))
                {
                    Logger.Write($"Ignore Pokemon - {pokemon.PokemonId} - is on ToNotCatch List", LogLevel.Debug);
                    return;
                }

                var encounter =
                    await Logic._client.Encounter.EncounterIncensePokemon(pokemon.EncounterId, pokemon.SpawnPointId);

                if (encounter.Result == IncenseEncounterResponse.Types.Result.IncenseEncounterSuccess)
                {
                    await CatchPokemonTask.Execute(encounter, pokemon);
                }
                else
                {
                    Logger.Write($"Encounter problem: {encounter.Result}", LogLevel.Warning);
                }
            }

            if (Logic._client.Settings.EvolvePokemon || Logic._client.Settings.EvolvePokemonAboveIV)
            {
                await EvolvePokemonTask.Execute();
            }
            if (Logic._client.Settings.TransferPokemon)
            {
                await TransferPokemonTask.Execute();
            }
        }
Example #30
0
        private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon)
        {
            CatchPokemonResponse caughtPokemonResponse;
            int attemptCounter = 1;
            do
            {//test
                var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault();
                

                var pokeball = await GetBestBall(encounter?.WildPokemon);
                if (pokeball == MiscEnums.Item.ITEM_UNKNOWN)
                {
                    Logger.Write($"No Pokeballs - We missed a {pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp}", LogLevel.Caught);
                    return;
                }
                if ((probability.HasValue && probability.Value < 0.35 && encounter.WildPokemon?.PokemonData?.Cp > 400) ||
                    PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData) >=
                    _clientSettings.KeepMinIVPercentage)
                {
                    await UseBerry(pokemon.EncounterId, pokemon.SpawnpointId);
                }

                var distance = LocationUtils.CalculateDistanceInMeters(_client.CurrentLat, _client.CurrentLng,
                    pokemon.Latitude, pokemon.Longitude);
                caughtPokemonResponse =
                    await
                        _client.CatchPokemon(pokemon.EncounterId, pokemon.SpawnpointId, pokemon.Latitude,
                            pokemon.Longitude, pokeball);
                if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess)
                {
                    foreach (int xp in caughtPokemonResponse.Scores.Xp)
                        _stats.AddExperience(xp);
                    _stats.IncreasePokemons();
                    var profile = await _client.GetProfile();
                    _stats.GetStardust(profile.Profile.Currency.ToArray()[1].Amount);
                }
                _stats.UpdateConsoleTitle(_inventory);

                if (encounter?.CaptureProbability?.CaptureProbability_ != null)
                {
                    string catchStatus = attemptCounter > 1 ? $"{caughtPokemonResponse.Status} Attempt #{attemptCounter}" : $"{caughtPokemonResponse.Status}";
                    Logger.Write($"({catchStatus}) | {pokemon.PokemonId} Lvl {PokemonInfo.GetLevel(encounter?.WildPokemon?.PokemonData)} ({encounter?.WildPokemon?.PokemonData?.Cp}/{PokemonInfo.CalculateMaxCP(encounter?.WildPokemon?.PokemonData)} CP) ({Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData)).ToString("0.00")}% perfect) | Chance: {Math.Round(Convert.ToDouble(encounter?.CaptureProbability?.CaptureProbability_.First()) * 100, 2)}% | {Math.Round(distance)}m dist | with {pokeball}", LogLevel.Caught);
                }
                attemptCounter++;
                await Task.Delay(2000);
            } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed ||
                     caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);
        }
Example #31
0
        public static Image GetPokemonImage(MapPokemon pokemon)
        {
            var additional = "";

            /*if (pokemon.PokemonDisplay.Costume != Costume.Unset) additional = "_" + pokemon.PokemonDisplay.Costume.ToString().Replace("-Unset", "");
             * if (pokemon.PokemonDisplay.Form != POGOProtos.Enums.Form.Unset) additional = "_" + pokemon.PokemonDisplay.Form.ToString().Replace("Unown", "").Replace("-ExclamationPoint", "_ExclamationPoint").Replace("-QuestionMark", "_QuestionMark").Replace("-Unset", "");
             * if (pokemon.PokemonDisplay.Shiny) additional = "_shiny";*/

            var image = (Image)Resources.PokemonDB.ResourceManager.GetObject($"_{(int)pokemon.PokemonId}{additional}");

            if (image != null)
            {
                return(image);
            }
            return((Image)Properties.Resources.ResourceManager.GetObject("question"));
            //return LoadPicture($"http://assets.pokemon.com/assets/cms2/img/pokedex/full/{(int)pokemon.PokemonId:000}.png");
        }
Example #32
0
        private ulong TrySnipePokemons(PokemonId pokeid, GeoCoordinate pokeCoords, GeoCoordinate returnCoords)
        {
            const bool goBack = true;
            var        tries  = 1;
            var        found  = false;
            ulong      caught = 0;

            do
            {
                SendToLog($"Try {tries} of {GlobalVars.SnipeOpts.NumTries}");
                var mapObjectsResponse = _client.Map.GetMapObjects(true).Result.Item1;
                var pokemons           = mapObjectsResponse.MapCells.SelectMany(i => i.CatchablePokemons);
                if (pokemons.Any())
                {
                    SendToLog($"Found {pokemons.Count()} catchable Pokemon(s)");
                    MapPokemon pokemon = null;
                    found = FindPokemon(pokeid, pokeCoords, pokemons, out pokemon);
                    if (found)
                    {
                        caught = CatchingLogic.CatchPokemon(pokemon.EncounterId, pokemon.SpawnPointId, pokemon.PokemonId, pokemon.Longitude, pokemon.Latitude, goBack, returnCoords.Latitude, returnCoords.Longitude);
                    }
                }
                tries++;
                if (!found)
                {
                    SendToLog($"No Pokemon Found!");
                    if ((tries <= GlobalVars.SnipeOpts.NumTries))
                    {
                        SendToLog($"Waiting {GlobalVars.SnipeOpts.WaitSecond} seconds for Pokemon to appear...");
                        RandomHelper.RandomSleep(GlobalVars.SnipeOpts.WaitSecond * 1200);
                    }
                }
            } while ((tries <= GlobalVars.SnipeOpts.NumTries) && !found);

            if (caught != 0)
            {
                SendToLog($"{pokeid} caught!");
            }
            else if (found)
            {
                SendToLog($"{ pokeid} not caught!");
            }

            return(caught);
        }
Example #33
0
        private bool PokemonWithinCatchSettings(MapPokemon pokemon)
        {
            CatchSetting catchSettings = UserSettings.CatchSettings.FirstOrDefault(x => x.Id == pokemon.PokemonId);

            if (catchSettings == null)
            {
                LogCaller(new LoggerEventArgs(String.Format("Failed to find catch setting for {0}. Attempting to catch", pokemon.PokemonId), LoggerTypes.Warning));

                return(true);
            }

            if (!catchSettings.Catch)
            {
                LogCaller(new LoggerEventArgs(String.Format("Skipping catching {0}", pokemon.PokemonId), LoggerTypes.Info));
            }

            return(catchSettings.Catch);
        }
        private async Task <MethodResult <EncounterResponse> > EncounterPokemon(MapPokemon mapPokemon)
        {
            var response = await ClientSession.RpcClient.SendRemoteProcedureCallAsync(new Request
            {
                RequestType    = RequestType.Encounter,
                RequestMessage = new EncounterMessage
                {
                    EncounterId     = mapPokemon.EncounterId,
                    PlayerLatitude  = ClientSession.Player.Latitude,
                    PlayerLongitude = ClientSession.Player.Longitude,
                    SpawnPointId    = mapPokemon.SpawnPointId
                }.ToByteString()
            });

            EncounterResponse eResponse = null;

            eResponse = EncounterResponse.Parser.ParseFrom(response);

            if (eResponse.Status == EncounterResponse.Types.Status.PokemonInventoryFull)
            {
                LogCaller(new LoggerEventArgs("Encounter failed. Pokemon inventory full", LoggerTypes.Warning));

                return(new MethodResult <EncounterResponse>
                {
                    Message = "Encounter failed. Pokemon inventory full"
                });
            }
            else if (eResponse.Status != EncounterResponse.Types.Status.EncounterSuccess)
            {
                LogCaller(new LoggerEventArgs(String.Format("Encounter failed with response {0}", eResponse.Status), LoggerTypes.Warning));

                return(new MethodResult <EncounterResponse>
                {
                    Message = "Encounter failed"
                });
            }

            return(new MethodResult <EncounterResponse>
            {
                Data = eResponse,
                Success = true,
                Message = "Success"
            });
        }
Example #35
0
        private async Task <MethodResult <EncounterResponse> > EncounterPokemon(MapPokemon mapPokemon)
        {
            try
            {
                EncounterResponse eResponse = await _client.Encounter.EncounterPokemon(mapPokemon.EncounterId, mapPokemon.SpawnPointId);

                if (eResponse.Status == EncounterResponse.Types.Status.PokemonInventoryFull)
                {
                    LogCaller(new LoggerEventArgs("Encounter failed. Pokemon inventory full", LoggerTypes.Warning));

                    return(new MethodResult <EncounterResponse>
                    {
                        Message = "Encounter failed. Pokemon inventory full"
                    });
                }
                else if (eResponse.Status != EncounterResponse.Types.Status.EncounterSuccess)
                {
                    LogCaller(new LoggerEventArgs(String.Format("Encounter failed with response {0}", eResponse.Status), LoggerTypes.Warning));

                    return(new MethodResult <EncounterResponse>
                    {
                        Message = "Encounter failed"
                    });
                }

                return(new MethodResult <EncounterResponse>
                {
                    Data = eResponse,
                    Success = true,
                    Message = "Success"
                });
            }
            catch (Exception ex)
            {
                LogCaller(new LoggerEventArgs("Failed to encounter pokemon due to error", LoggerTypes.Exception, ex));

                return(new MethodResult <EncounterResponse>
                {
                    Message = "Failed to encounter pokemon"
                });
            }
        }
Example #36
0
        public static Image GetImage(string name, PokemonData pokemon = null, MapPokemon _pokemon = null, int maxHeight = 0, int maxWidth = 0)
        {
            var image  = GetImage(name, pokemon, _pokemon);
            var ratioX = (double)maxWidth / image.Width;
            var ratioY = (double)maxHeight / image.Height;
            var ratio  = Math.Min(ratioX, ratioY);

            var newWidth  = (int)(image.Width * ratio);
            var newHeight = (int)(image.Height * ratio);

            var newImage = new Bitmap(newWidth, newHeight);

            using (var graphics = Graphics.FromImage(newImage))
                graphics.DrawImage(image, 0, 0, newWidth, newHeight);
            if (image != null)
            {
                return(newImage);
            }
            return((Image)Properties.Resources.ResourceManager.GetObject("question"));
        }
Example #37
0
        private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon)
        {
            CatchPokemonResponse caughtPokemonResponse;

            do
            {
                if (encounter?.CaptureProbability.CaptureProbability_.First() < 0.35)
                {
                    //Throw berry is we can
                    await UseBerry(pokemon.EncounterId, pokemon.SpawnpointId);
                }

                var pokeball = await GetBestBall(encounter?.WildPokemon);

                var distance = Navigation.DistanceBetween2Coordinates(_client.CurrentLat, _client.CurrentLng, pokemon.Latitude, pokemon.Longitude);
                caughtPokemonResponse = await _client.CatchPokemon(pokemon.EncounterId, pokemon.SpawnpointId, pokemon.Latitude, pokemon.Longitude, pokeball);

                Logger.Write(caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess ? $"We caught a {pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp} and CaptureProbability: {encounter?.CaptureProbability.CaptureProbability_.First()} using a {pokeball} in {Math.Round(distance)}m distance" : $"{pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp} CaptureProbability: {encounter?.CaptureProbability.CaptureProbability_.First()} in {Math.Round(distance)}m distance {caughtPokemonResponse.Status} while using a {pokeball}..", LogLevel.Info);
                await Task.Delay(2000);
            }while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);
        }
Example #38
0
        public static async Task Execute(ISession session, dynamic encounter, MapPokemon pokemon,
            FortData currentFortData = null, ulong encounterId = 0)
        {
            CatchPokemonResponse caughtPokemonResponse;
            var attemptCounter = 1;
            do
            {
                if (session.LogicSettings.MaxPokeballsPerPokemon > 0 &&
                    attemptCounter > session.LogicSettings.MaxPokeballsPerPokemon)
                    break;

                float probability = encounter?.CaptureProbability?.CaptureProbability_[0];

                var pokeball = await GetBestBall(session, encounter, probability);
                if (pokeball == ItemId.ItemUnknown)
                {
                    session.EventDispatcher.Send(new NoPokeballEvent
                    {
                        Id = encounter is EncounterResponse ? pokemon.PokemonId : encounter?.PokemonData.PokemonId,
                        Cp =
                            (encounter is EncounterResponse
                                ? encounter.WildPokemon?.PokemonData?.Cp
                                : encounter?.PokemonData?.Cp) ?? 0
                    });
                    return;
                }

                var isLowProbability = probability < 0.35;
                var isHighCp = encounter != null &&
                               (encounter is EncounterResponse
                                   ? encounter.WildPokemon?.PokemonData?.Cp
                                   : encounter.PokemonData?.Cp) > 400;
                var isHighPerfection =
                    PokemonInfo.CalculatePokemonPerfection(encounter is EncounterResponse
                        ? encounter.WildPokemon?.PokemonData
                        : encounter?.PokemonData) >= session.LogicSettings.KeepMinIvPercentage;

                if ((isLowProbability && isHighCp) || isHighPerfection)
                {
                    await
                        UseBerry(session,
                            encounter is EncounterResponse || encounter is IncenseEncounterResponse
                                ? pokemon.EncounterId
                                : encounterId,
                            encounter is EncounterResponse || encounter is IncenseEncounterResponse
                                ? pokemon.SpawnPointId
                                : currentFortData?.Id);
                }

                var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                    session.Client.CurrentLongitude,
                    encounter is EncounterResponse || encounter is IncenseEncounterResponse
                        ? pokemon.Latitude
                        : currentFortData.Latitude,
                    encounter is EncounterResponse || encounter is IncenseEncounterResponse
                        ? pokemon.Longitude
                        : currentFortData.Longitude);

                caughtPokemonResponse =
                    await session.Client.Encounter.CatchPokemon(
                        encounter is EncounterResponse || encounter is IncenseEncounterResponse
                            ? pokemon.EncounterId
                            : encounterId,
                        encounter is EncounterResponse || encounter is IncenseEncounterResponse
                            ? pokemon.SpawnPointId
                            : currentFortData.Id, pokeball);

                var lat = encounter is EncounterResponse || encounter is IncenseEncounterResponse
                             ? pokemon.Latitude : currentFortData.Latitude;
                var lng = encounter is EncounterResponse || encounter is IncenseEncounterResponse
                            ? pokemon.Longitude : currentFortData.Longitude;
                var evt = new PokemonCaptureEvent()
                {
                    Status = caughtPokemonResponse.Status,
                    Latitude = lat,
                    Longitude = lng
                };


                if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess)
                {
                    var totalExp = 0;

                    foreach (var xp in caughtPokemonResponse.CaptureAward.Xp)
                    {
                        totalExp += xp;
                    }
                    var profile = await session.Client.Player.GetPlayer();

                    evt.Exp = totalExp;
                    evt.Stardust = profile.PlayerData.Currencies.ToArray()[1].Amount;

                    var pokemonSettings = await session.Inventory.GetPokemonSettings();
                    var pokemonFamilies = await session.Inventory.GetPokemonFamilies();

                    var setting =
                        pokemonSettings.FirstOrDefault(q => pokemon != null && q.PokemonId == pokemon.PokemonId);
                    var family = pokemonFamilies.FirstOrDefault(q => setting != null && q.FamilyId == setting.FamilyId);

                    if (family != null)
                    {
                        family.Candy_ += caughtPokemonResponse.CaptureAward.Candy.Sum();

                        evt.FamilyCandies = family.Candy_;
                    }
                    else
                    {
                        evt.FamilyCandies = caughtPokemonResponse.CaptureAward.Candy.Sum();
                    }
                }


                evt.CatchType = encounter is EncounterResponse
                    ? session.Translation.GetTranslation(TranslationString.CatchTypeNormal)
                    : encounter is DiskEncounterResponse
                        ? session.Translation.GetTranslation(TranslationString.CatchTypeLure)
                        : session.Translation.GetTranslation(TranslationString.CatchTypeIncense);
                evt.Id = encounter is EncounterResponse ? pokemon.PokemonId : encounter?.PokemonData.PokemonId;
                evt.Level =
                    PokemonInfo.GetLevel(encounter is EncounterResponse
                        ? encounter.WildPokemon?.PokemonData
                        : encounter?.PokemonData);
                evt.Cp = encounter is EncounterResponse
                    ? encounter.WildPokemon?.PokemonData?.Cp
                    : encounter?.PokemonData?.Cp ?? 0;
                evt.MaxCp =
                    PokemonInfo.CalculateMaxCp(encounter is EncounterResponse
                        ? encounter.WildPokemon?.PokemonData
                        : encounter?.PokemonData);
                evt.Perfection =
                    Math.Round(
                        PokemonInfo.CalculatePokemonPerfection(encounter is EncounterResponse
                            ? encounter.WildPokemon?.PokemonData
                            : encounter?.PokemonData));
                evt.Probability =
                    Math.Round(probability * 100, 2);
                evt.Distance = distance;
                evt.Pokeball = pokeball;
                evt.Attempt = attemptCounter;
                await session.Inventory.RefreshCachedInventory();
                evt.BallAmount = await session.Inventory.GetItemAmountByType(pokeball);

                session.EventDispatcher.Send(evt);

                attemptCounter++;

                DelayingUtils.Delay(session.LogicSettings.DelayBetweenPokemonCatch, 2000);
            } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed ||
                     caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);
        }
Example #39
0
        private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon)
        {
            CatchPokemonResponse caughtPokemonResponse;
            int attemptCounter = 1;
            do
            {
                var bestBerry = await GetBestBerry(encounter?.WildPokemon);
                var inventoryBerries = await _inventory.GetItems();
                var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault();

                var bestPokeball = await GetBestBall(encounter?.WildPokemon);
                if (bestPokeball == MiscEnums.Item.ITEM_UNKNOWN)
                {
                    Logger.Write($"You don't own any Pokeballs :( - We missed a {pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp}", LogLevel.Warning);
                    return;
                }

                var berries = inventoryBerries.Where(p => (ItemId)p.Item_ == bestBerry).FirstOrDefault();
                if (bestBerry != ItemId.ItemUnknown && probability.HasValue && probability.Value < 0.35 && PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData) >= _clientSettings.KeepMinIVPercentage)
                {
                    var useRaspberry = await _client.UseCaptureItem(pokemon.EncounterId, bestBerry, pokemon.SpawnpointId);
                    Logger.Write($"{bestBerry} used, remaining: {berries.Count}", LogLevel.Berry);
                    await RandomHelper.RandomDelay(50, 200);
                }

                var distance = LocationUtils.CalculateDistanceInMeters(_client.CurrentLat, _client.CurrentLng, pokemon.Latitude, pokemon.Longitude);
                caughtPokemonResponse = await _client.CatchPokemon(pokemon.EncounterId, pokemon.SpawnpointId, pokemon.Latitude, pokemon.Longitude, bestPokeball);

                if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess)
                {
                    foreach (int xp in caughtPokemonResponse.Scores.Xp)
                        _stats.AddExperience(xp);
                    _stats.IncreasePokemons();
                    var profile = await _client.GetProfile();
                    _stats.GetStardust(profile.Profile.Currency.ToArray()[1].Amount);
                }
                _stats.UpdateConsoleTitle(_inventory);

                if (encounter?.CaptureProbability?.CaptureProbability_ != null)
                {
                    string catchStatus = attemptCounter > 1 ? $"{caughtPokemonResponse.Status} Attempt #{attemptCounter}" : $"{caughtPokemonResponse.Status}";
                    string receivedXP = catchStatus == "CatchSuccess" ? $"and received XP {caughtPokemonResponse.Scores.Xp.Sum()}" : $"";
                    Logger.Write($"({catchStatus}) | {pokemon.PokemonId} Lvl {PokemonInfo.GetLevel(encounter?.WildPokemon?.PokemonData)} (CP {encounter?.WildPokemon?.PokemonData?.Cp}/{PokemonInfo.CalculateMaxCP(encounter?.WildPokemon?.PokemonData)} | {Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData)).ToString("0.00")} % perfect) | Chance: {(float)((int)(encounter?.CaptureProbability?.CaptureProbability_.First() * 100)) / 100} | {Math.Round(distance)}m dist | with {bestPokeball} {receivedXP}", LogLevel.Pokemon);
                }

                attemptCounter++;
                await RandomHelper.RandomDelay(750, 1250);
            }
            while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);
        }
 public MapPokemonWrapper(MapPokemon mapPokemon)
 {
     _mapPokemon = mapPokemon;
     Geoposition =
         new Geopoint(new BasicGeoposition {Latitude = _mapPokemon.Latitude, Longitude = _mapPokemon.Longitude});
 }
Example #41
0
        private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon)
        {

            CatchPokemonResponse caughtPokemonResponse;
            do
            {
                PokemonData pokeData = encounter?.WildPokemon?.PokemonData;

               

                if (encounter?.CaptureProbability.CaptureProbability_.First() < (UserSettings.BerryProbability / 100))
                {
                    if (pokeData != null)
                    {
                        if (BerryList.Contains(pokeData.PokemonId))
                        {
                            await UseBerry(pokemon.EncounterId, pokemon.SpawnpointId);
                        }
                    }
                    
                    
                }

                var pokeball = await GetBestBall(encounter?.WildPokemon);
                
                caughtPokemonResponse = await _client.CatchPokemon(pokemon.EncounterId, pokemon.SpawnpointId, pokemon.Latitude, pokemon.Longitude, pokeball);

                Logger.Write(caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess ? $"We caught a {pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp} ({CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData).ToString("0.00")}% perfection) using a {pokeball}" : $"{pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp} got away while using a {pokeball}..", LogLevel.Info);

                if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess)
                {
                    pokeData = encounter?.WildPokemon?.PokemonData;

                    foreach (int xp in caughtPokemonResponse.Scores.Xp)
                        _stats.addExperience(xp);
                    _stats.increasePokemons();
                    _stats.updateConsoleTitle(_inventory);
                    await Events.PokemonCaught(encounter?.WildPokemon?.PokemonData);
                }

                await Task.Delay(rand.Next(1500, 3000));
            }
            while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed);
        }
Example #42
0
        private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon)
        {

            CatchPokemonResponse caughtPokemonResponse;
            do
            {
                if (encounter?.CaptureProbability.CaptureProbability_.First() < 0.35)
                {
                    //Throw berry is we can
                    await UseBerry(pokemon.EncounterId, pokemon.SpawnpointId);
                }

                var pokeball = await GetBestBall(encounter?.WildPokemon);
                var distance = Navigation.DistanceBetween2Coordinates(_client.CurrentLat, _client.CurrentLng, pokemon.Latitude, pokemon.Longitude);
                caughtPokemonResponse = await _client.CatchPokemon(pokemon.EncounterId, pokemon.SpawnpointId, pokemon.Latitude, pokemon.Longitude, pokeball);
                Logger.Write(caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess ? $"We caught a {pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp} and CaptureProbability: {encounter?.CaptureProbability.CaptureProbability_.First()} using a {pokeball} in {Math.Round(distance)}m distance" : $"{pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp} CaptureProbability: {encounter?.CaptureProbability.CaptureProbability_.First()} in {Math.Round(distance)}m distance {caughtPokemonResponse.Status} while using a {pokeball}..", LogLevel.Info);
                await Task.Delay(2000);
            }
            while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape) ;
        }
        public static async Task Execute(ISession session, CancellationToken cancellationToken, dynamic encounter, MapPokemon pokemon,
            FortData currentFortData = null, ulong encounterId = 0)
        {
            cancellationToken.ThrowIfCancellationRequested();

            // If the encounter is null nothing will work below, so exit now
            if (encounter == null) return;

            float probability = encounter?.CaptureProbability?.CaptureProbability_[0];

            // Check for pokeballs before proceeding
            var pokeball = await GetBestBall(session, encounter, probability);
            if (pokeball == ItemId.ItemUnknown) return;

            //Calculate CP and IV
            var pokemonCp = (encounter is EncounterResponse
                               ? encounter.WildPokemon?.PokemonData?.Cp
                               : encounter.PokemonData?.Cp);
            var pokemonIv = PokemonInfo.CalculatePokemonPerfection(encounter is EncounterResponse
                    ? encounter.WildPokemon?.PokemonData
                    : encounter?.PokemonData);

            // Determine whether to use berries or not
            if ((session.LogicSettings.UseBerriesOperator.ToLower().Equals("and") &&
                    pokemonIv >= session.LogicSettings.UseBerriesMinIv &&
                    pokemonCp >= session.LogicSettings.UseBerriesMinCp &&
                    probability < session.LogicSettings.UseBerriesBelowCatchProbability) ||
                (session.LogicSettings.UseBerriesOperator.ToLower().Equals("or") && (
                    pokemonIv >= session.LogicSettings.UseBerriesMinIv ||
                    pokemonCp >= session.LogicSettings.UseBerriesMinCp ||
                    probability < session.LogicSettings.UseBerriesBelowCatchProbability)))
            {
                await
                    UseBerry(session,
                        encounter is EncounterResponse || encounter is IncenseEncounterResponse
                            ? pokemon.EncounterId
                            : encounterId,
                        encounter is EncounterResponse || encounter is IncenseEncounterResponse
                            ? pokemon.SpawnPointId
                            : currentFortData?.Id);
            }

            // Calculate distance away
            var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                session.Client.CurrentLongitude,
                encounter is EncounterResponse || encounter is IncenseEncounterResponse
                    ? pokemon.Latitude
                    : currentFortData.Latitude,
                encounter is EncounterResponse || encounter is IncenseEncounterResponse
                    ? pokemon.Longitude
                    : currentFortData.Longitude);

            CatchPokemonResponse caughtPokemonResponse;
            var attemptCounter = 1;
            do
            {
                if ((session.LogicSettings.MaxPokeballsPerPokemon > 0 &&
                    attemptCounter > session.LogicSettings.MaxPokeballsPerPokemon))
                    break;

                pokeball = await GetBestBall(session, encounter, probability, true);
                if (pokeball == ItemId.ItemUnknown)
                {
                    session.EventDispatcher.Send(new NoPokeballEvent
                    {
                        Id = encounter is EncounterResponse ? pokemon.PokemonId : encounter?.PokemonData.PokemonId,
                        Cp =
                            (encounter is EncounterResponse
                                ? encounter.WildPokemon?.PokemonData?.Cp
                                : encounter?.PokemonData?.Cp) ?? 0
                    });
                    return;
                }

                caughtPokemonResponse =
                    await session.Client.Encounter.CatchPokemon(
                        encounter is EncounterResponse || encounter is IncenseEncounterResponse
                            ? pokemon.EncounterId
                            : encounterId,
                        encounter is EncounterResponse || encounter is IncenseEncounterResponse
                            ? pokemon.SpawnPointId
                            : currentFortData.Id, pokeball);

                var lat = encounter is EncounterResponse || encounter is IncenseEncounterResponse
                             ? pokemon.Latitude : currentFortData.Latitude;
                var lng = encounter is EncounterResponse || encounter is IncenseEncounterResponse
                            ? pokemon.Longitude : currentFortData.Longitude;
                var evt = new PokemonCaptureEvent()
                {
                    Status = caughtPokemonResponse.Status,
                    Latitude = lat,
                    Longitude = lng
                };

                if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess)
                {
                    var totalExp = 0;

                    foreach (var xp in caughtPokemonResponse.CaptureAward.Xp)
                    {
                        totalExp += xp;
                    }
                    var profile = await session.Client.Player.GetPlayer();

                    evt.Exp = totalExp;
                    evt.Stardust = profile.PlayerData.Currencies.ToArray()[1].Amount;

                    var pokemonSettings = await session.Inventory.GetPokemonSettings();
                    var pokemonFamilies = await session.Inventory.GetPokemonFamilies();

                    var setting =
                        pokemonSettings.FirstOrDefault(q => pokemon != null && q.PokemonId == pokemon.PokemonId);
                    var family = pokemonFamilies.FirstOrDefault(q => setting != null && q.FamilyId == setting.FamilyId);

                    if (family != null)
                    {
                        family.Candy_ += caughtPokemonResponse.CaptureAward.Candy.Sum();

                        evt.FamilyCandies = family.Candy_;
                    }
                    else
                    {
                        evt.FamilyCandies = caughtPokemonResponse.CaptureAward.Candy.Sum();
                    }

                    if (session.LogicSettings.TransferDuplicatePokemonOnCapture && session.LogicSettings.TransferDuplicatePokemon)
                        await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                }

                evt.CatchType = encounter is EncounterResponse
                    ? session.Translation.GetTranslation(TranslationString.CatchTypeNormal)
                    : encounter is DiskEncounterResponse
                        ? session.Translation.GetTranslation(TranslationString.CatchTypeLure)
                        : session.Translation.GetTranslation(TranslationString.CatchTypeIncense);
                evt.Id = encounter is EncounterResponse ? pokemon.PokemonId : encounter?.PokemonData.PokemonId;
                evt.Level =
                    PokemonInfo.GetLevel(encounter is EncounterResponse
                        ? encounter.WildPokemon?.PokemonData
                        : encounter?.PokemonData);
                evt.Cp = encounter is EncounterResponse
                    ? encounter.WildPokemon?.PokemonData?.Cp
                    : encounter?.PokemonData?.Cp ?? 0;
                evt.MaxCp =
                    PokemonInfo.CalculateMaxCp(encounter is EncounterResponse
                        ? encounter.WildPokemon?.PokemonData
                        : encounter?.PokemonData);
                evt.Perfection =
                    Math.Round(
                        PokemonInfo.CalculatePokemonPerfection(encounter is EncounterResponse
                            ? encounter.WildPokemon?.PokemonData
                            : encounter?.PokemonData));
                evt.Probability =
                    Math.Round(probability * 100, 2);
                evt.Distance = distance;
                evt.Pokeball = pokeball;
                evt.Attempt = attemptCounter;
                await session.Inventory.RefreshCachedInventory();
                evt.BallAmount = await session.Inventory.GetItemAmountByType(pokeball);

                session.EventDispatcher.Send(evt);

                attemptCounter++;

                DelayingUtils.Delay(session.LogicSettings.DelayBetweenPokemonCatch, 2000);
            } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed ||
                     caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);
        }
Example #44
0
        public static void Execute(Context ctx, StateMachine machine, EncounterResponse encounter, MapPokemon pokemon)
        {
            CatchPokemonResponse caughtPokemonResponse;
            var attemptCounter = 1;
            do
            {
                var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault();

                var pokeball = GetBestBall(ctx, encounter);
                if (pokeball == ItemId.ItemUnknown)
                {
                    machine.Fire(new NoPokeballEvent
                    {
                        Id = pokemon.PokemonId,
                        Cp = encounter?.WildPokemon?.PokemonData?.Cp ?? 0
                    });
                    return;
                }

                var isLowProbability = probability.HasValue && probability.Value < 0.35;
                var isHighCp = encounter != null && encounter.WildPokemon?.PokemonData?.Cp > 400;
                var isHighPerfection = PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData) >=
                                       ctx.LogicSettings.KeepMinIvPercentage;

                if ((isLowProbability && isHighCp) || isHighPerfection)
                {
                    UseBerry(ctx, machine, pokemon.EncounterId, pokemon.SpawnPointId);
                }

                var distance = LocationUtils.CalculateDistanceInMeters(ctx.Client.CurrentLatitude,
                    ctx.Client.CurrentLongitude, pokemon.Latitude, pokemon.Longitude);

                caughtPokemonResponse =
                    ctx.Client.Encounter.CatchPokemon(pokemon.EncounterId, pokemon.SpawnPointId, pokeball).Result;

                var evt = new PokemonCaptureEvent {Status = caughtPokemonResponse.Status};

                if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess)
                {
                    var totalExp = 0;

                    foreach (var xp in caughtPokemonResponse.CaptureAward.Xp)
                    {
                        totalExp += xp;
                    }
                    var profile = ctx.Client.Player.GetPlayer().Result;

                    evt.Exp = totalExp;
                    evt.Stardust = profile.PlayerData.Currencies.ToArray()[1].Amount;

                    var pokemonSettings = ctx.Inventory.GetPokemonSettings().Result;
                    var pokemonFamilies = ctx.Inventory.GetPokemonFamilies().Result;

                    var setting = pokemonSettings.FirstOrDefault(q => q.PokemonId == pokemon.PokemonId);
                    var family = pokemonFamilies.FirstOrDefault(q => q.FamilyId == setting.FamilyId);

                    if (family != null)
                    {
                        family.Candy += caughtPokemonResponse.CaptureAward.Candy.Sum();

                        evt.FamilyCandies = family.Candy;
                    }
                    else
                    {
                        evt.FamilyCandies = caughtPokemonResponse.CaptureAward.Candy.Sum();
                    }
                }

                if (encounter?.CaptureProbability?.CaptureProbability_ != null)
                {
                    evt.Id = pokemon.PokemonId;
                    evt.Level = PokemonInfo.GetLevel(encounter.WildPokemon?.PokemonData);
                    evt.Cp = encounter.WildPokemon?.PokemonData?.Cp ?? 0;
                    evt.MaxCp = PokemonInfo.CalculateMaxCp(encounter.WildPokemon?.PokemonData);
                    evt.Perfection =
                        Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter.WildPokemon?.PokemonData));
                    evt.Probability =
                        Math.Round(Convert.ToDouble(encounter.CaptureProbability?.CaptureProbability_.First())*100, 2);
                    evt.Distance = distance;
                    evt.Pokeball = pokeball;
                    evt.Attempt = attemptCounter;

                    machine.Fire(evt);
                }
                attemptCounter++;
                Thread.Sleep(2000);
            } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed ||
                     caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);
        }
Example #45
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken, dynamic encounter, MapPokemon pokemon,
            FortData currentFortData = null, ulong encounterId = 0)
        {
            AmountOfBerries = 0;
            cancellationToken.ThrowIfCancellationRequested();

            // If the encounter is null nothing will work below, so exit now
            if (encounter == null) return;

            float probability = encounter.CaptureProbability?.CaptureProbability_[0];

            // Check for pokeballs before proceeding
            var pokeball = await GetBestBall(session, encounter, probability);
            if (pokeball == ItemId.ItemUnknown) return;

            //Calculate CP and IV
            var pokemonCp = (encounter is EncounterResponse
                               ? encounter.WildPokemon?.PokemonData?.Cp
                               : encounter.PokemonData?.Cp);
            var pokemonIv = PokemonInfo.CalculatePokemonPerfection(encounter is EncounterResponse
                    ? encounter.WildPokemon?.PokemonData
                    : encounter?.PokemonData);

            // Calculate distance away
            var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                session.Client.CurrentLongitude,
                encounter is EncounterResponse || encounter is IncenseEncounterResponse
                    ? pokemon.Latitude
                    : currentFortData.Latitude,
                encounter is EncounterResponse || encounter is IncenseEncounterResponse
                    ? pokemon.Longitude
                    : currentFortData.Longitude);

            CatchPokemonResponse caughtPokemonResponse;
            var attemptCounter = 1;
            do
            {
                if ((session.LogicSettings.MaxPokeballsPerPokemon > 0 &&
                    attemptCounter > session.LogicSettings.MaxPokeballsPerPokemon))
                    break;

                pokeball = await GetBestBall(session, encounter, probability);
                if (pokeball == ItemId.ItemUnknown)
                {
                    session.EventDispatcher.Send(new NoPokeballEvent
                    {
                        Id = encounter is EncounterResponse ? pokemon.PokemonId : encounter?.PokemonData.PokemonId,
                        Cp =
                            (encounter is EncounterResponse
                                ? encounter.WildPokemon?.PokemonData?.Cp
                                : encounter?.PokemonData?.Cp) ?? 0
                    });
                    return;
                }

                // Determine whether to use berries or not
                if ((session.LogicSettings.UseBerriesOperator.ToLower().Equals("and") &&
                        pokemonIv >= session.LogicSettings.UseBerriesMinIv &&
                        pokemonCp >= session.LogicSettings.UseBerriesMinCp &&
                        probability < session.LogicSettings.UseBerriesBelowCatchProbability) ||
                    (session.LogicSettings.UseBerriesOperator.ToLower().Equals("or") && (
                        pokemonIv >= session.LogicSettings.UseBerriesMinIv ||
                        pokemonCp >= session.LogicSettings.UseBerriesMinCp ||
                        probability < session.LogicSettings.UseBerriesBelowCatchProbability)))
                {
                    
                    AmountOfBerries++;
                    if (AmountOfBerries <= session.LogicSettings.MaxBerriesToUsePerPokemon)
                    {
                        await
                       UseBerry(session,
                           encounter is EncounterResponse || encounter is IncenseEncounterResponse
                               ? pokemon.EncounterId
                               : encounterId,
                           encounter is EncounterResponse || encounter is IncenseEncounterResponse
                               ? pokemon.SpawnPointId
                               : currentFortData?.Id);
                    }
                   
                }

                //default to excellent throw
                var normalizedRecticleSize = 1.95;
                //default spin
                var spinModifier = 1.0;

                //Humanized throws
                if (session.LogicSettings.EnableHumanizedThrows)
                {
                    //thresholds: https://gist.github.com/anonymous/077d6dea82d58b8febde54ae9729b1bf
                    var spinTxt = "Curve";
                    var hitTxt = "Excellent";
                    if (pokemonCp > session.LogicSettings.ForceExcellentThrowOverCp ||
                        pokemonIv > session.LogicSettings.ForceExcellentThrowOverIv)
                    {
                        normalizedRecticleSize = Random.NextDouble() * (1.95 - 1.7) + 1.7;
                    }
                    else if (pokemonCp >= session.LogicSettings.ForceGreatThrowOverCp ||
                             pokemonIv >= session.LogicSettings.ForceGreatThrowOverIv)
                    {
                        normalizedRecticleSize = Random.NextDouble() * (1.95 - 1.3) + 1.3;
                        hitTxt = "Great";
                    }
                    else
                    {
                        var regularThrow = 100 - (session.LogicSettings.ExcellentThrowChance +
                                                  session.LogicSettings.GreatThrowChance +
                                                  session.LogicSettings.NiceThrowChance);
                        var rnd = Random.Next(1, 101);

                        if (rnd <= regularThrow)
                        {
                            normalizedRecticleSize = Random.NextDouble() * (1 - 0.1) + 0.1;
                            hitTxt = "Ordinary";
                        }
                        else if (rnd <= regularThrow + session.LogicSettings.NiceThrowChance)
                        {
                            normalizedRecticleSize = Random.NextDouble() * (1.3 - 1) + 1;
                            hitTxt = "Nice";
                        }
                        else if (rnd <=
                                 regularThrow + session.LogicSettings.NiceThrowChance +
                                 session.LogicSettings.GreatThrowChance)
                        {
                            normalizedRecticleSize = Random.NextDouble() * (1.7 - 1.3) + 1.3;
                            hitTxt = "Great";
                        }

                        if (Random.NextDouble() * 100 > session.LogicSettings.CurveThrowChance)
                        {
                            spinModifier = 0.0;
                            spinTxt = "Straight";
                        }
                    }

                    //round to 2 decimals
                    normalizedRecticleSize = Math.Round(normalizedRecticleSize, 2);

                    Logger.Write($"(Threw ball) {hitTxt} hit. {spinTxt}-ball...", LogLevel.Debug);
                }

                caughtPokemonResponse =
                    await session.Client.Encounter.CatchPokemon(
                        encounter is EncounterResponse || encounter is IncenseEncounterResponse
                            ? pokemon.EncounterId
                            : encounterId,
                        encounter is EncounterResponse || encounter is IncenseEncounterResponse
                            ? pokemon.SpawnPointId
                            : currentFortData.Id, pokeball, normalizedRecticleSize, spinModifier);

                var lat = encounter is EncounterResponse || encounter is IncenseEncounterResponse
                             ? pokemon.Latitude : currentFortData.Latitude;
                var lng = encounter is EncounterResponse || encounter is IncenseEncounterResponse
                            ? pokemon.Longitude : currentFortData.Longitude;
                var evt = new PokemonCaptureEvent()
                {
                    Status = caughtPokemonResponse.Status,
                    Latitude = lat,
                    Longitude = lng
                };

                if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess)
                {
                    var totalExp = 0;

                    foreach (var xp in caughtPokemonResponse.CaptureAward.Xp)
                    {
                        totalExp += xp;
                    }
                    var profile = await session.Client.Player.GetPlayer();

                    evt.Exp = totalExp;
                    evt.Stardust = profile.PlayerData.Currencies.ToArray()[1].Amount;
                    evt.UniqueId = caughtPokemonResponse.CapturedPokemonId;

                    var pokemonSettings = await session.Inventory.GetPokemonSettings();
                    var pokemonFamilies = await session.Inventory.GetPokemonFamilies();

                    var setting =
                        pokemonSettings.FirstOrDefault(q => pokemon != null && q.PokemonId == pokemon.PokemonId);
                    var family = pokemonFamilies.FirstOrDefault(q => setting != null && q.FamilyId == setting.FamilyId);

                    if (family != null)
                    {
                        family.Candy_ += caughtPokemonResponse.CaptureAward.Candy.Sum();

                        evt.FamilyCandies = family.Candy_;
                    }
                    else
                    {
                        evt.FamilyCandies = caughtPokemonResponse.CaptureAward.Candy.Sum();
                    }

                   
                }

                evt.CatchType = encounter is EncounterResponse
                    ? session.Translation.GetTranslation(TranslationString.CatchTypeNormal)
                    : encounter is DiskEncounterResponse
                        ? session.Translation.GetTranslation(TranslationString.CatchTypeLure)
                        : session.Translation.GetTranslation(TranslationString.CatchTypeIncense);
                evt.Id = encounter is EncounterResponse ? pokemon.PokemonId : encounter?.PokemonData.PokemonId;
                evt.Level =
                    PokemonInfo.GetLevel(encounter is EncounterResponse
                        ? encounter.WildPokemon?.PokemonData
                        : encounter?.PokemonData);
                evt.Cp = encounter is EncounterResponse
                    ? encounter.WildPokemon?.PokemonData?.Cp
                    : encounter?.PokemonData?.Cp ?? 0;
                evt.MaxCp =
                    PokemonInfo.CalculateMaxCp(encounter is EncounterResponse
                        ? encounter.WildPokemon?.PokemonData
                        : encounter?.PokemonData);
                evt.Perfection =
                    Math.Round(
                        PokemonInfo.CalculatePokemonPerfection(encounter is EncounterResponse
                            ? encounter.WildPokemon?.PokemonData
                            : encounter?.PokemonData));
                evt.Probability =
                    Math.Round(probability * 100, 2);
                evt.Distance = distance;
                evt.Pokeball = pokeball;
                evt.Attempt = attemptCounter;
                await session.Inventory.RefreshCachedInventory();
                evt.BallAmount = await session.Inventory.GetItemAmountByType(pokeball);

                session.EventDispatcher.Send(evt);

                attemptCounter++;
                if (session.LogicSettings.TransferDuplicatePokemonOnCapture && session.LogicSettings.TransferDuplicatePokemon)
                    await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                DelayingUtils.Delay(session.LogicSettings.DelayBetweenPokemonCatch, 0);
            } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed ||
                     caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);
        }
Example #46
0
 public async Task<EncounterResponse> EncounterPokemonAsync(MapPokemon pokemon)
 {
     var encounter = await _apiEncounter.EncounterPokemon(pokemon.EncounterId, pokemon.SpawnPointId);
     return encounter;
 }
Example #47
0
        private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon)
        {

            CatchPokemonResponse caughtPokemonResponse;
            do
            {
                var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault();
                if (probability.HasValue && probability.Value < 0.35 && encounter?.WildPokemon?.PokemonData?.Cp > 400)
                {
                    //Throw berry is we can
                    await UseBerry(pokemon.EncounterId, pokemon.SpawnpointId);
                }

                var pokeball = await GetBestBall(encounter?.WildPokemon);
                var distance = Navigation.DistanceBetween2Coordinates(_client.CurrentLat, _client.CurrentLng, pokemon.Latitude, pokemon.Longitude);
                caughtPokemonResponse = await _client.CatchPokemon(pokemon.EncounterId, pokemon.SpawnpointId, pokemon.Latitude, pokemon.Longitude, pokeball);
                Logger.Write(caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess ? $"(CATCH) {pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp} ({CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData).ToString("0.00")}% perfect) and CaptureProbability: {encounter?.CaptureProbability.CaptureProbability_.First()} using a {pokeball} in {Math.Round(distance)}m distance" : $"{pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp} CaptureProbability: {encounter?.CaptureProbability.CaptureProbability_.First()} in {Math.Round(distance)}m distance {caughtPokemonResponse.Status} while using a {pokeball}..", LogLevel.Info);
                await Task.Delay(2000);
            }
            while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape) ;
        }
Example #48
0
        private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon)
        {
            CatchPokemonResponse caughtPokemonResponse;
            var attemptCounter = 1;
            do
            {
                var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault();
                var bestPokeball = await GetBestBall(encounter);
                if (bestPokeball == MiscEnums.Item.ITEM_UNKNOWN)
                {
                    Logger.Write($"You don't own any Pokeballs :( - We missed a {pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp}", LogLevel.Warning);
                    return;
                }
                var bestBerry = await GetBestBerry(encounter);
                var inventoryBerries = await _inventory.GetItems();
                var berries = inventoryBerries.Where(p => (ItemId)p.Item_ == bestBerry).FirstOrDefault();
                if (bestBerry != ItemId.ItemUnknown && probability.HasValue && probability.Value < 0.35)
                {
                    await _client.UseCaptureItem(pokemon.EncounterId, bestBerry, pokemon.SpawnpointId);
                    berries.Count--;
                    Logger.Write($"{bestBerry} used, remaining: {berries.Count}", LogLevel.Berry);
                }

                var distance = LocationUtils.CalculateDistanceInMeters(_client.CurrentLat, _client.CurrentLng, pokemon.Latitude, pokemon.Longitude);
                caughtPokemonResponse = await _client.CatchPokemon(pokemon.EncounterId, pokemon.SpawnpointId, pokemon.Latitude, pokemon.Longitude, bestPokeball);

                if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess)
                {
                    foreach (var xp in caughtPokemonResponse.Scores.Xp)
                        _stats.AddExperience(xp);
                    _stats.IncreasePokemons();
                    var profile = await _client.GetProfile();
                    _stats.GetStardust(profile.Profile.Currency.ToArray()[1].Amount);
                }
                _stats.UpdateConsoleTitle(_client, _inventory);

                if (encounter?.CaptureProbability?.CaptureProbability_ != null)
                {
                    Func<MiscEnums.Item, string> returnRealBallName = a =>
                    {
                        switch (a)
                        {
                            case MiscEnums.Item.ITEM_POKE_BALL:
                                return "Poke";
                            case MiscEnums.Item.ITEM_GREAT_BALL:
                                return "Great";
                            case MiscEnums.Item.ITEM_ULTRA_BALL:
                                return "Ultra";
                            case MiscEnums.Item.ITEM_MASTER_BALL:
                                return "Master";
                            default:
                                return "Unknown";
                        }
                    };
                    var catchStatus = attemptCounter > 1
                        ? $"{caughtPokemonResponse.Status} Attempt #{attemptCounter}"
                        : $"{caughtPokemonResponse.Status}";

                    string receivedXP = catchStatus == "CatchSuccess" 
                        ? $"and received XP {caughtPokemonResponse.Scores.Xp.Sum()}" 
                        : $"";

                    Logger.Write($"({catchStatus}) | {pokemon.PokemonId} - Lvl {PokemonInfo.GetLevel(encounter?.WildPokemon?.PokemonData)} [CP {encounter?.WildPokemon?.PokemonData?.Cp}/{PokemonInfo.CalculateMaxCP(encounter?.WildPokemon?.PokemonData)} | IV: {Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData)).ToString("0.00")}% perfect] | Chance: {(float)((int)(encounter?.CaptureProbability?.CaptureProbability_.First() * 100)) / 100} | {distance:0.##}m dist | with a {returnRealBallName(bestPokeball)}Ball {receivedXP}", LogLevel.Pokemon);
                }

                attemptCounter++;
            }
            while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);
        }