From 32fdcf4c10d0f7beee9397062a8dfad31ae1bee8 Mon Sep 17 00:00:00 2001 From: Kurt Date: Mon, 3 Apr 2017 20:43:13 -0700 Subject: [PATCH] Minor tweak no functional change, just split up the filtering from the initial static fetch --- PKHeX/Legality/Core.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/PKHeX/Legality/Core.cs b/PKHeX/Legality/Core.cs index e14840692..903bc5150 100644 --- a/PKHeX/Legality/Core.cs +++ b/PKHeX/Legality/Core.cs @@ -899,7 +899,6 @@ internal static List getValidStaticEncounter(PKM pkm, GameVersi if (gameSource == GameVersion.Any) gameSource = (GameVersion)pkm.Version; - var enc = new List(); // Get possible encounters IEnumerable poss = getStaticEncounters(pkm, gameSource: gameSource); @@ -907,13 +906,18 @@ internal static List getValidStaticEncounter(PKM pkm, GameVersi if (lvl <= 0) return null; // Back Check against pkm + var enc = getMatchingStaticEncounters(pkm, poss, lvl).ToList(); + return enc.Any() ? enc : null; + } + private static IEnumerable getMatchingStaticEncounters(PKM pkm, IEnumerable poss, int lvl) + { foreach (EncounterStatic e in poss) { if (e.Nature != Nature.Random && pkm.Nature != (int)e.Nature) continue; - if(pkm.Gen3 && e.EggLocation != 0) - { - //Hartched gen 3 gift egg can not be differentiated form normal eggs + if (pkm.Gen3 && e.EggLocation != 0) + { + // Hatched gen 3 gift egg can not be differentiated from normal eggs if (!pkm.IsEgg || pkm.Format > 3) continue; if (e.EggLocation != pkm.Met_Location) @@ -946,9 +950,8 @@ internal static List getValidStaticEncounter(PKM pkm, GameVersi if (!AllowGBCartEra && GameVersion.GBCartEraOnly.Contains(e.Version)) continue; // disallow gb cart era encounters (as they aren't obtainable by Main/VC series) - enc.Add(e); + yield return e; } - return enc.Any() ? enc : null; } internal static EncounterTrade getValidIngameTrade(PKM pkm, GameVersion gameSource = GameVersion.Any) {