Example #1
0
        private static Dictionary <PokemonId, EvolveFilter> EvolveFilterConvertClbDictionary(CheckedListBox input)
        {
            var x       = input.CheckedItems.Cast <PokemonId>().ToList();
            var results = new Dictionary <PokemonId, EvolveFilter>();

            foreach (var i in x)
            {
                var y = new EvolveFilter();
                results.Add(i, y);
            }
            return(results);
        }
Example #2
0
        public async Task <bool> CanEvolvePokemon(PokemonData pokemon, EvolveFilter appliedFilter = null)
        {
            // Can't evolve pokemon in gyms.
            if (!string.IsNullOrEmpty(pokemon.DeployedFortId))
            {
                return(false);
            }

            IEnumerable <PokemonSettings> pokemonSettings = await GetPokemonSettings();

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

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


            int       familyCandy = GetCandyCount(pokemon.PokemonId);
            PokemonId evolveTo    = PokemonId.Missingno;

            if (appliedFilter != null && !string.IsNullOrEmpty(appliedFilter.EvolveTo) && Enum.TryParse <PokemonId>(appliedFilter.EvolveTo, true, out evolveTo))
            {
                var branch = settings.EvolutionBranch.FirstOrDefault(x => x.Evolution == evolveTo);
                if (branch == null)
                {
                    return(false);                //wrong setting, do not evolve this pokemon
                }
                if (branch.EvolutionItemRequirement != ItemId.ItemUnknown)
                {
                    var itemCount = GetItems().Count(x => x.ItemId == branch.EvolutionItemRequirement);

                    if (itemCount == 0 || familyCandy < branch.CandyCost)
                    {
                        return(false);
                    }
                }
            }
            else
            // Can't evolve if not enough candy.
            if (familyCandy < settings.CandyToEvolve)
            {
                return(false);
            }

            return(true);
        }
Example #3
0
        public int GetCandyToEvolve(PokemonSettings settings, EvolveFilter appliedFilter = null)
        {
            EvolutionBranch branch;
            PokemonId       evolveTo = PokemonId.Missingno;

            if (appliedFilter != null && !string.IsNullOrEmpty(appliedFilter.EvolveTo) && Enum.TryParse <PokemonId>(appliedFilter.EvolveTo, true, out evolveTo))
            {
                branch = settings.EvolutionBranch.FirstOrDefault(x => x.Evolution == evolveTo);
            }
            else
            {
                branch = settings.EvolutionBranch.FirstOrDefault(x => x.EvolutionItemRequirement == ItemId.ItemUnknown);
            }

            if (branch == null)
            {
                return(-1);
            }

            return(branch.CandyCost);
        }
