Exemplo n.º 1
0
        private static FortData[] GetNearbyGyms()
        {
            LocationUtils.updatePlayerLocation(Logic.objClient, Logic.objClient.CurrentLatitude, Logic.objClient.CurrentLongitude, Logic.objClient.CurrentAltitude);
            var mapObjectsResponse = Logic.objClient.Map.GetMapObjects().Result;

            var pokeGyms = mapObjectsResponse.MapCells.SelectMany(i => i.Forts)
                           .Where(i => i.Type == FortType.Gym)
                           .OrderBy(i => LocationUtils.CalculateDistanceInMeters(Logic.objClient.CurrentLatitude, Logic.objClient.CurrentLongitude, i.Latitude, i.Longitude))
                           .ToArray();

            Task.Factory.StartNew(() => RefreshGymsInMap(pokeGyms));
            return(pokeGyms);
        }
Exemplo n.º 2
0
        private static FortData[] GetNearbyGyms(GetMapObjectsResponse mapObjectsResponse = null)
        {
            //Logic.objClient.Player.UpdatePlayerLocation(Logic.objClient.CurrentLatitude, Logic.objClient.CurrentLongitude, Logic.objClient.CurrentAltitude);
            LocationUtils.updatePlayerLocation(Logic.objClient, Logic.objClient.CurrentLatitude, Logic.objClient.CurrentLongitude, Logic.objClient.CurrentAltitude);
            RandomHelper.RandomSleep(400);

            if (mapObjectsResponse == null)
            {
                mapObjectsResponse = Logic.objClient.Map.GetMapObjects().Result.Item1;
            }

            var pokeGyms = Logic.Instance.navigation
                           .pathByNearestNeighbour(
                mapObjectsResponse.MapCells.SelectMany(i => i.Forts)
                .Where(i => i.Type == FortType.Gym)
                .OrderBy(i => LocationUtils.CalculateDistanceInMeters(Logic.objClient.CurrentLatitude, Logic.objClient.CurrentLongitude, i.Latitude, i.Longitude))
                .ToArray(), GlobalVars.WalkingSpeedInKilometerPerHour);

            return(pokeGyms);
        }
Exemplo n.º 3
0
        public void Execute(PokemonId pokeid, GeoCoordinate remoteCoords)
        {
            GeoCoordinate returnCoords = new GeoCoordinate();

            returnCoords.Latitude  = _client.CurrentLatitude;
            returnCoords.Longitude = _client.CurrentLongitude;
            returnCoords.Altitude  = _client.CurrentAltitude;
            LocationUtils.updatePlayerLocation(_client, returnCoords.Latitude, returnCoords.Longitude, returnCoords.Altitude);

            //var result = _client.Player.UpdatePlayerLocation(returnCoords.Latitude, returnCoords.Longitude, returnCoords.Altitude).Result;

            if (_botSettings == null && _client == null)
            {
                SendToLog($" client or settings are not set");
                return;
            }

            try
            {
                remoteCoords.Altitude = LocationUtils.getAltitude(remoteCoords.Latitude, remoteCoords.Longitude);

                SendToLog($"Trying to capture {pokeid}  at { remoteCoords.Latitude } / {remoteCoords.Longitude}");
                SendToLog(LocationUtils.FindAddress(remoteCoords.Latitude, remoteCoords.Longitude));
                LocationUtils.updatePlayerLocation(_client, remoteCoords.Latitude, remoteCoords.Longitude, remoteCoords.Altitude);
                //result = _client.Player.UpdatePlayerLocation(remoteCoords.Latitude, remoteCoords.Longitude, remoteCoords.Altitude).Result;

                SendToLog($"We are at sniping location...");
                SendToLog($"Waiting {GlobalVars.SnipeOpts.WaitSecond} seconds for Pokemon to appear...");
                RandomHelper.RandomSleep(GlobalVars.SnipeOpts.WaitSecond * 1000, GlobalVars.SnipeOpts.WaitSecond * 1100);

                var catchedID = TrySnipePokemons(pokeid, remoteCoords, returnCoords);
                if ((catchedID > 0) && GlobalVars.SnipeOpts.TransferIt)
                {
                    var trResult = Logic.objClient.Inventory.TransferPokemon(catchedID);
                    if (trResult.Result == ReleasePokemonResponse.Types.Result.Success)
                    {
                        SendToLog("Pokemon was transfered.");
                        SendToLog("Candies awarded: " + trResult.CandyAwarded);
                    }
                }

                // Restore Position
                LocationUtils.updatePlayerLocation(_client, returnCoords.Latitude, returnCoords.Longitude, returnCoords.Altitude);
                //result = _client.Player.UpdatePlayerLocation(returnCoords.Latitude, returnCoords.Longitude, returnCoords.Altitude).Result;

                SendToLog($"Location after Snipe : {returnCoords.Latitude} / {returnCoords.Longitude} / {returnCoords.Altitude}");
                SendToLog(LocationUtils.FindAddress(returnCoords.Latitude, returnCoords.Longitude));

                RandomHelper.RandomSleep(20000, 22000);  // Avoid cache after snipe
            }
            catch (Exception ex)
            {
                Logger.ExceptionInfo(ex.ToString());
                SendToLog($"Go to {returnCoords.Latitude} / {returnCoords.Longitude} / {returnCoords.Altitude}.");
                LocationUtils.updatePlayerLocation(_client, returnCoords.Latitude, returnCoords.Longitude, returnCoords.Altitude);
                //result = _client.Player.UpdatePlayerLocation(returnCoords.Latitude, returnCoords.Longitude, returnCoords.Altitude).Result;
            }

            GlobalVars.SnipeOpts.Enabled    = false;
            GlobalVars.SnipeOpts.ID         = PokemonId.Missingno;
            GlobalVars.SnipeOpts.Location   = null;
            GlobalVars.SnipeOpts.WaitSecond = 6;
            GlobalVars.SnipeOpts.NumTries   = 3;
        }
