コード例 #1
0
ファイル: Logic.cs プロジェクト: Jeampan/Pokebot
        private async Task DisplayHighest(int NumberToShow = 10, List <PokemonData> PokemonSession = null)
        {
            Logger.Write("====== Highest CP ======", LogLevel.Info, ConsoleColor.Yellow);
            var highestsPokemonCp = await _inventory.GetHighestsCp(NumberToShow, PokemonSession);

            foreach (var pokemon in highestsPokemonCp)
            {
                Logger.Write(
                    $"# CP {pokemon.Cp.ToString().PadLeft(4, ' ')}/{PokemonInfo.CalculateMaxCP(pokemon).ToString().PadLeft(4, ' ')} | ({PokemonInfo.CalculatePokemonPerfection(pokemon).ToString("0.00")}% perfect)\t| Lvl {PokemonInfo.GetLevel(pokemon).ToString("00")}\t NAME: '{pokemon.PokemonId}'",
                    LogLevel.Info, ConsoleColor.Yellow);
            }
            Logger.Write("====== Highest Perfect ======", LogLevel.Info, ConsoleColor.Yellow);
            var highestsPokemonPerfect = await _inventory.GetHighestsPerfect(NumberToShow, PokemonSession);

            foreach (var pokemon in highestsPokemonPerfect)
            {
                Logger.Write(
                    $"# CP {pokemon.Cp.ToString().PadLeft(4, ' ')}/{PokemonInfo.CalculateMaxCP(pokemon).ToString().PadLeft(4, ' ')} | ({PokemonInfo.CalculatePokemonPerfection(pokemon).ToString("0.00")}% perfect)\t| Lvl {PokemonInfo.GetLevel(pokemon).ToString("00")}\t NAME: '{pokemon.PokemonId}'",
                    LogLevel.Info, ConsoleColor.Yellow);
            }
        }
コード例 #2
0
        private async Task DisplayHighests()
        {
            Logger.Write("====== DisplayHighestsCP ======", LogLevel.Info, ConsoleColor.Yellow);
            var highestsPokemonCp = await _inventory.GetHighestsCP(10);

            foreach (var pokemon in highestsPokemonCp)
            {
                Logger.Write(
                    $"# CP {pokemon.Cp.ToString().PadLeft(4, ' ')}/{PokemonInfo.CalculateMaxCP(pokemon).ToString().PadLeft(4, ' ')} | ({PokemonInfo.CalculatePokemonPerfection(pokemon).ToString("0.00")}% perfect)\t| Lvl {PokemonInfo.GetLevel(pokemon).ToString("00")}\t NAME: '{pokemon.PokemonId}'",
                    LogLevel.Info, ConsoleColor.Yellow);
            }
            Logger.Write("====== DisplayHighestsPerfect ======", LogLevel.Info, ConsoleColor.Yellow);
            var highestsPokemonPerfect = await _inventory.GetHighestsPerfect(10);

            foreach (var pokemon in highestsPokemonPerfect)
            {
                Logger.Write(
                    $"# CP {pokemon.Cp.ToString().PadLeft(4, ' ')}/{PokemonInfo.CalculateMaxCP(pokemon).ToString().PadLeft(4, ' ')} | ({PokemonInfo.CalculatePokemonPerfection(pokemon).ToString("0.00")}% perfect)\t| Lvl {PokemonInfo.GetLevel(pokemon).ToString("00")}\t NAME: '{pokemon.PokemonId}'",
                    LogLevel.Info, ConsoleColor.Yellow);
            }
        }
