Esempio n. 1
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            var currentTotalItems = await session.Inventory.GetTotalItemCount();

            var recycleInventoryAtUsagePercentage = session.LogicSettings.RecycleInventoryAtUsagePercentage > 1
                ? session.LogicSettings.RecycleInventoryAtUsagePercentage / 100 : session.LogicSettings.RecycleInventoryAtUsagePercentage;

            if (session.Runtime == null || session.Client?.Rnd == null || session.Profile?.PlayerData == null)
            {
                return;
            }

            if (session.Runtime.StopsHit + session.Client.Rnd.Next(5) > 13 || session.Profile.PlayerData.MaxItemStorage * recycleInventoryAtUsagePercentage < currentTotalItems)
            {
                await session.Inventory.RefreshCachedInventory(true);

                // need updated stardust information for upgrading, so refresh your profile now
                await DownloadProfile(session);

                await RecycleItemsTask.Execute(session, cancellationToken);

                if (session.LogicSettings.EvolveAllPokemonWithEnoughCandy ||
                    session.LogicSettings.EvolveAllPokemonAboveIv)
                {
                    await EvolvePokemonTask.Execute(session, cancellationToken);
                }
                if (session.LogicSettings.AutoFavoritePokemon)
                {
                    await FavoritePokemonTask.Execute(session, cancellationToken);
                }
                if (session.LogicSettings.AutomaticallyLevelUpPokemon)
                {
                    await LevelUpPokemonTask.Execute(session, cancellationToken);
                }
                if (session.LogicSettings.TransferDuplicatePokemon)
                {
                    await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                }
                if (session.LogicSettings.RenamePokemon)
                {
                    await RenamePokemonTask.Execute(session, cancellationToken);
                }
                session.Runtime.StopsHit = 0;
            }
        }
        //Please do not change GetPokeStops() in this file, it's specifically set
        //to only find stops within 40 meters
        //this is for gpx pathing, we are not going to the pokestops,
        //so do not make it more than 40 because it will never get close to those stops.
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var pokestopList = await GetPokeStops(session);

            while (pokestopList.Any())
            {
                cancellationToken.ThrowIfCancellationRequested();

                pokestopList =
                    pokestopList.OrderBy(
                        i =>
                        LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                session.Client.CurrentLongitude, i.Latitude, i.Longitude)).ToList();
                var pokeStop = pokestopList[0];
                pokestopList.RemoveAt(0);

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

                var fortSearch =
                    await session.Client.Fort.SearchFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude);

                if (fortSearch.ExperienceAwarded > 0)
                {
                    session.EventDispatcher.Send(new FortUsedEvent
                    {
                        Id        = pokeStop.Id,
                        Name      = fortInfo.Name,
                        Exp       = fortSearch.ExperienceAwarded,
                        Gems      = fortSearch.GemsAwarded,
                        Items     = StringUtils.GetSummedFriendlyNameOfItemAwardList(fortSearch.ItemsAwarded),
                        Latitude  = pokeStop.Latitude,
                        Longitude = pokeStop.Longitude
                    });
                }

                await RecycleItemsTask.Execute(session, cancellationToken);

                if (session.LogicSettings.TransferDuplicatePokemon)
                {
                    await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                }
            }
        }
Esempio n. 3
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            var prevState = session.State;

            session.State = BotState.Busy;
            var currentTotalItems = await session.Inventory.GetTotalItemCount();

            var recycleInventoryAtUsagePercentage = session.LogicSettings.RecycleInventoryAtUsagePercentage > 1
                ? session.LogicSettings.RecycleInventoryAtUsagePercentage / 100 : session.LogicSettings.RecycleInventoryAtUsagePercentage;

            if (session.Runtime.StopsHit % 5 + session.Client.rnd.Next(5) == 0 || session.Profile.PlayerData.MaxItemStorage * recycleInventoryAtUsagePercentage < currentTotalItems)
            {
                session.Runtime.StopsHit = 0;
                // need updated stardust information for upgrading, so refresh your profile now
                await DownloadProfile(session);

                await RecycleItemsTask.Execute(session, cancellationToken);

                if (session.LogicSettings.EvolveAllPokemonWithEnoughCandy ||
                    session.LogicSettings.EvolveAllPokemonAboveIv)
                {
                    await EvolvePokemonTask.Execute(session, cancellationToken);
                }
                if (session.LogicSettings.AutomaticallyLevelUpPokemon)
                {
                    await LevelUpPokemonTask.Execute(session, cancellationToken);
                }
                if (session.LogicSettings.TransferDuplicatePokemon)
                {
                    await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                }
                if (session.LogicSettings.RenamePokemon)
                {
                    await RenamePokemonTask.Execute(session, cancellationToken);
                }
                //Do we need this?
                //await DisplayPokemonStatsTask.Execute(session);
            }
            session.State = prevState;
        }
Esempio n. 4
0
        public void Run(CancellationToken cancellationToken)
        {
            if (_session.LogicSettings.EvolveAllPokemonAboveIv || _session.LogicSettings.EvolveAllPokemonWithEnoughCandy)
            {
                EvolvePokemonTask.Execute(_session, cancellationToken).Wait(cancellationToken);
            }
            if (_session.LogicSettings.AutomaticallyLevelUpPokemon)
            {
                LevelUpPokemonTask.Execute(_session, cancellationToken).Wait(cancellationToken);
            }
            if (_session.LogicSettings.TransferDuplicatePokemon)
            {
                TransferDuplicatePokemonTask.Execute(_session, cancellationToken).Wait(cancellationToken);
            }

            if (_session.LogicSettings.RenamePokemon)
            {
                RenamePokemonTask.Execute(_session, cancellationToken).Wait(cancellationToken);
            }

            RecycleItemsTask.Execute(_session, cancellationToken).Wait(cancellationToken);

            if (_session.LogicSettings.UseEggIncubators)
            {
                UseIncubatorsTask.Execute(_session, cancellationToken).Wait(cancellationToken);
            }

            if (_session.LogicSettings.UseGpxPathing)
            {
                FarmPokestopsGpxTask.Execute(_session, cancellationToken).Wait(cancellationToken);
            }
            else
            {
                FarmPokestopsTask.Execute(_session, cancellationToken).Wait(cancellationToken);
            }
        }