Exemplo n.º 4
0
        //public PlayerUpdateResponse HumanLikeWalking(GeoCoordinate targetLocation, double walkingSpeedInKilometersPerHour, Func<bool> functionExecutedWhileWalking, bool fromgoogle = false, bool log = true)
        public void HumanLikeWalking(GeoCoordinate targetLocation, double walkingSpeedInKilometersPerHour, Func <bool> functionExecutedWhileWalking, bool fromgoogle = false, bool log = true)
        {
            var randomFactor    = 0.5f;
            var randomMin       = (int)(walkingSpeedInKilometersPerHour * (1 - randomFactor));
            var randomMax       = (int)(walkingSpeedInKilometersPerHour * (1 + randomFactor));
            var RandomWalkSpeed = RandomDevice.Next(randomMin, randomMax);

            walkingSpeedInKilometersPerHour = RandomWalkSpeed + RandomDevice.NextDouble();
            var speedInMetersPerSecond = walkingSpeedInKilometersPerHour / 3.6;
            var sourceLocation         = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
            var distanceToTarget       = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

            if (log)
            {
                Logger.ColoredConsoleWrite(ConsoleColor.DarkCyan, $"Distance to target location: {distanceToTarget:0.##} meters. Will take {distanceToTarget / speedInMetersPerSecond:0.##} seconds!");
            }

            var nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
            var nextWaypointDistance = speedInMetersPerSecond;
            var waypoint             = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

            //Initial walking
            var requestSendDateTime = DateTime.Now;

            LocationUtils.updatePlayerLocation(_client, waypoint.Latitude, waypoint.Longitude, waypoint.Altitude);
            //var result =_client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude).Result;

            if (functionExecutedWhileWalking != null)
            {
                functionExecutedWhileWalking();
            }

            var locatePokemonWhileWalkingDateTime = DateTime.Now;

            do
            {
                //update user location on map
                Task.Factory.StartNew(() => Logic.Instance.infoObservable.PushNewGeoLocations(new GeoCoordinate(waypoint.Latitude, waypoint.Longitude)));

                var millisecondsUntilGetUpdatePlayerLocationResponse =
                    (DateTime.Now - requestSendDateTime).TotalMilliseconds;

                sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

                if (currentDistanceToTarget < 40)
                {
                    if (speedInMetersPerSecond > SpeedDownTo)
                    {
                        if (log)
                        {
                            Logger.ColoredConsoleWrite(ConsoleColor.DarkCyan, "We are within 40 meters of the target. Slowing down to ~10 km/h to not pass the target.");
                        }
                        speedInMetersPerSecond = SpeedDownTo;
                    }
                }

                nextWaypointDistance = Math.Min(currentDistanceToTarget, millisecondsUntilGetUpdatePlayerLocationResponse / 1000 * speedInMetersPerSecond);
                nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
                waypoint             = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);
                requestSendDateTime  = DateTime.Now;

                if (_botSettings.PauseTheWalking)
                {
                    //result = _client.Player.UpdatePlayerLocation(_client.CurrentLatitude, _client.CurrentLongitude, _client.CurrentAltitude).Result;
                    SetCoordinates(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude);
                }
                else
                {
                    try
                    {
                        //result = _client.Player.UpdatePlayerLocation(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude).Result;
                        SetCoordinates(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude);
                    }
                    catch (Exception e)
                    {
                        Logger.ColoredConsoleWrite(ConsoleColor.DarkRed, "Sending exception info to Logger");
                        Logger.AddLog("Exception Updating player Location:" + e.ToString());
                    }
                }

                if (functionExecutedWhileWalking != null && !_botSettings.PauseTheWalking)
                {
                    functionExecutedWhileWalking(); // look for pokemon
                }

                if (GlobalVars.SnipeOpts.Enabled)
                {
                    Logic.Instance.sniperLogic.Execute((PokemonId)GlobalVars.SnipeOpts.ID, GlobalVars.SnipeOpts.Location);
                    //_botSettings.SnipeOpts.Enabled = false;
                }

                RandomHelper.RandomSleep(500, 600);
            }while ((LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 30 && !fromgoogle) || LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 2);
            //return result;
        }