コード例 #3
0
        public async Task ExportPokemonToCSV(PlayerData player, string filename = "PokeList.csv")
        {
            if (player == null)
            {
                return;
            }
            var stats = await GetPlayerStats();

            var stat = stats.FirstOrDefault();

            if (stat == null)
            {
                return;
            }

            if (!Directory.Exists(export_path))
            {
                Directory.CreateDirectory(export_path);
            }
            if (Directory.Exists(export_path))
            {
                try
                {
                    string pokelist_file = Path.Combine(export_path, $"Profile_{player.Username}_{filename}");
                    if (File.Exists(pokelist_file))
                    {
                        File.Delete(pokelist_file);
                    }
                    string ls     = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator;
                    string header = "PokemonID,Name,NickName,CP / MaxCP,Perfection,True Value,Attack 1,Attack 2,HP,Attk,Def,Stamina,Familie Candies,ID,previewLink";
                    File.WriteAllText(pokelist_file, $"{header.Replace(",", $"{ls}")}");

                    var AllPokemon = await GetHighestsPerfect();

                    var myPokemonSettings = await GetPokemonSettings();

                    var pokemonSettings   = myPokemonSettings.ToList();
                    var myPokemonFamilies = await GetPokemonFamilies();

                    var   pokemonFamilies  = myPokemonFamilies.ToArray();
                    int   trainerLevel     = stat.Level;
                    int[] exp_req          = new[] { 0, 1000, 3000, 6000, 10000, 15000, 21000, 28000, 36000, 45000, 55000, 65000, 75000, 85000, 100000, 120000, 140000, 160000, 185000, 210000, 260000, 335000, 435000, 560000, 710000, 900000, 1100000, 1350000, 1650000, 2000000, 2500000, 3000000, 3750000, 4750000, 6000000, 7500000, 9500000, 12000000, 15000000, 20000000 };
                    int   exp_req_at_level = exp_req[stat.Level - 1];

                    using (var w = File.AppendText(pokelist_file))
                    {
                        w.WriteLine("");
                        foreach (var pokemon in AllPokemon)
                        {
                            string toEncode = $"{(int)pokemon.PokemonId}" + "," + trainerLevel + "," + PokemonInfo.GetLevel(pokemon) + "," + pokemon.Cp + "," + pokemon.Stamina;
                            //Generate base64 code to make it viewable here http://poke.isitin.org/#MTUwLDIzLDE3LDE5MDIsMTE4
                            var    encoded        = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(toEncode));
                            var    settings       = pokemonSettings.Single(x => x.PokemonId == pokemon.PokemonId);
                            var    familiecandies = pokemonFamilies.Single(x => settings.FamilyId == x.FamilyId).Candy_;
                            string perfection     = pokemon.GetPerfection().ToString("0.00");
                            perfection = perfection.Replace(",", ls == "," ? "." : ",");
                            string truevalue     = Context.Utility.CalculatePokemonValue(pokemon).ToString();
                            string content_part1 = $"{(int)pokemon.PokemonId},{pokemon.PokemonId},{pokemon.Nickname},{pokemon.Cp}/{PokemonInfo.CalculateMaxCP(pokemon)},";
                            string content_part2 = $",{truevalue},{pokemon.Move1},{pokemon.Move2},{pokemon.Stamina},{pokemon.IndividualAttack},{pokemon.IndividualDefense},{pokemon.IndividualStamina},{familiecandies},{pokemon.Id},http://poke.isitin.org/#{encoded}";
                            string content       = $"{content_part1.Replace(",", $"{ls}")}{perfection}{content_part2.Replace(",", $"{ls}")}";
                            w.WriteLine($"{content}");
                        }
                        w.Close();
                    }
                    //Logger.Write($"Export Player Infos and all Pokemon to \"\\Export\\{filename}\"", LogLevel.Info);
                }
                catch
                {
                    Logger.Write("Export Player Infos and all Pokemons to CSV not possible. File seems be in use!", LogLevel.Warning);
                }
            }
        }
