Ejemplo n.º 1
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            TinyIoC.TinyIoCContainer.Current.Resolve <MultiAccountManager>().ThrowIfSwitchAccountRequested();
            cancellationToken.ThrowIfCancellationRequested();
            if (!session.LogicSettings.CatchPokemon || session.CatchBlockTime > DateTime.Now)
            {
                return;
            }

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

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

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

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

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

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

                    if (encounter.Result == IncenseEncounterResponse.Types.Result.IncenseEncounterSuccess &&
                        session.LogicSettings.CatchPokemon)
                    {
                        //await CatchPokemonTask.Execute(session, cancellationToken, encounter, pokemon).ConfigureAwait(false);
                        await CatchPokemonTask.Execute(session, cancellationToken, encounter, pokemon,
                                                       currentFortData : null, sessionAllowTransfer : true).ConfigureAwait(false);
                    }
                    else if (encounter.Result == IncenseEncounterResponse.Types.Result.PokemonInventoryFull)
                    {
                        if (session.LogicSettings.TransferDuplicatePokemon || session.LogicSettings.TransferWeakPokemon)
                        {
                            session.EventDispatcher.Send(new WarnEvent
                            {
                                Message = session.Translation.GetTranslation(TranslationString.InvFullTransferring)
                            });
                            if (session.LogicSettings.TransferDuplicatePokemon)
                            {
                                await TransferDuplicatePokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                            }
                            if (session.LogicSettings.TransferWeakPokemon)
                            {
                                await TransferWeakPokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                            }
                            if (EvolvePokemonTask.IsActivated(session))
                            {
                                await EvolvePokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                            }
                        }
                        else
                        {
                            session.EventDispatcher.Send(new WarnEvent
                            {
                                Message = session.Translation.GetTranslation(TranslationString.InvFullTransferManually)
                            });
                        }
                    }
                    else
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message =
                                session.Translation.GetTranslation(TranslationString.EncounterProblem, encounter.Result)
                        });
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken,
                                         FortData originalPokestop, FortDetailsResponse fortInfo)
        {
            StartAsyncPollingTask(session, cancellationToken);

            pokestopCount++;
            pokestopCount = pokestopCount % 3;

            if (pokestopCount > 0 && !prioritySnipeFlag)
            {
                return;
            }

            InitSession(session);
            if (!_setting.CatchPokemon && !prioritySnipeFlag)
            {
                return;
            }

            cancellationToken.ThrowIfCancellationRequested();

            if (_setting.HumanWalkingSnipeTryCatchEmAll)
            {
                var checkBall = await CheckPokeballsToSnipe(_setting.HumanWalkingSnipeCatchEmAllMinBalls, session,
                                                            cancellationToken).ConfigureAwait(false);

                if (!checkBall && !prioritySnipeFlag)
                {
                    return;
                }
            }

            bool             caughtAnyPokemonInThisWalk = false;
            SnipePokemonInfo pokemon = null;

            do
            {
                cancellationToken.ThrowIfCancellationRequested();
                TinyIoC.TinyIoCContainer.Current.Resolve <MultiAccountManager>().ThrowIfSwitchAccountRequested();
                prioritySnipeFlag = false;
                pokemon           = await GetNextSnipeablePokemon(session.Client.CurrentLatitude, session.Client.CurrentLongitude,
                                                                  !caughtAnyPokemonInThisWalk).ConfigureAwait(false);

                if (pokemon != null)
                {
                    caughtAnyPokemonInThisWalk = true;
                    CalculateDistanceAndEstTime(pokemon);
                    var remainTimes = (pokemon.ExpiredTime - DateTime.Now).TotalSeconds * 0.95; //just use 90% times

                    //assume that 100m we catch 1 pokemon and it took 10 second for each.
                    var catchPokemonTimeEST =
                        (pokemon.Distance / 100) * 10;
                    string strPokemon      = session.Translation.GetPokemonTranslation(pokemon.PokemonId);
                    var    spinPokestopEST = (pokemon.Distance / 100) * 5;

                    bool catchPokemon = (pokemon.EstimatedTime + catchPokemonTimeEST) < remainTimes &&
                                        pokemon.Setting.CatchPokemonWhileWalking;
                    bool spinPokestop = pokemon.Setting.SpinPokestopWhileWalking &&
                                        (pokemon.EstimatedTime + catchPokemonTimeEST + spinPokestopEST) < remainTimes;
                    lock (threadLocker)
                    {
                        pokemon.IsCatching = true;
                    }
                    session.EventDispatcher.Send(new HumanWalkSnipeEvent()
                    {
                        PokemonId        = pokemon.PokemonId,
                        Latitude         = pokemon.Latitude,
                        Longitude        = pokemon.Longitude,
                        Distance         = pokemon.Distance,
                        Expires          = (pokemon.ExpiredTime - DateTime.Now).TotalSeconds,
                        Estimate         = (int)pokemon.EstimatedTime,
                        Setting          = pokemon.Setting,
                        CatchPokemon     = catchPokemon,
                        Pokemons         = ApplyFilter(rarePokemons.ToList()),
                        SpinPokeStop     = pokemon.Setting.SpinPokestopWhileWalking,
                        WalkSpeedApplied = pokemon.Setting.AllowSpeedUp
                            ? pokemon.Setting.MaxSpeedUpSpeed
                            : _session.LogicSettings.WalkingSpeedInKilometerPerHour,
                        Type   = HumanWalkSnipeEventTypes.StartWalking,
                        Rarity = PokemonGradeHelper.GetPokemonGrade(pokemon.PokemonId).ToString()
                    });
                    var snipeTarget = new SnipeLocation(pokemon.Latitude, pokemon.Longitude,
                                                        await LocationUtils.GetElevation(session.ElevationService, pokemon.Latitude, pokemon.Longitude).ConfigureAwait(false));

                    await session.Navigation.Move(
                        snipeTarget,
                        async() =>
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        await ActionsWhenTravelToSnipeTarget(session, cancellationToken, pokemon, catchPokemon, spinPokestop).ConfigureAwait(false);
                    },
                        session,
                        cancellationToken,
                        pokemon.Setting.AllowSpeedUp?pokemon.Setting.MaxSpeedUpSpeed : 0
                        ).ConfigureAwait(false);

                    session.EventDispatcher.Send(new HumanWalkSnipeEvent()
                    {
                        Latitude      = pokemon.Latitude,
                        Longitude     = pokemon.Longitude,
                        PauseDuration = pokemon.Setting.DelayTimeAtDestination / 1000,
                        Type          = HumanWalkSnipeEventTypes.DestinationReached,
                        UniqueId      = pokemon.UniqueId
                    });

                    //await Task.Delay(pokemon.Setting.DelayTimeAtDestination, cancellationToken).ConfigureAwait(false);
                    await CatchNearbyPokemonsTask
                    .Execute(session, cancellationToken, pokemon.PokemonId, pokemon.Setting.AllowTransferWhileWalking).ConfigureAwait(false);

                    await Task.Delay(1000, cancellationToken).ConfigureAwait(false);

                    if (!pokemon.IsVisited)
                    {
                        await CatchLurePokemonsTask.Execute(session, cancellationToken).ConfigureAwait(false);
                    }

                    lock (threadLocker)
                    {
                        pokemon.IsVisited  = true;
                        pokemon.IsCatching = false;
                    }

                    if (session.LogicSettings.TransferDuplicatePokemon)
                    {
                        await TransferDuplicatePokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                    }

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

                    if (EvolvePokemonTask.IsActivated(session))
                    {
                        await EvolvePokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                    }
                }
            } while (pokemon != null && _setting.HumanWalkingSnipeTryCatchEmAll);

            if (caughtAnyPokemonInThisWalk && (!_setting.HumanWalkingSnipeAlwaysWalkBack || _setting.UseGpxPathing))
            {
                if (session.LogicSettings.UseGpxPathing)
                {
                    await WalkingBackGPXPath(session, cancellationToken, originalPokestop, fortInfo).ConfigureAwait(false);
                }
                else
                {
                    await UpdateFarmingPokestop(session, cancellationToken).ConfigureAwait(false);
                }
            }
        }