Esempio n. 5
0
        public static async Task Execute(ISession session, FortData currentFortData, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (!session.LogicSettings.CatchWildPokemon)
            {
                return;
            }
            if (session.Runtime.PokeBallsToCollect > 0)
            {
                return;
            }

            if (!await CheckBotStateTask.Execute(session, cancellationToken))
            {
                return;
            }

            // Refresh inventory so that the player stats are fresh
            await session.Inventory.RefreshCachedInventory();

            session.EventDispatcher.Send(new DebugEvent()
            {
                Message = session.Translation.GetTranslation(TranslationString.LookingForLurePokemon)
            });

            var fortId = currentFortData.Id;

            if (currentFortData.LureInfo == null)
            {
                return;
            }

            var pokemonId = currentFortData.LureInfo.ActivePokemonId;

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

                if (encounter.Result == DiskEncounterResponse.Types.Result.Success)
                {
                    //var pokemons = await session.MapCache.MapPokemons(session);
                    //var pokemon = pokemons.FirstOrDefault(i => i.PokemonId == encounter.PokemonData.PokemonId);
                    session.EventDispatcher.Send(new DebugEvent()
                    {
                        Message = "Found a Lure Pokemon."
                    });

                    MapPokemon _pokemon = new MapPokemon
                    {
                        EncounterId           = currentFortData.LureInfo.EncounterId,
                        ExpirationTimestampMs = currentFortData.LureInfo.LureExpiresTimestampMs,
                        Latitude     = currentFortData.Latitude,
                        Longitude    = currentFortData.Longitude,
                        PokemonId    = currentFortData.LureInfo.ActivePokemonId,
                        SpawnPointId = currentFortData.LureInfo.FortId
                    };
                    if (session.LogicSettings.UsePokemonToNotCatchFilter &&
                        session.LogicSettings.PokemonsNotToCatch.Contains(_pokemon.PokemonId))
                    {
                        session.EventDispatcher.Send(new NoticeEvent()
                        {
                            Message = session.Translation.GetTranslation(TranslationString.PokemonIgnoreFilter, session.Translation.GetPokemonName(_pokemon.PokemonId))
                        });
                    }
                    else
                    {
                        session.EventDispatcher.Send(new PokemonsFoundEvent {
                            Pokemons = new[] { _pokemon }
                        });
                        PokemonCacheItem pokemon = new PokemonCacheItem(_pokemon);

                        var catchRes = await CatchPokemonTask.Execute(session, encounter, pokemon, cancellationToken, currentFortData, encounterId);

                        if (!catchRes)
                        {
                            session.Runtime.PokeBallsToCollect = 10;
                            return;
                        }
                        currentFortData.LureInfo = null;
                        session.EventDispatcher.Send(new PokemonDisappearEvent {
                            Pokemon = _pokemon
                        });
                    }

                    //await CatchPokemonTask.Execute(session, encounter, pokemon, currentFortData, encounterId);
                }
                else if (encounter.Result == DiskEncounterResponse.Types.Result.PokemonInventoryFull)
                {
                    if (session.LogicSettings.TransferDuplicatePokemon)
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.InvFullTransferring)
                        });
                        await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                    }
                    else
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.InvFullTransferManually)
                        });
                    }
                }
                else
                {
                    if (encounter.Result.ToString().Contains("NotAvailable"))
                    {
                        return;
                    }
                    session.EventDispatcher.Send(new WarnEvent
                    {
                        Message =
                            session.Translation.GetTranslation(TranslationString.EncounterProblemLurePokemon,
                                                               encounter.Result)
                    });
                }
                // always wait the delay amount between catches, ideally to prevent you from making another call too early after a catch event
                await Task.Delay(session.LogicSettings.DelayBetweenPokemonCatch);
            }
        }
Esempio n. 6
0
        public static async Task  Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            //Refresh inventory so that the player stats are fresh
            //await session.Inventory.RefreshCachedInventory(); too much inventore refresh

            session.EventDispatcher.Send(new DebugEvent()
            {
                Message = session.Translation.GetTranslation(TranslationString.LookingForPokemon)
            });

            var pokemons = await GetNearbyPokemons(session);

            if (session.LogicSettings.UsePokemonToNotCatchFilter)
            {
                var pokeToCatch =
                    pokemons.Select(x => x.BaseMapPokemon)
                    .Where(x => !session.LogicSettings.PokemonsNotToCatch.Contains(x.PokemonId));
                session.EventDispatcher.Send(new PokemonsFoundEvent {
                    Pokemons = pokeToCatch
                });
            }
            else
            {
                session.EventDispatcher.Send(new PokemonsFoundEvent {
                    Pokemons = pokemons.Select(x => x.BaseMapPokemon)
                });
            }
            foreach (var pokemon in pokemons)
            {
                cancellationToken.ThrowIfCancellationRequested();

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

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

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

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

                if (pokeBallsCount + greatBallsCount + ultraBallsCount + masterBallsCount == 0)
                {
                    session.EventDispatcher.Send(new NoticeEvent()
                    {
                        Message = session.Translation.GetTranslation(TranslationString.ZeroPokeballInv)
                    });
                    return;
                }

                if (session.LogicSettings.UsePokemonToNotCatchFilter &&
                    session.LogicSettings.PokemonsNotToCatch.Contains(pokemon.PokemonId))
                {
                    session.EventDispatcher.Send(new NoticeEvent()
                    {
                        Message =
                            session.Translation.GetTranslation(TranslationString.PokemonSkipped,
                                                               session.Translation.GetPokemonName(pokemon.PokemonId))
                    });
                    continue;
                }

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

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

                try
                {
                    switch (encounter.Status)
                    {
                    case EncounterResponse.Types.Status.EncounterSuccess:
                        await CatchPokemonTask.Execute(session, encounter, pokemon);

                        break;

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

                    default:
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message =
                                session.Translation.GetTranslation(TranslationString.EncounterProblem,
                                                                   encounter.Status)
                        });
                        break;
                    }
                }
                catch (Exception)
                {
                    session.EventDispatcher.Send(new WarnEvent
                    {
                        Message = "Error occured while trying to catch nearby pokemon"
                    });
                    await Task.Delay(5000, cancellationToken);
                }

                session.EventDispatcher.Send(new PokemonDisappearEvent {
                    Pokemon = pokemon.BaseMapPokemon
                });

                // always wait the delay amount between catches, ideally to prevent you from making another call too early after a catch event
                await Task.Delay(session.LogicSettings.DelayBetweenPokemonCatch);
            }
            return;
        }
