Exemple #1
0
        private List <PokemonData> GetPokemonByPossibleEvolve(IGrouping <PokemonId, PokemonData> pokemon, int limit)
        {
            PokemonSettings setting = null;

            if (!PokeSettings.TryGetValue(pokemon.Key, out setting))
            {
                LogCaller(new LoggerEventArgs(String.Format("Failed to find settings for pokemon {0}", pokemon.Key), LoggerTypes.Info));

                return(new List <PokemonData>());
            }

            Candy pokemonCandy = PokemonCandy.FirstOrDefault(x => x.FamilyId == setting.FamilyId);

            int candyToEvolve = setting.CandyToEvolve;
            int totalPokemon  = pokemon.Count();
            int totalCandy    = pokemonCandy.Candy_;

            if (candyToEvolve == 0)
            {
                return(new List <PokemonData>());
            }

            int maxPokemon = totalCandy / candyToEvolve;

            if (maxPokemon > limit)
            {
                maxPokemon = limit;
            }

            return(pokemon.OrderByDescending(x => x.Cp).Skip(maxPokemon).ToList());
        }
        public override int GetHashCode()
        {
            int hash = 1;

            if (Item != 0)
            {
                hash ^= Item.GetHashCode();
            }
            if (Stardust != false)
            {
                hash ^= Stardust.GetHashCode();
            }
            if (Pokecoin != false)
            {
                hash ^= Pokecoin.GetHashCode();
            }
            if (PokemonCandy != 0)
            {
                hash ^= PokemonCandy.GetHashCode();
            }
            if (Count != 0)
            {
                hash ^= Count.GetHashCode();
            }
            return(hash);
        }
        public override int GetHashCode()
        {
            int hash = 1;

            if (Item != 0)
            {
                hash ^= Item.GetHashCode();
            }
            if (Stardust != false)
            {
                hash ^= Stardust.GetHashCode();
            }
            if (Pokecoin != false)
            {
                hash ^= Pokecoin.GetHashCode();
            }
            if (PokemonCandy != 0)
            {
                hash ^= PokemonCandy.GetHashCode();
            }
            if (Count != 0)
            {
                hash ^= Count.GetHashCode();
            }
            if (Experience != false)
            {
                hash ^= Experience.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
Exemple #4
0
        private bool CanEvolvePokemon(PokemonData pokemon)
        {
            // Can't evolve pokemon in gyms.
            if (!string.IsNullOrEmpty(pokemon.DeployedFortId))
            {
                return(false);
            }

            var settings = PokeSettings.SingleOrDefault(x => x.Value.PokemonId == pokemon.PokemonId);

            // Can't evolve pokemon that are not evolvable.
            if (settings.Value.EvolutionIds.Count == 0 && settings.Value.EvolutionBranch.Count == 0)
            {
                return(false);
            }

            int familyCandy = PokemonCandy.FirstOrDefault(x => x.FamilyId == settings.Value.FamilyId).Candy_;

            bool canEvolve = false;

            // Check requirements for all branches, if we meet the requirements for any of them then we return true.
            foreach (var branch in settings.Value.EvolutionBranch)
            {
                var itemCount      = Items.Count(x => x.ItemId == branch.EvolutionItemRequirement);
                var Candies2Evolve = branch.CandyCost; // GetCandyToEvolve(settings);
                var Evolutions     = familyCandy / Candies2Evolve;

                if (branch.EvolutionItemRequirement != ItemId.ItemUnknown)
                {
                    if (itemCount == 0)
                    {
                        continue;  // Cannot evolve so check next branch
                    }
                }

                if (familyCandy < branch.CandyCost)
                {
                    continue;  // Cannot evolve so check next branch
                }
                // If we got here, then we can evolve so break out of loop.
                canEvolve = true;
            }
            return(canEvolve);
        }
Exemple #5
0
        private List <PokemonData> GetPokemonByPossibleEvolve(IGrouping <PokemonId, PokemonData> pokemon, int limit)
        {
            PokemonSettings setting = null;

            if (!PokeSettings.TryGetValue(pokemon.Key, out setting))
            {
                LogCaller(new LoggerEventArgs(String.Format("Failed to find settings for pokemon {0}", pokemon.Key), LoggerTypes.Info));

                return(new List <PokemonData>());
            }

            int pokemonCandy = 0;

            if (PokemonCandy.Any(x => x.FamilyId == setting.FamilyId))
            {
                pokemonCandy = PokemonCandy.Where(x => x.FamilyId == setting.FamilyId).FirstOrDefault().Candy_;
                //int pokemonCandy = PokemonCandy.SingleOrDefault(x => x.FamilyId == setting.FamilyId).Candy_;
            }

            int candyToEvolve = setting.EvolutionBranch.Select(x => x.CandyCost).FirstOrDefault();
            int totalPokemon  = pokemon.Count();

            if (candyToEvolve == 0)
            {
                //Not thinks good
                return(pokemon.OrderByDescending(x => x.Cp).ToList());
                //return new List<PokemonData>();
            }

            int maxPokemon = pokemonCandy / candyToEvolve;

            if (maxPokemon > limit)
            {
                maxPokemon = limit;
            }

            return(pokemon.OrderByDescending(x => x.Cp).Skip(maxPokemon).ToList());
        }
        private bool CanUpgradePokemon(PokemonData pokemon)
        {
            // Can't upgrade pokemon in gyms.
            if (!string.IsNullOrEmpty(pokemon.DeployedFortId))
            {
                return(false);
            }

            int pokemonLevel = (int)GetLevelFromCpMultiplier(pokemon.CpMultiplier + pokemon.AdditionalCpMultiplier);

            // Can't evolve unless pokemon level is lower than trainer.
            if (pokemonLevel >= Level + 2)
            {
                return(false);
            }

            int familyCandy = PokemonCandy.Where(x => x.FamilyId == GetPokemonSetting(pokemon.PokemonId).Data.FamilyId).FirstOrDefault().Candy_;

            // Can't evolve if not enough candy.
            int pokemonCandyNeededAlready = UpgradeSettings.CandyCost[pokemonLevel];

            if (familyCandy < pokemonCandyNeededAlready)
            {
                return(false);
            }

            // Can't evolve if not enough stardust.
            var stardustToUpgrade = UpgradeSettings.StardustCost[pokemonLevel];

            if (TotalStardust < stardustToUpgrade)
            {
                return(false);
            }

            return(true);
        }
        public async Task <MethodResult> ExportStats()
        {
            MethodResult result = await UpdateDetails();

            //Prevent API throttling
            await Task.Delay(500);

            if (!result.Success)
            {
                return(result);
            }

            //Possible some objects were empty.
            var builder = new StringBuilder();

            builder.AppendLine("=== Trainer Stats ===");

            if (Stats != null && PlayerData != null)
            {
                builder.AppendLine(String.Format("Group: {0}", UserSettings.GroupName));
                builder.AppendLine(String.Format("Username: {0}", UserSettings.Username));
                builder.AppendLine(String.Format("Password: {0}", UserSettings.Password));
                builder.AppendLine(String.Format("Level: {0}", Stats.Level));
                builder.AppendLine(String.Format("Current Trainer Name: {0}", PlayerData.Username));
                builder.AppendLine(String.Format("Team: {0}", PlayerData.Team));
                builder.AppendLine(String.Format("Stardust: {0:N0}", TotalStardust));
                builder.AppendLine(String.Format("Unique Pokedex Entries: {0}", Stats.UniquePokedexEntries));
            }
            else
            {
                builder.AppendLine("Failed to grab stats");
            }

            builder.AppendLine();

            builder.AppendLine("=== Pokemon ===");

            if (Pokemon != null)
            {
                foreach (PokemonData pokemon in Pokemon.OrderByDescending(x => x.Cp))
                {
                    string candy = "Unknown";

                    MethodResult <PokemonSettings> pSettings = GetPokemonSetting(pokemon.PokemonId);

                    if (pSettings.Success)
                    {
                        Candy pCandy = PokemonCandy.FirstOrDefault(x => x.FamilyId == pSettings.Data.FamilyId);

                        if (pCandy != null)
                        {
                            candy = pCandy.Candy_.ToString("N0");
                        }
                    }

                    double perfectResult = CalculateIVPerfection(pokemon);
                    string iv            = "Unknown";

                    iv = Math.Round(perfectResult, 2).ToString() + "%";

                    builder.AppendLine(String.Format("Pokemon: {0,-10} CP: {1, -5} IV: {2,-7} Primary: {3, -14} Secondary: {4, -14} Candy: {5}", pokemon.PokemonId, pokemon.Cp, iv, pokemon.Move1.ToString().Replace("Fast", ""), pokemon.Move2, candy));
                }
            }

            //Remove the hardcoded directory later
            try
            {
                string directoryName = "AccountStats";

                if (!Directory.Exists(directoryName))
                {
                    Directory.CreateDirectory(directoryName);
                }

                string fileName = UserSettings.Username.Split('@').First();

                string filePath = Path.Combine(directoryName, fileName) + ".txt";

                File.WriteAllText(filePath, builder.ToString());

                LogCaller(new LoggerEventArgs(String.Format("Finished exporting stats to file {0}", filePath), LoggerTypes.Info));

                return(new MethodResult
                {
                    Message = "Success",
                    Success = true
                });
            }
            catch (Exception ex)
            {
                LogCaller(new LoggerEventArgs("Failed to export stats due to exception", LoggerTypes.Warning, ex));

                return(new MethodResult());
            }
        }
Exemple #8
0
        private async Task <MethodResult <List <PokemonData> > > GetPokemonToEvolve()
        {
            if (!UserSettings.EvolvePokemon)
            {
                LogCaller(new LoggerEventArgs("Evolving disabled", LoggerTypes.Info));

                return(new MethodResult <List <PokemonData> >
                {
                    Data = new List <PokemonData>(),
                    Message = "Evolving disabled",
                    Success = true
                });
            }

            await UpdatePokemon(false);
            await UpdatePokemonCandy(false);

            MethodResult result = await GetItemTemplates();

            if (!result.Success)
            {
                LogCaller(new LoggerEventArgs("Failed to grab pokemon settings. Skipping evolution", LoggerTypes.Warning));

                return(new MethodResult <List <PokemonData> >
                {
                    Data = new List <PokemonData>(),
                    Success = true
                });
            }

            List <PokemonData> pokemonToEvolve = new List <PokemonData>();

            IEnumerable <IGrouping <PokemonId, PokemonData> > groupedPokemon = Pokemon.OrderByDescending(x => x.PokemonId).GroupBy(x => x.PokemonId);

            foreach (IGrouping <PokemonId, PokemonData> group in groupedPokemon)
            {
                EvolveSetting evolveSetting = UserSettings.EvolveSettings.FirstOrDefault(x => x.Id == group.Key);

                if (evolveSetting == null)
                {
                    LogCaller(new LoggerEventArgs(String.Format("Failed to find evolve settings for pokemon {0}", group.Key), LoggerTypes.Info));

                    continue;
                }

                if (!evolveSetting.Evolve)
                {
                    //Don't evolve
                    continue;
                }
                PokemonSettings setting;
                if (!PokeSettings.TryGetValue(group.Key, out setting))
                {
                    LogCaller(new LoggerEventArgs(String.Format("Failed to find settings for pokemon {0}", group.Key), LoggerTypes.Info));

                    continue;
                }

                if (setting.EvolutionIds.Count == 0)
                {
                    //Pokemon can't evolve
                    continue;
                }

                Candy pokemonCandy = PokemonCandy.FirstOrDefault(x => x.FamilyId == setting.FamilyId);
                List <PokemonData> pokemonGroupToEvolve = group.Where(x => x.Cp >= evolveSetting.MinCP).OrderByDescending(x => CalculateIVPerfection(x).Data).ToList();

                if (pokemonCandy == null)
                {
                    LogCaller(new LoggerEventArgs(String.Format("No candy found for pokemon {0}", group.Key), LoggerTypes.Info));

                    continue;
                }

                int candyToEvolve = setting.CandyToEvolve;
                int totalPokemon  = pokemonGroupToEvolve.Count;
                int totalCandy    = pokemonCandy.Candy_;

                int maxPokemon = totalCandy / candyToEvolve;

                foreach (PokemonData pData in pokemonGroupToEvolve.Take(maxPokemon))
                {
                    pokemonToEvolve.Add(pData);
                }
            }

            return(new MethodResult <List <PokemonData> >
            {
                Data = pokemonToEvolve,
                Message = "Success",
                Success = true
            });
        }
Exemple #9
0
        /// <summary>
        /// Load Inventory methodes.
        /// </summary>
        public void UpdateInventory(InventoryRefresh type)
        {
            if (!_client.LoggedIn)
            {
                return;
            }

            LogCaller(new LoggerEventArgs($"Updating inventory. Items to load: {type}", LoggerTypes.Debug));

            try
            {
                foreach (var item in _client.ClientSession.Player.Inventory.InventoryItems)
                {
                    AddRemoveOrUpdateItem(item);
                }

                switch (type)
                {
                case InventoryRefresh.All:
                    Items.Clear();
                    Pokemon.Clear();
                    Pokedex.Clear();
                    PokemonCandy.Clear();
                    Incubators.Clear();
                    Eggs.Clear();
                    Stats        = GetPlayerStats();
                    Items        = GetItemsData().ToList();
                    Pokedex      = GetPokedex().ToList();
                    PokemonCandy = GetCandies().ToList();
                    Incubators   = GetIncubators().ToList();
                    Eggs         = GetEggs().ToList();
                    Pokemon      = GetPokemons().ToList();
                    break;

                case InventoryRefresh.Items:
                    Items.Clear();
                    Items = GetItemsData().ToList();
                    break;

                case InventoryRefresh.Pokemon:
                    Pokemon.Clear();
                    Pokemon = GetPokemons().ToList();
                    break;

                case InventoryRefresh.Pokedex:
                    Pokedex.Clear();
                    Pokedex = GetPokedex().ToList();
                    break;

                case InventoryRefresh.PokemonCandy:
                    PokemonCandy.Clear();
                    PokemonCandy = GetCandies().ToList();
                    break;

                case InventoryRefresh.Incubators:
                    Incubators.Clear();
                    Incubators = GetIncubators().ToList();
                    break;

                case InventoryRefresh.Eggs:
                    Eggs.Clear();
                    Eggs = GetEggs().ToList();
                    break;

                case InventoryRefresh.Stats:
                    Stats = GetPlayerStats();
                    break;
                }
            }
            catch (Exception ex1)
            {
                LogCaller(new LoggerEventArgs(String.Format("Failed updating inventory."), LoggerTypes.Exception, ex1));
                ++_failedInventoryReponses;
            }
        }
Exemple #10
0
        private MethodResult <List <PokemonData> > GetPokemonToEvolve()
        {
            if (!UserSettings.EvolvePokemon)
            {
                LogCaller(new LoggerEventArgs("Evolving disabled", LoggerTypes.Info));

                return(new MethodResult <List <PokemonData> >
                {
                    Data = new List <PokemonData>(),
                    Message = "Evolving disabled",
                    Success = true
                });
            }

            var pokemonToEvolve = new List <PokemonData>();

            IEnumerable <IGrouping <PokemonId, PokemonData> > groupedPokemon = Pokemon.OrderByDescending(x => x.PokemonId).GroupBy(x => x.PokemonId);

            foreach (IGrouping <PokemonId, PokemonData> group in groupedPokemon)
            {
                EvolveSetting evolveSetting = UserSettings.EvolveSettings.FirstOrDefault(x => x.Id == group.Key);

                if (evolveSetting == null)
                {
                    LogCaller(new LoggerEventArgs(String.Format("Failed to find evolve settings for pokemon {0}", group.Key), LoggerTypes.Info));

                    continue;
                }

                if (!evolveSetting.Evolve)
                {
                    //Don't evolve
                    continue;
                }
                PokemonSettings setting;
                if (!PokeSettings.TryGetValue(group.Key, out setting))
                {
                    LogCaller(new LoggerEventArgs(String.Format("Failed to find settings for pokemon {0}", group.Key), LoggerTypes.Info));

                    continue;
                }

                Candy pokemonCandy = PokemonCandy.FirstOrDefault(x => x.FamilyId == setting.FamilyId);
                List <PokemonData> pokemonGroupToEvolve = group.Where(x => x.Cp >= evolveSetting.MinCP).OrderByDescending(x => CalculateIVPerfection(x)).ToList();

                if (pokemonCandy == null)
                {
                    LogCaller(new LoggerEventArgs(String.Format("No candy found for pokemon {0}", group.Key), LoggerTypes.Info));

                    continue;
                }

                int candyToEvolve = setting.EvolutionBranch.Select(x => x.CandyCost).FirstOrDefault();
                int totalPokemon  = pokemonGroupToEvolve.Count;
                int totalCandy    = pokemonCandy.Candy_;

                int maxPokemon = totalCandy / candyToEvolve;

                foreach (PokemonData pData in pokemonGroupToEvolve.Take(maxPokemon))
                {
                    if (!CanTransferOrEvolePokemon(pData, true))
                    {
                        LogCaller(new LoggerEventArgs(String.Format("Skipped {0}, this pokemon cant not be transfered maybe is a favorit, is deployed or is a buddy pokemon.", pData.PokemonId), LoggerTypes.Info));
                    }
                    else
                    {
                        pokemonToEvolve.Add(pData);
                    }
                }
            }

            return(new MethodResult <List <PokemonData> >
            {
                Data = pokemonToEvolve,
                Message = "Success",
                Success = true
            });
        }
Exemple #11
0
        public void UpdateInventory()
        {
            LogCaller(new LoggerEventArgs("Updating inventory.", LoggerTypes.Debug));

            try
            {
                var inventoryItems = _client?.ClientSession?.Player?.Inventory?.InventoryItems;
                if (inventoryItems == null)
                {
                    return;
                }
                Items.Clear();
                Pokemon.Clear();
                Pokedex.Clear();
                PokemonCandy.Clear();
                Incubators.Clear();
                Eggs.Clear();
                foreach (var inventoryItem in inventoryItems)
                {
                    if (inventoryItem.InventoryItemData?.PlayerStats != null)
                    {
                        Stats = inventoryItem.InventoryItemData.PlayerStats;
                    }
                    if (inventoryItem.InventoryItemData?.Item != null)
                    {
                        Items.Add(inventoryItem.InventoryItemData.Item);
                    }
                    if (inventoryItem.InventoryItemData?.PokedexEntry != null)
                    {
                        Pokedex.Add(inventoryItem.InventoryItemData.PokedexEntry);
                    }
                    if (inventoryItem.InventoryItemData?.Candy != null)
                    {
                        PokemonCandy.Add(inventoryItem.InventoryItemData.Candy);
                    }
                    if (inventoryItem.InventoryItemData?.EggIncubators != null)
                    {
                        foreach (var eggIncubator in inventoryItem.InventoryItemData.EggIncubators.EggIncubator)
                        {
                            if (eggIncubator != null)
                            {
                                Incubators.Add(eggIncubator);
                            }
                        }
                    }
                    if (inventoryItem.InventoryItemData?.PokemonData != null)
                    {
                        if (inventoryItem.InventoryItemData.PokemonData.IsEgg)
                        {
                            Eggs.Add(inventoryItem.InventoryItemData.PokemonData);
                        }
                        else
                        {
                            Pokemon.Add(inventoryItem.InventoryItemData.PokemonData);
                        }
                    }
                }
            }
            catch (Exception ex1)
            {
                AccountState = Enums.AccountState.TemporalBan;
                LogCaller(new LoggerEventArgs(String.Format("Failed updating inventory."), LoggerTypes.Debug, ex1));
                Stop();
            }
        }