Exemplo n.º 5
0
        public static ulong CatchPokemon(ulong encounterId, string spawnpointId, PokemonId pokeid, double pokeLong = 0, double pokeLat = 0, bool goBack = false, double returnLatitude = -1, double returnLongitude = -1, int luredPoke = 0)
        {
            ulong             ret = 0;
            EncounterResponse encounterPokemonResponse;

            //Offset Miss count here to account for user setting.
            var missCount = 0;

            if (GlobalVars.Max_Missed_throws <= 1)
            {
                missCount = 2;
            }

            if (GlobalVars.Max_Missed_throws == 2)
            {
                missCount = 1;
            }

            var forceHit = false;

            try
            {
                if (luredPoke == 0)
                {
                    encounterPokemonResponse = client.Encounter.EncounterPokemon(encounterId, spawnpointId).Result;
                }
                else if (luredPoke == 1)
                {
                    var DiscEncounterPokemonResponse = client.Encounter.EncounterLurePokemon(encounterId, spawnpointId);
                    encounterPokemonResponse        = new EncounterResponse();
                    encounterPokemonResponse.Status = DiskEncounterResultToEncounterStatus(DiscEncounterPokemonResponse.Result);

                    if (DiscEncounterPokemonResponse.Result == DiskEncounterResponse.Types.Result.Success)
                    {
                        encounterPokemonResponse.WildPokemon             = new WildPokemon();
                        encounterPokemonResponse.WildPokemon.EncounterId = encounterId;
                        encounterPokemonResponse.WildPokemon.PokemonData = DiscEncounterPokemonResponse.PokemonData;
                        encounterPokemonResponse.CaptureProbability      = new POGOProtos.Data.Capture.CaptureProbability();
                        encounterPokemonResponse.CaptureProbability.CaptureProbability_.Add(1.0F);
                    }
                }
                else
                {
                    var IncenseEncounterPokemonResponse = client.Encounter.EncounterIncensePokemon(encounterId, spawnpointId);
                    encounterPokemonResponse        = new EncounterResponse();
                    encounterPokemonResponse.Status = IncenseEncounterResultToEncounterStatus(IncenseEncounterPokemonResponse.Result);

                    if (IncenseEncounterPokemonResponse.Result == IncenseEncounterResponse.Types.Result.IncenseEncounterSuccess)
                    {
                        encounterPokemonResponse.WildPokemon             = new WildPokemon();
                        encounterPokemonResponse.WildPokemon.EncounterId = encounterId;
                        encounterPokemonResponse.WildPokemon.PokemonData = IncenseEncounterPokemonResponse.PokemonData;
                        encounterPokemonResponse.CaptureProbability      = IncenseEncounterPokemonResponse.CaptureProbability;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.ColoredConsoleWrite(ConsoleColor.Red, $"Error: Logic.cs - CatchPokemon - encounter: {ex.Message}");
                if (goBack)
                {
                    Logger.ColoredConsoleWrite(ConsoleColor.Cyan, $"(SNIPING) Go to {returnLatitude} / {returnLongitude} before starting the capture.");
                    Logger.ColoredConsoleWrite(ConsoleColor.Cyan, LocationUtils.FindAddress(returnLatitude, returnLongitude));
                    LocationUtils.updatePlayerLocation(client, returnLatitude, returnLongitude, GlobalVars.altitude);
                    var tmpMap = client.Map.GetMapObjects(true);
                }
                return(ret);
            }

            if (goBack)
            {
                Logger.ColoredConsoleWrite(ConsoleColor.Cyan, $"(SNIPING) Go to {returnLatitude} / {returnLongitude} before starting the capture.");
                Logger.ColoredConsoleWrite(ConsoleColor.Cyan, LocationUtils.FindAddress(returnLatitude, returnLongitude));
                LocationUtils.updatePlayerLocation(client, returnLatitude, returnLongitude, GlobalVars.altitude);
                var tmpMap = client.Map.GetMapObjects(true);
            }

            if (encounterPokemonResponse.Status == EncounterResponse.Types.Status.EncounterSuccess)
            {
                if (SkippedPokemon.Contains(encounterPokemonResponse.WildPokemon.EncounterId))
                {
                    Logger.ColoredConsoleWrite(ConsoleColor.Cyan, "Previously Skipped this Pokemon - Skipping Again!");
                    return(0);
                }

                var bestPokeball = GetBestBall(encounterPokemonResponse?.WildPokemon, false);

                var iv = PokemonGo.RocketAPI.PokemonInfo.CalculatePokemonPerfection(encounterPokemonResponse.WildPokemon.PokemonData);
                var strIVPerfection = iv.ToString("0.00");
                if (bestPokeball == ItemId.ItemUnknown)
                {
                    Logger.ColoredConsoleWrite(ConsoleColor.Red, $"No Pokeballs! - missed {pokeid} CP {encounterPokemonResponse?.WildPokemon?.PokemonData?.Cp} IV {strIVPerfection}%");
                    Logger.ColoredConsoleWrite(ConsoleColor.Red, "Detected all balls out of stock - disabling pokemon catch until restock of at least 1 ball type occurs");

                    Logic.Instance.pokeballoutofstock = true;
                    AllowCatchPokemon = false;

                    return(0);
                }

                var inventoryBerries = client.Inventory.GetItems();
                var probability      = encounterPokemonResponse?.CaptureProbability?.CaptureProbability_?.FirstOrDefault();
                var probability100   = Math.Round(probability.Value * 100);

                Logger.ColoredConsoleWrite(ConsoleColor.Magenta, $"Encountered {pokeid} CP {encounterPokemonResponse?.WildPokemon?.PokemonData?.Cp} IV {strIVPerfection}% Probability {probability100}%");
                if (encounterPokemonResponse.WildPokemon.PokemonData != null)
                {
                    SaveLocations(encounterPokemonResponse.WildPokemon, iv, probability100);
                }

                if (encounterPokemonResponse.WildPokemon.PokemonData != null &&
                    encounterPokemonResponse.WildPokemon.PokemonData.Cp >= GlobalVars.MinCPtoCatch &&
                    probability100 >= GlobalVars.MinProbToCatch &&
                    iv >= GlobalVars.MinIVtoCatch)
                {
                    var usedBerry = false;
                    var escaped   = false;
                    CatchPokemonResponse caughtPokemonResponse;
                    var inventory = client.Inventory.GetItems();
                    var razz      = inventory.FirstOrDefault(p => p.ItemId == ItemId.ItemRazzBerry);
                    var pinap     = inventory.FirstOrDefault(p => p.ItemId == ItemId.ItemPinapBerry);
                    var nanab     = inventory.FirstOrDefault(p => p.ItemId == ItemId.ItemNanabBerry);

                    do
                    {
                        // Check if the best ball is still valid
                        if (bestPokeball == ItemId.ItemUnknown)
                        {
                            Logger.ColoredConsoleWrite(ConsoleColor.Red, $"No Pokeballs! - missed {pokeid} CP {encounterPokemonResponse?.WildPokemon?.PokemonData?.Cp} IV {strIVPerfection}%");
                            Logger.ColoredConsoleWrite(ConsoleColor.Red, "Detected all balls out of stock - disabling pokemon catch until restock of at least 1 ball type occurs");

                            Logic.Instance.pokeballoutofstock = true;
                            AllowCatchPokemon = false;

                            return(0);
                        }


                        if (GlobalVars.UseRazzBerry && !usedBerry && (probability.Value < GlobalVars.razzberry_chance))
                        {
                            if (razz != null && razz.Count > 0)
                            {
                                //Throw berry
                                var useRazzberry = client.Encounter.UseItemEncounter(encounterId, ItemId.ItemRazzBerry, spawnpointId);
                                if (useRazzberry.Status == UseItemEncounterResponse.Types.Status.Success)
                                {
                                    razz.Count = razz.Count - 1;
                                    Logger.Info($"We used a Razz Berry. Remaining: {razz.Count}.");
                                    usedBerry = true;
                                }
                                else
                                {
                                    Logger.Info("RazzBerry Status: " + useRazzberry.Status);
                                }

                                RandomHelper.RandomSleep(250);
                            }
                            if (!client.Player.PlayerResponse.PlayerData.TutorialState.Contains(TutorialState.PokemonBerry))
                            {
                                Logic.Instance.Tutorial.MarkTutorialAsDone(TutorialState.PokemonBerry, client);
                            }
                        }

                        if (GlobalVars.PokemonPinap.Contains(pokeid) && !usedBerry)
                        {
                            try {
                                if (pinap != null && pinap.Count > 0)
                                {
                                    // Use a pinap
                                    var res = client.Encounter.UseItemEncounter(encounterId, ItemId.ItemPinapBerry, spawnpointId);
                                    if (res.Status == UseItemEncounterResponse.Types.Status.Success)
                                    {
                                        pinap.Count = pinap.Count - 1;
                                        Logger.Info($"We used a Pinap Berry. Remaining: {pinap.Count}.");
                                        usedBerry = true;
                                    }
                                    else
                                    {
                                        Logger.Info("PinapBerry Status: " + res.Status);
                                    }
                                    RandomHelper.RandomSleep(250);
                                }
                            } catch (Exception ex1) {
                                Logger.Debug("" + ex1);
                            }
                        }

                        var r = new Random();

                        if (GlobalVars.UseNanabBerry && !usedBerry)
                        {
                            try {
                                var reallyUseIt = (r.Next(0, 100) <= GlobalVars.NanabPercent);
                                if (GlobalVars.NanabPercent == 100 || reallyUseIt)
                                {
                                    if (nanab != null && nanab.Count > 0)
                                    {
                                        var res = client.Encounter.UseItemEncounter(encounterId, ItemId.ItemNanabBerry, spawnpointId);
                                        if (res.Status == UseItemEncounterResponse.Types.Status.Success)
                                        {
                                            nanab.Count = nanab.Count - 1;
                                            Logger.Info($"We used a Nabab Berry. Remaining: {nanab.Count}.");
                                            usedBerry = true;
                                        }
                                        else
                                        {
                                            Logger.Info("Status: " + res.Status);
                                        }
                                        RandomHelper.RandomSleep(250);
                                    }
                                }
                            } catch (Exception ex1) {
                                Logger.Debug("" + ex1);
                            }
                        }
                        // limit number of balls wasted by misses and log for UX because fools be tripin
                        switch (missCount)
                        {
                        case 0:
                            if (bestPokeball == ItemId.ItemMasterBall)
                            {
                                Logger.ColoredConsoleWrite(ConsoleColor.Magenta, "No messing around with your Master Balls! Forcing a hit on target.");
                                forceHit = true;
                            }
                            break;

                        case 1:
                            if (bestPokeball == ItemId.ItemUltraBall)
                            {
                                Logger.ColoredConsoleWrite(ConsoleColor.Magenta, "Not wasting more of your Ultra Balls! Forcing a hit on target.");
                                forceHit = true;
                            }
                            break;

                        case 2:
                            //adding another chance of forcing hit here to improve overall odds after 2 misses
                            var rInt = r.Next(0, 2);
                            forceHit |= rInt == 1;
                            break;

                        default:
                            // default to force hit after 3 wasted balls of any kind.
                            Logger.ColoredConsoleWrite(ConsoleColor.Magenta, "Enough misses! Forcing a hit on target.");
                            forceHit = true;
                            break;
                        }
                        if (missCount > 0)
                        {
                            //adding another chance of forcing hit here to improve overall odds after 1st miss
                            var rInt = r.Next(0, 3);
                            if (rInt == 1)
                            {
                                // lets hit
                                forceHit = true;
                            }
                        }

                        caughtPokemonResponse = CatchPokemonWithRandomVariables(encounterId, spawnpointId, bestPokeball, forceHit);
                        if (caughtPokemonResponse == null)
                        {
                            caughtPokemonResponse = new CatchPokemonResponse();
                        }

                        if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed)
                        {
                            Logger.ColoredConsoleWrite(ConsoleColor.Magenta, $"Missed { pokeid} while using {bestPokeball}");
                            missCount++;
                            RandomHelper.RandomSleep(1500, 3000);
                        }
                        else if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape)
                        {
                            Logger.ColoredConsoleWrite(ConsoleColor.Magenta, $"{pokeid} escaped while using {bestPokeball}");
                            usedBerry = false;
                            escaped   = true;
                            //reset forceHit in case we randomly triggered on last throw.
                            forceHit = false;
                            RandomHelper.RandomSleep(1500, 3000);
                        }
                        // Update the best ball to ensure we can still throw
                        bestPokeball = GetBestBall(encounterPokemonResponse?.WildPokemon, escaped);
                    } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);

                    if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess)
                    {
                        ret = caughtPokemonResponse.CapturedPokemonId;

                        if (GlobalVars.ShowPokemons)
                        {
                            Logic.Instance.DeletePokemonFromMap(encounterPokemonResponse.WildPokemon.SpawnPointId);
                        }

                        var curDate = DateTime.Now;
                        Task.Factory.StartNew(() => infoObservable.PushNewHuntStats($"{pokeLat}/{pokeLong};{pokeid};{curDate.Ticks};{curDate}" + Environment.NewLine));

                        var date = DateTime.Now;
                        if (caughtPokemonResponse.CaptureAward.Xp.Sum() >= 500)
                        {
                            if (GlobalVars.LogPokemons)
                            {
                                File.AppendAllText(GlobalVars.FileForPokemonsCaught, $"[{date}] Caught new {pokeid} (CP: {encounterPokemonResponse?.WildPokemon?.PokemonData?.Cp} | IV: {strIVPerfection}% | Pokeball used: {bestPokeball} | XP: {caughtPokemonResponse.CaptureAward.Xp.Sum()}) " + Environment.NewLine);
                            }
                            Logger.ColoredConsoleWrite(ConsoleColor.Gray, $"Caught {pokeid} CP {encounterPokemonResponse?.WildPokemon?.PokemonData?.Cp} IV {strIVPerfection}% got {caughtPokemonResponse.CaptureAward.Xp.Sum()} XP | {caughtPokemonResponse.CaptureAward.Candy.Sum()} Candies | {caughtPokemonResponse.CaptureAward.Stardust.Sum()} Stardust");
                            Setout.pokemonCatchCount++;
                            Setout.SaveSession();
                            // Wrong: TutorialState.PokemonCapture is not for the first wild pokemon caught.
                            // if (!client.Player.PlayerResponse.PlayerData.TutorialState.Contains(TutorialState.PokemonCapture)) Logic.Instance.Tutorial.MarkTutorialAsDone(TutorialState.PokemonCapture, client, pokeid);
                        }
                        else
                        {
                            if (GlobalVars.LogPokemons)
                            {
                                File.AppendAllText(GlobalVars.FileForPokemonsCaught, $"[{date}] Caught {pokeid} (CP: {encounterPokemonResponse?.WildPokemon?.PokemonData?.Cp} | IV: {strIVPerfection}% | Pokeball used: {bestPokeball} | XP: {caughtPokemonResponse.CaptureAward.Xp.Sum()}) " + Environment.NewLine);
                            }
                            Logger.ColoredConsoleWrite(ConsoleColor.Gray, $"Caught {pokeid} CP {encounterPokemonResponse?.WildPokemon?.PokemonData?.Cp} IV {strIVPerfection}% got {caughtPokemonResponse.CaptureAward.Xp.Sum()} XP | {caughtPokemonResponse.CaptureAward.Candy.Sum()} Candies | {caughtPokemonResponse.CaptureAward.Stardust.Sum()} Stardust");
                            Setout.pokemonCatchCount++;
                            Setout.SaveSession();

                            if (Logic.Instance.Telegram != null)
                            {
                                Logic.Instance.Telegram.sendInformationText(TelegramUtil.TelegramUtilInformationTopics.Catch, pokeid, encounterPokemonResponse?.WildPokemon?.PokemonData?.Cp, strIVPerfection, bestPokeball, caughtPokemonResponse.CaptureAward.Xp.Sum());
                            }
                        }
                        Logic.Instance.BotStats.AddPokemon(1);
                        Logic.Instance.BotStats.AddExperience(caughtPokemonResponse.CaptureAward.Xp.Sum());
                        Logic.Instance.BotStats.AddStardust(caughtPokemonResponse.CaptureAward.Stardust.Sum());
                        Setout.RefreshConsoleTitle(client);
                        RandomHelper.RandomSleep(1500, 2000);
                    }
                    else
                    {
                        Logger.ColoredConsoleWrite(ConsoleColor.DarkYellow, $"{pokeid} CP {encounterPokemonResponse?.WildPokemon?.PokemonData?.Cp} IV {strIVPerfection}% got away while using {bestPokeball}..");
                        Logic.FailedSoftban++;
                        if (Logic.FailedSoftban > 10)
                        {
                            Logger.ColoredConsoleWrite(ConsoleColor.Red, $"Soft Ban Detected - Stopping Bot to prevent perma-ban. Try again in 4-24 hours and be more careful next time!");
                            Setout.LimitReached("");
                        }
                    }
                }
                else
                {
                    Logger.ColoredConsoleWrite(ConsoleColor.Magenta, "Pokemon CP or IV or Prob lower than Configured Min to Catch - Skipping Pokemon");
                    SkippedPokemon.Add(encounterPokemonResponse.WildPokemon.EncounterId);
                }
            }
            else if (encounterPokemonResponse.Status == EncounterResponse.Types.Status.PokemonInventoryFull)
            {
                Logger.Warning("You have no free space for new pokemons...transfer some as soon as possible.");
            }
            else
            {
                Logger.Debug(encounterPokemonResponse.Status.ToString());
            }
            return(ret);
        }
