Beispiel #1
0
        public static void AddSnipeItem(ISession session, MSniperInfo2 item, bool byPassValidation = false)
        {
            if (OutOffBallBlock > DateTime.Now ||
                autoSnipePokemons.Exists(x => x.EncounterId == item.EncounterId) ||
                session.Cache[item.EncounterId.ToString()] != null)
            {
                return;
            }

            if (byPassValidation)
            {
                autoSnipePokemons.Add(item);
                Logger.Write("Manual snipe item queued");
                return;
            }
            item.Iv = Math.Round(item.Iv, 2);
            SnipeFilter filter = new SnipeFilter()
            {
                SnipeIV = session.LogicSettings.MinIVForAutoSnipe
            };

            var pokemonId = (PokemonId)item.PokemonId;

            if (session.LogicSettings.PokemonSnipeFilters.ContainsKey(pokemonId))
            {
                filter = session.LogicSettings.PokemonSnipeFilters[pokemonId];
            }
            //hack, this case we can't determite move :)

            if (filter.SnipeIV < item.Iv && item.Move1 == PokemonMove.Absorb && item.Move2 == PokemonMove.Absorb)
            {
                autoSnipePokemons.Add(item);
                return;
            }
            //ugly but readable
            if ((string.IsNullOrEmpty(filter.Operator) || filter.Operator == Operator.or.ToString()) &&
                (filter.SnipeIV < item.Iv ||
                 (filter.Moves != null &&
                  filter.Moves.Count > 0 &&
                  filter.Moves.Any(x => x[0] == item.Move1 && x[1] == item.Move2))
                ))

            {
                autoSnipePokemons.Add(item);
            }

            if (filter.Operator == Operator.and.ToString() &&
                (filter.SnipeIV < item.Iv &&
                 (filter.Moves != null &&
                  filter.Moves.Count > 0 &&
                  filter.Moves.Any(x => x[0] == item.Move1 && x[1] == item.Move2))
                ))
            {
                autoSnipePokemons.Add(item);
            }
        }
