Ejemplo n.º 1
0
        private static async Task UpdateFarmingPokestop(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var nearestStop = session.VisibleForts.OrderBy(i =>
                                                           LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
                                                                                                   session.Client.CurrentLongitude, i.Latitude, i.Longitude)).FirstOrDefault();

            if (nearestStop != null)
            {
                var walkedDistance = LocationUtils.CalculateDistanceInMeters(nearestStop.Latitude, nearestStop.Longitude, session.Client.CurrentLatitude, session.Client.CurrentLongitude);
                if (walkedDistance > session.LogicSettings.HumanWalkingSnipeWalkbackDistanceLimit)
                {
                    await Task.Delay(3000, cancellationToken);

                    var nearbyPokeStops = await UseNearbyPokestopsTask.UpdateFortsData(session);

                    var notexists = nearbyPokeStops.Where(p => !session.VisibleForts.Exists(x => x.Id == p.Id)).ToList();
                    session.AddVisibleForts(notexists);
                    session.EventDispatcher.Send(new PokeStopListEvent {
                        Forts = notexists
                    });
                    session.EventDispatcher.Send(new HumanWalkSnipeEvent
                    {
                        Type            = HumanWalkSnipeEventTypes.PokestopUpdated,
                        Pokestops       = notexists,
                        NearestDistance = walkedDistance
                    });
                }
            }
        }
Ejemplo n.º 2
0
        private static async Task ActionsWhenTravelToSnipeTarget(ISession session, CancellationToken cancellationToken,
                                                                 SnipePokemonInfo pokemon, bool allowCatchPokemon, bool allowSpinPokeStop)
        {
            var distance = LocationUtils.CalculateDistanceInMeters(
                pokemon.Latitude,
                pokemon.Longitude,
                session.Client.CurrentLatitude,
                session.Client.CurrentLongitude
                );

            if (allowCatchPokemon && distance > 50.0)
            {
                // Catch normal map Pokemon
                await CatchNearbyPokemonsTask.Execute(session, cancellationToken, sessionAllowTransfer : false);
            }
            if (allowSpinPokeStop)
            {
                //looking for neaby pokestop. spin it
                await UseNearbyPokestopsTask.SpinPokestopNearBy(session, cancellationToken, null);
            }
            if (session.LogicSettings.ActivateMSniper)
            {
                await MSniperServiceTask.Execute(session, cancellationToken);
            }
        }
Ejemplo n.º 3
0
        public static async Task Execute(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)
            {
                Logger.Write(
                    session.Translation.GetTranslation(TranslationString.FarmPokestopsOutsideRadius, distanceFromStart),
                    LogLevel.Warning);

                var eggWalker = new EggWalker(1000, session);

                await session.Navigation.Move(new GeoCoordinate(
                                                  session.Settings.DefaultLatitude,
                                                  session.Settings.DefaultLongitude,
                                                  LocationUtils.getElevation(session.Settings.DefaultLatitude,
                                                                             session.Settings.DefaultLongitude)),
                                              null,
                                              session,
                                              cancellationToken);

                // we have moved this distance, so apply it immediately to the egg walker.
                await eggWalker.ApplyDistance(distanceFromStart, cancellationToken);
            }

            // initialize the variables in UseNearbyPokestopsTask here, as this is a fresh start.
            UseNearbyPokestopsTask.Initialize();
            await UseNearbyPokestopsTask.Execute(session, cancellationToken);
        }
Ejemplo n.º 4
0
 private static async Task WalkingBackGPXPath(ISession session, CancellationToken cancellationToken, FortData originalPokestop)
 {
     var destination = new GeoCoordinate(originalPokestop.Latitude, originalPokestop.Longitude,
                                         LocationUtils.getElevation(session, originalPokestop.Latitude, originalPokestop.Longitude));
     await session.Navigation.Move(destination,
                                   async() =>
     {
         await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
         await UseNearbyPokestopsTask.SpinPokestopNearBy(session, cancellationToken);
     },
                                   session,
                                   cancellationToken);
 }
