diff --git a/PKHeX/Legality/Core.cs b/PKHeX/Legality/Core.cs index 41b87e527..a09cf4cb0 100644 --- a/PKHeX/Legality/Core.cs +++ b/PKHeX/Legality/Core.cs @@ -294,6 +294,11 @@ internal static EncounterStatic getValidStaticEncounter(PKM pkm) if (e.Level != pkm.Met_Level) continue; } + else + { + if (e.Level > pkm.Met_Level) + continue; + } if (e.Gender != -1 && e.Gender != pkm.Gender) continue; if (e.Form != pkm.AltForm && !FormChange.Contains(pkm.Species) && !e.SkipFormCheck) @@ -350,7 +355,9 @@ internal static EncounterTrade getValidIngameTrade(PKM pkm) return null; if (pkm.HasOriginalMetLocation && z.Location != pkm.Met_Location) return null; - if (z.Level != pkm.Met_Level) + if (pkm.HasOriginalMetLocation && z.Level != pkm.Met_Level) + return null; + if (!pkm.HasOriginalMetLocation && z.Level > pkm.Met_Level) return null; if (z.Nature != Nature.Random && (int)z.Nature != pkm.Nature) return null; @@ -421,7 +428,7 @@ internal static int getMaxSpeciesOrigin(int generation) default: return -1; } } - + internal static int[] getFutureGenEvolutions(int generation) { switch (generation) @@ -1016,14 +1023,31 @@ private static IEnumerable getValidEncounterSlots(PKM pkm, Encoun bool ignoreSlotLevel = ignoreLevel; IEnumerable slots = loc.Slots.Where(slot => vs.Any(evo => evo.Species == slot.Species && (ignoreSlotLevel || evo.Level >= slot.LevelMin - df))); - if (pkm.Format < 3 || pkm.VC) - return slots; // no met level or special encounter considerations - // Filter for Met Level - int lvl = pkm.Met_Level; + int lvl = (pkm.Format < 3) ? pkm.CurrentLevel : pkm.Met_Level; int gen = pkm.GenNumber; - bool ignoreMetLevel = ignoreLevel || gen <= 4 && pkm.Format != gen; - var encounterSlots = slots.Where(slot => ignoreMetLevel || slot.LevelMin - df <= lvl && lvl <= slot.LevelMax + (slot.AllowDexNav ? dn : df)).ToList(); + IEnumerable encounterSlots; + if(pkm.HasOriginalMetLocation) + encounterSlots = slots.Where(slot => ignoreLevel || slot.LevelMin - df <= lvl && lvl <= slot.LevelMax + (slot.AllowDexNav ? dn : df)).ToList(); + else + { + //See comments in getEvolutionChainsAllGens for more info in this sentence + if (gen == 3 && pkm.Format > 4 && lvl == pkm.CurrentLevel && FutureEvolutionsGen3_LevelUp.Contains(pkm.Species)) + lvl--; + //Those encounters with level min greater that met level are not valid for this pokemon + encounterSlots = slots.Where(slot => ignoreLevel || slot.LevelMin <= lvl).ToList(); + } + + if(gen <= 2) + { + //For gen 1 and 2 return minimun level slot + //Minimun level is needed to check available moves, because there is no move reminder in gen 1, + //There are moves in the level up table that cant be legally obtained + EncounterSlot slotMin = encounterSlots.OrderBy(slot => slot.LevelMin).FirstOrDefault(); + if (slotMin != null) + slotdata.Add(slotMin); + return slotdata; + } // Pressure Slot EncounterSlot slotMax = encounterSlots.OrderByDescending(slot => slot.LevelMax).FirstOrDefault(); @@ -1036,7 +1060,7 @@ private static IEnumerable getValidEncounterSlots(PKM pkm, Encoun slotdata.Add(slotMax); return slotdata; } - if (!DexNav) + if (gen == 6 || !DexNav) { // Filter for Form Specific slotdata.AddRange(WildForms.Contains(pkm.Species) @@ -1048,6 +1072,11 @@ private static IEnumerable getValidEncounterSlots(PKM pkm, Encoun } List eslots = encounterSlots.Where(slot => !WildForms.Contains(pkm.Species) || slot.Form == pkm.AltForm).ToList(); + if(gen <=4) + { + slotdata.AddRange(eslots); + return slotdata; + } if (slotMax != null) eslots.Add(slotMax); foreach (EncounterSlot s in eslots) @@ -1092,7 +1121,7 @@ private static IEnumerable getValidPreEvolutions(PKM pkm, int lvl = -1 return new List { new DexLevel { Species = 292, Level = lvl, MinLevel =20 }, - new DexLevel { Species = 290, Level = lvl - 1, MinLevel = 1 } + new DexLevel { Species = 290, Level = lvl-1, MinLevel = 1 } }; var et = getEvolutionTable(pkm); diff --git a/PKHeX/Legality/Tables3.cs b/PKHeX/Legality/Tables3.cs index 34cbb69e2..91ec69374 100644 --- a/PKHeX/Legality/Tables3.cs +++ b/PKHeX/Legality/Tables3.cs @@ -87,5 +87,12 @@ public static partial class Legal { 407,424,429,430,461,462,463,464,465,466,467,468,469,470,471,472,473,474,475,476,477,700 }; + + internal static readonly int[] FutureEvolutionsGen3_LevelUp = new int[] + { + 424, 461, 462, 463, 465, 469, 470, 471, 472, 473, 476 + }; + // Ambipom Weavile Magnezone Lickilicky Tangrowth + // Yanmega Leafeon Glaceon Mamoswine Gliscor Probopass } }