Example #1
0
        public static IEnumerable <EncounterEgg> GenerateEggs(PKM pkm, bool all = false)
        {
            var table            = EvolutionTree.GetEvolutionTree(pkm, 2);
            int maxSpeciesOrigin = Legal.GetMaxSpeciesOrigin(2);
            var evos             = table.GetValidPreEvolutions(pkm, maxLevel: 100, maxSpeciesOrigin: maxSpeciesOrigin, skipChecks: true);

            return(GenerateEggs(pkm, evos, all));
        }
Example #2
0
        internal static EvoCriteria GetBaseSpecies(PKM pkm, int maxSpeciesOrigin, int generation, int skipOption = 0)
        {
            int tree  = generation;
            var table = EvolutionTree.GetEvolutionTree(pkm, tree);
            var evos  = table.GetValidPreEvolutions(pkm, maxLevel: 100, maxSpeciesOrigin: maxSpeciesOrigin, skipChecks: true);

            return(GetBaseSpecies(evos, skipOption));
        }
Example #3
0
File: Core.cs Project: LLNet/PKHeX
        internal static int GetBaseSpecies(PKM pkm, int skipOption = 0, int generation = -1)
        {
            int tree             = generation != -1 ? generation : pkm.Format;
            var table            = EvolutionTree.GetEvolutionTree(tree);
            int maxSpeciesOrigin = generation != -1 ? GetMaxSpeciesOrigin(generation) : -1;
            var evos             = table.GetValidPreEvolutions(pkm, maxLevel: 100, maxSpeciesOrigin: maxSpeciesOrigin, skipChecks: true);

            return(GetBaseSpecies(pkm, evos, skipOption));
        }
Example #4
0
        /// <summary>
        /// Gets possible encounters that allow all moves requested to be learned.
        /// </summary>
        /// <param name="pk">Rough Pokémon data which contains the requested species, gender, and form.</param>
        /// <param name="moves">Moves that the resulting <see cref="IEncounterable"/> must be able to learn.</param>
        /// <param name="version">Specific version to iterate for.</param>
        /// <returns>A consumable <see cref="IEncounterable"/> list of possible encounters.</returns>
        public static IEnumerable <IEncounterable> GenerateVersionEncounters(PKM pk, IEnumerable <int> moves, GameVersion version)
        {
            pk.Version = (int)version;
            var et = EvolutionTree.GetEvolutionTree(pk.Format);
            var dl = et.GetValidPreEvolutions(pk, maxLevel: 100, skipChecks: true);

            int[] needs = GetNeededMoves(pk, moves, dl);

            return(PriorityList.SelectMany(type => GetPossibleOfType(pk, needs, version, type)));
        }
Example #5
0
        /// <summary>
        /// Gets possible encounters that allow all moves requested to be learned.
        /// </summary>
        /// <param name="pk">Rough Pokémon data which contains the requested species, gender, and form.</param>
        /// <param name="moves">Moves that the resulting <see cref="IEncounterable"/> must be able to learn.</param>
        /// <param name="version">Specific version to iterate for.</param>
        /// <returns>A consumable <see cref="IEncounterable"/> list of possible encounters.</returns>
        public static IEnumerable <IEncounterable> GenerateVersionEncounters(PKM pk, IEnumerable <int> moves, GameVersion version)
        {
            pk.Version = (int)version;
            var et = EvolutionTree.GetEvolutionTree(pk, pk.Species <= Legal.MaxSpeciesID_7_USUM ? 7 : PKX.Generation); // temp workaround as G8 doesn't have all evolutions
            var dl = et.GetValidPreEvolutions(pk, maxLevel: 100, skipChecks: true);

            int[] needs = GetNeededMoves(pk, moves, dl);

            return(PriorityList.SelectMany(type => GetPossibleOfType(pk, needs, version, type)));
        }
        /// <summary>
        /// Gets possible encounters that allow all moves requested to be learned.
        /// </summary>
        /// <param name="pk">Rough Pokémon data which contains the requested species, gender, and form.</param>
        /// <param name="moves">Moves that the resulting <see cref="IEncounterable"/> must be able to learn.</param>
        /// <param name="version">Specific version to iterate for.</param>
        /// <returns>A consumable <see cref="IEncounterable"/> list of possible encounters.</returns>
        public static IEnumerable <IEncounterable> GenerateVersionEncounters(PKM pk, IEnumerable <int> moves, GameVersion version)
        {
            pk.Version = (int)version;
            var et = EvolutionTree.GetEvolutionTree(PKX.Generation);
            var dl = et.GetValidPreEvolutions(pk, maxLevel: 100, skipChecks: true);

            int[] needs = GetNeededMoves(pk, moves, dl);

            foreach (var enc in GetPossible(pk, needs, version))
            {
                yield return(enc);
            }
        }
        /// <summary>
        /// Gets possible encounters that allow all moves requested to be learned.
        /// </summary>
        /// <param name="pk">Rough Pokémon data which contains the requested species, gender, and form.</param>
        /// <param name="moves">Moves that the resulting <see cref="IEncounterable"/> must be able to learn.</param>
        /// <param name="version">Specific version to iterate for.</param>
        /// <returns>A consumable <see cref="IEncounterable"/> list of possible encounters.</returns>
        public static IEnumerable <IEncounterable> GenerateVersionEncounters(PKM pk, IEnumerable <int> moves, GameVersion version)
        {
            pk.Version = (int)version;
            if (version == GameVersion.GO && pk.Format >= 8)
            {
                pk.Met_Location = Locations.GO8; // needed to yield the GO->HOME table instead of GO->LGPE. HOME is a superset of LGPE's possible encounters.
            }
            var et    = EvolutionTree.GetEvolutionTree(pk.Format);
            var chain = et.GetValidPreEvolutions(pk, maxLevel: 100, skipChecks: true);

            int[] needs = GetNeededMoves(pk, moves, chain);

            return(PriorityList.SelectMany(type => GetPossibleOfType(pk, needs, version, type, chain)));
        }