Exemplo n.º 6
0
        public static StartGymBattleResponse StartGymBattle(Client client, string gymId, ulong defendingPokemonId,
                                                            IEnumerable <ulong> attackingPokemonIds)
        {
            StartGymBattleResponse resp = null;
            var numTries    = 3;
            var startFailed = false;
            var deltaValue  = 0.001;

            do
            {
                resp = client.Fort.StartGymBattle(gymId, defendingPokemonId, attackingPokemonIds);
                if (resp == null)
                {
                    Logger.Debug("(Gym) - Response to start battle was null.");
                    startFailed = true;
                }
                else
                {
                    if (resp.BattleLog == null)
                    {
                        Logger.Debug("(Gym) - BatlleLog to start battle was null");
                        startFailed = true;
                    }
                }

                if (startFailed)
                {
                    RandomHelper.RandomSleep(5000);
                    if (GlobalVars.Gyms.Testing == "Fire Request Block Two")
                    {
                        client.Login.FireRequestBlockTwo().Wait();
                        RandomHelper.RandomSleep(2000);
                    }
                    else if (GlobalVars.Gyms.Testing == "Wait 2 minutes before of next try" && numTries == 3)
                    {
                        // 120 secondos
                        Logger.Info("Waiting 2 minutes before of next attack try");
                        if (GlobalVars.CatchPokemon)
                        {
                            Logger.Info("While, we will try to catch pokemons");
                        }
                        var rnd = RandomHelper.RandomNumber(50, 90) * 0.00001;
                        // 0.00001 = 1 meters
                        //http://gizmodo.com/how-precise-is-one-degree-of-longitude-or-latitude-1631241162
                        Logger.Debug("going to 50 meters far of gym");
                        LocationUtils.updatePlayerLocation(client, client.CurrentLongitude + rnd, client.CurrentLatitude, client.CurrentAltitude);
                        RandomHelper.RandomSleep(10000);
                        CatchingLogic.Execute();
                        RandomHelper.RandomSleep(10000);
                        CatchingLogic.Execute();
                        Logger.Debug("returning to gym location");
                        // go back
                        LocationUtils.updatePlayerLocation(client, client.CurrentLongitude - rnd, client.CurrentLatitude, client.CurrentAltitude);
                        RandomHelper.RandomSleep(10000);
                        CatchingLogic.Execute();
                        client.Login.FireRequestBlockTwo().Wait();
                        RandomHelper.RandomSleep(2000);
                    }
                    else
                    {
                        RandomHelper.RandomSleep(2000);
                        var gmo = client.Map.GetMapObjects().Result;
                        client.Login.FireRequestBlockTwo().Wait();
                        RandomHelper.RandomSleep(2000);
                    }
                }
                else
                {
                    Logger.Debug("StartGymBattle Response:" + resp);
                }
                numTries--;
            } while (startFailed && numTries > 0);
            return(resp);
        }
