コード例 #1
0
        private static IEnumerable <IEncounterable> GenerateRawEncounters3CXD(PKM pkm)
        {
            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?partial = null;

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

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

            if (partial is not null)
            {
                yield return(partial);
            }
        }
コード例 #2
0
ファイル: EncounterGenerator8.cs プロジェクト: wowjinxy/PKHeX
        public static IEnumerable <IEncounterable> GetEncounters(PKM pkm)
        {
            var chain = EncounterOrigin.GetOriginChain(pkm);

            return(pkm.Version switch
            {
                (int)GameVersion.GO => EncounterGenerator7.GetEncountersGO(pkm, chain),
                _ => GetEncountersMainline(pkm, chain)
            });
コード例 #3
0
        private static IEnumerable <IEncounterable> GenerateRawEncounters(PKM pkm)
        {
            int ctr = 0;

            var chain = EncounterOrigin.GetOriginChain(pkm);

            if (pkm.WasEvent || pkm.WasEventEgg || pkm.WasLink)
            {
                foreach (var z in GetValidGifts(pkm, chain))
                {
                    yield return(z); ++ctr;
                }
                if (ctr != 0)
                {
                    yield break;
                }
            }

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

            foreach (var z in GetValidStaticEncounter(pkm, chain))
            {
                yield return(z); ++ctr;
            }
            if (ctr != 0)
            {
                yield break;
            }

            foreach (var z in GetValidWildEncounters(pkm, chain))
            {
                yield return(z); ++ctr;
            }
            if (ctr != 0)
            {
                yield break;
            }

            foreach (var z in GetValidEncounterTrades(pkm, chain))
            {
                yield return(z); ++ctr;
            }
        }
コード例 #4
0
        private static IEnumerable <IEncounterable> GenerateRawEncounters8(PKM pkm)
        {
            // Static Encounters can collide with wild encounters (close match); don't break if a Static Encounter is yielded.
            int ctr = 0;

            var chain = EncounterOrigin.GetOriginChain(pkm);

            if (pkm.WasEvent || pkm.WasEventEgg)
            {
                foreach (var z in GetValidGifts(pkm, chain))
                {
                    yield return(z); ++ctr;
                }
                if (ctr != 0)
                {
                    yield break;
                }
            }

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

            foreach (var z in GetValidStaticEncounter(pkm, chain))
            {
                yield return(z); ++ctr;
            }
            // if (ctr != 0) yield break;
            foreach (var z in GetValidWildEncounters(pkm, chain))
            {
                yield return(z); ++ctr;
            }

            if (ctr != 0)
            {
                yield break;
            }
            foreach (var z in GetValidEncounterTrades(pkm, chain))
            {
                yield return(z); ++ctr;
            }
        }
コード例 #5
0
        public static IEnumerable <IEncounterable> GetEncounters(PKM pkm)
        {
            int ctr = 0;

            var chain = EncounterOrigin.GetOriginChain(pkm);

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

            if (pkm.WasEvent || pkm.WasEventEgg || pkm.WasLink)
            {
                foreach (var z in GetValidGifts(pkm, chain))
                {
                    var match = z.GetMatchRating(pkm);
                    switch (match)
                    {
                    case Match: yield return(z); break;

                    case Deferred: deferred ??= z; break;

                    case PartialMatch: partial ??= z; break;
                    }
                    ++ctr;
                }

                if (ctr != 0)
                {
                    if (deferred != null)
                    {
                        yield return(deferred);
                    }

                    if (partial != null)
                    {
                        yield return(partial);
                    }

                    yield break;
                }
            }

            if (pkm.WasBredEgg)
            {
                foreach (var z in GenerateEggs(pkm, 6))
                {
                    yield return(z); ++ctr;
                }
                if (ctr == 0)
                {
                    yield break;
                }
            }

            foreach (var z in GetValidStaticEncounter(pkm, chain))
            {
                var match = z.GetMatchRating(pkm);
                switch (match)
                {
                case Match: yield return(z); ++ctr; break;

                case Deferred: deferred ??= z; break;

                case PartialMatch: partial ??= z; break;
                }
            }
            if (ctr != 0)
            {
                yield break;
            }

            foreach (var z in GetValidWildEncounters(pkm, chain))
            {
                var match = z.GetMatchRating(pkm);
                switch (match)
                {
                case Match: yield return(z); ++ctr; break;

                case Deferred: deferred ??= z; break;

                case PartialMatch: partial ??= z; break;
                }
            }
            if (ctr != 0)
            {
                yield break;
            }

            foreach (var z in GetValidEncounterTrades(pkm, chain))
            {
                var match = z.GetMatchRating(pkm);
                switch (match)
                {
                case Match: yield return(z); /*++ctr*/ break;

                case Deferred: deferred ??= z; break;

                case PartialMatch: partial ??= z; break;
                }
            }

            if (deferred != null)
            {
                yield return(deferred);
            }

            if (partial != null)
            {
                yield return(partial);
            }
        }
コード例 #6
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);
            }
        }