Ejemplo n.º 5
0
 private static async Task WalkingBackGPXPath(ISession session, CancellationToken cancellationToken, FortData originalPokestop, FortDetailsResponse fortInfo)
 {
     var destination = new FortLocation(originalPokestop.Latitude, originalPokestop.Longitude,
                                        LocationUtils.getElevation(session.ElevationService, originalPokestop.Latitude, originalPokestop.Longitude), originalPokestop, fortInfo);
     await session.Navigation.Move(destination,
                                   async() =>
     {
         await MSniperServiceTask.Execute(session, cancellationToken);
         await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
         await UseNearbyPokestopsTask.SpinPokestopNearBy(session, cancellationToken);
     },
                                   session,
                                   cancellationToken);
 }
Ejemplo n.º 6
0
 private static async Task WalkingBackGPXPath(ISession session, CancellationToken cancellationToken, FortData originalPokestop)
 {
     var destination = new FortLocation(originalPokestop.Latitude, originalPokestop.Longitude,
                                        LocationUtils.getElevation(session, originalPokestop.Latitude, originalPokestop.Longitude), originalPokestop, null);
     await session.Navigation.Move(destination,
                                   async() =>
     {
         if (session.LogicSettings.ActivateMSniper)
         {
             await MSniperServiceTask.Execute(session, cancellationToken);
         }
         await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
         await UseNearbyPokestopsTask.SpinPokestopNearBy(session, cancellationToken);
     },
                                   session,
                                   cancellationToken);
 }
Ejemplo n.º 7
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

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

            var response = await session.Client.Player.UpdatePlayerLocation(session.Client.CurrentLatitude, session.Client.CurrentLongitude, session.Client.CurrentAltitude, 0);

            // Edge case for when the client somehow ends up outside the defined radius
            if (session.LogicSettings.MaxTravelDistanceInMeters != 0 && checkForMoveBackToDefault &&
                distanceFromStart > session.LogicSettings.MaxTravelDistanceInMeters)
            {
                checkForMoveBackToDefault = false;
                Logger.Write(
                    session.Translation.GetTranslation(TranslationString.FarmPokestopsOutsideRadius, distanceFromStart),
                    LogLevel.Warning);

                var eggWalker = new EggWalker(1000, session);

                var defaultLocation = new MapLocation(session.Settings.DefaultLatitude,
                                                      session.Settings.DefaultLongitude,
                                                      LocationUtils.getElevation(session.ElevationService, session.Settings.DefaultLatitude, session.Settings.DefaultLongitude)
                                                      );

                await session.Navigation.Move(defaultLocation,
                                              async() =>
                {
                    await MSniperServiceTask.Execute(session, cancellationToken);
                },
                                              session,
                                              cancellationToken);

                // we have moved this distance, so apply it immediately to the egg walker.
                await eggWalker.ApplyDistance(distanceFromStart, cancellationToken);
            }
            checkForMoveBackToDefault = false;

            await CatchNearbyPokemonsTask.Execute(session, cancellationToken);

            // initialize the variables in UseNearbyPokestopsTask here, as this is a fresh start.
            UseNearbyPokestopsTask.Initialize();
            await UseNearbyPokestopsTask.Execute(session, cancellationToken);
        }