Esempio n. 7
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            var tracks    = GetGpxTracks(session);
            var eggWalker = new EggWalker(1000, session);

            for (var curTrk = 0; curTrk < tracks.Count; curTrk++)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var track         = tracks.ElementAt(curTrk);
                var trackSegments = track.Segments;
                for (var curTrkSeg = 0; curTrkSeg < trackSegments.Count; curTrkSeg++)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    var trackPoints = track.Segments.ElementAt(0).TrackPoints;
                    for (var curTrkPt = 0; curTrkPt < trackPoints.Count; curTrkPt++)
                    {
                        cancellationToken.ThrowIfCancellationRequested();

                        var nextPoint = trackPoints.ElementAt(curTrkPt);
                        var distance  = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                                session.Client.CurrentLongitude,
                                                                                Convert.ToDouble(nextPoint.Lat, CultureInfo.InvariantCulture),
                                                                                Convert.ToDouble(nextPoint.Lon, CultureInfo.InvariantCulture));

                        if (distance > 5000)
                        {
                            session.EventDispatcher.Send(new ErrorEvent
                            {
                                Message =
                                    session.Translation.GetTranslation(TranslationString.DesiredDestTooFar,
                                                                       nextPoint.Lat, nextPoint.Lon, session.Client.CurrentLatitude,
                                                                       session.Client.CurrentLongitude)
                            });
                            break;
                        }

                        var pokestopList = await GetPokeStops(session);

                        session.EventDispatcher.Send(new PokeStopListEvent {
                            Forts = session.MapCache.baseFortDatas.ToList()
                        });

                        while (pokestopList.Any())
                        // warning: this is never entered due to ps cooldowns from UseNearbyPokestopsTask
                        {
                            cancellationToken.ThrowIfCancellationRequested();

                            pokestopList =
                                pokestopList.OrderBy(
                                    i =>
                                    LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                            session.Client.CurrentLongitude, i.Latitude, i.Longitude)).ToList();
                            var pokeStop = pokestopList[0];
                            pokestopList.RemoveAt(0);

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

                            if (pokeStop.LureInfo != null)
                            {
                                session.EventDispatcher.Send(new DebugEvent()
                                {
                                    Message = "This pokestop has a lure!"
                                });
                                await CatchLurePokemonsTask.Execute(session, pokeStop.BaseFortData, cancellationToken);
                            }

                            var fortSearch =
                                await session.Client.Fort.SearchFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude);

                            if (fortSearch.ExperienceAwarded > 0)
                            {
                                session.EventDispatcher.Send(new FortUsedEvent
                                {
                                    Id        = pokeStop.Id,
                                    Name      = fortInfo.Name,
                                    Exp       = fortSearch.ExperienceAwarded,
                                    Gems      = fortSearch.GemsAwarded,
                                    Items     = StringUtils.GetSummedFriendlyNameOfItemAwardList(fortSearch.ItemsAwarded),
                                    Latitude  = pokeStop.Latitude,
                                    Longitude = pokeStop.Longitude
                                });
                                session.MapCache.UsedPokestop(pokeStop, session);
                            }
                            if (fortSearch.ItemsAwarded.Count > 0)
                            {
                                await session.Inventory.RefreshCachedInventory();
                            }
                        }

                        if (DateTime.Now > _lastTasksCall)
                        {
                            _lastTasksCall =
                                DateTime.Now.AddMilliseconds(Math.Min(session.LogicSettings.DelayBetweenPlayerActions,
                                                                      3000));

                            await RecycleItemsTask.Execute(session, cancellationToken);

                            if (session.LogicSettings.SnipeAtPokestops || session.LogicSettings.UseSnipeLocationServer)
                            {
                                await SnipePokemonTask.Execute(session, cancellationToken);
                            }

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

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

                            if (session.LogicSettings.RenamePokemon)
                            {
                                await RenamePokemonTask.Execute(session, cancellationToken);
                            }
                        }

                        var targetLocation = new GeoCoordinate(Convert.ToDouble(trackPoints.ElementAt(curTrkPt).Lat, CultureInfo.InvariantCulture),
                                                               Convert.ToDouble(trackPoints.ElementAt(curTrkPt).Lon, CultureInfo.InvariantCulture));

                        Navigation navi = new Navigation(session.Client);
                        navi.UpdatePositionEvent += (lat, lng, alt) =>
                        {
                            session.EventDispatcher.Send(new UpdatePositionEvent {
                                Latitude = lat, Longitude = lng, Altitude = alt
                            });
                        };
                        var nextMoveSpeed = session.Client.rnd.NextInRange(session.LogicSettings.WalkingSpeedMin, session.LogicSettings.WalkingSpeedMax) * session.Settings.MoveSpeedFactor;

                        session.State = BotState.Walk;
                        await navi.HumanPathWalking(
                            session,
                            targetLocation,
                            nextMoveSpeed,
                            async() =>
                        {
                            await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                            //Catch Incense Pokemon
                            await CatchIncensePokemonsTask.Execute(session, cancellationToken);

                            return(true);
                        },
                            async() =>
                        {
                            await UseNearbyPokestopsTask.Execute(session, cancellationToken);
                            return(true);
                        },
                            cancellationToken
                            );

                        session.State = BotState.Idle;

                        await eggWalker.ApplyDistance(distance, cancellationToken);
                    } //end trkpts
                }     //end trksegs
            }         //end tracks
        }