Ejemplo n.º 3
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken,
                                         PokemonId priority = PokemonId.Missingno, bool sessionAllowTransfer = true)
        {
            var manager = TinyIoCContainer.Current.Resolve <MultiAccountManager>();

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

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

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

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

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

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

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

            if (nearbyPokemons == null)
            {
                return;
            }

            Logger.Write($"Spotted {nearbyPokemons.Count()} pokemon in the area. Trying to catch them all.", LogLevel.Debug);

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

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

            EncounterResponse encounter = null;

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

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

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

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

                    if (EvolvePokemonTask.IsActivated(session))
                    {
                        await EvolvePokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                    }
                }
            }

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

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

            if (pokemons.Count > 0)
            {
                if (PokeBalls >= session.LogicSettings.PokeballsToKeepForSnipe)  // Don't display if not enough Pokeballs - TheWizrad1328
                {
                    Logger.Write($"Catching {pokemons.Count} Pokemon Nearby...", LogLevel.Info);
                }
                else
                {
                    Logger.Write($"collecting {session.LogicSettings.PokeballsToKeepForSnipe - PokeBalls} more Pokeballs. Catching of pokemon is temporarily susspended...", LogLevel.Info);
                }
            }

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

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

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

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

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

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

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

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

                //to avoid duplicated encounter when snipe priority pokemon

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

                if (encounter.Status == EncounterResponse.Types.Status.EncounterSuccess &&
                    session.LogicSettings.CatchPokemon)
                {
                    // Catch the Pokemon
                    await CatchPokemonTask.Execute(session, cancellationToken, encounter, pokemon,
                                                   currentFortData : null, sessionAllowTransfer : sessionAllowTransfer).ConfigureAwait(false);
                }
                else if (encounter.Status == EncounterResponse.Types.Status.PokemonInventoryFull)
                {
                    if (session.LogicSettings.TransferDuplicatePokemon || session.LogicSettings.TransferWeakPokemon)
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.InvFullTransferring)
                        });
                        if (session.LogicSettings.TransferDuplicatePokemon)
                        {
                            await TransferDuplicatePokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                        }
                        if (session.LogicSettings.TransferWeakPokemon)
                        {
                            await TransferWeakPokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                        }
                        if (EvolvePokemonTask.IsActivated(session))
                        {
                            await EvolvePokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                        }
                    }
                    else
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.InvFullTransferManually)
                        });
                    }
                }
                else
                {
                    session.EventDispatcher.Send(new WarnEvent
                    {
                        Message =
                            session.Translation.GetTranslation(TranslationString.EncounterProblem, encounter.Status)
                    });
                }
                encounter = null;
                // If pokemon is not last pokemon in list, create delay between catches, else keep moving.
                if (!Equals(pokemons.ElementAtOrDefault(pokemons.Count() - 1), pokemon))
                {
                    await Task.Delay(session.LogicSettings.DelayBetweenPokemonCatch, cancellationToken).ConfigureAwait(false);
                }
            }
        }