Exemplo n.º 7
0
        public void Execute(PokemonId pokeid, GeoCoordinate remoteCoords)
        {
            var returnCoords = new GeoCoordinate();

            returnCoords.Latitude  = _client.CurrentLatitude;
            returnCoords.Longitude = _client.CurrentLongitude;
            returnCoords.Altitude  = _client.CurrentAltitude;

            var distanceToTarget = LocationUtils.CalculateDistanceInMeters(returnCoords, remoteCoords);

            if (distanceToTarget > 100000)
            {
                Logger.Warning("Distance greater than 100 kms. Skipping Snipe.");
                return;
            }


            //LocationUtils.updatePlayerLocation(_client, returnCoords.Latitude, returnCoords.Longitude, returnCoords.Altitude);

            if (_botSettings == null && _client == null)
            {
                SendToLog($" client or settings are not set");
                return;
            }

            try {
                remoteCoords.Altitude = LocationUtils.GetAltitude(remoteCoords.Latitude, remoteCoords.Longitude);

                SendToLog($"Trying to capture {pokeid}  at { remoteCoords.Latitude } / {remoteCoords.Longitude}");
                SendToLog(LocationUtils.FindAddress(remoteCoords.Latitude, remoteCoords.Longitude));
                LocationUtils.updatePlayerLocation(_client, remoteCoords.Latitude, remoteCoords.Longitude, remoteCoords.Altitude, false);
                var gmp = _client.Map.GetMapObjects(true).Result;

                SendToLog($"We are at sniping location...");
                SendToLog($"Waiting {GlobalVars.SnipeOpts.WaitSecond} seconds for Pokemon to appear...");
                RandomHelper.RandomSleep(GlobalVars.SnipeOpts.WaitSecond * 1000);

                var catchedID = 0UL;
                if (pokeid == PokemonId.Missingno)
                {
                    catchedID = TrySnipeGym(remoteCoords, returnCoords);
                }
                else
                {
                    RandomHelper.RandomSleep(1000);
                    catchedID = TrySnipePokemons(pokeid, remoteCoords, returnCoords);
                }

                LocationUtils.updatePlayerLocation(_client, returnCoords.Latitude, returnCoords.Longitude, returnCoords.Altitude);
                gmp = _client.Map.GetMapObjects(true).Result;

                SendToLog($"Location after Snipe : {_client.CurrentLatitude} / {_client.CurrentLongitude} / {_client.CurrentAltitude}");
                SendToLog(LocationUtils.FindAddress(_client.CurrentLatitude, _client.CurrentLongitude));

                if ((catchedID > 0) && GlobalVars.SnipeOpts.TransferIt && pokeid != PokemonId.Missingno)
                {
                    var trResult = Logic.objClient.Inventory.ReleasePokemon(catchedID);
                    if (trResult.Result == ReleasePokemonResponse.Types.Result.Success)
                    {
                        SendToLog("Pokemon was transfered.");
                        SendToLog("Candies awarded: " + trResult.CandyAwarded);
                    }
                }

                RandomHelper.RandomSleep(20000, 22000);  // Avoid cache after snipe
            } catch (Exception ex) {
                Logger.ExceptionInfo(ex.ToString());
                SendToLog($"Go to {returnCoords.Latitude} / {returnCoords.Longitude} / {returnCoords.Altitude}.");
                LocationUtils.updatePlayerLocation(_client, returnCoords.Latitude, returnCoords.Longitude, returnCoords.Altitude);
                var gmp = _client.Map.GetMapObjects(true).Result;
            }

            GlobalVars.SnipeOpts.Enabled    = false;
            GlobalVars.SnipeOpts.ID         = PokemonId.Missingno;
            GlobalVars.SnipeOpts.Location   = null;
            GlobalVars.SnipeOpts.WaitSecond = 6;
            GlobalVars.SnipeOpts.NumTries   = 3;
        }