Ejemplo n.º 8
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            var tracks    = GetGpxTracks(session);
            var eggWalker = new EggWalker(1000, session);

            if (!_resumeTrack.HasValue || !_resumeTrackSeg.HasValue || !_resumeTrackPt.HasValue)
            {
                _resumeTrack    = session.LogicSettings.ResumeTrack;
                _resumeTrackSeg = session.LogicSettings.ResumeTrackSeg;
                _resumeTrackPt  = session.LogicSettings.ResumeTrackPt;

                // initialize the variables in UseNearbyPokestopsTask here, as this is a fresh start.
                UseNearbyPokestopsTask.Initialize();
            }

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

                var track         = tracks.ElementAt(curTrk);
                var trackSegments = track.Segments;

                for (var curTrkSeg = _resumeTrackSeg.Value; curTrkSeg < trackSegments.Count; curTrkSeg++)
                {
                    _resumeTrackSeg = curTrkSeg;
                    cancellationToken.ThrowIfCancellationRequested();

                    var trackPoints = trackSegments.ElementAt(curTrkSeg).TrackPoints;

                    for (var curTrkPt = _resumeTrackPt.Value; curTrkPt < trackPoints.Count; curTrkPt++)
                    {
                        _resumeTrackPt = 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 lat = Convert.ToDouble(trackPoints.ElementAt(curTrkPt).Lat, CultureInfo.InvariantCulture);
                        var lng = Convert.ToDouble(trackPoints.ElementAt(curTrkPt).Lon, CultureInfo.InvariantCulture);

                        IGeoLocation destination = new GPXPointLocation(lat, lng, LocationUtils.getElevation(session.ElevationService, lat, lng));

                        await session.Navigation.Move(destination,
                                                      async() =>
                        {
                            await MSniperServiceTask.Execute(session, cancellationToken);

                            await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                            //Catch Incense Pokemon
                            await CatchIncensePokemonsTask.Execute(session, cancellationToken);
                            await UseNearbyPokestopsTask.Execute(session, cancellationToken);
                        },
                                                      session,
                                                      cancellationToken);

                        await eggWalker.ApplyDistance(distance, cancellationToken);

                        // Return to FarmState/StateMachine if we have reached both user defined limits
                        if ((UseNearbyPokestopsTask._pokestopLimitReached || UseNearbyPokestopsTask._pokestopTimerReached) &&
                            (CatchPokemonTask._catchPokemonLimitReached || CatchPokemonTask._catchPokemonTimerReached))
                        {
                            return;
                        }
                    } //end trkpts
                    _resumeTrackPt = 0;
                }     //end trksegs
                _resumeTrackSeg = 0;
            }         //end tracks
            _resumeTrack = 0;
        }
Ejemplo n.º 9
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            var tracks    = GetGpxTracks(session);
            var curTrkPt  = 0;
            var curTrk    = 0;
            var maxTrk    = tracks.Count - 1;
            var curTrkSeg = 0;
            var eggWalker = new EggWalker(1000, session);

            while (curTrk <= maxTrk)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var track         = tracks.ElementAt(curTrk);
                var trackSegments = track.Segments;
                var maxTrkSeg     = trackSegments.Count - 1;
                while (curTrkSeg <= maxTrkSeg)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    var trackPoints = track.Segments.ElementAt(0).TrackPoints;
                    var maxTrkPt    = trackPoints.Count - 1;
                    while (curTrkPt <= maxTrkPt)
                    {
                        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(Common.TranslationString.DesiredDestTooFar, nextPoint.Lat, nextPoint.Lon, session.Client.CurrentLatitude, session.Client.CurrentLongitude)
                            });
                            break;
                        }

                        var pokestopList = await GetPokeStops(session);

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

                        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);

                            if (pokeStop.LureInfo != null)
                            {
                                await CatchLurePokemonsTask.Execute(session, pokeStop, 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
                                });
                            }
                            if (fortSearch.ItemsAwarded.Count > 0)
                            {
                                await session.Inventory.RefreshCachedInventory();
                            }

                            await RecycleItemsTask.Execute(session, cancellationToken);

                            if (session.LogicSettings.SnipeAtPokestops)
                            {
                                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.RenameAboveIv)
                            {
                                await RenamePokemonTask.Execute(session, cancellationToken);
                            }
                        }

                        await session.Navigation.HumanPathWalking(
                            trackPoints.ElementAt(curTrkPt),
                            session.LogicSettings.WalkingSpeedInKilometerPerHour,
                            async() =>
                        {
                            await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                            //Catch Incense Pokemon
                            await CatchIncensePokemonsTask.Execute(session, cancellationToken);
                            await UseNearbyPokestopsTask.Execute(session, cancellationToken);
                            return(true);
                        },
                            cancellationToken
                            );

                        await eggWalker.ApplyDistance(distance, cancellationToken);

                        if (curTrkPt >= maxTrkPt)
                        {
                            curTrkPt = 0;
                        }
                        else
                        {
                            curTrkPt++;
                        }
                    } //end trkpts
                    if (curTrkSeg >= maxTrkSeg)
                    {
                        curTrkSeg = 0;
                    }
                    else
                    {
                        curTrkSeg++;
                    }
                } //end trksegs
                if (curTrk >= maxTrkSeg)
                {
                    curTrk = 0;
                }
                else
                {
                    curTrk++;
                }
            } //end tracks
        }