Beispiel #2
0
 public static async Task <bool> CatchWithSnipe(ISession session, MSniperInfo2 encounterId,
                                                CancellationToken cancellationToken)
 {
     cancellationToken.ThrowIfCancellationRequested();
     return(await SnipePokemonTask.Snipe(
                session,
                new List <PokemonId>() { (PokemonId)encounterId.PokemonId },
                encounterId.Latitude,
                encounterId.Longitude,
                cancellationToken
                ));
 }
 public static async Task <bool> CatchWithSnipe(ISession session, MSniperInfo2 encounterId,
                                                CancellationToken cancellationToken)
 {
     cancellationToken.ThrowIfCancellationRequested();
     TinyIoC.TinyIoCContainer.Current.Resolve <MultiAccountManager>().ThrowIfSwitchAccountRequested();
     return(await SnipePokemonTask.Snipe(
                session,
                new List <PokemonId>() { (PokemonId)encounterId.PokemonId },
                encounterId.Latitude,
                encounterId.Longitude,
                cancellationToken
                ));
 }
        //private static void Msocket_MessageReceived(object sender, MessageReceivedEventArgs e)
        //{
        //    try
        //    {
        //        SocketCmd cmd = e.GetSocketCmd();
        //        switch (cmd)
        //        {
        //            case SocketCmd.IpLimit:
        //                Logger.Write("(IpLimit) " + e.GetSocketData().First(), LogLevel.Service, ConsoleColor.Red);
        //                break;
        //            case SocketCmd.ServerLimit:
        //                Logger.Write("(ServerLimit) " + e.GetSocketData().First(), LogLevel.Service, ConsoleColor.Red);
        //                break;
        //            case SocketCmd.Identity://first request
        //                UserUniequeId = e.GetSocketData().First();
        //                SendToMSniperServer(UserUniequeId);//confirm
        //                Logger.Write($"(Identity) [ {UserUniequeId} ] connection establisted", LogLevel.Service);
        //                break;

        //            case SocketCmd.PokemonCount://server asks what is in your hand (every 3 minutes)
        //                RefreshLocationQueue();
        //                var x = LocationQueue.GroupBy(p => p.PokemonName)
        //                    .Select(s => new PokemonCount { PokemonId = s.First().GetPokemonName(), Count = s.Count() })
        //                    .ToList();
        //                SendToMSniperServer(JsonConvert.SerializeObject(x));
        //                break;

        //            case SocketCmd.SendPokemon://sending encounters
        //                RefreshLocationQueue();
        //                LocationQueue = LocationQueue.OrderByDescending(p => p.Iv).ToList();
        //                int rq = 1;
        //                if (LocationQueue.Count < int.Parse(e.GetSocketData().First()))
        //                {
        //                    rq = LocationQueue.Count;
        //                }
        //                else
        //                {
        //                    rq = int.Parse(e.GetSocketData().First());
        //                }
        //                var selected = LocationQueue.GetRange(0, rq);
        //                SendToMSniperServer(JsonConvert.SerializeObject(selected));
        //                AddToVisited(selected.Select(p => p.GetEncounterId()).ToList());
        //                LocationQueue.RemoveRange(0, rq);
        //                break;

        //            case SocketCmd.SendOneSpecies://server needs one type pokemon
        //                RefreshLocationQueue();
        //                PokemonId speciesId = (PokemonId)Enum.Parse(typeof(PokemonId), e.GetSocketData().First());
        //                int requestCount = int.Parse(e.GetSocketData()[1]);
        //                var onespecies = LocationQueue.Where(p => p.GetPokemonName() == speciesId).ToList();
        //                onespecies = onespecies.OrderByDescending(p => p.Iv).ToList();
        //                if (onespecies.Count > 0)
        //                {
        //                    List<EncounterInfo> oneType;
        //                    if (onespecies.Count > requestCount)
        //                    {
        //                        oneType = LocationQueue.GetRange(0, requestCount);
        //                        AddToVisited(oneType.Select(p => p.GetEncounterId()).ToList());
        //                        LocationQueue.RemoveRange(0, requestCount);
        //                    }
        //                    else
        //                    {
        //                        oneType = LocationQueue.GetRange(0, LocationQueue.Count);
        //                        LocationQueue.Clear();
        //                    }
        //                    SendToMSniperServer(JsonConvert.SerializeObject(oneType));
        //                }
        //                break;

        //            case SocketCmd.Brodcaster://receiving encounter information from server

        //                //// disabled fornow
        //                //var xcoming = JsonConvert.DeserializeObject<List<EncounterInfo>>(e.GetSocketData().First());
        //                //xcoming = FindNew(xcoming);
        //                //ReceivedPokemons.AddRange(xcoming);
        //                //
        //                //RefreshReceivedPokemons();
        //                //TimeSpan ts = DateTime.Now - lastNotify;
        //                //if (ts.TotalMinutes >= 5)
        //                //{
        //                //    Logger.Write($"total active spawns:[ {ReceivedPokemons.Count} ]", LogLevel.Service);
        //                //    lastNotify = DateTime.Now;
        //                //}
        //                break;
        //            case SocketCmd.None:
        //                Logger.Write("UNKNOWN ERROR", LogLevel.Service, ConsoleColor.Red);
        //                //throw Exception
        //                break;
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        socket.Close();
        //        Logger.Write(ex.Message, LogLevel.Service, ConsoleColor.Red);
        //        //throw ex;
        //    }
        //}
        //private static void RefreshReceivedPokemons()
        //{
        //    var pkmns = ReceivedPokemons
        //        .Where(p => TimeStampToDateTime(p.Expiration) > DateTime.Now)
        //        .ToList();
        //    ReceivedPokemons.Clear();
        //    ReceivedPokemons.AddRange(pkmns);
        //}
        //private static void SendToMSniperServer(string message)
        //{
        //    try
        //    {
        //        socket.Send($"{message}");
        //    }
        //    catch (Exception ex)
        //    {
        //        socket.Close();
        //        Logger.Write(ex.Message, LogLevel.Service, ConsoleColor.Red);
        //        //throw ex;
        //    }
        //}
        #endregion
        public static void AddSnipeItem(ISession session, MSniperInfo2 item)
        {
            if (OutOffBallBlock > DateTime.Now)
            {
                return;
            }

            SnipeFilter filter = new SnipeFilter()
            {
                SnipeIV = session.LogicSettings.MinIVForAutoSnipe
            };

            var pokemonId = (PokemonId)item.PokemonId;

            if (session.LogicSettings.PokemonSnipeFilters.ContainsKey(pokemonId))
            {
                filter = session.LogicSettings.PokemonSnipeFilters[pokemonId];
            }
            //hack, this case we can't determite move :)

            if (filter.SnipeIV < item.Iv && item.Move1 == PokemonMove.Absorb && item.Move2 == PokemonMove.Absorb)
            {
                autoSnipePokemons.Add(item);
                return;
            }
            //ugly but readable
            if ((string.IsNullOrEmpty(filter.Operator) || filter.Operator == Operator.or.ToString()) &&
                (filter.SnipeIV < item.Iv ||
                 (filter.Moves != null &&
                  filter.Moves.Count > 0 &&
                  filter.Moves.Any(x => x[0] == item.Move1 && x[1] == item.Move2))
                ))

            {
                autoSnipePokemons.Add(item);
            }

            if (filter.Operator == Operator.and.ToString() &&
                (filter.SnipeIV < item.Iv &&
                 (filter.Moves != null &&
                  filter.Moves.Count > 0 &&
                  filter.Moves.Any(x => x[0] == item.Move1 && x[1] == item.Move2))
                ))
            {
                autoSnipePokemons.Add(item);
            }
        }
        public static bool AddSnipeItem(ISession session, MSniperInfo2 item, bool byPassValidation = false)
        {
            if (isBlocking)
            {
                return(false);
            }
            //this pokemon has been recorded as expires
            if (item.EncounterId > 0 && expiredCache.Get(item.EncounterId.ToString()) != null)
            {
                return(false);
            }

            //fake & annoy data
            if (Math.Abs(item.Latitude) > 90 || Math.Abs(item.Longitude) > 180 || item.Iv > 100)
            {
                return(false);
            }

            lock (locker)
            {
                Func <MSniperInfo2, bool> checkExisting = (MSniperInfo2 x) =>
                {
                    return((x.EncounterId > 0 && x.EncounterId == item.EncounterId) ||
                           (x.EncounterId == 0 && Math.Round(x.Latitude, 6) == Math.Round(item.Latitude, 6) &&
                            Math.Round(x.Longitude, 6) == Math.Round(item.Longitude, 6) &&
                            x.PokemonId == item.PokemonId));
                };

                //remove existing item that
                autoSnipePokemons.RemoveAll(x => checkExisting(x));
                pokedexSnipePokemons.RemoveAll(x => checkExisting(x));
                manualSnipePokemons.RemoveAll(x => checkExisting(x));
            }

            if (!byPassValidation &&
                session.LogicSettings.AutoSnipeMaxDistance > 0 &&
                LocationUtils.CalculateDistanceInMeters(session.Settings.DefaultLatitude, session.Settings.DefaultLongitude, item.Latitude, item.Longitude) > session.LogicSettings.AutoSnipeMaxDistance * 1000)
            {
                return(false);
            }

            lock (locker)
            {
                item.AddedTime = DateTime.Now;
                //just keep pokemon in last 2 min
                autoSnipePokemons.RemoveAll(x => x.AddedTime.AddSeconds(SNIPE_SAFE_TIME) < DateTime.Now);
                pokedexSnipePokemons.RemoveAll(x => x.AddedTime.AddMinutes(SNIPE_SAFE_TIME) < DateTime.Now);
            }
            if (OutOffBallBlock > DateTime.Now ||
                autoSnipePokemons.Exists(x => x.EncounterId == item.EncounterId && item.EncounterId > 0) ||
                (item.EncounterId > 0 && session.Cache[item.EncounterId.ToString()] != null) ||
                (session.LogicSettings.SnipeIgnoreUnknownIv && item.Iv == 0 && !byPassValidation))
            {
                return(false);
            }

            item.Iv = Math.Round(item.Iv, 2);
            if (session.LogicSettings.SnipePokemonNotInPokedex)
            {
                //sometime the API return pokedex not correct, we need cahe this list, need lean everyetime peopellogi
                var pokedex = session.Inventory.GetPokeDexItems().Select(x => x.InventoryItemData?.PokedexEntry?.PokemonId).Where(x => x != null).ToList();
                var update  = pokedex.Where(x => !pokedexList.Contains(x.Value)).ToList();

                pokedexList.AddRange(update.Select(x => x.Value));

                //Logger.Debug($"Pokedex Entry : {pokedexList.Count()}");

                if (pokedexList.Count > 0 &&
                    !pokedexList.Exists(x => x == (PokemonId)item.PokemonId) &&
                    !pokedexSnipePokemons.Exists(p => p.PokemonId == item.PokemonId) &&
                    (!session.LogicSettings.AutosnipeVerifiedOnly ||
                     (session.LogicSettings.AutosnipeVerifiedOnly && item.IsVerified())))
                {
                    session.EventDispatcher.Send(new WarnEvent()
                    {
                        Message = session.Translation.GetTranslation(TranslationString.SnipePokemonNotInPokedex,
                                                                     session.Translation.GetPokemonTranslation((PokemonId)item.PokemonId))
                    });
                    item.Priority = 0;
                    pokedexSnipePokemons.Add(item); //Add as hight priority snipe entry
                    return(true);
                }
            }
            var         pokemonId = (PokemonId)item.PokemonId;
            SnipeFilter filter    = session.LogicSettings.PokemonSnipeFilters.GetFilter <SnipeFilter>(pokemonId);

            lock (locker)
            {
                if (byPassValidation)
                {
                    item.Priority = -1;
                    manualSnipePokemons.Add(item);

                    Logger.Write($"(MANUAL SNIPER) Pokemon added |  {(PokemonId)item.PokemonId} [{item.Latitude},{item.Longitude}] IV {item.Iv}%");
                    return(true);
                }

                item.Priority = filter.Priority;

                if (filter.VerifiedOnly && item.EncounterId == 0)
                {
                    return(false);
                }

                //check candy
                int candy = session.Inventory.GetCandyCount(pokemonId);
                if (candy < filter.AutoSnipeCandy)
                {
                    autoSnipePokemons.Add(item);
                    return(true);
                }

                if (filter.IsMatch(item.Iv, item.Move1, item.Move2, item.Level, item.EncounterId > 0))
                {
                    autoSnipePokemons.Add(item);
                    return(true);
                }
            }
            return(false);
        }
        public static async Task <bool> CatchFromService(ISession session,
                                                         CancellationToken cancellationToken, MSniperInfo2 encounterId)
        {
            cancellationToken.ThrowIfCancellationRequested();
            double originalLat = session.Client.CurrentLatitude;
            double originalLng = session.Client.CurrentLongitude;

            EncounterResponse encounter;

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


                await session.Client.Misc.RandomAPICall();

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

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

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

                return(false);
            }

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

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

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

            return(await CatchPokemonTask.Execute(
                       session, cancellationToken, encounter, pokemon, currentFortData : null, sessionAllowTransfer : true
                       ));
        }