Exemplo n.º 8
0
        public void HumanLikeWalking(GeoCoordinate targetLocation, double walkingSpeedInKilometersPerHour, Func <bool> functionExecutedWhileWalking, bool fromgoogle = false, bool log = true)
        {
            /* removing random factors*/

            /*const float randomFactor = 0.5f;
             * var randomMin = (int)(walkingSpeedInKilometersPerHour * (1 - randomFactor));
             * var randomMax = (int)(walkingSpeedInKilometersPerHour * (1 + randomFactor));
             * walkingSpeedInKilometersPerHour = RandomDevice.Next(randomMin, randomMax);*/

            var speedInMetersPerSecond = walkingSpeedInKilometersPerHour / 3.6;

            Logger.Debug("speed In Meters Per Seconds to use: " + speedInMetersPerSecond);
            var sourceLocation   = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
            var distanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

            Logger.Debug($"Distance to target location: {distanceToTarget:0.##} meters. Will take {distanceToTarget / speedInMetersPerSecond:0.##} seconds!");
            var nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
            var nextWaypointDistance = speedInMetersPerSecond;
            var waypoint             = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);

            //Initial walking
            var requestSendDateTime = DateTime.Now;

            LocationUtils.updatePlayerLocation(_client, waypoint.Latitude, waypoint.Longitude, waypoint.Altitude);

            if (functionExecutedWhileWalking != null)
            {
                functionExecutedWhileWalking();
            }

            do
            {
                //update user location on map
                Task.Factory.StartNew(() => Logic.Instance.infoObservable.PushNewGeoLocations(new GeoCoordinate(waypoint.Latitude, waypoint.Longitude)));

                var millisecondsUntilGetUpdatePlayerLocationResponse =
                    (DateTime.Now - requestSendDateTime).TotalMilliseconds;

                sourceLocation = new GeoCoordinate(_client.CurrentLatitude, _client.CurrentLongitude);
                var currentDistanceToTarget = LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation);

                if (currentDistanceToTarget < 40)
                {
                    if (speedInMetersPerSecond > SpeedDownTo)
                    {
                        Logger.Warning("We are within 40 meters of the target. Slowing down to ~10 km/h to not pass the target.");
                        speedInMetersPerSecond = SpeedDownTo;
                    }
                }

                nextWaypointDistance = Math.Min(currentDistanceToTarget, millisecondsUntilGetUpdatePlayerLocationResponse / 1000 * speedInMetersPerSecond);
                nextWaypointBearing  = LocationUtils.DegreeBearing(sourceLocation, targetLocation);
                waypoint             = LocationUtils.CreateWaypoint(sourceLocation, nextWaypointDistance, nextWaypointBearing);
                requestSendDateTime  = DateTime.Now;

                SetCoordinates(waypoint.Latitude, waypoint.Longitude, waypoint.Altitude);

                if (functionExecutedWhileWalking != null && !_botSettings.PauseTheWalking)
                {
                    functionExecutedWhileWalking(); // look for pokemon
                }
                if (GlobalVars.SnipeOpts.Enabled)
                {
                    Logic.Instance.sniperLogic.Execute((PokemonId)GlobalVars.SnipeOpts.ID, GlobalVars.SnipeOpts.Location);
                }

                RandomHelper.RandomSleep(500, 600);
            }while ((LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 30 && !fromgoogle) || LocationUtils.CalculateDistanceInMeters(sourceLocation, targetLocation) >= 2);
        }