Ejemplo n.º 10
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            var tracks    = GetGpxTracks(session);
            var eggWalker = new EggWalker(1000, session);

            if (_resumeTrack + _resumeTrackSeg + _resumeTrackPt == 0)
            {
                _resumeTrack    = session.LogicSettings.ResumeTrack;
                _resumeTrackSeg = session.LogicSettings.ResumeTrackSeg;
                _resumeTrackPt  = session.LogicSettings.ResumeTrackPt;

                // initialize the variables in UseNearbyPokestopsTask here, as this is a fresh start.
                UseNearbyPokestopsTask.Initialize();
            }

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

                var track         = tracks.ElementAt(curTrk);
                var trackSegments = track.Segments;

                for (var curTrkSeg = _resumeTrackSeg; curTrkSeg < trackSegments.Count; curTrkSeg++)
                {
                    _resumeTrackSeg = curTrkSeg;
                    cancellationToken.ThrowIfCancellationRequested();

                    var trackPoints = trackSegments.ElementAt(curTrkSeg).TrackPoints;

                    for (var curTrkPt = _resumeTrackPt; curTrkPt < trackPoints.Count; curTrkPt++)
                    {
                        _resumeTrackPt = 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 geo = new GeoCoordinate(Convert.ToDouble(trackPoints.ElementAt(curTrkPt).Lat, CultureInfo.InvariantCulture),
                                                    Convert.ToDouble(trackPoints.ElementAt(curTrkPt).Lon, CultureInfo.InvariantCulture));

                        await session.Navigation.Move(geo,
                                                      async() =>
                        {
                            await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                            //Catch Incense Pokemon
                            await CatchIncensePokemonsTask.Execute(session, cancellationToken);
                            await UseNearbyPokestopsTask.Execute(session, cancellationToken);
                            return(true);
                        },
                                                      session,
                                                      cancellationToken);

                        await eggWalker.ApplyDistance(distance, cancellationToken);
                    } //end trkpts
                    _resumeTrackPt = 0;
                }     //end trksegs
                _resumeTrackSeg = 0;
            }         //end tracks
            _resumeTrack = 0;
        }
Ejemplo n.º 11
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;

                if (curTrkSeg >= trackSegments.Count)
                {
                    curTrkSeg = 0;
                }
                for (; curTrkSeg < trackSegments.Count; curTrkSeg++)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    var trackPoints = track.Segments.ElementAt(curTrkSeg).TrackPoints;

                    if (curTrkPt >= trackPoints.Count)
                    {
                        curTrkPt = 0;
                    }
                    for (; 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);

                        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)
                            {
                                await CatchLurePokemonsTask.Execute(session, pokeStop, 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
                                });
                            }
                            else
                            {
                                await RecycleItemsTask.Execute(session, cancellationToken);
                            }

                            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.EvolveAllPokemonWithEnoughCandy ||
                                session.LogicSettings.EvolveAllPokemonAboveIv ||
                                session.LogicSettings.UseLuckyEggsWhileEvolving ||
                                session.LogicSettings.KeepPokemonsThatCanEvolve)
                            {
                                await EvolvePokemonTask.Execute(session, cancellationToken);
                            }
                            await GetPokeDexCount.Execute(session, cancellationToken);

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

                            if (session.LogicSettings.AutoFavoritePokemon)
                            {
                                await FavoritePokemonTask.Execute(session, cancellationToken);
                            }

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

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

                        await session.Navigation.Move(geo,
                                                      async() =>
                        {
                            await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                            //Catch Incense Pokemon
                            await CatchIncensePokemonsTask.Execute(session, cancellationToken);
                            await UseNearbyPokestopsTask.Execute(session, cancellationToken);
                            return(true);
                        },
                                                      session,
                                                      cancellationToken);

                        await eggWalker.ApplyDistance(distance, cancellationToken);
                    } //end trkpts
                }     //end trksegs
            }         //end tracks
        }