Ejemplo n.º 4
0
        private static async Task DoActionAtPokeStop(ISession session, CancellationToken cancellationToken, FortData pokeStop, FortDetailsResponse fortInfo, bool doNotTrySpin = false)
        {
            //Catch Lure Pokemon
            if (pokeStop.LureInfo != null)
            {
                // added for cooldowns
                await Task.Delay(Math.Min(session.LogicSettings.DelayBetweenPlayerActions, 3000)).ConfigureAwait(false);

                await CatchLurePokemonsTask.Execute(session, pokeStop, cancellationToken).ConfigureAwait(false);
            }

            // Spin as long as we haven't reached the user defined limits
            if (!_pokestopLimitReached && !_pokestopTimerReached)
            {
                await FarmPokestop(session, pokeStop, fortInfo, cancellationToken, doNotTrySpin).ConfigureAwait(false);
            }
            else
            {
                // We hit the pokestop limit but not the pokemon limit. So we want to set the cooldown on the pokestop so that
                // we keep moving and don't walk back and forth between 2 pokestops.
                pokeStop.CooldownCompleteTimestampMs = DateTime.UtcNow.ToUnixTime() + 5 * 60 * 1000; // 5 minutes to cooldown for pokestop.
            }

            if (++_stopsHit >= _storeRi)     //TODO: OR item/pokemon bag is full //check stopsHit against storeRI random without dividing.
            {
                _storeRi  = _rc.Next(6, 12); //set new storeRI for new random value
                _stopsHit = 0;

                if (session.LogicSettings.UseNearActionRandom)
                {
                    await HumanRandomActionTask.Execute(session, cancellationToken).ConfigureAwait(false);
                }
                else
                {
                    await RecycleItemsTask.Execute(session, cancellationToken).ConfigureAwait(false);

                    if (session.LogicSettings.UseLuckyEggConstantly)
                    {
                        await UseLuckyEggConstantlyTask.Execute(session, cancellationToken).ConfigureAwait(false);
                    }
                    if (session.LogicSettings.UseIncenseConstantly)
                    {
                        await UseIncenseConstantlyTask.Execute(session, cancellationToken).ConfigureAwait(false);
                    }
                    if (session.LogicSettings.TransferDuplicatePokemon)
                    {
                        await TransferDuplicatePokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                    }
                    if (session.LogicSettings.TransferWeakPokemon)
                    {
                        await TransferWeakPokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                    }
                    if (EvolvePokemonTask.IsActivated(session))
                    {
                        await EvolvePokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                    }
                    if (session.LogicSettings.AutomaticallyLevelUpPokemon)
                    {
                        await LevelUpPokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                    }
                    if (session.LogicSettings.RenamePokemon)
                    {
                        await RenamePokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                    }

                    await GetPokeDexCount.Execute(session, cancellationToken).ConfigureAwait(false);
                }
            }
        }