Example #4
0
        public async Task <bool> CanEvolvePokemon(PokemonData pokemon, EvolveFilter appliedFilter = null, bool checkEvolveFilterRequirements = false)
        {
            // Can't evolve pokemon in gyms.
            if (!string.IsNullOrEmpty(pokemon.DeployedFortId))
            {
                return(false);
            }

            IEnumerable <PokemonSettings> pokemonSettings = await GetPokemonSettings();

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

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

            int familyCandy = GetCandyCount(pokemon.PokemonId);

            if (checkEvolveFilterRequirements)
            {
                if (!appliedFilter.Operator.BoolFunc(
                        appliedFilter.MinIV <= pokemon.Perfection(),
                        appliedFilter.MinLV <= pokemon.Level(),
                        appliedFilter.MinCP <= pokemon.CP(),
                        (appliedFilter.Moves == null ||
                         appliedFilter.Moves.Count == 0 ||
                         appliedFilter.Moves.Any(x => x[0] == pokemon.Move1 && x[1] == pokemon.Move2)
                        )
                        ))
                {
                    return(false);
                }

                if (appliedFilter.MinCandiesBeforeEvolve > 0 && familyCandy < appliedFilter.MinCandiesBeforeEvolve)
                {
                    return(false);
                }
            }

            PokemonId evolveTo = PokemonId.Missingno;

            if (appliedFilter != null && !string.IsNullOrEmpty(appliedFilter.EvolveTo) && Enum.TryParse <PokemonId>(appliedFilter.EvolveTo, true, out evolveTo))
            {
                var branch = settings.EvolutionBranch.FirstOrDefault(x => x.Evolution == evolveTo);
                if (branch == null)
                {
                    return(false); //wrong setting, do not evolve this pokemon
                }
                if (branch.EvolutionItemRequirement != ItemId.ItemUnknown)
                {
                    var itemCount = GetItems().Count(x => x.ItemId == branch.EvolutionItemRequirement);

                    if (itemCount == 0)
                    {
                        return(false);
                    }
                }

                if (familyCandy < branch.CandyCost)
                {
                    return(false);
                }
            }
            else
            {
                // Check requirements for all branches, if we meet the requirements for any of them then we return true.
                foreach (var branch in settings.EvolutionBranch)
                {
                    if (branch.EvolutionItemRequirement != ItemId.ItemUnknown)
                    {
                        var itemCount = GetItems().Count(x => x.ItemId == branch.EvolutionItemRequirement);

                        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.
                    break;
                }
            }

            return(true);
        }
Example #5
0
        private bool IsEvolveBySpecificFilter(PokemonData pokemon, PokemonSettings settings, int familyCandy, EvolveFilter appliedFilter)
        {
            if (appliedFilter == null || !ownerSession.LogicSettings.EvolvePokemonsThatMatchFilter)
            {
                return(false);
            }

            if (!appliedFilter.Operator.BoolFunc(
                    appliedFilter.MinIV <= pokemon.Perfection(),
                    appliedFilter.MinLV <= pokemon.Level(),
                    appliedFilter.MinCP <= pokemon.CP(),
                    (appliedFilter.Moves == null ||
                     appliedFilter.Moves.Count == 0 ||
                     appliedFilter.Moves.Any(x => x[0] == pokemon.Move1 && x[1] == pokemon.Move2)
                    )
                    ))
            {
                return(false);
            }

            int minCandiesBeforeEvolve = appliedFilter.MinCandiesBeforeEvolve;

            if (minCandiesBeforeEvolve > 0)
            {
                if (ownerSession.LogicSettings.EvolvePreserveMinCandiesFromFilter)
                {
                    minCandiesBeforeEvolve += GetCandyToEvolve(settings, appliedFilter);
                }
                if (familyCandy < minCandiesBeforeEvolve)
                {
                    return(false);
                }
            }

            return(true);
        }
Example #6
0
        public async Task <bool> CanEvolvePokemon(PokemonData pokemon, EvolveFilter appliedFilter = null, bool checkEvolveFilterRequirements = false)
        {
            // Can't evolve pokemon in gyms.
            if (!string.IsNullOrEmpty(pokemon.DeployedFortId))
            {
                return(false);
            }

            IEnumerable <PokemonSettings> pokemonSettings = await GetPokemonSettings().ConfigureAwait(false);

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

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

            int familyCandy = await GetCandyCount(pokemon.PokemonId).ConfigureAwait(false);

            if (checkEvolveFilterRequirements &&
                !IsEvolveByGlobalIvFilter(pokemon) &&
                !IsEvolveBySpecificFilter(pokemon, settings, familyCandy, appliedFilter))
            {
                return(false);
            }

            PokemonId evolveTo = PokemonId.Missingno;

            if (appliedFilter != null && !string.IsNullOrEmpty(appliedFilter.EvolveTo) && Enum.TryParse <PokemonId>(appliedFilter.EvolveTo, true, out evolveTo))
            {
                var branch = settings.EvolutionBranch.FirstOrDefault(x => x.Evolution == evolveTo);
                if (branch == null)
                {
                    return(false); //wrong setting, do not evolve this pokemon
                }
                if (branch.EvolutionItemRequirement != ItemId.ItemUnknown)
                {
                    var itemCount = (await GetItems().ConfigureAwait(false)).Count(x => x.ItemId == branch.EvolutionItemRequirement);

                    if (itemCount == 0)
                    {
                        return(false);
                    }
                }

                if (familyCandy < branch.CandyCost)
                {
                    return(false);
                }
            }
            else
            {
                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.EvolutionBranch)
                {
                    var itemCount      = (await GetItems().ConfigureAwait(false)).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);
            }
            return(true);
        }