Esempio n. 8
0
        public static async Task Teleport(ISession session, CancellationToken cancellationToken, Random random)
        {
            bool ShownSoftBanMessage = false;
            int  stopsToHit          = 20; //We should return to the main loop after some point, might as well limit this.
            //Not sure where else we could put this? Configs maybe if we incorporate
            //deciding how many pokestops in a row we want to hit before doing things like recycling?
            //might increase xp/hr not stopping every 5 stops. - Pocket


            //TODO: run through this with a fine-tooth comb and optimize it.
            var pokestopList = await GetPokeStops(session);

            for (int stopsHit = 0; stopsHit < stopsToHit; stopsHit++)
            {
                RuntimeSettings.BreakOutOfPathing = false;
                if (pokestopList.Count > 0)
                {
                    //start at 0 ends with 19 = 20 for the leechers{
                    cancellationToken.ThrowIfCancellationRequested();

                    var distanceFromStart = LocationUtils.CalculateDistanceInMeters(
                        session.Settings.DefaultLatitude, session.Settings.DefaultLongitude,
                        session.Client.CurrentLatitude, session.Client.CurrentLongitude);

                    // Edge case for when the client somehow ends up outside the defined radius
                    if (session.LogicSettings.MaxTravelDistanceInMeters != 0 &&
                        distanceFromStart > session.LogicSettings.MaxTravelDistanceInMeters)
                    {
                        session.EventDispatcher.Send(new WarnEvent()
                        {
                            Message = session.Translation.GetTranslation(TranslationString.FarmPokestopsOutsideRadius, distanceFromStart)
                        });
                        await Task.Delay(1000, cancellationToken);

                        await session.Navigation.Move(
                            new GeoCoordinate(session.Settings.DefaultLatitude, session.Settings.DefaultLongitude),
                            session.LogicSettings.WalkingSpeedMin, session.LogicSettings.WalkingSpeedMax, null, null, cancellationToken, session);
                    }
                    if (session.ForceMoveJustDone)
                    {
                        session.ForceMoveJustDone = false;
                    }
                    if (session.ForceMoveTo != null)
                    {
                        await ForceMoveTask.Execute(session, cancellationToken);

                        pokestopList = await GetPokeStops(session);
                    }


                    var displayStatsHit = 0;
                    var eggWalker       = new EggWalker(1000, session);

                    if (pokestopList.Count <= 0)
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.FarmPokestopsNoUsableFound)
                        });
                    }

                    session.EventDispatcher.Send(new PokeStopListEvent {
                        Forts = session.MapCache.baseFortDatas.ToList()
                    });

                    cancellationToken.ThrowIfCancellationRequested();

                    //resort
                    pokestopList =
                        pokestopList.OrderBy(
                            i =>
                            LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                    session.Client.CurrentLongitude, i.Latitude, i.Longitude)).ToList();

                    if (session.LogicSettings.UsePokeStopLuckyNumber)
                    {
                        if (pokestopList.Count >= session.LogicSettings.PokestopSkipLuckyNumberMinUse)
                        {
                            int rng = random.Next(session.LogicSettings.PokestopSkipLuckyMin, session.LogicSettings.PokestopSkipLuckyMax);
#if DEBUG
                            Logger.Write("Skip Pokestop RNG: " + rng.ToString() + " against " + session.LogicSettings.PokestopSkipLuckyNumber.ToString(), LogLevel.Debug);
#endif
                            if (rng == session.LogicSettings.PokestopSkipLuckyNumber)
                            {
#if DEBUG
                                Logger.Write("Skipping Pokestop due to the rng god's will.", LogLevel.Debug);
#endif
                                pokestopList.RemoveAt(0);
                            }
                        }
                    }


                    var pokeStop = pokestopList[0];
                    pokestopList.RemoveAt(0);
                    RuntimeSettings.TargetStopID = pokeStop.Id;
                    var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                           session.Client.CurrentLongitude, pokeStop.Latitude, pokeStop.Longitude);
                    var fortInfo = await session.Client.Fort.GetFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude);

                    session.EventDispatcher.Send(new FortTargetEvent {
                        Id = fortInfo.FortId, Name = fortInfo.Name, Distance = distance, Latitude = fortInfo.Latitude, Longitude = fortInfo.Longitude, Description = fortInfo.Description, url = fortInfo.ImageUrls[0]
                    });
                    if (session.LogicSettings.Teleport)
                    {
                        await session.Client.Player.UpdatePlayerLocation(fortInfo.Latitude, fortInfo.Longitude,
                                                                         session.Client.Settings.DefaultAltitude);
                    }

                    else
                    {
                        await session.Navigation.Move(new GeoCoordinate(pokeStop.Latitude, pokeStop.Longitude),
                                                      session.LogicSettings.WalkingSpeedMin, session.LogicSettings.WalkingSpeedMax,
                                                      async() =>
                        {
                            if (session.LogicSettings.CatchWildPokemon)
                            {
                                // Catch normal map Pokemon
                                await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                                //Catch Incense Pokemon remove this for time contraints
                                //await CatchIncensePokemonsTask.Execute(session, cancellationToken);
                            }
                            return(true);
                        },
                                                      async() =>
                        {
                            await UseNearbyPokestopsTask.Execute(session, cancellationToken);
                            return(true);
                        },

                                                      cancellationToken, session);
                    }
                    if (!session.ForceMoveJustDone)
                    {
                        FortSearchResponse fortSearch;
                        var       timesZeroXPawarded = 0;
                        var       fortTry            = 0;  //Current check
                        const int retryNumber        = 50; //How many times it needs to check to clear softban
                        const int zeroCheck          = 5;  //How many times it checks fort before it thinks it's softban
                        if (RuntimeSettings.BreakOutOfPathing)
                        {
                            continue;
                        }
                        do
                        {
                            cancellationToken.ThrowIfCancellationRequested();

                            fortSearch =
                                await session.Client.Fort.SearchFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude);

                            if (fortSearch.ExperienceAwarded > 0 && timesZeroXPawarded > 0)
                            {
                                timesZeroXPawarded = 0;
                            }
                            if (fortSearch.ExperienceAwarded == 0)
                            {
                                timesZeroXPawarded++;

                                if (timesZeroXPawarded > zeroCheck)
                                {
                                    if ((int)fortSearch.CooldownCompleteTimestampMs != 0)
                                    {
                                        break;
                                        // Check if successfully looted, if so program can continue as this was "false alarm".
                                    }

                                    fortTry += 1;

                                    if (!ShownSoftBanMessage)
                                    {
                                        session.EventDispatcher.Send(new FortFailedEvent
                                        {
                                            Name = fortInfo.Name,
                                            Try  = fortTry,
                                            Max  = retryNumber - zeroCheck
                                        });
                                        ShownSoftBanMessage = true;
                                    }
                                    await Task.Delay(session.LogicSettings.DelaySoftbanRetry);
                                }
                            }
                            else
                            {
                                session.EventDispatcher.Send(new FortUsedEvent
                                {
                                    Id            = pokeStop.Id,
                                    Name          = fortInfo.Name,
                                    Exp           = fortSearch.ExperienceAwarded,
                                    Gems          = fortSearch.GemsAwarded,
                                    Items         = StringUtils.GetSummedFriendlyNameOfItemAwardList(fortSearch.ItemsAwarded),
                                    Latitude      = pokeStop.Latitude,
                                    Longitude     = pokeStop.Longitude,
                                    InventoryFull = fortSearch.Result == FortSearchResponse.Types.Result.InventoryFull,
                                    Description   = fortInfo.Description,
                                    url           = fortInfo.ImageUrls[0]
                                });
                                session.MapCache.UsedPokestop(pokeStop);
                                session.EventDispatcher.Send(new InventoryNewItemsEvent()
                                {
                                    Items = fortSearch.ItemsAwarded.ToItemList()
                                });
                                break; //Continue with program as loot was succesfull.
                            }
                        } while (fortTry < retryNumber - zeroCheck);
                        //Stop trying if softban is cleaned earlier or if 40 times fort looting failed.

                        ShownSoftBanMessage = false;
                        await Task.Delay(session.LogicSettings.DelayPokestop);


                        //Catch Lure Pokemon

                        if (session.LogicSettings.CatchWildPokemon)
                        {
                            if (pokeStop.LureInfo != null)
                            {
                                await CatchLurePokemonsTask.Execute(session, pokeStop.BaseFortData, cancellationToken);
                            }
                            // Catch normal map Pokemon
                            if (session.LogicSettings.Teleport)
                            {
                                await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                            }
                            //Catch Incense Pokemon
                            await CatchIncensePokemonsTask.Execute(session, cancellationToken);
                        }


                        await eggWalker.ApplyDistance(distance, cancellationToken);

                        if (++stopsHit % 5 == 0) //TODO: OR item/pokemon bag is full
                        {
                            // need updated stardust information for upgrading, so refresh your profile now
                            await DownloadProfile(session);

                            if (fortSearch.ItemsAwarded.Count > 0)
                            {
                                await session.Inventory.RefreshCachedInventory();
                            }
                            await RecycleItemsTask.Execute(session, cancellationToken);

                            if (session.LogicSettings.EvolveAllPokemonWithEnoughCandy ||
                                session.LogicSettings.EvolveAllPokemonAboveIv)
                            {
                                await EvolvePokemonTask.Execute(session, cancellationToken);
                            }
                            if (session.LogicSettings.AutomaticallyLevelUpPokemon)
                            {
                                await LevelUpPokemonTask.Execute(session, cancellationToken);
                            }
                            if (session.LogicSettings.TransferDuplicatePokemon)
                            {
                                await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                            }
                            if (session.LogicSettings.RenamePokemon)
                            {
                                await RenamePokemonTask.Execute(session, cancellationToken);
                            }
                            if (++displayStatsHit >= 4)
                            {
                                await DisplayPokemonStatsTask.Execute(session);
                            }
                        }
                    }
                    if (session.LogicSettings.SnipeAtPokestops || session.LogicSettings.UseSnipeLocationServer)
                    {
                        await SnipePokemonTask.Execute(session, cancellationToken);
                    }
                }
            }
        }
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (!session.LogicSettings.CatchWildPokemon)
            {
                return;
            }
            if (session.Runtime.PokeBallsToCollect > 0)
            {
                return;
            }

            var usedItems = await session.Inventory.GetUsedItems();

            if (usedItems == null || !usedItems.Any(x => x.ItemId == ItemId.ItemIncenseOrdinary || x.ItemId == ItemId.ItemIncenseSpicy ||
                                                    x.ItemId == ItemId.ItemIncenseCool || x.ItemId == ItemId.ItemIncenseFloral))
            {
                return;
            }

            // Refresh inventory so that the player stats are fresh
            //await session.Inventory.RefreshCachedInventory();

            session.EventDispatcher.Send(new DebugEvent
            {
                Message = session.Translation.GetTranslation(TranslationString.LookingForIncensePokemon)
            });

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

            if (incensePokemon.Result == GetIncensePokemonResponse.Types.Result.IncenseEncounterAvailable)
            {
                if (session.LogicSettings.UsePokemonToNotCatchFilter &&
                    session.LogicSettings.PokemonsNotToCatch.Contains(incensePokemon.PokemonId))
                {
                    //session.EventDispatcher.Send(new NoticeEvent
                    //{
                    //    Message = session.Translation.GetTranslation(TranslationString.PokemonIgnoreFilter, session.Translation.GetPokemonName(pokemon.PokemonId))
                    //});
                }
                else
                {
                    var mapPokemon = new MapPokemon
                    {
                        EncounterId           = incensePokemon.EncounterId,
                        ExpirationTimestampMs = incensePokemon.DisappearTimestampMs,
                        Latitude     = incensePokemon.Latitude,
                        Longitude    = incensePokemon.Longitude,
                        PokemonId    = incensePokemon.PokemonId,
                        SpawnPointId = incensePokemon.EncounterLocation
                    };
                    var pokemon = new PokemonCacheItem(mapPokemon);

                    session.EventDispatcher.Send(new PokemonsFoundEvent {
                        Pokemons = new[] { mapPokemon }
                    });

                    await Task.Delay(session.LogicSettings.DelayCatchIncensePokemon, cancellationToken);

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

                    if (encounter.Result == IncenseEncounterResponse.Types.Result.IncenseEncounterSuccess)
                    {
                        var catchRes = await CatchPokemonTask.Execute(session, encounter, pokemon, cancellationToken);

                        if (!catchRes)
                        {
                            session.Runtime.PokeBallsToCollect = 10;
                            return;
                        }
                    }
                    else if (encounter.Result == IncenseEncounterResponse.Types.Result.PokemonInventoryFull)
                    {
                        if (session.LogicSettings.TransferDuplicatePokemon)
                        {
                            session.EventDispatcher.Send(new WarnEvent
                            {
                                Message = session.Translation.GetTranslation(TranslationString.InvFullTransferring)
                            });
                            await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                        }
                        else
                        {
                            session.EventDispatcher.Send(new WarnEvent
                            {
                                Message = session.Translation.GetTranslation(TranslationString.InvFullTransferManually)
                            });
                        }
                    }
                    else
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message =
                                session.Translation.GetTranslation(TranslationString.EncounterProblem, encounter.Result)
                        });
                    }
                    session.EventDispatcher.Send(new PokemonDisappearEvent {
                        EncounterId = pokemon.EncounterId
                    });
                }
            }
        }
