public static IEnumerable <EncounterEgg> GenerateEggs(PKM pkm, IReadOnlyList <EvoCriteria> chain, bool all = false)
        {
            int species = pkm.Species;

            if (NoHatchFromEgg.Contains(species))
            {
                yield break;
            }

            int gen = pkm.GenNumber;

            if (gen <= 1)
            {
                yield break; // can't get eggs
            }
            if (NoHatchFromEggForm(species, pkm.AltForm, gen))
            {
                yield break; // can't originate from eggs
            }
            // version is a true indicator for all generation 3-5 origins
            var ver = (GameVersion)pkm.Version;
            int lvl = gen <= 3 ? 5 : 1;
            int max = GetMaxSpeciesOrigin(gen);

            var e = EvoBase.GetBaseSpecies(chain, 0);

            if (e.Species <= max && !NoHatchFromEggFormGen(e.Species, e.Form, ver))
            {
                yield return(new EncounterEgg(e.Species, e.Form, lvl, gen, ver));

                if (gen > 5 && (pkm.WasTradedEgg || all) && HasOtherGamePair(ver))
                {
                    yield return(new EncounterEgg(e.Species, e.Form, lvl, gen, GetOtherTradePair(ver)));
                }
            }

            if (!GetSplitBreedGeneration(gen).Contains(species))
            {
                yield break; // no other possible species
            }
            var o = EvoBase.GetBaseSpecies(chain, 1);

            if (o.Species == e.Species)
            {
                yield break;
            }

            if (o.Species <= max && !NoHatchFromEggFormGen(o.Species, o.Form, ver))
            {
                yield return(new EncounterEggSplit(o.Species, o.Form, lvl, gen, ver, e.Species));

                if (gen > 5 && (pkm.WasTradedEgg || all) && HasOtherGamePair(ver))
                {
                    yield return(new EncounterEggSplit(o.Species, o.Form, lvl, gen, GetOtherTradePair(ver), e.Species));
                }
            }
        }
예제 #2
0
        public static IEnumerable <EncounterEgg> GenerateEggs(PKM pkm, IReadOnlyList <EvoCriteria> chain, int generation, bool all = false)
        {
            System.Diagnostics.Debug.Assert(generation >= 3); // if generating Gen2 eggs, use the other generator.
            int species = pkm.Species;

            if (!Breeding.CanHatchAsEgg(species))
            {
                yield break;
            }
            if (!Breeding.CanHatchAsEgg(species, pkm.Form, generation))
            {
                yield break; // can't originate from eggs
            }
            // version is a true indicator for all generation 3-5 origins
            var ver = (GameVersion)pkm.Version;

            if (!Breeding.CanGameGenerateEggs(ver))
            {
                yield break;
            }

            int lvl = generation <= 3 ? 5 : 1;
            int max = GetMaxSpeciesOrigin(generation);

            var e = EvoBase.GetBaseSpecies(chain, 0);

            if (e.Species <= max && Breeding.CanHatchAsEgg(e.Species, e.Form, ver))
            {
                yield return(new EncounterEgg(e.Species, e.Form, lvl, generation, ver));

                if (generation > 5 && (pkm.WasTradedEgg || all) && HasOtherGamePair(ver))
                {
                    yield return(new EncounterEgg(e.Species, e.Form, lvl, generation, GetOtherTradePair(ver)));
                }
            }

            if (!Breeding.GetSplitBreedGeneration(generation).Contains(species))
            {
                yield break; // no other possible species
            }
            var o = EvoBase.GetBaseSpecies(chain, 1);

            if (o.Species == e.Species)
            {
                yield break;
            }

            if (o.Species <= max && Breeding.CanHatchAsEgg(o.Species, o.Form, ver))
            {
                yield return(new EncounterEgg(o.Species, o.Form, lvl, generation, ver));

                if (generation > 5 && (pkm.WasTradedEgg || all) && HasOtherGamePair(ver))
                {
                    yield return(new EncounterEgg(o.Species, o.Form, lvl, generation, GetOtherTradePair(ver)));
                }
            }
        }