Ejemplo n.º 12
0
        private static async Task StartGymAttackLogic(ISession session, FortDetailsResponse fortInfo,
                                                      GetGymDetailsResponse fortDetails, FortData gym, CancellationToken cancellationToken)
        {
            var defenders = fortDetails.GymState.Memberships.Select(x => x.PokemonData).ToList();

            if (session.Profile.PlayerData.Team != fortInfo.TeamColor)
            {
                if (session.LogicSettings.GymConfig.MaxGymLevelToAttack < GetGymLevel(gym.GymPoints))
                {
                    Logger.Write($"This is gym level {GetGymLevel(gym.GymPoints)} > {session.LogicSettings.GymConfig.MaxGymLevelToAttack} in your config. Bot walk away...", LogLevel.Gym, ConsoleColor.Red);
                    return;
                }

                if (session.LogicSettings.GymConfig.MaxDefendersToAttack < defenders.Count)
                {
                    Logger.Write($"This is gym has   {defenders.Count} defender  > {session.LogicSettings.GymConfig.MaxDefendersToAttack} in your config. Bot walk away...", LogLevel.Gym, ConsoleColor.Red);
                    return;
                }
            }

            await session.Inventory.RefreshCachedInventory();

            var badassPokemon = await session.Inventory.GetHighestCpForGym(6);

            var pokemonDatas = badassPokemon as PokemonData[] ?? badassPokemon.ToArray();

            if (defenders.Count == 0)
            {
                return;
            }

            Logger.Write("Start battle with : " + string.Join(", ", defenders.Select(x => x.PokemonId.ToString())));

            // Heal pokemon
            foreach (var pokemon in pokemonDatas)
            {
                if (pokemon.Stamina <= 0)
                {
                    await RevivePokemon(session, pokemon);
                }

                if (pokemon.Stamina <= 0)
                {
                    Logger.Write("You are out of revive potions! Can't resurect attacker", LogLevel.Gym, ConsoleColor.Magenta);
                    return;
                }

                if (pokemon.Stamina < pokemon.StaminaMax)
                {
                    await HealPokemon(session, pokemon);
                }

                if (pokemon.Stamina < pokemon.StaminaMax)
                {
                    Logger.Write(string.Format("You are out of healing potions! {0} ({1} CP) haven't got fully healed", pokemon.PokemonId, pokemon.Cp), LogLevel.Gym, ConsoleColor.Magenta);
                }
            }
            await Task.Delay(2000);

            var  index           = 0;
            bool isVictory       = true;
            bool isFailedToStart = false;
            List <BattleAction> battleActions = new List <BattleAction>();
            ulong defenderPokemonId           = defenders.First().Id;

            while (index < defenders.Count())
            {
                cancellationToken.ThrowIfCancellationRequested();
                var thisAttackActions = new List <BattleAction>();

                StartGymBattleResponse result = null;
                try
                {
                    await Task.Delay(2000);

                    result = await StartBattle(session, gym, pokemonDatas, defenders.FirstOrDefault(x => x.Id == defenderPokemonId));
                }
                #pragma warning disable 0168
                catch (APIBadRequestException e)
                #pragma warning restore 0168
                {
                    Logger.Write("Can't start battle", LogLevel.Gym);
                    isFailedToStart = true;
                    isVictory       = false;
                    _startBattleCounter--;

                    var newFots = await UseNearbyPokestopsTask.UpdateFortsData(session);

                    gym = newFots.FirstOrDefault(w => w.Id == gym.Id);

                    break;
                }

                index++;
                // If we can't start battle in 10 tries, let's skip the gym
                if (result == null || result.Result == StartGymBattleResponse.Types.Result.Unset)
                {
                    session.EventDispatcher.Send(new GymErrorUnset {
                        GymName = fortInfo.Name
                    });
                    isVictory = false;
                    break;
                }

                if (result.Result != StartGymBattleResponse.Types.Result.Success)
                {
                    break;
                }
                switch (result.BattleLog.State)
                {
                case BattleState.Active:
                    Logger.Write($"Time to start Attack Mode", LogLevel.Gym, ConsoleColor.DarkYellow);
                    thisAttackActions = await AttackGym(session, cancellationToken, gym, result);

                    battleActions.AddRange(thisAttackActions);
                    break;

                case BattleState.Defeated:
                    isVictory = false;
                    break;

                case BattleState.StateUnset:
                    isVictory = false;
                    break;

                case BattleState.TimedOut:
                    isVictory = false;
                    break;

                case BattleState.Victory:
                    break;

                default:
                    Logger.Write($"Unhandled result starting gym battle:\n{result}");
                    break;
                }

                var rewarded   = battleActions.Select(x => x.BattleResults?.PlayerExperienceAwarded).Where(x => x != null);
                var lastAction = battleActions.LastOrDefault();

                if (lastAction.Type == BattleActionType.ActionTimedOut ||
                    lastAction.Type == BattleActionType.ActionUnset ||
                    lastAction.Type == BattleActionType.ActionDefeat)
                {
                    isVictory = false;
                    break;
                }

                var faintedPKM      = battleActions.Where(x => x != null && x.Type == BattleActionType.ActionFaint).Select(x => x.ActivePokemonId).Distinct();
                var livePokemons    = pokemonDatas.Where(x => !faintedPKM.Any(y => y == x.Id));
                var faintedPokemons = pokemonDatas.Where(x => faintedPKM.Any(y => y == x.Id));
                pokemonDatas = livePokemons.Concat(faintedPokemons).ToArray();

                if (lastAction.Type == BattleActionType.ActionVictory)
                {
                    if (lastAction.BattleResults != null)
                    {
                        var exp   = lastAction.BattleResults.PlayerExperienceAwarded;
                        var point = lastAction.BattleResults.GymPointsDelta;
                        gym.GymPoints    += point;
                        defenderPokemonId = unchecked ((ulong)lastAction.BattleResults.NextDefenderPokemonId);

                        Logger.Write(string.Format("Exp: {0}, Gym points: {1}" /*, Next defender id: {2}"*/, exp, point, defenderPokemonId), LogLevel.Gym, ConsoleColor.Magenta);
                    }
                    continue;
                }
            }

            if (isVictory)
            {
                if (gym.GymPoints < 0)
                {
                    gym.GymPoints = 0;
                }
                await Execute(session, cancellationToken, gym, fortInfo);
            }

            if (isFailedToStart && _startBattleCounter > 0)
            {
                //session.ReInitSessionWithNextBot();
                await Execute(session, cancellationToken, gym, fortInfo);
            }

            if (_startBattleCounter <= 0)
            {
                _startBattleCounter = 3;
            }
        }