Esempio n. 10
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            // Refresh inventory so that the player stats are fresh
            await session.Inventory.RefreshCachedInventory();

            session.EventDispatcher.Send(new DebugEvent()
            {
                Message = session.Translation.GetTranslation(TranslationString.LookingForIncensePokemon)
            });

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

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

                session.EventDispatcher.Send(new PokemonsFoundEvent {
                    Pokemons = new MapPokemon[] { _pokemon }
                });

                if (session.LogicSettings.UsePokemonToNotCatchFilter &&
                    session.LogicSettings.PokemonsNotToCatch.Contains(pokemon.PokemonId))
                {
                    session.EventDispatcher.Send(new NoticeEvent()
                    {
                        Message = session.Translation.GetTranslation(TranslationString.PokemonIgnoreFilter, session.Translation.GetPokemonName(pokemon.PokemonId))
                    });
                }
                else
                {
                    var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                           session.Client.CurrentLongitude, pokemon.Latitude, pokemon.Longitude);
                    await Task.Delay(session.LogicSettings.DelayCatchIncensePokemon);

                    var encounter =
                        await
                        session.Client.Encounter.EncounterIncensePokemon(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(TranslationString.InvFullTransferring)
                            });
                            await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                        }
                        else
                        {
                            session.EventDispatcher.Send(new WarnEvent
                            {
                                Message = session.Translation.GetTranslation(TranslationString.InvFullTransferManually)
                            });
                        }
                    }
                    else
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message =
                                session.Translation.GetTranslation(TranslationString.EncounterProblem, encounter.Result)
                        });
                    }
                }
                session.EventDispatcher.Send(new PokemonDisappearEvent {
                    Pokemon = pokemon.BaseMapPokemon
                });
            }
        }
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var pokestopList = await GetPokeStops(session);

            var stopsHit  = 0;
            var eggWalker = new EggWalker(1000, session);

            if (pokestopList.Count <= 0)
            {
                session.EventDispatcher.Send(new WarnEvent
                {
                    Message = session.Translation.GetTranslation(TranslationString.FarmPokestopsNoUsableFound)
                });
            }

            session.EventDispatcher.Send(new PokeStopListEvent {
                Forts = pokestopList
            });


            while (pokestopList.Any())
            {
                cancellationToken.ThrowIfCancellationRequested();

                if (session.ForceMoveTo != null)
                {
                    await ForceMoveTask.Execute(session, cancellationToken);
                }

                var newPokestopList = (await GetPokeStops(session)).OrderBy(i =>
                                                                            LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                                                                    session.Client.CurrentLongitude, i.Latitude, i.Longitude)).Where(x => pokestopList.All(i => i.Id != x.Id) && LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                                                                                                                                                                                                                         session.Client.CurrentLongitude, x.Latitude, x.Longitude) < session.LogicSettings.MaxTravelDistanceInMeters).ToList();
                session.EventDispatcher.Send(new PokeStopListEvent {
                    Forts = newPokestopList
                });
                pokestopList.AddRange(newPokestopList);

                var pokeStop = pokestopList.OrderBy(i => LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                                                 session.Client.CurrentLongitude, i.Latitude, i.Longitude)).First(x => x.CooldownCompleteTimestampMs < DateTime.UtcNow.ToUnixTime());
                pokeStop.CooldownCompleteTimestampMs = DateTime.UtcNow.ToUnixTime() + 300 * 1000;

                var tooFarPokestops = pokestopList.Where(i => LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                                                      session.Client.CurrentLongitude, i.Latitude, i.Longitude) > session.LogicSettings.MaxTravelDistanceInMeters).ToList();

                foreach (var tooFar in tooFarPokestops)
                {
                    pokestopList.Remove(tooFar);
                }

                var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                       session.Client.CurrentLongitude, pokeStop.Latitude, pokeStop.Longitude);
                var fortInfo = await session.Client.Fort.GetFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude);

                session.EventDispatcher.Send(new FortTargetEvent {
                    Name = fortInfo.Name, Distance = distance
                });
                if (session.LogicSettings.Teleport)
                {
                    await session.Client.Player.UpdatePlayerLocation(fortInfo.Latitude, fortInfo.Longitude,
                                                                     session.Client.Settings.DefaultAltitude);
                }
                else
                {
                    await moveToPokestop(session, cancellationToken, pokeStop);
                }

                await CatchWildPokemonsTask.Execute(session, cancellationToken);

                FortSearchResponse fortSearch;
                var       timesZeroXPawarded = 0;
                var       fortTry            = 0;  //Current check
                const int retryNumber        = 50; //How many times it needs to check to clear softban
                const int zeroCheck          = 5;  //How many times it checks fort before it thinks it's softban
                do
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    fortSearch =
                        await session.Client.Fort.SearchFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude);

                    if (fortSearch.ExperienceAwarded > 0 && timesZeroXPawarded > 0)
                    {
                        timesZeroXPawarded = 0;
                    }
                    if (fortSearch.ExperienceAwarded == 0)
                    {
                        if (TimesZeroXPawarded == 0)
                        {
                            await moveToPokestop(session, cancellationToken, pokeStop);
                        }
                        timesZeroXPawarded++;

                        if (timesZeroXPawarded > zeroCheck)
                        {
                            if ((int)fortSearch.CooldownCompleteTimestampMs != 0)
                            {
                                break;
                                // Check if successfully looted, if so program can continue as this was "false alarm".
                            }

                            fortTry += 1;

                            session.EventDispatcher.Send(new FortFailedEvent
                            {
                                Name = fortInfo.Name,
                                Try  = fortTry,
                                Max  = retryNumber - zeroCheck
                            });
                            if (session.LogicSettings.Teleport)
                            {
                                await Task.Delay(session.LogicSettings.DelaySoftbanRetry);
                            }
                            else
                            {
                                await DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 400);
                            }
                        }
                    }
                    else
                    {
                        session.EventDispatcher.Send(new FortUsedEvent
                        {
                            Id            = pokeStop.Id,
                            Name          = fortInfo.Name,
                            Exp           = fortSearch.ExperienceAwarded,
                            Gems          = fortSearch.GemsAwarded,
                            Items         = StringUtils.GetSummedFriendlyNameOfItemAwardList(fortSearch.ItemsAwarded),
                            Latitude      = pokeStop.Latitude,
                            Longitude     = pokeStop.Longitude,
                            InventoryFull = fortSearch.Result == FortSearchResponse.Types.Result.InventoryFull
                        });

                        break; //Continue with program as loot was succesfull.
                    }
                } while (fortTry < retryNumber - zeroCheck);
                //Stop trying if softban is cleaned earlier or if 40 times fort looting failed.


                if (session.LogicSettings.Teleport)
                {
                    await Task.Delay(session.LogicSettings.DelayPokestop);
                }
                else
                {
                    await Task.Delay(1000, cancellationToken);
                }


                //Catch Lure Pokemon


                if (pokeStop.LureInfo != null)
                {
                    await CatchLurePokemonsTask.Execute(session, pokeStop, cancellationToken);
                }
                if (session.LogicSettings.Teleport)
                {
                    await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                }

                await eggWalker.ApplyDistance(distance, cancellationToken);

                if (stopsHit++ == 5 + session.Client.rnd.Next(5)) //TODO: OR item/pokemon bag is full
                {
                    stopsHit = 0;
                    if (fortSearch.ItemsAwarded.Count > 0)
                    {
                        await session.Inventory.RefreshCachedInventory();
                    }
                    await RecycleItemsTask.Execute(session, cancellationToken);

                    if (session.LogicSettings.EvolveAllPokemonWithEnoughCandy ||
                        session.LogicSettings.EvolveAllPokemonAboveIv)
                    {
                        await EvolvePokemonTask.Execute(session, cancellationToken);
                    }
                    if (session.LogicSettings.AutomaticallyLevelUpPokemon)
                    {
                        await LevelUpPokemonTask.Execute(session, cancellationToken);
                    }
                    if (session.LogicSettings.TransferDuplicatePokemon)
                    {
                        await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                    }
                    if (session.LogicSettings.RenamePokemon)
                    {
                        await RenamePokemonTask.Execute(session, cancellationToken);
                    }
                }

                if (session.LogicSettings.SnipeAtPokestops || session.LogicSettings.UseSnipeLocationServer)
                {
                    await SnipePokemonTask.Execute(session, cancellationToken);
                }
            }
        }