Example #8
0
        /// <summary>
        /// Gets an enumerable list of species IDs from the possible lineage of the <see cref="pkm"/> based on its current format.
        /// </summary>
        /// <param name="pkm">Pokémon to fetch the lineage for.</param>
        internal static IEnumerable <int> GetLineage(PKM pkm)
        {
            if (pkm.IsEgg)
            {
                return new[] { pkm.Species }
            }
            ;

            var table   = EvolutionTree.GetEvolutionTree(pkm.Format);
            var lineage = table.GetValidPreEvolutions(pkm, maxLevel: pkm.CurrentLevel);

            return(lineage.Select(evolution => evolution.Species));
        }
    }
        /// <summary>
        /// Gets possible encounters that allow all moves requested to be learned.
        /// </summary>
        /// <param name="pk">Rough Pokémon data which contains the requested species, gender, and form.</param>
        /// <param name="moves">Moves that the resulting <see cref="IEncounterable"/> must be able to learn.</param>
        /// <param name="version">Specific version to iterate for.</param>
        /// <returns>A consumable <see cref="IEncounterable"/> list of possible encounters.</returns>
        public static IEnumerable <IEncounterable> GenerateVersionEncounters(PKM pk, IEnumerable <int> moves, GameVersion version)
        {
            pk.Version = (int)version;
            var et = EvolutionTree.GetEvolutionTree(PKX.Generation);
            var dl = et.GetValidPreEvolutions(pk, maxLevel: 100, skipChecks: true);

            var gens     = VerifyCurrentMoves.GetGenMovesCheckOrder(pk);
            var canlearn = gens.SelectMany(z => Legal.GetValidMoves(pk, dl, z));
            var needs    = moves.Except(canlearn).ToArray();

            foreach (var enc in GetPossible(pk, needs, version))
            {
                yield return(enc);
            }
        }
Example #10
0
        /// <summary>
        /// Gets possible encounters that allow all moves requested to be learned.
        /// </summary>
        /// <param name="pk">Rough Pokémon data which contains the requested species, gender, and form.</param>
        /// <param name="moves">Moves that the resulting <see cref="IEncounterable"/> must be able to learn.</param>
        /// <param name="version">Specific version to iterate for.</param>
        /// <returns>A consumable <see cref="IEncounterable"/> list of possible encounters.</returns>
        public static IEnumerable <IEncounterable> GenerateVersionEncounters(PKM pk, IEnumerable <int> moves, GameVersion version)
        {
            pk.Version = (int)version;
            var format = pk.Format;

            if (format is 2 && version is GameVersion.RD or GameVersion.GN or GameVersion.BU or GameVersion.YW)
            {
                format = 1; // try excluding baby pokemon from our evolution chain, for move learning purposes.
            }
            var et    = EvolutionTree.GetEvolutionTree(format);
            var chain = et.GetValidPreEvolutions(pk, maxLevel: 100, skipChecks: true);

            int[] needs = GetNeededMoves(pk, moves, chain);

            return(PriorityList.SelectMany(type => GetPossibleOfType(pk, needs, version, type, chain)));
        }
