From e04b96a9b35750192f2ec70ae98467715abc5875 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 12 Jul 2020 20:58:07 -0500 Subject: [PATCH] Fix dizzy punch egg recognition & gen2 hatch conter verification Closes #2939 Fixes #2938 Inline some logic where appropriate for egg levels --- PKHeX.Core/Legality/Core.cs | 3 -- .../Legality/Encounters/Data/Encounters2.cs | 14 ++++----- .../EncounterStatic/EncounterStatic2Odd.cs | 30 +++++++++++++++++++ .../Generator/EncounterEggGenerator.cs | 2 +- .../Legality/Encounters/IEncounterable.cs | 2 +- .../Legality/Verifiers/LevelVerifier.cs | 4 +-- PKHeX.Core/PKM/PK2.cs | 2 +- 7 files changed, 42 insertions(+), 15 deletions(-) create mode 100644 PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic2Odd.cs diff --git a/PKHeX.Core/Legality/Core.cs b/PKHeX.Core/Legality/Core.cs index 23fdb2f7c..70b7e074c 100644 --- a/PKHeX.Core/Legality/Core.cs +++ b/PKHeX.Core/Legality/Core.cs @@ -119,9 +119,6 @@ namespace PKHeX.Core }; } - internal static int GetEggHatchLevel(PKM pkm) => GetEggHatchLevel(pkm.Format); - internal static int GetEggHatchLevel(int gen) => gen <= 3 ? 5 : 1; - internal static ICollection GetSplitBreedGeneration(int generation) { switch (generation) diff --git a/PKHeX.Core/Legality/Encounters/Data/Encounters2.cs b/PKHeX.Core/Legality/Encounters/Data/Encounters2.cs index 209b36e96..061a26b3f 100644 --- a/PKHeX.Core/Legality/Encounters/Data/Encounters2.cs +++ b/PKHeX.Core/Legality/Encounters/Data/Encounters2.cs @@ -214,13 +214,13 @@ namespace PKHeX.Core { new EncounterStatic { Species = 245, Level = 40, Location = 023, Version = GameVersion.C }, // Suicune @ Tin Tower - new EncounterStatic { Species = 172, Level = 05, Version = GameVersion.C, Moves = new [] {146}, EggLocation = 256, EggCycles = 20 }, // Pichu Dizzy Punch - new EncounterStatic { Species = 173, Level = 05, Version = GameVersion.C, Moves = new [] {146}, EggLocation = 256, EggCycles = 20 }, // Cleffa Dizzy Punch - new EncounterStatic { Species = 174, Level = 05, Version = GameVersion.C, Moves = new [] {146}, EggLocation = 256, EggCycles = 20 }, // Igglybuff Dizzy Punch - new EncounterStatic { Species = 236, Level = 05, Version = GameVersion.C, Moves = new [] {146}, EggLocation = 256, EggCycles = 20 }, // Tyrogue Dizzy Punch - new EncounterStatic { Species = 238, Level = 05, Version = GameVersion.C, Moves = new [] {146}, EggLocation = 256, EggCycles = 20 }, // Smoochum Dizzy Punch - new EncounterStatic { Species = 239, Level = 05, Version = GameVersion.C, Moves = new [] {146}, EggLocation = 256, EggCycles = 20 }, // Elekid Dizzy Punch - new EncounterStatic { Species = 240, Level = 05, Version = GameVersion.C, Moves = new [] {146}, EggLocation = 256, EggCycles = 20 }, // Magby Dizzy Punch + new EncounterStatic2Odd(172), // Pichu Dizzy Punch + new EncounterStatic2Odd(173), // Cleffa Dizzy Punch + new EncounterStatic2Odd(174), // Igglybuff Dizzy Punch + new EncounterStatic2Odd(236), // Tyrogue Dizzy Punch + new EncounterStatic2Odd(238), // Smoochum Dizzy Punch + new EncounterStatic2Odd(239), // Elekid Dizzy Punch + new EncounterStatic2Odd(240), // Magby Dizzy Punch new EncounterStatic { Species = 147, Level = 15, Location = 042, Version = GameVersion.C, Moves = new [] {245} }, // Dratini ExtremeSpeed diff --git a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic2Odd.cs b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic2Odd.cs new file mode 100644 index 000000000..0638f40ca --- /dev/null +++ b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic2Odd.cs @@ -0,0 +1,30 @@ +namespace PKHeX.Core +{ + public sealed class EncounterStatic2Odd : EncounterStatic + { + private const int Dizzy = 146; + private static readonly int[] _dizzy = { Dizzy }; + + public EncounterStatic2Odd(int species) + { + Species = species; + Level = 5; + Version = GameVersion.C; + Moves = _dizzy; + EggLocation = 256; + EggCycles = 20; + } + + public override bool IsMatch(PKM pkm, int lvl) + { + // Let it get picked up as regular EncounterEgg under other conditions. + if (pkm.Format > 2) + return false; + if (pkm.Move1 != Dizzy && pkm.Move2 != Dizzy && pkm.Move3 != Dizzy && pkm.Move4 != Dizzy) + return false; + if (pkm.IsEgg && pkm.EXP != 125) + return false; + return base.IsMatch(pkm, lvl); + } + } +} \ No newline at end of file diff --git a/PKHeX.Core/Legality/Encounters/Generator/EncounterEggGenerator.cs b/PKHeX.Core/Legality/Encounters/Generator/EncounterEggGenerator.cs index f8b326630..c55da2e12 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/EncounterEggGenerator.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/EncounterEggGenerator.cs @@ -30,7 +30,7 @@ namespace PKHeX.Core // version is a true indicator for all generation 3-5 origins var ver = (GameVersion)pkm.Version; - int lvl = GetEggHatchLevel(gen); + int lvl = gen <= 3 ? 5 : 1; int max = GetMaxSpeciesOrigin(gen); var e = EvoBase.GetBaseSpecies(chain, 0); diff --git a/PKHeX.Core/Legality/Encounters/IEncounterable.cs b/PKHeX.Core/Legality/Encounters/IEncounterable.cs index e7c084cbf..154e7d0ae 100644 --- a/PKHeX.Core/Legality/Encounters/IEncounterable.cs +++ b/PKHeX.Core/Legality/Encounters/IEncounterable.cs @@ -30,7 +30,7 @@ if (!pkm.HasOriginalMetLocation) return encounter.IsWithinRange(pkm.CurrentLevel); if (encounter.EggEncounter) - return pkm.CurrentLevel == Legal.GetEggHatchLevel(pkm); + return pkm.CurrentLevel == encounter.LevelMin; if (encounter is MysteryGift g) return pkm.CurrentLevel == g.Level; return pkm.CurrentLevel == pkm.Met_Level; diff --git a/PKHeX.Core/Legality/Verifiers/LevelVerifier.cs b/PKHeX.Core/Legality/Verifiers/LevelVerifier.cs index 7bf6ac264..fc0a211ea 100644 --- a/PKHeX.Core/Legality/Verifiers/LevelVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/LevelVerifier.cs @@ -37,7 +37,7 @@ namespace PKHeX.Core if (pkm.IsEgg) { - int elvl = Legal.GetEggHatchLevel(pkm); + int elvl = EncounterMatch.LevelMin; if (elvl != pkm.CurrentLevel) { data.AddLine(GetInvalid(string.Format(LEggFMetLevel_0, elvl))); @@ -67,7 +67,7 @@ namespace PKHeX.Core var EncounterMatch = data.EncounterOriginal; if (pkm.IsEgg) { - int elvl = Legal.GetEggHatchLevel(pkm); + const int elvl = 5; if (elvl != pkm.CurrentLevel) data.AddLine(GetInvalid(string.Format(LEggFMetLevel_0, elvl))); return; diff --git a/PKHeX.Core/PKM/PK2.cs b/PKHeX.Core/PKM/PK2.cs index f5d437c08..c241d59de 100644 --- a/PKHeX.Core/PKM/PK2.cs +++ b/PKHeX.Core/PKM/PK2.cs @@ -86,7 +86,7 @@ namespace PKHeX.Core #endregion public override bool IsEgg { get; set; } - + public override int OT_Friendship { get => CurrentFriendship; set => CurrentFriendship = value; } public override bool HasOriginalMetLocation => CaughtData != 0; public override int Version { get => (int)GameVersion.GSC; set { } }