コード例 #4
0
        private static void StartIncubation()
        {
            try
            {
                if (GlobalVars.RelocateDefaultLocation)
                {
                    return;
                }
                var inventory  = Logic.objClient.Inventory.GetInventory();
                var incubators = Logic.objClient.Inventory.GetEggIncubators().ToList();
                var unusedEggs = (Logic.objClient.Inventory.GetEggs()).Where(x => string.IsNullOrEmpty(x.EggIncubatorId)).OrderBy(x => x.EggKmWalkedTarget - x.EggKmWalkedStart).ToList();
                var pokemons   = (Logic.objClient.Inventory.GetPokemons()).ToList();

                var playerStats = Logic.objClient.Inventory.GetPlayerStats();
                var stats       = playerStats.First();

                var kmWalked = stats.KmWalked;

                var logs = Path.Combine(logPath, "EggLog.txt");
                var date = DateTime.Now.ToString();

                var unusedEggsBasicInc   = eggsHatchingAllowedBasicInc(unusedEggs);
                var unusedEggsUnlimitInc = eggsHatchingAllowed(unusedEggs);

                foreach (var incubator in rememberedIncubators)
                {
                    var hatched = pokemons.FirstOrDefault(x => !x.IsEgg && x.Id == incubator.PokemonId);
                    if (hatched == null)
                    {
                        continue;
                    }

                    if (GlobalVars.LogEggs)
                    {
                        var MaxCP     = PokemonInfo.CalculateMaxCP(hatched);
                        var Level     = PokemonInfo.GetLevel(hatched);
                        var IVPercent = PokemonInfo.CalculatePokemonPerfection(hatched).ToString("0.00");
                        File.AppendAllText(logs, $"[{date}] - Egg hatched and we got a {hatched.PokemonId} (CP: {hatched.Cp} | MaxCP: {MaxCP} | Level: {Level} | IV: {IVPercent}% )" + Environment.NewLine);
                    }
                    Logger.ColoredConsoleWrite(ConsoleColor.DarkYellow, "Egg hatched and we got a " + hatched.PokemonId + " CP: " + hatched.Cp + " MaxCP: " + PokemonInfo.CalculateMaxCP(hatched) + " Level: " + PokemonInfo.GetLevel(hatched) + " IV: " + PokemonInfo.CalculatePokemonPerfection(hatched).ToString("0.00") + "%");
                }

                if ((unusedEggsUnlimitInc.Count < 1) && (unusedEggsUnlimitInc.Count < 1))
                {
                    Logger.ColoredConsoleWrite(ConsoleColor.DarkYellow, "There are not Allowed Eggs to hatch");
                    return;
                }

                var newRememberedIncubators = new List <IncubatorUsage>();

                foreach (EggIncubator incubator in incubators)
                {
                    if (incubator.PokemonId == 0)
                    {
                        // If is basic incubator and user don't want use it, we go to the next incubator
                        if ((incubator.ItemId == ItemId.ItemIncubatorBasic) &&
                            (!GlobalVars.UseBasicIncubators))
                        {
                            continue;
                        }

                        POGOProtos.Data.PokemonData egg;
                        if (incubator.ItemId == ItemId.ItemIncubatorBasic)
                        {
                            egg = GlobalVars.EggsAscendingSelectionBasicInc ? unusedEggsBasicInc.FirstOrDefault() : unusedEggsBasicInc.LastOrDefault();
                        }
                        else
                        {
                            egg = GlobalVars.EggsAscendingSelection ? unusedEggsUnlimitInc.FirstOrDefault() : unusedEggsUnlimitInc.LastOrDefault();
                        }

                        // If there is not eggs then we finish this function
                        if (egg == null)
                        {
                            return;
                        }

                        var response = Logic.objClient.Inventory.UseItemEggIncubator(incubator.Id, egg.Id);
                        try
                        {
                            unusedEggsUnlimitInc.Remove(egg);
                            unusedEggsBasicInc.Remove(egg);
                        }
                        catch (Exception ex) {
                            Logger.ColoredConsoleWrite(ConsoleColor.Red, "Error: Logic.cs - StartIncubation()");
                            Logger.ColoredConsoleWrite(ConsoleColor.Red, ex.Message);
                        }
                        newRememberedIncubators.Add(new IncubatorUsage {
                            IncubatorId = incubator.Id, PokemonId = egg.Id
                        });
                        Logger.ColoredConsoleWrite(ConsoleColor.DarkYellow, "Added Egg which needs " + egg.EggKmWalkedTarget + "km");
                        // We need some sleep here or this shit explodes
                        RandomHelper.RandomSleep(100, 200);
                    }
                    else
                    {
                        newRememberedIncubators.Add(new IncubatorUsage
                        {
                            IncubatorId = incubator.Id,
                            PokemonId   = incubator.PokemonId
                        });

                        Logger.ColoredConsoleWrite(ConsoleColor.DarkYellow, "Egg (" + (incubator.TargetKmWalked - incubator.StartKmWalked) + "km) need to walk " + Math.Round(incubator.TargetKmWalked - kmWalked, 2) + " km.");
                    }
                }
                if (!newRememberedIncubators.SequenceEqual(rememberedIncubators))
                {
                    rememberedIncubators = newRememberedIncubators;
                }
            }
            catch (Exception ex)
            {
                // Leave this here: Logger.Error(e.StackTrace);
                Logger.ColoredConsoleWrite(ConsoleColor.DarkYellow, "Egg: We dont have any eggs we could incubate.");
                Logger.ColoredConsoleWrite(ConsoleColor.Red, ex.Message);
            }
        }
