Exemple #1
0
        public static void Execute()
        {
            if (!GlobalVars.Gyms.Farm)
            {
                Logger.Debug("Farm gyms is not enabled.");
                return;
            }
            //narrow map data to gyms within walking distance
            var gyms = GetNearbyGyms();

            Logger.Debug("gyms: " + gyms.Count());
            var gymsWithinRangeStanding = gyms.Where(i => LocationUtils.CalculateDistanceInMeters(Logic.objClient.CurrentLatitude, Logic.objClient.CurrentLongitude, i.Latitude, i.Longitude) <= 40);
            var inRange = gymsWithinRangeStanding.Count();

            Logger.Debug("gymsWithinRangeStanding: " + inRange);

            if (gymsWithinRangeStanding.Any())
            {
                Logger.ColoredConsoleWrite(ConsoleColor.DarkGray, $"(Gym) - {inRange} gyms are within range of the user");

                foreach (var element in gymsWithinRangeStanding)
                {
                    var gym = element;
                    if (gymsVisited.Contains(gym.Id))
                    {
                        Logger.ColoredConsoleWrite(ConsoleColor.DarkGray, "(Gym) - This gym was already visited.");
                        continue;
                    }
                    var attackCount = 1;
                    while (attackCount <= GlobalVars.Gyms.MaxAttacks && !gymsVisited.Contains(gym.Id))
                    {
                        Logger.Debug("(Gym) - Attack number " + attackCount);
                        CheckAndPutInNearbyGym(gym, Logic.objClient);
                        attackCount++;
                        if (attackCount <= GlobalVars.Gyms.MaxAttacks && !gymsVisited.Contains(gym.Id))
                        {
                            RandomHelper.RandomSleep(900);
                            gym = GetNearbyGyms().FirstOrDefault(x => x.Id == gym.Id);
                        }
                        if (attackCount > GlobalVars.Gyms.MaxAttacks)
                        {
                            Logger.Warning("(Gym) - Maximum number of attacks reached. Will be checked after of one minute.");
                            AddVisited(gym.Id, 60000);
                        }
                    }
                    Setout.SetCheckTimeToRun();
                    RandomHelper.RandomSleep(300);
                }
                GlobalVars.PauseTheWalking &= !restoreWalkingAfterLogic;
            }
        }