Esempio n. 12
0
        public static async Task NoTeleport(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var distanceFromStart = LocationUtils.CalculateDistanceInMeters(
                session.Settings.DefaultLatitude, session.Settings.DefaultLongitude,
                session.Client.CurrentLatitude, session.Client.CurrentLongitude);

            // Edge case for when the client somehow ends up outside the defined radius
            if (session.LogicSettings.MaxTravelDistanceInMeters != 0 &&
                distanceFromStart > session.LogicSettings.MaxTravelDistanceInMeters)
            {
                session.EventDispatcher.Send(new WarnEvent()
                {
                    Message = session.Translation.GetTranslation(TranslationString.FarmPokestopsOutsideRadius, distanceFromStart)
                });
                await Task.Delay(1000, cancellationToken);

                await session.Navigation.HumanLikeWalking(
                    new GeoCoordinate(session.Settings.DefaultLatitude, session.Settings.DefaultLongitude),
                    session.LogicSettings.WalkingSpeedInKilometerPerHour, null, cancellationToken);
            }

            var pokestopList = await GetPokeStops(session);

            var stopsHit        = 0;
            var displayStatsHit = 0;
            var eggWalker       = new EggWalker(1000, session);

            if (pokestopList.Count <= 0)
            {
                session.EventDispatcher.Send(new WarnEvent
                {
                    Message = session.Translation.GetTranslation(TranslationString.FarmPokestopsNoUsableFound)
                });
            }

            session.EventDispatcher.Send(new PokeStopListEvent {
                Forts = pokestopList
            });

            while (pokestopList.Any())
            {
                cancellationToken.ThrowIfCancellationRequested();

                //resort
                pokestopList =
                    pokestopList.OrderBy(
                        i =>
                        LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                session.Client.CurrentLongitude, i.Latitude, i.Longitude)).ToList();
                var pokeStop = pokestopList[0];
                pokestopList.RemoveAt(0);

                var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                       session.Client.CurrentLongitude, pokeStop.Latitude, pokeStop.Longitude);
                var fortInfo = await session.Client.Fort.GetFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude);

                session.EventDispatcher.Send(new FortTargetEvent {
                    Id = fortInfo.FortId, Name = fortInfo.Name, Distance = distance, Latitude = fortInfo.Latitude, Longitude = fortInfo.Longitude, Description = fortInfo.Description, url = fortInfo.ImageUrls[0]
                });
                if (session.LogicSettings.Teleport)
                {
                    await session.Client.Player.UpdatePlayerLocation(fortInfo.Latitude, fortInfo.Longitude,
                                                                     session.Client.Settings.DefaultAltitude);
                }

                else
                {
                    await session.Navigation.HumanLikeWalking(new GeoCoordinate(pokeStop.Latitude, pokeStop.Longitude),
                                                              session.LogicSettings.WalkingSpeedInKilometerPerHour,
                                                              async() =>
                    {
                        // Catch normal map Pokemon
                        await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                        //Catch Incense Pokemon
                        await CatchIncensePokemonsTask.Execute(session, cancellationToken);
                        return(true);
                    }, cancellationToken);
                }

                FortSearchResponse fortSearch;
                var       timesZeroXPawarded = 0;
                var       fortTry            = 0;  //Current check
                const int retryNumber        = 50; //How many times it needs to check to clear softban
                const int zeroCheck          = 5;  //How many times it checks fort before it thinks it's softban
                do
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    fortSearch =
                        await session.Client.Fort.SearchFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude);

                    if (fortSearch.ExperienceAwarded > 0 && timesZeroXPawarded > 0)
                    {
                        timesZeroXPawarded = 0;
                    }
                    if (fortSearch.ExperienceAwarded == 0)
                    {
                        timesZeroXPawarded++;

                        if (timesZeroXPawarded > zeroCheck)
                        {
                            if ((int)fortSearch.CooldownCompleteTimestampMs != 0)
                            {
                                break;
                                // Check if successfully looted, if so program can continue as this was "false alarm".
                            }

                            fortTry += 1;

                            session.EventDispatcher.Send(new FortFailedEvent
                            {
                                Name = fortInfo.Name,
                                Try  = fortTry,
                                Max  = retryNumber - zeroCheck
                            });
                            if (session.LogicSettings.Teleport)
                            {
                                await Task.Delay(session.LogicSettings.DelaySoftbanRetry);
                            }
                            else
                            {
                                await DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 400);
                            }
                        }
                    }
                    else
                    {
                        session.EventDispatcher.Send(new FortUsedEvent
                        {
                            Id            = pokeStop.Id,
                            Name          = fortInfo.Name,
                            Exp           = fortSearch.ExperienceAwarded,
                            Gems          = fortSearch.GemsAwarded,
                            Items         = StringUtils.GetSummedFriendlyNameOfItemAwardList(fortSearch.ItemsAwarded),
                            Latitude      = pokeStop.Latitude,
                            Longitude     = pokeStop.Longitude,
                            InventoryFull = fortSearch.Result == FortSearchResponse.Types.Result.InventoryFull,
                            Description   = fortInfo.Description,
                            url           = fortInfo.ImageUrls[0]
                        });

                        break; //Continue with program as loot was succesfull.
                    }
                } while (fortTry < retryNumber - zeroCheck);
                //Stop trying if softban is cleaned earlier or if 40 times fort looting failed.


                if (session.LogicSettings.Teleport)
                {
                    await Task.Delay(session.LogicSettings.DelayPokestop);
                }
                else
                {
                    await Task.Delay(1000, cancellationToken);
                }


                //Catch Lure Pokemon


                if (pokeStop.LureInfo != null)
                {
                    await CatchLurePokemonsTask.Execute(session, pokeStop, cancellationToken);
                }
                if (session.LogicSettings.Teleport)
                {
                    await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                }

                await eggWalker.ApplyDistance(distance, cancellationToken);

                if (++stopsHit % 5 == 0) //TODO: OR item/pokemon bag is full
                {
                    stopsHit = 0;
                    // need updated stardust information for upgrading, so refresh your profile now
                    await DownloadProfile(session);

                    if (fortSearch.ItemsAwarded.Count > 0)
                    {
                        await session.Inventory.RefreshCachedInventory();
                    }
                    await RecycleItemsTask.Execute(session, cancellationToken);

                    if (session.LogicSettings.EvolveAllPokemonWithEnoughCandy ||
                        session.LogicSettings.EvolveAllPokemonAboveIv)
                    {
                        await EvolvePokemonTask.Execute(session, cancellationToken);
                    }
                    if (session.LogicSettings.AutomaticallyLevelUpPokemon)
                    {
                        await LevelUpPokemonTask.Execute(session, cancellationToken);
                    }
                    if (session.LogicSettings.TransferDuplicatePokemon)
                    {
                        await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                    }
                    if (session.LogicSettings.RenamePokemon)
                    {
                        await RenamePokemonTask.Execute(session, cancellationToken);
                    }
                    if (++displayStatsHit >= 4)
                    {
                        await DisplayPokemonStatsTask.Execute(session);

                        displayStatsHit = 0;
                    }
                }

                if (session.LogicSettings.SnipeAtPokestops || session.LogicSettings.UseSnipeLocationServer)
                {
                    await SnipePokemonTask.Execute(session, cancellationToken);
                }
            }
        }