コード例 #5
0
        private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon)
        {
            CatchPokemonResponse caughtPokemonResponse;
            var attemptCounter = 1;

            do
            {
                var probability  = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault();
                var bestPokeball = await GetBestBall(encounter);

                if (bestPokeball == MiscEnums.Item.ITEM_UNKNOWN)
                {
                    Logger.Write($"You don't own any Pokeballs :( - We missed a {pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp}", LogLevel.Warning);
                    return;
                }
                var bestBerry = await GetBestBerry(encounter);

                var inventoryBerries = await _inventory.GetItems();

                var berries = inventoryBerries.Where(p => (ItemId)p.Item_ == bestBerry).FirstOrDefault();
                if (bestBerry != ItemId.ItemUnknown && probability.HasValue && probability.Value < 0.35)
                {
                    await _client.UseCaptureItem(pokemon.EncounterId, bestBerry, pokemon.SpawnpointId);

                    berries.Count--;
                    Logger.Write($"{bestBerry} used, remaining: {berries.Count}", LogLevel.Berry);
                    await RandomHelper.RandomDelay(50, 200);
                }

                var distance = LocationUtils.CalculateDistanceInMeters(_client.CurrentLat, _client.CurrentLng, pokemon.Latitude, pokemon.Longitude);
                caughtPokemonResponse = await _client.CatchPokemon(pokemon.EncounterId, pokemon.SpawnpointId, pokemon.Latitude, pokemon.Longitude, bestPokeball);

                if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess)
                {
                    foreach (var xp in caughtPokemonResponse.Scores.Xp)
                    {
                        _stats.AddExperience(xp);
                    }
                    _stats.IncreasePokemons();
                    var profile = await _client.GetProfile();

                    _stats.GetStardust(profile.Profile.Currency.ToArray()[1].Amount);
                }
                _stats.UpdateConsoleTitle(_client, _inventory);

                if (encounter?.CaptureProbability?.CaptureProbability_ != null)
                {
                    Func <MiscEnums.Item, string> returnRealBallName = a =>
                    {
                        switch (a)
                        {
                        case MiscEnums.Item.ITEM_POKE_BALL:
                            return("Poke");

                        case MiscEnums.Item.ITEM_GREAT_BALL:
                            return("Great");

                        case MiscEnums.Item.ITEM_ULTRA_BALL:
                            return("Ultra");

                        case MiscEnums.Item.ITEM_MASTER_BALL:
                            return("Master");

                        default:
                            return("Unknown");
                        }
                    };
                    var catchStatus = attemptCounter > 1
                        ? $"{caughtPokemonResponse.Status} Attempt #{attemptCounter}"
                        : $"{caughtPokemonResponse.Status}";

                    string receivedXP = catchStatus == "CatchSuccess"
                        ? $"and received XP {caughtPokemonResponse.Scores.Xp.Sum()}"
                        : $"";

                    Logger.Write($"({catchStatus}) | {pokemon.PokemonId} Lvl {PokemonInfo.GetLevel(encounter?.WildPokemon?.PokemonData)} (CP {encounter?.WildPokemon?.PokemonData?.Cp}/{PokemonInfo.CalculateMaxCP(encounter?.WildPokemon?.PokemonData)} | {Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData)).ToString("0.00")} % perfect) | Chance: {(float)((int)(encounter?.CaptureProbability?.CaptureProbability_.First() * 100)) / 100} | {Math.Round(distance)}m dist | with a {returnRealBallName(bestPokeball)}Ball {receivedXP}", LogLevel.Pokemon);
                }

                attemptCounter++;
                await RandomHelper.RandomDelay(750, 1250);
            }while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed || caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);
        }