コード例 #7
0
ファイル: EncounterGenerator5.cs プロジェクト: zekroman/PKHeX
        public static IEnumerable <IEncounterable> GetEncounters(PKM pkm)
        {
            int ctr = 0;

            var chain = EncounterOrigin.GetOriginChain(pkm);

            if (pkm.FatefulEncounter)
            {
                foreach (var z in GetValidGifts(pkm, chain))
                {
                    yield return(z); ++ctr;
                }
                if (ctr != 0)
                {
                    yield break;
                }
            }

            if (Locations.IsEggLocationBred5(pkm.Egg_Location))
            {
                foreach (var z in GenerateEggs(pkm, 5))
                {
                    yield return(z); ++ctr;
                }
                if (ctr == 0)
                {
                    yield break;
                }
            }

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

            foreach (var z in GetValidStaticEncounter(pkm, chain))
            {
                var match = z.GetMatchRating(pkm);
                switch (match)
                {
                case Match: yield return(z); ++ctr; break;

                case Deferred: deferred ??= z; break;

                case PartialMatch: partial ??= z; break;
                }
            }
            if (ctr != 0)
            {
                yield break;
            }

            foreach (var z in GetValidWildEncounters(pkm, chain))
            {
                var match = z.GetMatchRating(pkm);
                switch (match)
                {
                case Match: yield return(z); ++ctr; break;

                case Deferred: deferred ??= z; break;

                case PartialMatch: partial ??= z; break;
                }
            }
            if (ctr != 0)
            {
                yield break;
            }

            foreach (var z in GetValidEncounterTrades(pkm, chain))
            {
                var match = z.GetMatchRating(pkm);
                switch (match)
                {
                case Match: yield return(z); /*++ctr*/ break;

                case Deferred: deferred ??= z; break;

                case PartialMatch: partial ??= z; break;
                }
            }

            if (deferred != null)
            {
                yield return(deferred);
            }

            if (partial != null)
            {
                yield return(partial);
            }
        }
コード例 #8
0
        private static IEnumerable <IEncounterable> GenerateRawEncounters3(PKM pkm, LegalInfo info)
        {
            var chain = EncounterOrigin.GetOriginChain(pkm);

            foreach (var z in GetValidGifts(pkm, chain))
            {
                yield return(z);
            }
            foreach (var z in GetValidEncounterTrades(pkm, chain))
            {
                yield return(z);
            }

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

            if (!safari)
            {
                foreach (var z in GetValidStaticEncounter(pkm, chain))
                {
                    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, chain))
            {
                bool defer = z.IsDeferred3(species, pkm, safari);
                var  frame = slots.Find(s => s.IsSlotCompatibile((EncounterSlot3)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)
            {
                yield break;
            }
            foreach (var z in GetValidStaticEncounter(pkm, chain))
            {
                yield return(z);
            }
        }
コード例 #9
0
        private static IEnumerable <IEncounterable> GenerateRawEncounters4(PKM pkm, LegalInfo info)
        {
            bool wasEvent = pkm.WasEvent || pkm.WasEventEgg; // egg events?
            var  chain    = EncounterOrigin.GetOriginChain(pkm);

            if (wasEvent)
            {
                int ctr = 0;
                foreach (var z in GetValidGifts(pkm, chain))
                {
                    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, chain))
            {
                yield return(z);
            }

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

            if (!safariSport)
            {
                foreach (var z in GetValidStaticEncounter(pkm, chain))
                {
                    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, chain))
            {
                bool defer = z.IsDeferred4(species, pkm, safari, sport);
                var  frame = slots.Find(s => s.IsSlotCompatibile((EncounterSlot4)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)
            {
                yield break;
            }
            foreach (var z in GetValidStaticEncounter(pkm, chain))
            {
                yield return(z);
            }
        }