Exemplo n.º 9
0
        public static StartGymBattleResponse StartGymBattle(Client client, string gymId, ulong defendingPokemonId,
                                                            IEnumerable <ulong> attackingPokemonIds)
        {
            StartGymBattleResponse resp = null;
            var numTries = 3;
            var startOk  = false;

            do
            {
                try {
                    resp = client.Fort.StartGymBattle(gymId, defendingPokemonId, attackingPokemonIds).Result;
                    if (resp == null)
                    {
                        Logger.Debug("(Gym) - Response to start battle was null.");
                    }
                    else
                    {
                        if (resp.BattleLog == null)
                        {
                            Logger.Debug("(Gym) - BatlleLog to start battle was null");
                        }
                        else
                        {
                            startOk = true;
                            Logger.Debug("StartGymBattle Response:" + resp);
                        }
                    }
                } catch (Exception ex1) {
                    Logger.ExceptionInfo("StartGymBattle: " + ex1);
                    RandomHelper.RandomSleep(5000);
                    if (GlobalVars.Gyms.Testing == "Relogin")
                    {
                        client.Login.DoLogin().Wait();
                    }
                    else if (GlobalVars.Gyms.Testing == "GetPlayer")
                    {
                        client.Player.GetPlayer();
                        RandomHelper.RandomSleep(3000);
                    }
                    else if (GlobalVars.Gyms.Testing == "Wait 2 minutes catching pokemons")
                    {
                        if (GlobalVars.CatchPokemon)
                        {
                            Logger.Info("Trying to catch pokemons until next attack");
                        }
                        // 0.00001 = 1 meters
                        // http://www.um.es/geograf/sigmur/temariohtml/node6_mn.html
                        //http://gizmodo.com/how-precise-is-one-degree-of-longitude-or-latitude-1631241162
                        var gymloc = new GeoCoordinate(client.CurrentLongitude, client.CurrentLatitude, client.CurrentAltitude);
                        for (var times = 1; times < 5; times++)
                        {
                            var rnd = RandomHelper.GetLongRandom(8, 9) * 0.00001;
                            Logger.Debug("going to 8 meters far of gym");
                            LocationUtils.updatePlayerLocation(client, gymloc.Longitude + rnd, gymloc.Latitude, gymloc.Altitude);
                            RandomHelper.RandomSleep(10000);
                            CatchingLogic.Execute();
                            rnd = RandomHelper.GetLongRandom(8, 9) * 0.00001;
                            Logger.Debug("going to 8 meters far of gym");
                            LocationUtils.updatePlayerLocation(client, gymloc.Longitude + rnd, gymloc.Latitude, gymloc.Altitude);
                            RandomHelper.RandomSleep(10000);
                            CatchingLogic.Execute();
                            Logger.Debug("returning to gym location");
                            // go back
                            LocationUtils.updatePlayerLocation(client, gymloc.Longitude, gymloc.Latitude, gymloc.Altitude);
                            RandomHelper.RandomSleep(10000);
                            CatchingLogic.Execute();
                        }
                        RandomHelper.RandomSleep(2000);
                    }
                    else
                    {
                        RandomHelper.RandomSleep(115000);
                        client.Login.DoLogin().Wait();
                    }
                }
                numTries--;
            } while (!startOk && numTries > 0);
            return(resp);
        }