Exemple #2
0
        public static bool Execute(GetMapObjectsResponse mapObjectsResponse)
        {
            client         = Logic.objClient;
            infoObservable = Logic.Instance.infoObservable;
            //bypass catching pokemon if disabled
            if (GlobalVars.CatchPokemon && AllowCatchPokemon)
            {
                if (mapObjectsResponse == null)
                {
                    mapObjectsResponse = client.Map.GetMapObjects().Result;
                }

                MapPokemon mapIncensePokemon = null;
                try {
                    var duration = Setout.lastincenseuse - DateTime.Now;
                    Logger.Debug("last incense use duration: " + duration);
                    if (duration.TotalMilliseconds > 0)
                    {
                        var incensePokemon = client.Map.GetIncensePokemons();
                        Logger.Debug("incensePokemon: " + incensePokemon);
                        if (incensePokemon.Result == GetIncensePokemonResponse.Types.Result.IncenseEncounterAvailable)
                        {
                            mapIncensePokemon                       = new MapPokemon();
                            mapIncensePokemon.EncounterId           = incensePokemon.EncounterId;
                            mapIncensePokemon.Longitude             = incensePokemon.Longitude;
                            mapIncensePokemon.Latitude              = incensePokemon.Latitude;
                            mapIncensePokemon.PokemonDisplay        = incensePokemon.PokemonDisplay;
                            mapIncensePokemon.PokemonId             = incensePokemon.PokemonId;
                            mapIncensePokemon.SpawnPointId          = incensePokemon.EncounterLocation;
                            mapIncensePokemon.ExpirationTimestampMs = incensePokemon.DisappearTimestampMs;

                            Logger.ColoredConsoleWrite(ConsoleColor.Magenta, $"Found incensed Pokemon: {mapIncensePokemon.PokemonId}");
                            if (GlobalVars.ShowPokemons)
                            {
                                infoObservable.PushNewPokemonLocation(mapIncensePokemon);
                            }
                        }
                        else
                        {
                            Logger.Debug("incensePokemon.Result: " + incensePokemon.Result);
                        }
                    }
                } catch (Exception ex1) {
                    Logger.ExceptionInfo(ex1.ToString());
                }

                if (mapIncensePokemon != null)
                {
                    if (!GlobalVars.catchPokemonSkipList.Contains(mapIncensePokemon.PokemonId))
                    {
                        CatchIncensedPokemon(mapIncensePokemon.EncounterId, mapIncensePokemon.SpawnPointId, mapIncensePokemon.PokemonId, mapIncensePokemon.Longitude, mapIncensePokemon.Latitude);
                    }
                }

                var pokemons = mapObjectsResponse.MapCells.SelectMany(i => i.CatchablePokemons).OrderBy(i => LocationUtils.CalculateDistanceInMeters(client.CurrentLatitude, client.CurrentLongitude, i.Latitude, i.Longitude));
                Logger.Debug($"Pokemons Catchable: {pokemons.Count()}");

                var nearbyPokemons = mapObjectsResponse.MapCells.SelectMany(i => i.NearbyPokemons);
                Logger.Debug($"Pokemons Nearby: {nearbyPokemons.Count()}");
                var wildPokemons = mapObjectsResponse.MapCells.SelectMany(i => i.WildPokemons).OrderBy(i => LocationUtils.CalculateDistanceInMeters(client.CurrentLatitude, client.CurrentLongitude, i.Latitude, i.Longitude));
                Logger.Debug($"Pokemons Wild: {wildPokemons.Count()}");
                if (pokemons.Any())
                {
                    var strNames = pokemons.Aggregate("", (current, pokemon) => current + (pokemon.PokemonId + ", "));
                    strNames = strNames.Substring(0, strNames.Length - 2);

                    Logger.ColoredConsoleWrite(ConsoleColor.Magenta, $"Found {pokemons.Count()} catchable Pokemon(s): " + strNames);
                    if (GlobalVars.ShowPokemons)
                    {
                        ShowNearbyPokemons(pokemons);
                    }
                }
                else
                {
                    zeroCachablePokemons++;
                    if (zeroCachablePokemons > 10)
                    {
                        zeroCachablePokemons = 0;
                        //client.Login.DoLogin().Wait();
                        //client.Login.Reauthenticate().Wait();
                    }
                    return(false);
                }


                //catch them all!
                foreach (var pokemon in pokemons)
                {
                    #region Stats Log

                    //increment log stats counter and log stats
                    Setout.count++;

                    if (Setout.count >= 9)
                    {
                        Setout.Execute();
                    }

                    #endregion


                    #region Skip pokemon if in list

                    if (GlobalVars.catchPokemonSkipList.Contains(pokemon.PokemonId))
                    {
                        Logger.ColoredConsoleWrite(ConsoleColor.Green, "Skipped Pokemon: " + pokemon.PokemonId);
                        continue;
                    }

                    #endregion

                    //get distance to pokemon
                    var distance = LocationUtils.CalculateDistanceInMeters(client.CurrentLatitude, client.CurrentLongitude, pokemon.Latitude, pokemon.Longitude);

                    RandomHelper.RandomSleep(distance > 100 ? 1000 : 100, distance > 100 ? 1100 : 110);

                    // Do Catch here
                    CatchPokemon(pokemon.EncounterId, pokemon.SpawnPointId, pokemon.PokemonId, pokemon.Longitude, pokemon.Latitude);
                }
                client.Map.GetMapObjects(true).Wait();   //force Map Objects Update
                client.Inventory.GetHoloInventory(true); //force Inventory Update
                return(true);
            }
            return(false);
        }
Exemple #3
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);
        }