コード例 #6
0
        public static async Task StartIncubation(Client _client)
        {
            try
            {
                await _client.Inventory.RefreshCachedInventory(); // REFRESH

                var incubators = (await _client.Inventory.GetEggIncubators()).ToList();
                var unusedEggs = (await _client.Inventory.GetEggs()).Where(x => string.IsNullOrEmpty(x.EggIncubatorId)).OrderBy(x => x.EggKmWalkedTarget - x.EggKmWalkedStart).ToList();
                var pokemons   = (await _client.Inventory.GetPokemons()).ToList();

                var playerStats = await _client.Inventory.GetPlayerStats();

                var stats = playerStats.First();

                var kmWalked = stats.KmWalked;

                var rememberedIncubatorsFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + "\\Configs", "incubators.json");
                var rememberedIncubators         = GetRememberedIncubators(rememberedIncubatorsFilePath);

                foreach (var incubator in rememberedIncubators)
                {
                    var hatched = pokemons.FirstOrDefault(x => !x.IsEgg && x.Id == incubator.PokemonId);
                    if (hatched == null)
                    {
                        continue;
                    }

                    Logger.ColoredConsoleWrite(ConsoleColor.DarkYellow, "Egg hatched and we got a " + hatched.PokemonId + " CP: " + hatched.Cp + " MaxCP: " + PokemonInfo.CalculateMaxCP(hatched) + " Level: " + PokemonInfo.GetLevel(hatched) + " IV: " + PokemonInfo.CalculatePokemonPerfection(hatched).ToString("0.00") + "%");
                }

                var newRememberedIncubators = new List <IncubatorUsage>();

                foreach (var incubator in incubators)
                {
                    if (incubator.PokemonId == 0)
                    {
                        // Unlimited incubators prefer short eggs, limited incubators prefer long eggs
                        // Special case: If only one incubator is available at all, it will prefer long eggs
                        var egg = (incubator.ItemId == ItemId.ItemIncubatorBasicUnlimited && incubators.Count > 1)
                            ? unusedEggs.FirstOrDefault()
                            : unusedEggs.LastOrDefault();

                        if (egg == null)
                        {
                            continue;
                        }

                        if (egg.EggKmWalkedTarget < 5 && incubator.ItemId != ItemId.ItemIncubatorBasicUnlimited)
                        {
                            continue;
                        }

                        var response = await _client.Inventory.UseItemEggIncubator(incubator.Id, egg.Id);

                        unusedEggs.Remove(egg);

                        newRememberedIncubators.Add(new IncubatorUsage {
                            IncubatorId = incubator.Id, PokemonId = egg.Id
                        });

                        Logger.ColoredConsoleWrite(ConsoleColor.DarkYellow, "Added Egg which needs " + egg.EggKmWalkedTarget + "km");
                        // More Sleep
                        await RandomHelper.RandomDelay(300, 500);
                    }
                    else
                    {
                        newRememberedIncubators.Add(new IncubatorUsage
                        {
                            IncubatorId = incubator.Id,
                            PokemonId   = incubator.PokemonId
                        });

                        Logger.ColoredConsoleWrite(ConsoleColor.DarkYellow, "Egg (" + (incubator.TargetKmWalked - incubator.StartKmWalked) + "km) need to walk " + Math.Round(incubator.TargetKmWalked - kmWalked, 2) + " km.");
                    }
                }

                if (!newRememberedIncubators.SequenceEqual(rememberedIncubators))
                {
                    SaveRememberedIncubators(newRememberedIncubators, rememberedIncubatorsFilePath);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e.StackTrace.ToString());
            }
        }