Example #11
0
        private static int GetDexSizeOffset(DexSizeType group, int index) => 0x3978 + (index * 6) + ((int)group * 0x45C); // blockofs + 0xF78 + ([186*6]*n) + x*6

        private void SetSizeData(PB7 pkm, DexSizeType group)
        {
            var tree    = EvolutionTree.GetEvolutionTree(pkm, 7);
            int species = pkm.Species;
            int form    = pkm.AltForm;

            int height = pkm.HeightScalar;
            int weight = pkm.WeightScalar;

            // update for all species in potential lineage
            var allspec = tree.GetEvolutionsAndPreEvolutions(species, form);

            foreach (var s in allspec)
            {
                SetSizeData(group, s, form, height, weight);
            }
        }
Example #12
0
        internal static List <EvoCriteria> GetValidPreEvolutions(PKM pkm, int maxspeciesorigin = -1, int lvl = -1, int minLevel = 1, bool skipChecks = false)
        {
            if (lvl < 0)
            {
                lvl = pkm.CurrentLevel;
            }

            if (maxspeciesorigin == -1 && pkm.InhabitedGeneration(2) && pkm.Format <= 2 && pkm.GenNumber == 1)
            {
                maxspeciesorigin = MaxSpeciesID_2;
            }

            int tree = Math.Max(2, pkm.Format);
            var et   = EvolutionTree.GetEvolutionTree(pkm, tree);

            return(et.GetValidPreEvolutions(pkm, maxLevel: lvl, maxSpeciesOrigin: maxspeciesorigin, skipChecks: skipChecks, minLevel: minLevel));
        }
Example #13
0
        internal static List <EvoCriteria> GetValidPreEvolutions(PKM pkm, int maxspeciesorigin = -1, int lvl = -1, int minLevel = 1, bool skipChecks = false)
        {
            if (lvl < 0)
            {
                lvl = pkm.CurrentLevel;
            }
            if (pkm.IsEgg && !skipChecks)
            {
                return(new List <EvoCriteria>(1)
                {
                    new EvoCriteria(pkm.Species, pkm.AltForm)
                    {
                        Level = lvl, MinLevel = lvl
                    },
                });
            }

            // Shedinja's evolution case can be a little tricky; hard-code handling.
            if (pkm.Species == (int)Species.Shedinja && lvl >= 20 && (!pkm.HasOriginalMetLocation || pkm.Met_Level + 1 <= lvl))
            {
                return(new List <EvoCriteria>(2)
                {
                    new EvoCriteria((int)Species.Shedinja, 0)
                    {
                        Level = lvl, MinLevel = 20
                    },
                    new EvoCriteria((int)Species.Nincada, 0)
                    {
                        Level = lvl, MinLevel = 1
                    },
                });
            }

            if (maxspeciesorigin == -1 && pkm.InhabitedGeneration(2) && pkm.Format <= 2 && pkm.GenNumber == 1)
            {
                maxspeciesorigin = MaxSpeciesID_2;
            }

            int tree = Math.Max(2, pkm.Format);
            var et   = EvolutionTree.GetEvolutionTree(pkm, tree);

            return(et.GetValidPreEvolutions(pkm, maxLevel: lvl, maxSpeciesOrigin: maxspeciesorigin, skipChecks: skipChecks, minLevel: minLevel));
        }
        /// <summary>
        /// Gets possible encounters that allow all moves requested to be learned.
        /// </summary>
        /// <param name="pk">Rough Pokémon data which contains the requested species, gender, and form.</param>
        /// <param name="moves">Moves that the resulting <see cref="IEncounterable"/> must be able to learn.</param>
        /// <param name="version">Specific version to iterate for.</param>
        /// <returns>A consumable <see cref="IEncounterable"/> list of possible encounters.</returns>
        public static IEnumerable <IEncounterable> GenerateVersionEncounters(PKM pk, IEnumerable <int> moves, GameVersion version)
        {
            if (pk.Species == 0) // can enter this method after failing to set a species ID that cannot exist in the format
            {
                return(Array.Empty <IEncounterable>());
            }
            pk.Version = (int)version;
            var format = pk.Format;

            if (format is 2 && version is GameVersion.RD or GameVersion.GN or GameVersion.BU or GameVersion.YW)
            {
                format = 1; // try excluding baby pokemon from our evolution chain, for move learning purposes.
            }
            var et    = EvolutionTree.GetEvolutionTree(pk, format);
            var chain = et.GetValidPreEvolutions(pk, maxLevel: 100, skipChecks: true);

            int[] needs = GetNeededMoves(pk, moves, chain);

            return(PriorityList.SelectMany(type => GetPossibleOfType(pk, needs, version, type, chain)));
        }
