From 54611032c97e1a6d267409f53eebf73007d73fc8 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 23 May 2021 12:50:42 -0700 Subject: [PATCH] Refine crystal egg checks Disallow crystal eggs if met data is not present Set crystal met location more fluidly --- .../Encounters/EncounterMisc/EncounterEgg.cs | 19 +++++++++++---- .../Specific/EncounterEggGenerator2.cs | 23 ++++++++++++++++++- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/PKHeX.Core/Legality/Encounters/EncounterMisc/EncounterEgg.cs b/PKHeX.Core/Legality/Encounters/EncounterMisc/EncounterEgg.cs index 19d753202..a45bea201 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterMisc/EncounterEgg.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterMisc/EncounterEgg.cs @@ -39,9 +39,10 @@ public PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria) sav.ApplyTo(pk); + int lang = (int)Language.GetSafeLanguage(Generation, (LanguageID)sav.Language, version); pk.Species = Species; pk.Form = Form; - pk.Nickname = SpeciesName.GetSpeciesNameGeneration(Species, sav.Language, gen); + pk.Nickname = SpeciesName.GetSpeciesNameGeneration(Species, lang, gen); pk.CurrentLevel = Level; pk.Version = (int)version; pk.Ball = (int)Ball.Poke; @@ -51,14 +52,22 @@ public PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria) pk.HealPP(); SetPINGA(pk, criteria); - if (gen <= 2 && version != GameVersion.C) + if (gen <= 2) + { + if (version != GameVersion.C) + { + pk.OT_Gender = 0; + } + else + { + pk.Met_Location = Locations.HatchLocationC; + pk.Met_Level = 1; + } return pk; + } SetMetData(pk); - if (gen < 3) - return pk; - if (gen >= 4) pk.SetEggMetData(version, (GameVersion)sav.Game); diff --git a/PKHeX.Core/Legality/Encounters/Generator/Specific/EncounterEggGenerator2.cs b/PKHeX.Core/Legality/Encounters/Generator/Specific/EncounterEggGenerator2.cs index 8c718c836..155153e2c 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Specific/EncounterEggGenerator2.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Specific/EncounterEggGenerator2.cs @@ -37,11 +37,32 @@ public static IEnumerable GenerateEggs(PKM pkm, IReadOnlyList Legal.MaxSpeciesID_2) yield break; - if (ParseSettings.AllowGen2Crystal(pkm)) + if (GetCanBeCrystalEgg(pkm, species, all)) yield return new EncounterEgg(species, 0, 5, 2, GameVersion.C); // gen2 egg yield return new EncounterEgg(species, 0, 5, 2, GameVersion.GS); // gen2 egg } + private static bool GetCanBeCrystalEgg(PKM pkm, int species, bool all) + { + if (!ParseSettings.AllowGen2Crystal(pkm)) + return false; + + if (all) + return true; + + // Check if the met data is present or could have been erased. + if (pkm.Format > 2) + return true; // doesn't have original met location + if (pkm.Met_Location != 0) + return true; // has original met location + if (species < Legal.MaxSpeciesID_1) + return true; // can trade RBY to wipe location + if (pkm.Species < Legal.MaxSpeciesID_1) + return true; // can trade RBY to wipe location + + return false; + } + private static bool GetCanBeEgg(PKM pkm) { bool canBeEgg = !pkm.Gen1_NotTradeback && GetCanBeEgg2(pkm);