Beispiel #7
0
        public static async Task <bool> AddSnipeItem(ISession session, MSniperInfo2 item, bool byPassValidation = false)
        {
            if (isBlocking)
            {
                return(false);
            }
            if (Math.Abs(item.Latitude) > 90 || Math.Abs(item.Longitude) > 180)
            {
                return(false);
            }

            if (!byPassValidation &&
                session.LogicSettings.AutoSnipeMaxDistance > 0 &&
                LocationUtils.CalculateDistanceInMeters(session.Settings.DefaultLatitude, session.Settings.DefaultLongitude, item.Latitude, item.Longitude) > session.LogicSettings.AutoSnipeMaxDistance * 1000)
            {
                return(false);
            }

            lock (locker)
            {
                item.AddedTime = DateTime.Now;
                //just keep pokemon in last 2 min
                autoSnipePokemons.RemoveAll(x => x.AddedTime.AddSeconds(SNIPE_SAFE_TIME) <
                                            DateTime
                                            .Now);          // || (x.ExpiredTime > 0 && x.ExpiredTime < DateTime.Now.ToUnixTime()));
                pokedexSnipePokemons.RemoveAll(x => x.AddedTime.AddMinutes(2) < DateTime.Now);
            }
            if (OutOffBallBlock > DateTime.Now ||
                autoSnipePokemons.Exists(x => x.EncounterId == item.EncounterId && item.EncounterId > 0) ||
                (item.EncounterId > 0 && session.Cache[item.EncounterId.ToString()] != null) ||
                (session.LogicSettings.SnipeIgnoreUnknownIv && item.Iv == 0 && !byPassValidation))
            {
                return(false);
            }

            item.Iv = Math.Round(item.Iv, 2);
            if (session.LogicSettings.SnipePokemonNotInPokedex)
            {
                var pokedex = await session.Inventory.GetPokeDexItems();

                if (!pokedex.Exists(x => x.InventoryItemData?.PokedexEntry?.PokemonId == (PokemonId)item.PokemonId) &&
                    !pokedexSnipePokemons.Exists(p => p.PokemonId == item.PokemonId) &&
                    (!session.LogicSettings.AutosnipeVerifiedOnly ||
                     (session.LogicSettings.AutosnipeVerifiedOnly &&
                      (item.EncounterId > 0 || (item.Move1 != PokemonMove.MoveUnset &&
                                                item.Move2 != PokemonMove.MoveUnset)))))
                {
                    session.EventDispatcher.Send(new WarnEvent()
                    {
                        Message = session.Translation.GetTranslation(TranslationString.SnipePokemonNotInPokedex,
                                                                     session.Translation.GetPokemonTranslation((PokemonId)item.PokemonId))
                    });
                    item.Priority = 0;
                    pokedexSnipePokemons.Add(item); //Add as hight priority snipe entry
                    return(true);
                }
            }
            SnipeFilter filter = new SnipeFilter()
            {
                SnipeIV         = session.LogicSettings.MinIVForAutoSnipe,
                VerifiedOnly    = session.LogicSettings.AutosnipeVerifiedOnly,
                AustoSnipeCandy = session.LogicSettings.DefaultAutoSnipeCandy
            };

            var pokemonId = (PokemonId)item.PokemonId;

            if (session.LogicSettings.PokemonSnipeFilters.ContainsKey(pokemonId))
            {
                filter = session.LogicSettings.PokemonSnipeFilters[pokemonId];
            }

            var candy = session.Inventory.GetCandy(pokemonId);

            lock (locker)
            {
                if (byPassValidation)
                {
                    item.Priority = -1;
                    manualSnipePokemons.Add(item);

                    Logger.Write($"(MANUAL SNIPER) Pokemon added |  {(PokemonId)item.PokemonId} [{item.Latitude},{item.Longitude}] IV {item.Iv}%");
                    return(true);
                }

                item.Priority = filter.Priority;

                if (filter.VerifiedOnly && item.EncounterId == 0)
                {
                    return(false);
                }
                //check candy

                if (candy < filter.AustoSnipeCandy)
                {
                    autoSnipePokemons.Add(item);
                    return(true);
                }

                //if not verified and undetermine move.
                if (filter.SnipeIV <= item.Iv &&
                    item.Move1 == PokemonMove.MoveUnset && item.Move2 == PokemonMove.MoveUnset &&
                    (filter.Moves == null || filter.Moves.Count == 0))
                {
                    autoSnipePokemons.Add(item);
                    return(true);
                }
                //ugly but readable
                if ((string.IsNullOrEmpty(filter.Operator) || filter.Operator == Operator.or.ToString()) &&
                    (filter.SnipeIV <= item.Iv ||
                     (filter.Moves != null &&
                      filter.Moves.Count > 0 &&
                      filter.Moves.Any(x => x[0] == item.Move1 && x[1] == item.Move2))
                    ))

                {
                    autoSnipePokemons.Add(item);
                    return(true);
                }

                if (filter.Operator == Operator.and.ToString() &&
                    (filter.SnipeIV <= item.Iv &&
                     (filter.Moves != null &&
                      filter.Moves.Count > 0 &&
                      filter.Moves.Any(x => x[0] == item.Move1 && x[1] == item.Move2))
                    ))
                {
                    autoSnipePokemons.Add(item);
                    return(true);
                }
            }
            return(false);
        }
