From 7f87d43c41af5b5e7443fa3cf8f9b3cf561c03c0 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 26 Aug 2018 11:15:32 -0700 Subject: [PATCH] Add enum for ball; use in checks Increases readability instead of using hex IDs --- PKHeX.Core/Legality/Verifiers/Ball.cs | 44 ++++++++ PKHeX.Core/Legality/Verifiers/BallVerifier.cs | 103 ++++++++++-------- 2 files changed, 99 insertions(+), 48 deletions(-) create mode 100644 PKHeX.Core/Legality/Verifiers/Ball.cs diff --git a/PKHeX.Core/Legality/Verifiers/Ball.cs b/PKHeX.Core/Legality/Verifiers/Ball.cs new file mode 100644 index 000000000..f30655e6c --- /dev/null +++ b/PKHeX.Core/Legality/Verifiers/Ball.cs @@ -0,0 +1,44 @@ +namespace PKHeX.Core +{ + public enum Ball + { + None = 0, + + Master = 1, + Ultra = 2, + Great = 3, + Poke = 4, + + Safari = 5, + + Net = 6, + Dive = 7, + Nest = 8, + Repeat = 9, + Timer = 10, + Luxury = 11, + Premier = 12, + Dusk = 13, + Heal = 14, + Quick = 15, + + Cherish = 16, + + Fast = 17, + Level = 18, + Lure = 19, + Heavy = 20, + Love = 21, + Friend = 22, + Moon = 23, + + Sport = 24, + Dream = 25, + Beast = 26, + } + + public static partial class Extensions + { + public static bool IsApricornBall(this Ball ball) => Ball.Fast <= ball && ball <= Ball.Moon; + } +} \ No newline at end of file diff --git a/PKHeX.Core/Legality/Verifiers/BallVerifier.cs b/PKHeX.Core/Legality/Verifiers/BallVerifier.cs index df48a03d8..f38e80d6e 100644 --- a/PKHeX.Core/Legality/Verifiers/BallVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/BallVerifier.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using static PKHeX.Core.LegalityCheckStrings; +using static PKHeX.Core.Ball; namespace PKHeX.Core { @@ -25,37 +26,43 @@ private CheckResult VerifyBall(LegalityAnalysis data) var Info = data.Info; // Fixed ball cases -- can be only one ball ever - if (EncounterMatch is MysteryGift g) - return VerifyBallMysteryGift(data, g); - if (EncounterMatch is EncounterLink l) - return VerifyBallEquals(data, l.Ball); - if (EncounterMatch is EncounterTrade t) - return VerifyBallEquals(data, t.Ball); - if (EncounterMatch is EncounterStatic s && s.Gift) - return VerifyBallEquals(data, s.Ball); + switch (EncounterMatch) + { + case MysteryGift g: + return VerifyBallMysteryGift(data, g); + case EncounterLink l: + return VerifyBallEquals(data, l.Ball); + case EncounterTrade t: + return VerifyBallEquals(data, t.Ball); + case EncounterStatic s when s.Gift: + return VerifyBallEquals(data, s.Ball); + } // Capture / Inherit cases -- can be one of many balls var pkm = data.pkm; if (pkm.Species == 292 && Info.Generation > 3) // Shedinja. For gen3, copy the ball from Nincada - return VerifyBallEquals(data, 4); // Pokeball Only + return VerifyBallEquals(data, (int)Poké); // Pokeball Only - if (pkm.Ball == 0x14 && Legal.AlolanCaptureNoHeavyBall.Contains(EncounterMatch.Species) && !EncounterMatch.EggEncounter && pkm.SM) + if (pkm.Ball == (int)Heavy && Legal.AlolanCaptureNoHeavyBall.Contains(EncounterMatch.Species) && !EncounterMatch.EggEncounter && pkm.SM) return GetInvalid(V116); // Heavy Ball, can inherit if from egg (USUM fixed catch rate calc) - if (EncounterMatch is EncounterStatic e) - return VerifyBallStatic(data, e); - if (EncounterMatch is EncounterSlot w) - return VerifyBallWild(data, w); - if (EncounterMatch is EncounterEgg) - return VerifyBallEgg(data); - - return VerifyBallEquals(data, 4); // Pokeball + switch (EncounterMatch) + { + case EncounterStatic e: + return VerifyBallStatic(data, e); + case EncounterSlot w: + return VerifyBallWild(data, w); + case EncounterEgg _: + return VerifyBallEgg(data); + default: + return VerifyBallEquals(data, (int)Poké); // Pokeball + } } private CheckResult VerifyBallMysteryGift(LegalityAnalysis data, MysteryGift g) { if (g.Gen4 && g.Species == 490 && g.Ball == 0) // there is no ball data in Manaphy Mystery Gift from Gen4 - return VerifyBallEquals(data, 4); // Pokeball + return VerifyBallEquals(data, (int)Poké); // Pokeball return VerifyBallEquals(data, g.Ball); } @@ -69,7 +76,7 @@ private CheckResult VerifyBallStatic(LegalityAnalysis data, EncounterStatic s) private CheckResult VerifyBallWild(LegalityAnalysis data, EncounterSlot w) { if (w.Location == 30016 && w.Generation == 7) // Poké Pelago - return VerifyBallEquals(data, 4); // Pokeball + return VerifyBallEquals(data, (int)Poké); // Pokeball var Info = data.Info; @@ -77,9 +84,9 @@ private CheckResult VerifyBallWild(LegalityAnalysis data, EncounterSlot w) // mixed possible encounters between safari, BCC and other encounters // That means is the first encounter is not safari then there is no safari encounter in the array if (3 <= Info.Generation && Info.Generation <= 4 && w.Type.IsSafariType()) - return VerifyBallEquals(data, 5); // Safari Ball + return VerifyBallEquals(data, (int)Safari); // Safari Ball if (Info.Generation == 4 && w.Type == SlotType.BugContest) - return VerifyBallEquals(data, 0x18); // Sport Ball + return VerifyBallEquals(data, (int)Sport); // Sport Ball return VerifyBallEquals(data, Legal.GetWildBalls(data.pkm)); } @@ -87,13 +94,13 @@ private CheckResult VerifyBallEgg(LegalityAnalysis data) { var pkm = data.pkm; if (data.Info.Generation < 6) // No inheriting Balls - return VerifyBallEquals(data, 4); // Must be Pokéball -- no ball inheritance. + return VerifyBallEquals(data, (int)Poké); // Must be Pokéball -- no ball inheritance. - switch (pkm.Ball) + switch ((Ball)pkm.Ball) { - case 0x04: return GetValid(V119); // Poké Ball - case 0x01: return GetInvalid(V117); // Master Ball - case 0x10: return GetInvalid(V120); // Cherish Ball + case Poké: return GetValid(V119); // Poké Ball + case Master: return GetInvalid(V117); // Master Ball + case Cherish: return GetInvalid(V120); // Cherish Ball default: return VerifyBallInherited(data); } } @@ -113,14 +120,11 @@ private CheckResult VerifyBallEggGen6(LegalityAnalysis data) var pkm = data.pkm; int species = data.EncounterMatch.Species; if (pkm.Gender == 2 || Legal.BreedMaleOnly.Contains(species)) // Genderless - return VerifyBallEquals(data, 4); // Must be Pokéball as ball can only pass via mother (not Ditto!) + return VerifyBallEquals(data, (int)Poké); // Must be Pokéball as ball can only pass via mother (not Ditto!) - int ball = pkm.Ball; + Ball ball = (Ball)pkm.Ball; - if (ball >= 26) - return GetInvalid(V126); - - if (ball == 0x05) // Safari Ball + if (ball == Safari) // Safari Ball { if (!Legal.Inherit_Safari.Contains(species)) return GetInvalid(V121); @@ -128,7 +132,7 @@ private CheckResult VerifyBallEggGen6(LegalityAnalysis data) return GetInvalid(V122); return GetValid(V123); } - if (0x10 < ball && ball < 0x18) // Apricorn Ball + if (ball.IsApricornBall()) // Apricorn Ball { if (!Legal.Inherit_Apricorn6.Contains(species)) return GetInvalid(V121); @@ -136,7 +140,7 @@ private CheckResult VerifyBallEggGen6(LegalityAnalysis data) return GetInvalid(V122); return GetValid(V123); } - if (ball == 0x18) // Sport Ball + if (ball == Sport) // Sport Ball { if (!Legal.Inherit_Sport.Contains(species)) return GetInvalid(V121); @@ -144,7 +148,7 @@ private CheckResult VerifyBallEggGen6(LegalityAnalysis data) return GetInvalid(V122); return GetValid(V123); } - if (ball == 0x19) // Dream Ball + if (ball == Dream) // Dream Ball { if (pkm.AbilityNumber == 4 && Legal.Ban_DreamHidden.Contains(species)) return GetInvalid(V122); @@ -152,13 +156,13 @@ private CheckResult VerifyBallEggGen6(LegalityAnalysis data) return GetValid(V123); return GetInvalid(V121); } - if (0x0D <= ball && ball <= 0x0F) // Dusk Heal Quick + if (Dusk <= ball && ball <= Quick) // Dusk Heal Quick { if (!Legal.Ban_Gen4Ball_6.Contains(species)) return GetValid(V123); return GetInvalid(V121); } - if (0x02 <= ball && ball <= 0x0C) // Don't worry, Ball # 0x05 was already checked. + if (Ultra <= ball && ball <= Premier) // Don't worry, Safari was already checked. { if (Legal.Ban_Gen3Ball.Contains(species)) return GetInvalid(V121); @@ -174,6 +178,9 @@ private CheckResult VerifyBallEggGen6(LegalityAnalysis data) return GetInvalid(V121); } + if (ball >= Dream) + return GetInvalid(V126); + return NONE; } @@ -182,11 +189,11 @@ private CheckResult VerifyBallEggGen7(LegalityAnalysis data) var pkm = data.pkm; int species = data.EncounterMatch.Species; if (722 <= species && species <= 730) // G7 Starters - return VerifyBallEquals(data, 4); + return VerifyBallEquals(data, (int)Poké); - int ball = pkm.Ball; + Ball ball = (Ball)pkm.Ball; - if (ball == 0x05) // Safari Ball + if (ball == Safari) { if (!(Legal.Inherit_Safari.Contains(species) || Legal.Inherit_SafariMale.Contains(species))) return GetInvalid(V121); @@ -194,7 +201,7 @@ private CheckResult VerifyBallEggGen7(LegalityAnalysis data) return GetInvalid(V122); return GetValid(V123); } - if (0x10 < ball && ball < 0x18) // Apricorn Ball + if (ball.IsApricornBall()) // Apricorn Ball { if (!Legal.Inherit_Apricorn7.Contains(species)) return GetInvalid(V121); @@ -202,7 +209,7 @@ private CheckResult VerifyBallEggGen7(LegalityAnalysis data) return GetInvalid(V122); return GetValid(V123); } - if (ball == 0x18) // Sport Ball + if (ball == Sport) // Sport Ball { if (!Legal.Inherit_Sport.Contains(species)) return GetInvalid(V121); @@ -210,26 +217,26 @@ private CheckResult VerifyBallEggGen7(LegalityAnalysis data) return GetInvalid(V122); return GetValid(V123); } - if (ball == 0x19) // Dream Ball + if (ball == Dream) // Dream Ball { if (Legal.Inherit_Dream.Contains(species) || Legal.Inherit_DreamMale.Contains(species)) return GetValid(V123); return GetInvalid(V121); } - if (0x0D <= ball && ball <= 0x0F) // Dusk Heal Quick + if (Dusk <= ball && ball <= Quick) // Dusk Heal Quick { if (!Legal.Ban_Gen4Ball_7.Contains(species)) return GetValid(V123); return GetInvalid(V121); } - if (0x02 <= ball && ball <= 0x0C) // Don't worry, Ball # 0x05 was already checked. + if (Ultra <= ball && ball <= Premier) // Don't worry, Safari was already checked. { if (!Legal.Ban_Gen3Ball_7.Contains(species)) return GetValid(V123); return GetInvalid(V121); } - if (ball == 26) + if (ball == Beast) { if (species == 669 && pkm.AltForm == 3 && pkm.AbilityNumber == 4) return GetInvalid(V122); // Can't obtain Flabébé-Blue with Hidden Ability in wild @@ -243,7 +250,7 @@ private CheckResult VerifyBallEggGen7(LegalityAnalysis data) if (species > 721) return VerifyBallEquals(data, Legal.WildPokeballs7); - if (ball >= 27) + if (ball > Beast) return GetInvalid(V126); return NONE;