Example #15
0
File: Core.cs Project: LLNet/PKHeX
        public static int GetLowestLevel(PKM pkm, int startLevel)
        {
            if (startLevel == -1)
            {
                startLevel = 100;
            }

            var table = EvolutionTree.GetEvolutionTree(pkm.Format);
            int count = 1;

            for (int i = 100; i >= startLevel; i--)
            {
                var evos = table.GetValidPreEvolutions(pkm, maxLevel: i, minLevel: startLevel, skipChecks: true);
                if (evos.Count < count) // lost an evolution, prior level was minimum current level
                {
                    return(evos.Max(evo => evo.Level) + 1);
                }
                count = evos.Count;
            }
            return(startLevel);
        }
Example #16
0
        internal static List <EvoCriteria> GetValidPreEvolutions(PKM pkm, int maxspeciesorigin = -1, int lvl = -1, bool skipChecks = false)
        {
            if (lvl < 0)
            {
                lvl = pkm.CurrentLevel;
            }
            if (pkm.IsEgg && !skipChecks)
            {
                return new List <EvoCriteria>
                       {
                           new EvoCriteria {
                               Species = pkm.Species, Level = lvl, MinLevel = lvl
                           },
                       }
            }
            ;
            if (pkm.Species == 292 && lvl >= 20 && (!pkm.HasOriginalMetLocation || pkm.Met_Level + 1 <= lvl))
            {
                return new List <EvoCriteria>
                       {
                           new EvoCriteria {
                               Species = 292, Level = lvl, MinLevel = 20
                           },
                           new EvoCriteria {
                               Species = 290, Level = pkm.GenNumber < 5 ? lvl : lvl - 1, MinLevel = 1
                           }
                           // Shedinja spawns after evolving, which is after level up moves were prompted. Not for future generations.
                       }
            }
            ;
            if (maxspeciesorigin == -1 && pkm.InhabitedGeneration(2) && pkm.Format <= 2 && pkm.GenNumber == 1)
            {
                maxspeciesorigin = MaxSpeciesID_2;
            }

            int tree = maxspeciesorigin == MaxSpeciesID_2 ? 2 : pkm.Format;
            var et   = EvolutionTree.GetEvolutionTree(tree);

            return(et.GetValidPreEvolutions(pkm, maxLevel: lvl, maxSpeciesOrigin: maxspeciesorigin, skipChecks: skipChecks));
        }
Example #17
0
        internal static List <EvoCriteria> GetValidPreEvolutions(PKM pkm, int maxspeciesorigin = -1, int lvl = -1, int minLevel = 1, bool skipChecks = false)
        {
            if (lvl < 0)
            {
                lvl = pkm.CurrentLevel;
            }
            if (pkm.IsEgg && !skipChecks)
            {
                return(new List <EvoCriteria>(1)
                {
                    new EvoCriteria {
                        Species = pkm.Species, Level = lvl, MinLevel = lvl
                    },
                });
            }

            if (pkm.Species == 292 && lvl >= 20 && (!pkm.HasOriginalMetLocation || pkm.Met_Level + 1 <= lvl))
            {
                return(new List <EvoCriteria>(2)
                {
                    new EvoCriteria {
                        Species = 292, Level = lvl, MinLevel = 20
                    },
                    new EvoCriteria {
                        Species = 290, Level = lvl, MinLevel = 1
                    }
                });
            }

            if (maxspeciesorigin == -1 && pkm.InhabitedGeneration(2) && pkm.Format <= 2 && pkm.GenNumber == 1)
            {
                maxspeciesorigin = MaxSpeciesID_2;
            }

            int tree = maxspeciesorigin == MaxSpeciesID_2 ? 2 : pkm.Format;
            var et   = EvolutionTree.GetEvolutionTree(pkm, tree);

            return(et.GetValidPreEvolutions(pkm, maxLevel: lvl, maxSpeciesOrigin: maxspeciesorigin, skipChecks: skipChecks, minLevel: minLevel));
        }