Beispiel #8
0
        public static async Task <bool> CatchFromService(ISession session,
                                                         CancellationToken cancellationToken, MSniperInfo2 encounterId)
        {
            cancellationToken.ThrowIfCancellationRequested();

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

            bool captchaShowed = false;
            EncounterResponse encounter;

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

                await Task.Delay(1000, cancellationToken);

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

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

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

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

                return(false);
            }
            PokemonData encounteredPokemon;

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

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

            return(await CatchPokemonTask.Execute(
                       session, cancellationToken, encounter, pokemon, currentFortData : null, sessionAllowTransfer : true
                       ));
        }
        public static async Task 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);
            }
            finally
            {
                await LocationUtils.UpdatePlayerLocationWithAltitude(session,
                                                                     new GeoCoordinate(lat, lon, session.Client.CurrentAltitude), 0); // Speed set to 0 for random speed.
            }

            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;// No success to work with
            }

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

            await CatchPokemonTask.Execute(session, cancellationToken, encounter, pokemon, currentFortData : null, sessionAllowTransfer : true);
        }
Beispiel #10
0
        public static async Task <bool> SnipeUnverifiedPokemon(ISession session, MSniperInfo2 sniperInfo, CancellationToken cancellationToken)
        {
            var latitude  = sniperInfo.Latitude;
            var longitude = sniperInfo.Longitude;

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

            var catchedPokemon = false;

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

            MapPokemon catchablePokemon;
            int        retry = 3;

            bool useWalk = session.LogicSettings.EnableHumanWalkingSnipe;

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

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

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

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

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

                try
                {
                    do
                    {
                        retry--;

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

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

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

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

                    return(false);
                }

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

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

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

                        break;

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

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

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

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

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

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

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

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

            var catchedPokemon = false;

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

            MapPokemon catchablePokemon;
            int        retry = 3;

            bool isCaptchaShow = false;

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

                    latitude  += 0.00000001;
                    longitude += 0.00000001;

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

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

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

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

                return(false);
            }

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

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

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

                    break;

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

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

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

            if (catchedPokemon)
            {
                session.Stats.SnipeCount++;
            }
            session.EventDispatcher.Send(new SnipeModeEvent {
                Active = false
            });
            return(true);
            //await Task.Delay(session.LogicSettings.DelayBetweenPlayerActions, cancellationToken).ConfigureAwait(false);
        }