コード例 #7
0
        public void ExportPokemonToCSV(PlayerData player, string filename = "PokemonList.csv")
        {
            if (player == null)
            {
                return;
            }
            var stats = GetPlayerStats();
            var stat  = stats.FirstOrDefault();

            if (stat == null)
            {
                return;
            }

            string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Configs");

            if (Directory.Exists(path))
            {
                try
                {
                    string pokelist_file = Path.Combine(path, $"Profile_{player.Username}_{filename}");
                    if (File.Exists(pokelist_file))
                    {
                        File.Delete(pokelist_file);
                    }
                    string ls     = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator;
                    string header = "PokemonID,Name,NickName,CP / MaxCP,IV Perfection in %,Attack 1,Attack 2,HP,Attk,Def,Stamina,Familie Candies,IsInGym,IsFavorite,previewLink";
                    File.WriteAllText(pokelist_file, header.Replace(",", ls));

                    var   AllPokemon        = GetHighestsPerfect();
                    var   myPokemonSettings = GetPokemonSettings();
                    var   pokemonSettings   = myPokemonSettings.ToList();
                    var   myPokemonFamilies = GetPokemonFamilies();
                    var   pokemonFamilies   = myPokemonFamilies.ToArray();
                    int   trainerLevel      = stat.Level;
                    int[] exp_req           = new[] { 0, 1000, 3000, 6000, 10000, 15000, 21000, 28000, 36000, 45000, 55000, 65000, 75000, 85000, 100000, 120000, 140000, 160000, 185000, 210000, 260000, 335000, 435000, 560000, 710000, 900000, 1100000, 1350000, 1650000, 2000000, 2500000, 3000000, 3750000, 4750000, 6000000, 7500000, 9500000, 12000000, 15000000, 20000000 };
                    int   exp_req_at_level  = exp_req[stat.Level - 1];

                    using (var w = File.AppendText(pokelist_file))
                    {
                        w.WriteLine("");
                        foreach (var pokemon in AllPokemon)
                        {
                            string toEncode = $"{(int)pokemon.PokemonId}" + "," + trainerLevel + "," + PokemonInfo.GetLevel(pokemon) + "," + pokemon.Cp + "," + pokemon.Stamina;
                            //Generate base64 code to make it viewable here http://poke.isitin.org/#MTUwLDIzLDE3LDE5MDIsMTE4
                            var encoded = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(toEncode));

                            string IsInGym    = string.Empty;
                            string IsFavorite = string.Empty;

                            if (pokemon.Favorite != 0)
                            {
                                IsFavorite = "Yes";
                            }
                            else
                            {
                                IsFavorite = "No";
                            }

                            var    settings       = pokemonSettings.SingleOrDefault(x => x.PokemonId == pokemon.PokemonId);
                            var    familiecandies = pokemonFamilies.SingleOrDefault(x => settings.FamilyId == x.FamilyId).Candy_;
                            string perfection     = PokemonInfo.CalculatePokemonPerfection(pokemon).ToString("0.00");
                            perfection = perfection.Replace(",", ls == "," ? "." : ",");
                            string content_part1 = $"{(int)pokemon.PokemonId},{pokemon.PokemonId},{pokemon.Nickname},{pokemon.Cp}/{PokemonInfo.CalculateMaxCP(pokemon)},";
                            string content_part2 = $",{pokemon.Move1},{pokemon.Move2},{pokemon.Stamina},{pokemon.IndividualAttack},{pokemon.IndividualDefense},{pokemon.IndividualStamina},{familiecandies},{IsInGym},{IsFavorite},http://poke.isitin.org/#{encoded}";
                            var    str1          = content_part1.Replace(",", ls);
                            var    str2          = content_part2.Replace(",", ls);
                            string content       = $"{str1}\"{perfection}\"{str2}";
                            w.WriteLine($"{content}");
                        }
                        w.Close();
                    }
                    Logger.ColoredConsoleWrite(ConsoleColor.Green, $"Export Player Infos and all Pokemon to \"\\Config\\{filename}\"");
                }
                catch
                {
                    Logger.Error("Export Player Infos and all Pokemons to CSV not possible. File seems be in use!" /*, LogLevel.Warning*/);
                }
            }
        }