예제 #3
0
        private static IEnumerable <IEncounterable> GetEncounters12(PKM pkm, LegalInfo info)
        {
            int baseSpecies = EvoBase.GetBaseSpecies(pkm).Species;

            if ((pkm.Format == 1 && baseSpecies > MaxSpeciesID_1) || baseSpecies > MaxSpeciesID_2)
            {
                yield break;
            }

            foreach (var z in GenerateFilteredEncounters12(pkm))
            {
                info.Generation = z.Generation;
                info.Game       = z.Version;
                yield return(z);
            }
        }
예제 #4
0
        private static bool IsEvolutionValid(PKM pkm, int minSpecies = -1, int minLevel = -1)
        {
            var curr = EvolutionChain.GetValidPreEvolutions(pkm, minLevel: minLevel);
            var min  = curr.FindLast(z => z.Species == minSpecies);

            if (min != null && min.Level < minLevel)
            {
                return(false);
            }
            var poss = EvolutionChain.GetValidPreEvolutions(pkm, maxLevel: 100, minLevel: minLevel, skipChecks: true);

            if (minSpecies != -1)
            {
                int last = poss.FindLastIndex(z => z.Species == minSpecies);
                return(curr.Count >= last);
            }
            int gen = pkm.GenNumber;

            if (gen >= 3 && GetSplitBreedGeneration(gen).Contains(EvoBase.GetBaseSpecies(poss, 1).Species))
            {
                return(curr.Count >= poss.Count - 1);
            }
            return(curr.Count >= poss.Count);
        }
예제 #5
0
        private static IEnumerable <IEncounterable> GenerateRawEncounters12(PKM pkm, GameVersion game)
        {
            bool gsc = GameVersion.GSC.Contains(game);

            // Since encounter matching is super weak due to limited stored data in the structure
            // Calculate all 3 at the same time and pick the best result (by species).
            // Favor special event move gifts as Static Encounters when applicable
            var maxspeciesorigin = gsc ? MaxSpeciesID_2 : MaxSpeciesID_1;
            var vs = EvolutionChain.GetValidPreEvolutions(pkm, maxspeciesorigin: maxspeciesorigin);

            var deferred = new List <IEncounterable>();

            foreach (var t in GetValidEncounterTrades(pkm, vs, game))
            {
                // some OTs are longer than the keyboard entry; don't defer these
                if (pkm.Format >= 7 && pkm.OT_Name.Length <= (pkm.Japanese || pkm.Korean ? 5 : 7))
                {
                    deferred.Add(t);
                    continue;
                }
                yield return(t);
            }
            foreach (var s in GetValidStaticEncounter(pkm, vs, game))
            {
                // Valid stadium and non-stadium encounters, return only non-stadium encounters, they are less restrictive
                switch (s.Version)
                {
                case GameVersion.Stadium:
                case GameVersion.Stadium2:
                    deferred.Add(s);
                    continue;

                case GameVersion.EventsGBGen2:
                    if (!s.EggEncounter && !pkm.HasOriginalMetLocation)
                    {
                        continue;
                    }
                    if (pkm.Japanese)
                    {
                        deferred.Add(s);
                    }
                    continue;

                case GameVersion.C when gsc && pkm.Format == 2:     // Crystal specific data needs to be present
                    if (!s.EggEncounter && !pkm.HasOriginalMetLocation)
                    {
                        continue;
                    }
                    if (s.Species == 251 && ParseSettings.AllowGBCartEra)     // no celebi, the GameVersion.EventsGBGen2 will pass thru
                    {
                        continue;
                    }
                    break;
                }
                yield return(s);
            }
            foreach (var e in GetValidWildEncounters12(pkm, vs, game))
            {
                yield return(e);
            }

            if (gsc)
            {
                var canBeEgg = GetCanBeEgg(pkm);
                if (canBeEgg)
                {
                    int species = EvoBase.GetBaseSpecies(pkm, generation: pkm.Format == 1 ? 2 : -1, maxSpeciesOrigin: MaxSpeciesID_2).Species;
                    if (ParseSettings.AllowGen2Crystal(pkm))
                    {
                        yield return(new EncounterEgg(species, 0, 5, 2, GameVersion.C)); // gen2 egg
                    }
                    yield return(new EncounterEgg(species, 0, 5, 2, GameVersion.GS));    // gen2 egg
                }
            }

            foreach (var d in deferred)
            {
                yield return(d);
            }
        }