Beispiel #12
0
        public static bool AddSnipeItem(ISession session, MSniperInfo2 item, bool byPassValidation = false)
        {
            if (isBlocking)
            {
                return(false);
            }
            //this pokemon has been recorded as expires
            if (item.EncounterId > 0 && expiredCache.Get(item.EncounterId.ToString()) != null)
            {
                return(false);
            }

            //fake & annoy data
            if (Math.Abs(item.Latitude) > 90 || Math.Abs(item.Longitude) > 180)
            {
                return(false);
            }

            lock (locker)
            {
                Func <MSniperInfo2, bool> checkExisting = (MSniperInfo2 x) => {
                    return((x.EncounterId > 0 && x.EncounterId == item.EncounterId) ||
                           (x.EncounterId == 0 && Math.Round(x.Latitude, 6) == Math.Round(item.Latitude, 6) &&
                            Math.Round(x.Longitude, 6) == Math.Round(item.Longitude, 6) &&
                            x.PokemonId == item.PokemonId));
                };

                //remove existing item that
                autoSnipePokemons.RemoveAll(x => checkExisting(x));
                pokedexSnipePokemons.RemoveAll(x => checkExisting(x));
                manualSnipePokemons.RemoveAll(x => checkExisting(x));
            }

            if (!byPassValidation &&
                session.LogicSettings.AutoSnipeMaxDistance > 0 &&
                LocationUtils.CalculateDistanceInMeters(session.Settings.DefaultLatitude, session.Settings.DefaultLongitude, item.Latitude, item.Longitude) > session.LogicSettings.AutoSnipeMaxDistance * 1000)
            {
                return(false);
            }

            lock (locker)
            {
                item.AddedTime = DateTime.Now;
                //just keep pokemon in last 2 min
                autoSnipePokemons.RemoveAll(x => x.AddedTime.AddSeconds(SNIPE_SAFE_TIME) < DateTime.Now);
                pokedexSnipePokemons.RemoveAll(x => x.AddedTime.AddMinutes(SNIPE_SAFE_TIME) < DateTime.Now);
            }
            if (OutOffBallBlock > DateTime.Now ||
                autoSnipePokemons.Exists(x => x.EncounterId == item.EncounterId && item.EncounterId > 0) ||
                (item.EncounterId > 0 && session.Cache[item.EncounterId.ToString()] != null) ||
                (session.LogicSettings.SnipeIgnoreUnknownIv && item.Iv == 0 && !byPassValidation))
            {
                return(false);
            }

            item.Iv = Math.Round(item.Iv, 2);
            if (session.LogicSettings.SnipePokemonNotInPokedex)
            {
                var pokedex = session.Inventory.GetPokeDexItems();

                if (!pokedex.Exists(x => x.InventoryItemData?.PokedexEntry?.PokemonId == (PokemonId)item.PokemonId) &&
                    !pokedexSnipePokemons.Exists(p => p.PokemonId == item.PokemonId) &&
                    (!session.LogicSettings.AutosnipeVerifiedOnly ||
                     (session.LogicSettings.AutosnipeVerifiedOnly &&
                      (item.EncounterId > 0 || (item.Move1 != PokemonMove.MoveUnset &&
                                                item.Move2 != PokemonMove.MoveUnset)))))
                {
                    session.EventDispatcher.Send(new WarnEvent()
                    {
                        Message = session.Translation.GetTranslation(TranslationString.SnipePokemonNotInPokedex,
                                                                     session.Translation.GetPokemonTranslation((PokemonId)item.PokemonId))
                    });
                    item.Priority = 0;
                    pokedexSnipePokemons.Add(item); //Add as hight priority snipe entry
                    return(true);
                }
            }
            SnipeFilter filter = new SnipeFilter()
            {
                SnipeIV        = session.LogicSettings.MinIVForAutoSnipe,
                VerifiedOnly   = session.LogicSettings.AutosnipeVerifiedOnly,
                AutoSnipeCandy = session.LogicSettings.DefaultAutoSnipeCandy,
                Level          = 0
            };

            var pokemonId = (PokemonId)item.PokemonId;

            if (session.LogicSettings.PokemonSnipeFilters.ContainsKey(pokemonId))
            {
                filter = session.LogicSettings.PokemonSnipeFilters[pokemonId];
            }

            lock (locker)
            {
                if (byPassValidation)
                {
                    item.Priority = -1;
                    manualSnipePokemons.Add(item);

                    Logger.Write($"(MANUAL SNIPER) Pokemon added |  {(PokemonId)item.PokemonId} [{item.Latitude},{item.Longitude}] IV {item.Iv}%");
                    return(true);
                }

                item.Priority = filter.Priority;

                if (filter.VerifiedOnly && item.EncounterId == 0)
                {
                    return(false);
                }

                //check candy
                int candy = session.Inventory.GetCandyCount(pokemonId);
                if (candy < filter.AutoSnipeCandy)
                {
                    autoSnipePokemons.Add(item);
                    return(true);
                }

                if (filter.IsMatch(item.Iv, item.Move1, item.Move2, item.Level, item.EncounterId > 0))
                {
                    autoSnipePokemons.Add(item);
                    return(true);
                }
            }
            return(false);
        }