コード例 #8
0
ファイル: Logic.cs プロジェクト: Jeampan/Pokebot
        private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon)
        {
            CatchPokemonResponse caughtPokemonResponse;
            var attemptCounter = 1;

            do
            {
                var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault();

                var pokeball = await GetBestBall(encounter);

                if (pokeball == ItemId.ItemUnknown)
                {
                    Logger.Write(
                        $"No Pokeballs - We missed a {pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp}",
                        LogLevel.Caught);
                    return;
                }
                if ((probability.HasValue && probability.Value < 0.35 && encounter.WildPokemon?.PokemonData?.Cp > 400) ||
                    PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData) >=
                    _clientSettings.KeepMinIVPercentage)
                {
                    await UseBerry(pokemon.EncounterId, pokemon.SpawnPointId);
                }

                var distance = LocationUtils.CalculateDistanceInMeters(_client.CurrentLatitude, _client.CurrentLongitude,
                                                                       pokemon.Latitude, pokemon.Longitude);
                caughtPokemonResponse =
                    await
                    _client.Encounter.CatchPokemon(pokemon.EncounterId, pokemon.SpawnPointId, pokeball);

                if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess)
                {
                    foreach (var xp in caughtPokemonResponse.CaptureAward.Xp)
                    {
                        _stats.AddExperience(xp);
                    }
                    _stats.IncreasePokemons();
                    var profile = await _client.Player.GetPlayer();

                    _stats.GetStardust(profile.PlayerData.Currencies.ToArray()[1].Amount);
                }
                _stats.UpdateConsoleTitle(_inventory);

                if (encounter?.CaptureProbability?.CaptureProbability_ != null)
                {
                    Func <ItemId, string> returnRealBallName = a =>
                    {
                        switch (a)
                        {
                        case ItemId.ItemPokeBall:
                            return("Poke");

                        case ItemId.ItemGreatBall:
                            return("Great");

                        case ItemId.ItemUltraBall:
                            return("Ultra");

                        case ItemId.ItemMasterBall:
                            return("Master");

                        default:
                            return("Unknown");
                        }
                    };
                    var catchStatus = attemptCounter > 1
                        ? $"{caughtPokemonResponse.Status} Attempt #{attemptCounter}"
                        : $"{caughtPokemonResponse.Status}";

                    var color = ConsoleColor.Green;

                    if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchFlee)
                    {
                        color = ConsoleColor.Red;
                    }

                    Logger.Write(
                        $"({catchStatus}) | {pokemon.PokemonId} Lvl {PokemonInfo.GetLevel(encounter.WildPokemon?.PokemonData)} ({encounter.WildPokemon?.PokemonData?.Cp}/{PokemonInfo.CalculateMaxCP(encounter.WildPokemon?.PokemonData)} CP) ({Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter.WildPokemon?.PokemonData)).ToString("0.00")}% perfect) | Chance: {Math.Round(Convert.ToDouble(encounter.CaptureProbability?.CaptureProbability_.First())*100, 2)}% | {Math.Round(distance)}m dist | with a {returnRealBallName(pokeball)}Ball.",
                        LogLevel.Caught, color);

                    if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess)
                    {
                        _caughtInSession.Add(encounter.WildPokemon?.PokemonData);
                        _narrator.Speak($"{pokemon.PokemonId}, {encounter.WildPokemon?.PokemonData?.Cp}");
                        Statistics.KeptPokemon++;

                        _map.Invoke(new MethodInvoker(delegate() {
                            var pokemonOverlay     = _map.Overlays[3];
                            GMapMarker foundMarker = null;

                            for (int i = 0; i < pokemonOverlay.Markers.Count; i++)
                            {
                                var marker = pokemonOverlay.Markers[i];

                                if (Math.Round(marker.Position.Lat, 12) == Math.Round(encounter.WildPokemon.Latitude, 12) &&
                                    Math.Round(marker.Position.Lng, 12) == Math.Round(encounter.WildPokemon.Longitude, 12))
                                {
                                    foundMarker = marker;
                                    break;
                                }
                            }

                            var position = new GMap.NET.PointLatLng(Math.Round(encounter.WildPokemon.Latitude, 12), Math.Round(encounter.WildPokemon.Longitude, 12));
                            _client.Map.CaughtMarkers.Add(new KeyValuePair <int, GMap.NET.PointLatLng>((int)pokemon.PokemonId, position));

                            if (foundMarker != null)
                            {
                                pokemonOverlay.Markers.Remove(foundMarker);
                            }
                        }));
                    }
                }
                attemptCounter++;
                await Task.Delay(2000);
            } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed ||
                     caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);
        }
コード例 #9
0
 public static int GetMaxCP(this PokemonData pokemon)
 {
     return(PokemonInfo.CalculateMaxCP(pokemon));
 }