Exemplo n.º 10
0
        public static StartGymBattleResponse StartGymBattle(Client client, string gymId, ulong defendingPokemonId,
                                                            IEnumerable <ulong> attackingPokemonIds)
        {
            StartGymBattleResponse resp = null;
            var numTries    = 3;
            var startFailed = false;

            do
            {
                resp = client.Fort.StartGymBattle(gymId, defendingPokemonId, attackingPokemonIds);
                if (resp == null)
                {
                    Logger.Debug("(Gym) - Response to start battle was null.");
                    startFailed = true;
                }
                else
                {
                    if (resp.BattleLog == null)
                    {
                        Logger.Debug("(Gym) - BatlleLog to start battle was null");
                        startFailed = true;
                    }
                }

                if (startFailed)
                {
                    RandomHelper.RandomSleep(5000);
                    if (GlobalVars.Gyms.Testing == "Fire Request Block Two")
                    {
                        client.Login.FireRequestBlockTwo().Wait();
                        RandomHelper.RandomSleep(2000);
                    }
                    else if (GlobalVars.Gyms.Testing == "Wait 2 minutes before of next try" && numTries == 3)
                    {
                        if (GlobalVars.CatchPokemon)
                        {
                            Logger.Info("While, we will try to catch pokemons");
                        }
                        // 0.00001 = 1 meters
                        // http://www.um.es/geograf/sigmur/temariohtml/node6_mn.html
                        //http://gizmodo.com/how-precise-is-one-degree-of-longitude-or-latitude-1631241162
                        var gymloc = new GeoCoordinate(client.CurrentLongitude, client.CurrentLatitude, client.CurrentAltitude);
                        for (var times = 1; times < 5; times++)
                        {
                            var rnd = RandomHelper.RandomNumber(50, 90) * 0.00001;
                            Logger.Debug("going to 50 meters far of gym");
                            LocationUtils.updatePlayerLocation(client, gymloc.Longitude + rnd, gymloc.Latitude, gymloc.Altitude);
                            RandomHelper.RandomSleep(10000);
                            CatchingLogic.Execute();
                            rnd = RandomHelper.RandomNumber(50, 90) * 0.00001;
                            Logger.Debug("going to 50 meters far of gym");
                            LocationUtils.updatePlayerLocation(client, gymloc.Longitude + rnd, gymloc.Latitude, gymloc.Altitude);
                            RandomHelper.RandomSleep(10000);
                            CatchingLogic.Execute();
                            Logger.Debug("returning to gym location");
                            // go back
                            LocationUtils.updatePlayerLocation(client, gymloc);
                            RandomHelper.RandomSleep(10000);
                            CatchingLogic.Execute();
                        }
                        RandomHelper.RandomSleep(2000);
                    }
                    else
                    {
                        RandomHelper.RandomSleep(5000);
                    }
                }
                else
                {
                    Logger.Debug("StartGymBattle Response:" + resp);
                }
                numTries--;
            } while (startFailed && numTries > 0);
            return(resp);
        }