diff --git a/PKHeX.Core/Legality/Encounters/EncounterEgg.cs b/PKHeX.Core/Legality/Encounters/EncounterEgg.cs index 545f57e85..d106081a9 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterEgg.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterEgg.cs @@ -1,4 +1,6 @@ -namespace PKHeX.Core +using System; + +namespace PKHeX.Core { /// /// Egg Encounter Data @@ -15,6 +17,58 @@ public GameVersion Game; public bool SplitBreed; - public PKM ConvertToPKM(ITrainerInfo SAV) => throw new System.NotImplementedException(); + public PKM ConvertToPKM(ITrainerInfo SAV) + { + var pk = PKMConverter.GetBlank(SAV.Generation); + SAV.ApplyToPKM(pk); + + pk.Species = Species; + pk.Nickname = PKX.GetSpeciesNameGeneration(Species, pk.Language, SAV.Generation); + pk.CurrentLevel = Level; + pk.Version = (int)Game; + + var moves = Legal.GetEggMoves(pk, Species, pk.AltForm, Game); + pk.Moves = moves; + pk.SetMaximumPPCurrent(moves); + pk.SetRandomIVs(); + + if (pk.Format <= 2 && Game != GameVersion.C) + return pk; + + pk.PID = Util.Rand32(); + pk.RefreshAbility(Util.Rand.Next(2)); + pk.Ball = 4; + + pk.Met_Level = EncounterSuggestion.GetSuggestedEncounterEggMetLevel(pk); + pk.Met_Location = EncounterSuggestion.GetSuggestedEggMetLocation(pk); + + if (pk.Format < 4) + return pk; + + bool traded = (int)Game == SAV.Game; + pk.Egg_Location = EncounterSuggestion.GetSuggestedEncounterEggLocationEgg(pk, traded); + pk.EggMetDate = pk.MetDate = DateTime.Today; + + if (pk.Format < 6) + return pk; + + if (pk.Format != SAV.Generation) + { + pk.HT_Name = SAV.OT; + pk.HT_Gender = SAV.Gender; + if (SAV.Generation == 6) + { + pk.Geo1_Country = SAV.Country; + pk.Geo1_Region = SAV.SubRegion; + } + } + if (SAV.Generation == 6) + pk.SetHatchMemory6(); + + pk.SetRandomEC(); + pk.RelearnMoves = moves; + + return pk; + } } } diff --git a/Tests/PKHeX.Tests/Simulator/ShowdownSetTests.cs b/Tests/PKHeX.Tests/Simulator/ShowdownSetTests.cs index 0860edd95..a92fd84d3 100644 --- a/Tests/PKHeX.Tests/Simulator/ShowdownSetTests.cs +++ b/Tests/PKHeX.Tests/Simulator/ShowdownSetTests.cs @@ -27,7 +27,16 @@ namespace PKHeX.Tests.Simulator Assert.IsTrue(!encs.Any()); pk7.HT_Name = "PKHeX"; encs = EncounterMovesetGenerator.GenerateEncounters(pk7, set.Moves, GameVersion.MN); - Assert.IsTrue(encs.Any()); + var first = encs.FirstOrDefault(); + Assert.IsTrue(first != null); + + var egg = (EncounterEgg)first; + var info = new SimpleTrainerInfo(); + var pk = egg.ConvertToPKM(info); + Assert.IsTrue(pk.Species != set.Species); + + var la = new LegalityAnalysis(pk); + Assert.IsTrue(la.Valid); } private const string SetGlaceonUSUMTutor =