Ejemplo n.º 5
0
        public static async Task Execute(ISession session, FortData currentFortData,
                                         CancellationToken cancellationToken)
        {
            TinyIoC.TinyIoCContainer.Current.Resolve <MultiAccountManager>().ThrowIfSwitchAccountRequested();
            cancellationToken.ThrowIfCancellationRequested();
            if (!session.LogicSettings.CatchPokemon ||
                session.CatchBlockTime > DateTime.Now)
            {
                return;
            }

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

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


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

            var fortId = currentFortData.Id;

            var pokemonId = currentFortData.LureInfo.ActivePokemonId;

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

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

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

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

            var randomCommand = Enumerable.Range(1, 8).OrderBy(x => ActionRandom.Next()).Take(8).ToList();

            for (int i = 0; i < 8; i++)
            {
                cancellationToken.ThrowIfCancellationRequested();
                TinyIoC.TinyIoCContainer.Current.Resolve <MultiAccountManager>().ThrowIfSwitchAccountRequested();
                switch (randomCommand[i])
                {
                case 1:
                    // Handling of Eggs and Incubators preferably needs to happen every time.
                    // While monitoring the previous setting of 50% propability we ended up with
                    // over an hour of execution without setting any new Eggs for incubation (entering
                    // UseEggIncubators).
                    if (session.LogicSettings.UseEggIncubators)
                    {
                        if (ActionRandom.Next(1, 10) > 0)
                        {
                            await UseIncubatorsTask.Execute(session, cancellationToken).ConfigureAwait(false);
                        }
                    }
                    break;

                case 2:
                    if (session.LogicSettings.TransferDuplicatePokemon)
                    {
                        if (ActionRandom.Next(1, 10) > 4)
                        {
                            await TransferDuplicatePokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                        }
                    }
                    if (session.LogicSettings.TransferWeakPokemon)
                    {
                        if (ActionRandom.Next(1, 10) > 4)
                        {
                            await TransferWeakPokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                        }
                    }
                    if (ActionRandom.Next(1, 10) > 4)
                    {
                        if (EvolvePokemonTask.IsActivated(session))
                        {
                            await EvolvePokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                        }
                    }
                    break;

                case 3:
                    if (session.LogicSettings.UseLuckyEggConstantly)
                    {
                        if (ActionRandom.Next(1, 10) > 4)
                        {
                            await UseLuckyEggConstantlyTask.Execute(session, cancellationToken).ConfigureAwait(false);
                        }
                    }
                    break;

                case 4:
                    if (session.LogicSettings.UseIncenseConstantly)
                    {
                        if (ActionRandom.Next(1, 10) > 4)
                        {
                            await UseIncenseConstantlyTask.Execute(session, cancellationToken).ConfigureAwait(false);
                        }
                    }
                    break;

                case 5:
                    if (session.LogicSettings.RenamePokemon)
                    {
                        if (ActionRandom.Next(1, 10) > 4)
                        {
                            await RenamePokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                        }
                    }
                    break;

                case 6:
                    if (session.LogicSettings.AutoFavoritePokemon)
                    {
                        if (ActionRandom.Next(1, 10) > 4)
                        {
                            await FavoritePokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                        }
                    }
                    break;

                case 7:
                    if (ActionRandom.Next(1, 10) > 4)
                    {
                        await RecycleItemsTask.Execute(session, cancellationToken).ConfigureAwait(false);
                    }
                    break;

                case 8:
                    if (session.LogicSettings.AutomaticallyLevelUpPokemon)
                    {
                        if (ActionRandom.Next(1, 10) > 4)
                        {
                            await LevelUpPokemonTask.Execute(session, cancellationToken).ConfigureAwait(false);
                        }
                    }
                    break;
                }
            }

            await GetPokeDexCount.Execute(session, cancellationToken).ConfigureAwait(false);
        }