Exemple #4
0
        public static void Execute()
        {
            if (!GlobalVars.Gyms.Farm)
            {
                Logger.Debug("Farm gyms is not enabled.");
                return;
            }

            //narrow map data to gyms within walking distance
            var gyms = GetNearbyGyms();
            var gymsWithinRangeStanding = gyms.Where(i => LocationUtils.CalculateDistanceInMeters(Logic.objClient.CurrentLatitude, Logic.objClient.CurrentLongitude, i.Latitude, i.Longitude) <= 40);

            Logger.Debug("gymsWithinRangeStanding: " + gymsWithinRangeStanding.Count() + " (of " + gyms.Count() + ")");

            if (gymsWithinRangeStanding.Any())
            {
                Logger.Debug("(Gym) Reviving pokemons.");
                ReviveAndCurePokemons(Logic.objClient);

                Logger.ColoredConsoleWrite(ConsoleColor.DarkGray, $"(Gym) {gymsWithinRangeStanding.Count()} gyms are within your range.");

                foreach (FortData gym in gymsWithinRangeStanding)
                {
                    if (gymsVisited.Contains(gym.Id))
                    {
                        Logger.ColoredConsoleWrite(ConsoleColor.DarkGray, $"(Gym) This gym was already visited.");
                        continue;
                    }

                    if (gym.RaidInfo != null && !gym.RaidInfo.IsRaidHidden)
                    {
                        Logger.ColoredConsoleWrite(ConsoleColor.DarkGray, $"(Gym) This gym is in Raid mode (still not supported), skipping.");
                        AddVisited(gym.Id);
                        continue;
                    }

                    if (GlobalVars.Gyms.Farm && (gym.OwnedByTeam == TeamColor.Neutral || gym.OwnedByTeam == Logic.objClient.Player.PlayerResponse.PlayerData.Team))
                    {
                        CheckAndPutInNearbyGym(gym, Logic.objClient);

                        // We can add training later
                    }

                    if (GlobalVars.Gyms.Attack && (gym.OwnedByTeam != TeamColor.Neutral && gym.OwnedByTeam != Logic.objClient.Player.PlayerResponse.PlayerData.Team))
                    {
                        var gymDetails = Logic.objClient.Fort.GymGetInfo(gym.Id, gym.Latitude, gym.Longitude);
                        if (gymDetails.GymStatusAndDefenders.GymDefender.Count >= 1 && gymDetails.GymStatusAndDefenders.GymDefender.Count <= GlobalVars.Gyms.NumDefenders)
                        {
                            restoreWalkingAfterLogic   = !GlobalVars.PauseTheWalking;
                            GlobalVars.PauseTheWalking = true;

                            Logger.Debug("(Gym) Stop walking.");

                            var attackCount = 1;
                            while (attackCount <= GlobalVars.Gyms.MaxAttacks)
                            {
                                Logger.Debug($"(Gym: {gymDetails.Name}) We can attack this {gym.OwnedByTeam} gym. Attack number: " + attackCount);
                                BattleState isVictory = GymsLogicAttack.AttackGym(gym, Logic.objClient);
                                switch (isVictory)
                                {
                                case BattleState.StateUnset:
                                    Logger.ColoredConsoleWrite(gymColorLog, $"(Gym: {gymDetails.Name}) NULL detected, something failed.");
                                    attackCount = GlobalVars.Gyms.MaxAttacks;
                                    break;

                                case BattleState.Defeated:
                                    Logger.ColoredConsoleWrite(gymColorLog, $"(Gym: {gymDetails.Name}) Battle Lost.");
                                    attackCount = GlobalVars.Gyms.MaxAttacks;
                                    break;

                                default:
                                    Logger.ColoredConsoleWrite(gymColorLog, $"(Gym: {gymDetails.Name}) We have won the attack.");
                                    RandomHelper.RandomSleep(2000);
                                    gyms = GetNearbyGyms();
                                    // Add: refresh only this gym
                                    CheckAndPutInNearbyGym(gym, Logic.objClient);
                                    break;
                                }

                                attackCount++;
                                Logger.Debug("(Gym) Reviving pokemons.");
                                ReviveAndCurePokemons(Logic.objClient);
                            }
                            Logger.Warning($"(Gym) Maximum number of {GlobalVars.Gyms.MaxAttacks} attacks reached.");
                        }
                        else
                        {
                            Logger.ColoredConsoleWrite(gymColorLog, $"(Gym) This gym has more than {GlobalVars.Gyms.NumDefenders} defenders, skipping.");
                            continue;
                        }
                    }

                    AddVisited(gym.Id);
                    Setout.SetCheckTimeToRun();
                }
                GlobalVars.PauseTheWalking &= !restoreWalkingAfterLogic;
            }
        }