コード例 #10
0
        private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon)
        {
            CatchPokemonResponse caughtPokemonResponse;
            var attemptCounter = 1;

            do
            {
                var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault();

                var pokeball = await GetBestBall(encounter);

                if (pokeball == ItemId.ItemUnknown)
                {
                    Logger.Write(
                        $"No Pokeballs - We missed a {pokemon.PokemonId} with CP {encounter?.WildPokemon?.PokemonData?.Cp}",
                        LogLevel.Caught);
                    return;
                }
                if ((probability.HasValue && probability.Value < 0.35 && encounter.WildPokemon?.PokemonData?.Cp > 400) ||
                    PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData) >=
                    _clientSettings.KeepMinIVPercentage)
                {
                    await UseBerry(pokemon.EncounterId, pokemon.SpawnPointId);
                }

                var distance = LocationUtils.CalculateDistanceInMeters(_client.CurrentLat, _client.CurrentLng,
                                                                       pokemon.Latitude, pokemon.Longitude);
                caughtPokemonResponse =
                    await
                    _client.CatchPokemon(pokemon.EncounterId, pokemon.SpawnPointId, pokeball);

                if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess)
                {
                    foreach (var xp in caughtPokemonResponse.CaptureAward.Xp)
                    {
                        _stats.AddExperience(xp);
                    }
                    _stats.IncreasePokemons();
                    var profile = await _client.GetPlayer();

                    _stats.GetStardust(profile.PlayerData.Currencies.ToArray()[1].Amount);
                }
                _stats.UpdateConsoleTitle(_inventory);

                if (encounter?.CaptureProbability?.CaptureProbability_ != null)
                {
                    Func <ItemId, string> returnRealBallName = a =>
                    {
                        switch (a)
                        {
                        case ItemId.ItemPokeBall:
                            return("Poke");

                        case ItemId.ItemGreatBall:
                            return("Great");

                        case ItemId.ItemUltraBall:
                            return("Ultra");

                        case ItemId.ItemMasterBall:
                            return("Master");

                        default:
                            return("Unknown");
                        }
                    };
                    var catchStatus = attemptCounter > 1
                        ? $"{caughtPokemonResponse.Status} Attempt #{attemptCounter}"
                        : $"{caughtPokemonResponse.Status}";
                    Logger.Write(
                        $"({catchStatus}) | {pokemon.PokemonId} Lvl {PokemonInfo.GetLevel(encounter.WildPokemon?.PokemonData)} ({encounter.WildPokemon?.PokemonData?.Cp}/{PokemonInfo.CalculateMaxCP(encounter.WildPokemon?.PokemonData)} CP) ({Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter.WildPokemon?.PokemonData)).ToString("0.00")}% perfect) | Chance: {Math.Round(Convert.ToDouble(encounter.CaptureProbability?.CaptureProbability_.First())*100, 2)}% | {Math.Round(distance)}m dist | with a {returnRealBallName(pokeball)}Ball.",
                        LogLevel.Caught);
                }
                attemptCounter++;
                await Task.Delay(2000);
            } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed ||
                     caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);
        }
コード例 #11
0
        private async Task CatchEncounter(DiskEncounterResponse encounter, PokemonData pokemon, ulong encounterId, string locationGUID)
        {
            CatchPokemonResponse caughtPokemonResponse;
            var attemptCounter = 1;

            do
            {
                //var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault();

                var pokeball = ItemId.ItemPokeBall;
                if (pokeball == ItemId.ItemUnknown)
                {
                    Logger.Write(
                        $"No Pokeballs - We missed a {pokemon.PokemonId} with CP {pokemon.Cp}",
                        LogLevel.Caught);
                    return;
                }

                caughtPokemonResponse =
                    await
                    _client.CatchPokemon(encounterId, locationGUID, pokeball);

                if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess)
                {
                    foreach (var xp in caughtPokemonResponse.CaptureAward.Xp)
                    {
                        _stats.AddExperience(xp);
                    }
                    _stats.IncreasePokemons();
                    var profile = await _client.GetPlayer();

                    _stats.GetStardust(profile.PlayerData.Currencies.ToArray()[1].Amount);
                }
                _stats.UpdateConsoleTitle(_inventory);

                var catchStatus = attemptCounter > 1
                                                ? $"{caughtPokemonResponse.Status} Attempt #{attemptCounter}"
                                                : $"{caughtPokemonResponse.Status}";
                Logger.Write(
                    $"(LURED {catchStatus}) | {pokemon.PokemonId} Lvl {PokemonInfo.GetLevel(pokemon)} ({pokemon?.Cp}/{PokemonInfo.CalculateMaxCP(pokemon)} CP) ({Math.Round(PokemonInfo.CalculatePokemonPerfection(pokemon)).ToString("0.00")}% perfect)", LogLevel.Caught);

                attemptCounter++;
                await Task.Delay(2000);
            } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed ||
                     caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);
        }