Esempio n. 13
0
        public static async Task Execute(ISession session, FortData currentFortData, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            // Refresh inventory so that the player stats are fresh
            await session.Inventory.RefreshCachedInventory();

            session.EventDispatcher.Send(new DebugEvent()
            {
                Message = session.Translation.GetTranslation(TranslationString.LookingForLurePokemon)
            });

            var fortId = currentFortData.Id;

            var pokemonId = currentFortData.LureInfo.ActivePokemonId;

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

                var pokemon = new MapPokemon
                {
                    EncounterId = encounterId,
                    Latitude    = currentFortData.Latitude,
                    Longitude   = currentFortData.Longitude,
                    PokemonId   = pokemonId
                };
                session.EventDispatcher.Send(new PokemonsFoundEvent {
                    Pokemons = new MapPokemon[] { pokemon }
                });

                if (encounter.Result == DiskEncounterResponse.Types.Result.Success)
                {
                    await CatchPokemonTask.Execute(session, encounter, null, currentFortData, encounterId);
                }
                else if (encounter.Result == DiskEncounterResponse.Types.Result.PokemonInventoryFull)
                {
                    if (session.LogicSettings.TransferDuplicatePokemon)
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.InvFullTransferring)
                        });
                        await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
                    }
                    else
                    {
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message = session.Translation.GetTranslation(TranslationString.InvFullTransferManually)
                        });
                    }
                }
                else
                {
                    if (encounter.Result.ToString().Contains("NotAvailable"))
                    {
                        session.EventDispatcher.Send(new PokemonDisappearEvent {
                            Pokemon = pokemon
                        });
                        return;
                    }
                    session.EventDispatcher.Send(new WarnEvent
                    {
                        Message =
                            session.Translation.GetTranslation(TranslationString.EncounterProblemLurePokemon,
                                                               encounter.Result)
                    });
                }
                session.EventDispatcher.Send(new PokemonDisappearEvent {
                    Pokemon = pokemon
                });
            }
        }
