From c21f8bf45f9e4a4dc5bfd33c57ce656f0ae0115e Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 8 May 2018 20:13:55 -0700 Subject: [PATCH] More generator updates Blazing past 251, now stopped at 280 (trade ralts, gender mismatch??) --- .../Legality/Encounters/EncounterLink.cs | 6 +-- .../Legality/Encounters/EncounterSlot.cs | 7 ++- .../Generator/EncounterMovesetGenerator.cs | 43 +++++++++++++------ PKHeX.Core/Legality/RNG/PIDGenerator.cs | 11 +++-- PKHeX.Core/Legality/VivillonTables.cs | 17 ++++++++ 5 files changed, 62 insertions(+), 22 deletions(-) diff --git a/PKHeX.Core/Legality/Encounters/EncounterLink.cs b/PKHeX.Core/Legality/Encounters/EncounterLink.cs index 06728c8a3..6b646f1f5 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterLink.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterLink.cs @@ -59,6 +59,7 @@ public PKM ConvertToPKM(ITrainerInfo SAV) SAV.ApplyToPKM(pk); pk.Version = (int)version; + pk.Gender = pk.PersonalInfo.RandomGender; pk.Language = lang; var moves = Moves.Length != 0 ? Moves : Legal.GetEncounterMoves(pk, Level, version); @@ -72,9 +73,8 @@ public PKM ConvertToPKM(ITrainerInfo SAV) if (RibbonClassic) pk.RibbonClassic = true; - if (OT) - pk.SetRandomMemory6(); - else + pk.SetRandomMemory6(); + if (!OT) SAV.ApplyHandlingTrainerInfo(pk); return pk; diff --git a/PKHeX.Core/Legality/Encounters/EncounterSlot.cs b/PKHeX.Core/Legality/Encounters/EncounterSlot.cs index ce30e0099..b77d7d3ff 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterSlot.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterSlot.cs @@ -79,9 +79,14 @@ public PKM ConvertToPKM(ITrainerInfo SAV) pk.Language = lang; pk.CurrentLevel = level; pk.Version = (int)version; - pk.AltForm = Form; pk.Nickname = PKX.GetSpeciesNameGeneration(Species, lang, Generation); pk.Ball = GetBall(); + if (Form != 31) + pk.AltForm = Form; + else if (Species == 664 || Species == 665 || Species == 666) + pk.AltForm = Legal.GetVivillonPattern(SAV.Country, SAV.SubRegion); + else + pk.AltForm = Util.Rand.Next(pk.PersonalInfo.FormeCount); if (pk.Format > 2 || Version == GameVersion.C) { diff --git a/PKHeX.Core/Legality/Encounters/Generator/EncounterMovesetGenerator.cs b/PKHeX.Core/Legality/Encounters/Generator/EncounterMovesetGenerator.cs index 2e077a9e3..66b5b01c0 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/EncounterMovesetGenerator.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/EncounterMovesetGenerator.cs @@ -213,18 +213,8 @@ private static IEnumerable GetStatic(PKM pk, IReadOnlyCollectio var encs = EncounterStaticGenerator.GetPossible(pk); foreach (var enc in encs) { - if (enc.Generation == 4) - { - switch (pk.Species) - { - case 491 when enc.Location == 079 && !pk.Pt: // DP Darkrai - continue; - case 492 when enc.Location == 063 && !pk.Pt: // DP Shaymin - continue; - case 493 when enc.Location == 086: // Azure Flute Arceus - continue; - } - } + if (enc.IsUnobtainable(pk)) + continue; if (needs.Count == 0) { yield return enc; @@ -270,7 +260,7 @@ private static IEnumerable GetSlots(PKM pk, IReadOnlyCollection GetSlots(PKM pk, IReadOnlyCollection> 16; + var pid = B & 0xFFFF0000 | A >> 16; + if (type == PIDType.Method_1_Unown || type == PIDType.Method_2_Unown || type == PIDType.Method_4_Unown) + pk.PID = (pid >> 16) | (pid << 16); // swap halves + else + pk.PID = pid; var skipIV1Frame = type == PIDType.Method_2 || type == PIDType.Method_2_Unown; if (skipIV1Frame) @@ -74,11 +78,10 @@ private static void SetValuesFromSeedXDRNG(PKM pk, uint seed) pk.SID = (int)((seed = rng.Next(seed)) >> 16); seed = rng.Advance(seed, 2); // PID calls consumed break; - case 196: + case 196: // Colo Espeon pk.TID = (int)((seed = rng.Next(seed)) >> 16); pk.SID = (int)((seed = rng.Next(seed)) >> 16); - seed = rng.Advance(seed, 5); // skip over Umbreon - seed = rng.Advance(seed, 2); // PID calls consumed + seed = rng.Advance(seed, 9); // PID calls consumed, skip over Umbreon break; } var A = rng.Next(seed); // IV1 diff --git a/PKHeX.Core/Legality/VivillonTables.cs b/PKHeX.Core/Legality/VivillonTables.cs index db3a5022f..9d8b6b971 100644 --- a/PKHeX.Core/Legality/VivillonTables.cs +++ b/PKHeX.Core/Legality/VivillonTables.cs @@ -263,5 +263,22 @@ public static bool CheckVivillonPattern(int form, int country, int region) return ct.otherforms.Any(e => e.form == form && e.region.Contains(region)); } + + /// + /// Compares the Vivillon pattern against its country and region to determine if the pattern is able to be obtained legally. + /// + /// Country ID + /// Console Region ID + public static int GetVivillonPattern(int country, int region) + { + CountryTable ct = RegionFormTable.Where(t => t.countryID == country).FirstOrDefault(); + if (ct.otherforms == null) // empty struct = no forms referenced + return ct.mainform; // No subregion table + + foreach (var sub in ct.otherforms) + if (sub.region.Contains(region)) + return sub.form; + return ct.mainform; + } } } \ No newline at end of file