Ejemplo n.º 13
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            var tracks    = GetGpxTracks(session);
            var eggWalker = new EggWalker(1000, session);

            if (_resumeTrack + _resumeTrackSeg + _resumeTrackPt == 0)
            {
                _resumeTrack    = session.LogicSettings.ResumeTrack;
                _resumeTrackSeg = session.LogicSettings.ResumeTrackSeg;
                _resumeTrackPt  = session.LogicSettings.ResumeTrackPt;
            }

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

                var track         = tracks.ElementAt(curTrk);
                var trackSegments = track.Segments;

                for (var curTrkSeg = _resumeTrackSeg; curTrkSeg < trackSegments.Count; curTrkSeg++)
                {
                    _resumeTrackSeg = curTrkSeg;
                    cancellationToken.ThrowIfCancellationRequested();

                    var trackPoints = trackSegments.ElementAt(curTrkSeg).TrackPoints;

                    for (var curTrkPt = _resumeTrackPt; curTrkPt < trackPoints.Count; curTrkPt++)
                    {
                        _resumeTrackPt = 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;
                        }

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

                            await RecycleItemsTask.Execute(session, cancellationToken);

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

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

                            if (session.LogicSettings.AutoFavoritePokemon)
                            {
                                await FavoritePokemonTask.Execute(session, cancellationToken);
                            }

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

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

                        await session.Navigation.Move(geo,
                                                      async() =>
                        {
                            await CatchNearbyPokemonsTask.Execute(session, cancellationToken);
                            //Catch Incense Pokemon
                            await CatchIncensePokemonsTask.Execute(session, cancellationToken);
                            await UseNearbyPokestopsTask.Execute(session, cancellationToken);
                            return(true);
                        },
                                                      session,
                                                      cancellationToken);

                        await eggWalker.ApplyDistance(distance, cancellationToken);
                    } //end trkpts
                    _resumeTrackPt = 0;
                }     //end trksegs
                _resumeTrackSeg = 0;
            }         //end tracks
            _resumeTrack = 0;
        }