예제 #1
0
        private static IEnumerable <IEncounterable> GenerateRawEncounters3(PKM pkm, LegalInfo info)
        {
            foreach (var z in GetValidGifts(pkm))
            {
                yield return(z);
            }
            foreach (var z in GetValidEncounterTrades(pkm))
            {
                yield return(z);
            }

            var  deferIncompat = new Queue <IEncounterable>();
            bool safari        = pkm.Ball == 0x05; // never static encounters

            if (!safari)
            {
                foreach (var z in GetValidStaticEncounter(pkm))
                {
                    if (z.Gift && pkm.Ball != 4)
                    {
                        deferIncompat.Enqueue(z);
                    }
                    else
                    {
                        yield return(z);
                    }
                }
            }

            int species      = pkm.Species;
            var deferNoFrame = new Queue <IEncounterable>();
            var deferFrame   = new Queue <IEncounterable>();

            pkm.WasEgg = false; // clear flag if set from static
            var slots = FrameFinder.GetFrames(info.PIDIV, pkm).ToList();

            foreach (var z in GetValidWildEncounters34(pkm))
            {
                bool defer = z.IsDeferred3(species, pkm, safari);
                var  frame = slots.Find(s => s.IsSlotCompatibile(z, pkm));
                if (defer)
                {
                    if (frame != null)
                    {
                        deferFrame.Enqueue(z);
                    }
                    else
                    {
                        deferIncompat.Enqueue(z);
                    }
                    continue;
                }
                if (frame == null)
                {
                    deferNoFrame.Enqueue(z);
                    continue;
                }
                yield return(z);
            }
            info.FrameMatches = false;
            foreach (var z in deferNoFrame)
            {
                yield return(z);
            }
            info.FrameMatches = true;
            foreach (var z in deferFrame)
            {
                yield return(z);
            }
            info.FrameMatches = false;

            if (pkm.Version != 15) // no eggs in C/XD
            {
                foreach (var z in GenerateEggs(pkm))
                {
                    yield return(z);
                }
            }

            foreach (var z in deferIncompat)
            {
                yield return(z);
            }
            // do static encounters if they were deferred to end, spit out any possible encounters for invalid pkm
            if (safari)
            {
                foreach (var z in GetValidStaticEncounter(pkm))
                {
                    yield return(z);
                }
            }
        }
예제 #2
0
        private static IEnumerable <IEncounterable> GenerateRawEncounters3(PKM pkm, LegalInfo info)
        {
            var chain = EncounterOrigin.GetOriginChain(pkm);

            // Mystery Gifts
            foreach (var z in GetValidGifts(pkm, chain))
            {
                // Don't bother deferring matches.
                var match = z.GetMatchRating(pkm);
                if (match != PartialMatch)
                {
                    yield return(z);
                }
            }

            // Trades
            foreach (var z in GetValidEncounterTrades(pkm, chain))
            {
                // Don't bother deferring matches.
                var match = z.GetMatchRating(pkm);
                if (match != PartialMatch)
                {
                    yield return(z);
                }
            }

            IEncounterable?deferred = null;
            IEncounterable?partial  = null;

            // Static Encounter
            // Defer everything if Safari Ball
            bool safari = pkm.Ball == 0x05; // never static encounters

            if (!safari)
            {
                foreach (var z in GetValidStaticEncounter(pkm, chain))
                {
                    var match = z.GetMatchRating(pkm);
                    if (match == PartialMatch)
                    {
                        partial ??= z;
                    }
                    else
                    {
                        yield return(z);
                    }
                }
            }

            // Encounter Slots
            var slots = FrameFinder.GetFrames(info.PIDIV, pkm).ToList();

            foreach (var z in GetValidWildEncounters(pkm, chain))
            {
                var match = z.GetMatchRating(pkm);
                if (match == PartialMatch)
                {
                    partial ??= z;
                    continue;
                }

                var frame = slots.Find(s => s.IsSlotCompatibile((EncounterSlot3)z, pkm));
                if (frame == null)
                {
                    deferred ??= z;
                    continue;
                }
                yield return(z);
            }

            info.FrameMatches = false;
            if (deferred is EncounterSlot3 x)
            {
                yield return(x);
            }

            if (pkm.Version != (int)GameVersion.CXD) // no eggs in C/XD
            {
                foreach (var z in GenerateEggs(pkm, 3))
                {
                    yield return(z);
                }
            }

            if (partial is EncounterSlot3 y)
            {
                var frame = slots.Find(s => s.IsSlotCompatibile(y, pkm));
                info.FrameMatches = frame != null;
                yield return(y);
            }

            // do static encounters if they were deferred to end, spit out any possible encounters for invalid pkm
            if (!safari)
            {
                yield break;
            }

            partial = null;

            foreach (var z in GetValidStaticEncounter(pkm, chain))
            {
                var match = z.GetMatchRating(pkm);
                if (match == PartialMatch)
                {
                    partial ??= z;
                }
                else
                {
                    yield return(z);
                }
            }

            if (partial is not null)
            {
                yield return(partial);
            }
        }
예제 #3
0
        private static IEnumerable <IEncounterable> GenerateRawEncounters4(PKM pkm, LegalInfo info)
        {
            bool wasEvent = pkm.WasEvent || pkm.WasEventEgg; // egg events?

            if (wasEvent)
            {
                int ctr = 0;
                foreach (var z in GetValidGifts(pkm))
                {
                    yield return(z); ++ctr;
                }
                if (ctr != 0)
                {
                    yield break;
                }
            }
            if (pkm.WasBredEgg)
            {
                foreach (var z in GenerateEggs(pkm))
                {
                    yield return(z);
                }
            }
            foreach (var z in GetValidEncounterTrades(pkm))
            {
                yield return(z);
            }

            var  deferIncompat = new Queue <IEncounterable>();
            bool sport         = pkm.Ball == 0x18; // never static encounters (conflict with non bcc / bcc)
            bool safari        = pkm.Ball == 0x05; // never static encounters
            bool safariSport   = safari || sport;

            if (!safariSport)
            {
                foreach (var z in GetValidStaticEncounter(pkm))
                {
                    if (z.Gift && pkm.Ball != 4)
                    {
                        deferIncompat.Enqueue(z);
                    }
                    else
                    {
                        yield return(z);
                    }
                }
            }

            int species      = pkm.Species;
            var deferNoFrame = new Queue <IEncounterable>();
            var deferFrame   = new Queue <IEncounterable>();
            var slots        = FrameFinder.GetFrames(info.PIDIV, pkm).ToList();

            foreach (var z in GetValidWildEncounters34(pkm))
            {
                bool defer = z.IsDeferred4(species, pkm, safari, sport);
                var  frame = slots.Find(s => s.IsSlotCompatibile(z, pkm));
                if (defer)
                {
                    if (frame != null)
                    {
                        deferFrame.Enqueue(z);
                    }
                    else
                    {
                        deferIncompat.Enqueue(z);
                    }
                    continue;
                }
                if (frame == null)
                {
                    deferNoFrame.Enqueue(z);
                    continue;
                }
                yield return(z);
            }
            info.FrameMatches = false;
            foreach (var z in deferNoFrame)
            {
                yield return(z);
            }
            info.FrameMatches = true;
            foreach (var z in deferFrame)
            {
                yield return(z);
            }
            info.FrameMatches = false;

            foreach (var z in deferIncompat)
            {
                yield return(z);
            }

            // do static encounters if they were deferred to end, spit out any possible encounters for invalid pkm
            if (safariSport)
            {
                foreach (var z in GetValidStaticEncounter(pkm))
                {
                    yield return(z);
                }
            }
        }