public static async Task Execute()
        {
            await Inventory.GetCachedInventory(true);

            var pokemonToEvolve = await Inventory.GetPokemonToEvolve(Logic._client.Settings.PrioritizeIVOverCP, Logic._client.Settings.PokemonsToEvolve);

            if (pokemonToEvolve == null || !pokemonToEvolve.Any())
            {
                return;
            }

            Logger.Write($"Found {pokemonToEvolve.Count()} Pokemon for Evolve:", LogLevel.Debug);
            foreach (var pokemon in pokemonToEvolve)
            {
                var evolvePokemonOutProto = await Logic._client.Inventory.EvolvePokemon(pokemon.Id);

                await Inventory.GetCachedInventory(true);

                Logger.Write(evolvePokemonOutProto.Result == EvolvePokemonResponse.Types.Result.Success
                        ? $"{pokemon.PokemonId} [CP: {pokemon.Cp}/{PokemonInfo.CalculateMaxCp(pokemon)} | IV: { PokemonInfo.CalculatePokemonPerfection(pokemon).ToString("0.00")}% perfect] | received XP {evolvePokemonOutProto.ExperienceAwarded}"
                        : $"Failed: {pokemon.PokemonId}. EvolvePokemonOutProto.Result was {evolvePokemonOutProto.Result}, stopping evolving {pokemon.PokemonId}"
                             , LogLevel.Evolve);

                if (evolvePokemonOutProto.Result == EvolvePokemonResponse.Types.Result.Success)
                {
                    BotStats.ExperienceThisSession += evolvePokemonOutProto.ExperienceAwarded;
                }
            }
            await BotStats.GetPokeDexCount();

            BotStats.UpdateConsoleTitle();
        }
예제 #2
0
        public static async Task Execute(dynamic encounter, MapPokemon pokemon, FortData currentFortData = null, ulong encounterId = 0)
        {
            // If the encounter is null nothing will work below, so exit now
            if (encounter == null)
            {
                return;
            }
            float probability = encounter.CaptureProbability?.CaptureProbability_[0];

            var catchType   = encounter is EncounterResponse ? "Normal" : encounter is DiskEncounterResponse ? "Lure" : "Incense";
            var Id          = encounter is EncounterResponse ? pokemon.PokemonId : encounter?.PokemonData.PokemonId;
            var Level       = PokemonInfo.GetLevel(encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData : encounter?.PokemonData);
            var Cp          = encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData?.Cp : encounter?.PokemonData?.Cp ?? 0;
            var MaxCp       = PokemonInfo.CalculateMaxCp(encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData : encounter?.PokemonData);
            var Iv          = PokemonInfo.CalculatePokemonPerfection(encounter is EncounterResponse ? encounter.WildPokemon?.PokemonData : encounter?.PokemonData);
            var Probability = Math.Round(probability * 100, 2);
            var distance    = LocationUtils.CalculateDistanceInMeters(Logic._client.CurrentLatitude,
                                                                      Logic._client.CurrentLongitude,
                                                                      encounter is EncounterResponse || encounter is IncenseEncounterResponse ? pokemon.Latitude : currentFortData.Latitude,
                                                                      encounter is EncounterResponse || encounter is IncenseEncounterResponse ? pokemon.Longitude : currentFortData.Longitude);

            if (!float.IsNaN(probability) && probability < 0.35)
            {
                await
                UseBerry(encounter is EncounterResponse || encounter is IncenseEncounterResponse?pokemon.EncounterId : encounterId,
                         encounter is EncounterResponse || encounter is IncenseEncounterResponse?pokemon.SpawnPointId : currentFortData?.Id);
            }

            CatchPokemonResponse caughtPokemonResponse;
            var attemptCounter = 1;

            do
            {
                var pokeball = await GetBestBall(encounter, probability);

                if (pokeball == ItemId.ItemUnknown)
                {
                    Logger.Write($"You don't own any Pokeballs :( - We missed a {Id} with CP {Cp}", LogLevel.Warning);
                    return;
                }

                caughtPokemonResponse =
                    await Logic._client.Encounter.CatchPokemon(
                        encounter is EncounterResponse || encounter is IncenseEncounterResponse?pokemon.EncounterId : encounterId,
                        encounter is EncounterResponse || encounter is IncenseEncounterResponse?pokemon.SpawnPointId : currentFortData.Id, pokeball);

                if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess)
                {
                    BotStats.ExperienceThisSession    += caughtPokemonResponse.CaptureAward.Xp.Sum();
                    BotStats.PokemonCaughtThisSession += 1;
                    await BotStats.GetPokeDexCount();

                    await BotStats.GetPokemonCount();

                    var profile = await Logic._client.Player.GetPlayer();

                    BotStats.TotalStardust = profile.PlayerData.Currencies.ToArray()[1].Amount;
                    BotStats.UpdateConsoleTitle();
                }

                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 receivedXp = caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess
                        ? $"and received XP {caughtPokemonResponse.CaptureAward.Xp.Sum()}"
                        : $"";

                    await Inventory.GetCachedInventory(true);

                    var BallAmount = await Inventory.GetItemAmountByType(pokeball);

                    Logger.Write($"({catchStatus} / {catchType}) | {Id} - Lvl {Level} [CP {Cp}/{MaxCp} | IV: {Iv.ToString("0.00")}% perfect] | Chance: {Probability} | {distance:0.##}m dist | with a {returnRealBallName(pokeball)}Ball [Remaining: {BallAmount}] {receivedXp}", LogLevel.Pokemon);
                }

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