Esempio n. 14
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            // Refresh inventory so that the player stats are fresh
            await session.Inventory.RefreshCachedInventory();

            session.EventDispatcher.Send(new DebugEvent()
            {
                Message = session.Translation.GetTranslation(TranslationString.LookingForPokemon)
            });

            var pokemons = await GetNearbyPokemons(session);

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

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

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

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

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

                if (pokeBallsCount + greatBallsCount + ultraBallsCount + masterBallsCount == 0)
                {
                    session.EventDispatcher.Send(new NoticeEvent()
                    {
                        Message = session.Translation.GetTranslation(TranslationString.ZeroPokeballInv)
                    });
                    return;
                }

                if (session.LogicSettings.UsePokemonToNotCatchFilter &&
                    session.LogicSettings.PokemonsNotToCatch.Contains(pokemon.PokemonId))
                {
                    session.EventDispatcher.Send(new NoticeEvent()
                    {
                        Message = session.Translation.GetTranslation(TranslationString.PokemonSkipped, session.Translation.GetPokemonName(pokemon.PokemonId))
                    });
                    continue;
                }

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

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

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

                // If pokemon is not last pokemon in list, create delay between catches, else keep moving.
                if (!Equals(pokemons.ElementAtOrDefault(pokemons.Count() - 1), pokemon))
                {
                    if (session.LogicSettings.Teleport)
                    {
                        await Task.Delay(session.LogicSettings.DelayBetweenPokemonCatch);
                    }
                    else
                    {
                        await Task.Delay(session.LogicSettings.DelayBetweenPokemonCatch, cancellationToken);
                    }
                }
            }
        }
        public static async Task  Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            //Refresh inventory so that the player stats are fresh
            //await session.Inventory.RefreshCachedInventory(); too much inventory refresh

            await CheckChallengeDoneTask.Execute(session, cancellationToken);

            await CheckChallengeTask.Execute(session, cancellationToken);

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

            if (session.Runtime.PokeBallsToCollect > 0)
            {
                return;
            }

            //session.EventDispatcher.Send(new DebugEvent()
            //{
            //    Message = session.Translation.GetTranslation(TranslationString.LookingForPokemon)
            //});

            var pokemons = await GetNearbyPokemons(session);

            if (session.LogicSettings.UsePokemonToNotCatchFilter)
            {
                pokemons = pokemons.Where(x => !session.LogicSettings.PokemonsNotToCatch.Contains(x.PokemonId)).ToList();
            }

            session.EventDispatcher.Send(new PokemonsFoundEvent {
                Pokemons = pokemons.Select(x => x.BaseMapPokemon)
            });
            if (!await CheckBotStateTask.Execute(session, cancellationToken))
            {
                return;
            }

            var prevState = session.State;

            session.State = BotState.FoundPokemons;

            pokemons = pokemons.OrderByDescending(x => x.PokemonId.HowRare()).ToList();

            foreach (var pokemon in pokemons)
            {
                if (pokemon.ExpirationTimestampMs > DateTime.UtcNow.ToUnixTime())
                {
                    continue;
                }

                cancellationToken.ThrowIfCancellationRequested();

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

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

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

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

                if (pokeBallsCount + greatBallsCount + ultraBallsCount + masterBallsCount == 0)
                {
                    session.EventDispatcher.Send(new NoticeEvent
                    {
                        Message = session.Translation.GetTranslation(TranslationString.ZeroPokeballInv)
                    });
                    session.State = prevState;
                    session.Runtime.PokeBallsToCollect = 10;
                    session.EventDispatcher.Send(new PokemonDisappearEvent {
                        EncounterId = pokemon.EncounterId
                    });
                    continue;
                }

                if (session.LogicSettings.UsePokemonToNotCatchFilter &&
                    session.LogicSettings.PokemonsNotToCatch.Contains(pokemon.PokemonId))
                {
                    if (!pokemon.Caught)
                    {
                        session.EventDispatcher.Send(new NoticeEvent
                        {
                            Message =
                                session.Translation.GetTranslation(TranslationString.PokemonSkipped,
                                                                   session.Translation.GetPokemonName(pokemon.PokemonId))
                        });
                    }
                    pokemon.Caught = true;
                    session.EventDispatcher.Send(new PokemonDisappearEvent {
                        EncounterId = pokemon.EncounterId
                    });
                    continue;
                }

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

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

                try
                {
                    switch (encounter.Status)
                    {
                    case EncounterResponse.Types.Status.EncounterSuccess:
                        var catchRes = await CatchPokemonTask.Execute(session, encounter, pokemon, cancellationToken);

                        if (!catchRes)
                        {
                            session.Runtime.PokeBallsToCollect = 10;
                            session.State = prevState;

                            foreach (var p in pokemons)
                            {
                                session.EventDispatcher.Send(new PokemonDisappearEvent {
                                    EncounterId = p.EncounterId
                                });
                            }

                            return;
                        }
                        break;

                    case EncounterResponse.Types.Status.PokemonInventoryFull:
                        if (session.LogicSettings.TransferDuplicatePokemon)
                        {
                            session.EventDispatcher.Send(new WarnEvent
                            {
                                Message = session.Translation.GetTranslation(TranslationString.InvFullTransferring)
                            });
                            session.State = BotState.Idle;
                            await TransferDuplicatePokemonTask.Execute(session, cancellationToken);

                            session.State = BotState.FoundPokemons;
                        }
                        else
                        {
                            session.EventDispatcher.Send(new WarnEvent
                            {
                                Message =
                                    session.Translation.GetTranslation(TranslationString.InvFullTransferManually)
                            });
                        }
                        break;

                    default:
                        session.EventDispatcher.Send(new WarnEvent
                        {
                            Message =
                                session.Translation.GetTranslation(TranslationString.EncounterProblem,
                                                                   encounter.Status)
                        });
                        break;
                    }
                }
                catch (Exception)
                {
                    session.EventDispatcher.Send(new WarnEvent
                    {
                        Message = session.Translation.GetTranslation(TranslationString.ErrorCatchNearby)
                    });
                    await Task.Delay(5000, cancellationToken);
                }

                session.EventDispatcher.Send(new PokemonDisappearEvent {
                    EncounterId = pokemon.EncounterId
                });

                // always wait the delay amount between catches, ideally to prevent you from making another call too early after a catch event
                await Task.Delay(session.LogicSettings.DelayBetweenPokemonCatch, cancellationToken);
            }
            session.State = prevState;
        }