diff --git a/PKHeX.Core/Legality/Analysis.cs b/PKHeX.Core/Legality/Analysis.cs index 34fd237f2..16a761618 100644 --- a/PKHeX.Core/Legality/Analysis.cs +++ b/PKHeX.Core/Legality/Analysis.cs @@ -81,9 +81,7 @@ private IEnumerable AllSuggestedRelearnMoves return _allSuggestedRelearnMoves; if (Error || Info == null) return new int[4]; - var gender = pkm.PersonalInfo.Gender; - var inheritLvlMoves = (gender > 0 && gender < 255) || Legal.MixedGenderBreeding.Contains(Info.EncounterMatch.Species); - return _allSuggestedRelearnMoves = Legal.GetValidRelearn(pkm, Info.EncounterMatch.Species, inheritLvlMoves).ToArray(); + return _allSuggestedRelearnMoves = Legal.GetValidRelearn(pkm, Info.EncounterMatch.Species, (GameVersion)pkm.Version).ToArray(); } } @@ -130,7 +128,7 @@ public LegalityAnalysis(PKM pk, PersonalTable table = null) && Info.Moves.All(m => m.Valid) && Info.Relearn.All(m => m.Valid); - if (pkm.FatefulEncounter && Info.Relearn.Any(chk => !chk.Valid) && EncounterMatch is EncounterInvalid) + if (!Valid && pkm.FatefulEncounter && Info.Relearn.Any(chk => !chk.Valid) && EncounterMatch is EncounterInvalid) AddLine(Severity.Indeterminate, LFatefulGiftMissing, CheckIdentifier.Fateful); } #if SUPPRESS @@ -299,6 +297,8 @@ private void UpdateChecks() private string GetLegalityReport() { + if (Valid) + return L_ALegal; if (!Parsed || Info == null) return L_AnalysisUnavailable; @@ -308,7 +308,7 @@ private string GetLegalityReport() for (int i = 0; i < 4; i++) { if (!vMoves[i].Valid) - lines.Add(string.Format(L_F0_M_1_2, vMoves[i].Rating, i + 1, vMoves[i].Comment)); + lines.Add(vMoves[i].Format(L_F0_M_1_2, i + 1)); } if (pkm.Format >= 6) @@ -316,19 +316,13 @@ private string GetLegalityReport() for (int i = 0; i < 4; i++) { if (!vRelearn[i].Valid) - lines.Add(string.Format(L_F0_RM_1_2, vRelearn[i].Rating, i + 1, vRelearn[i].Comment)); + lines.Add(vRelearn[i].Format(L_F0_RM_1_2, i + 1)); } } - if (lines.Count == 0 && Parse.All(chk => chk.Valid) && Valid) - return L_ALegal; - // Build result string... - var outputLines = Parse.Where(chk => !chk.Valid); // Only invalid - lines.AddRange(outputLines.Select(chk => string.Format(L_F0_1, chk.Rating, chk.Comment))); - - if (lines.Count == 0) - return L_AError; + var outputLines = Parse.Where(chk => !chk.Valid); + lines.AddRange(outputLines.Select(chk => chk.Format(L_F0_1))); return string.Join(Environment.NewLine, lines); } @@ -351,7 +345,7 @@ private string GetVerboseLegalityReport() var move = vMoves[i]; if (!move.Valid) continue; - var msg = string.Format(L_F0_M_1_2, move.Rating, i + 1, move.Comment); + var msg = move.Format(L_F0_M_1_2, i + 1); if (pkm.Format != move.Generation) msg += $" [Gen{move.Generation}]"; lines.Add(msg); @@ -362,7 +356,7 @@ private string GetVerboseLegalityReport() for (int i = 0; i < 4; i++) { if (vRelearn[i].Valid) - lines.Add(string.Format(L_F0_RM_1_2, vRelearn[i].Rating, i + 1, vRelearn[i].Comment)); + lines.Add(vRelearn[i].Format(L_F0_RM_1_2, i + 1)); } } @@ -370,7 +364,7 @@ private string GetVerboseLegalityReport() lines.Add(br[1]); var outputLines = Parse.Where(chk => chk?.Valid == true && chk.Comment != L_AValid).OrderBy(chk => chk.Judgement); // Fishy sorted to top - lines.AddRange(outputLines.Select(chk => string.Format(L_F0_1, chk.Rating, chk.Comment))); + lines.AddRange(outputLines.Select(chk => chk.Format(L_F0_1))); lines.AddRange(br); lines.Add(string.Format(L_FEncounterType_0, EncounterName)); diff --git a/PKHeX.Core/Legality/Core.cs b/PKHeX.Core/Legality/Core.cs index 5559e7bc2..14f6e2178 100644 --- a/PKHeX.Core/Legality/Core.cs +++ b/PKHeX.Core/Legality/Core.cs @@ -99,9 +99,14 @@ internal static IEnumerable GetValidMoves(PKM pkm, IReadOnlyList GetValidRelearn(PKM pkm, int species, GameVersion version = GameVersion.Any) + { + return GetValidRelearn(pkm, species, GetCanInheritMoves(species), version); + } + internal static IEnumerable GetValidRelearn(PKM pkm, int species, bool inheritlvlmoves, GameVersion version = GameVersion.Any) { - List r = new List { 0 }; + var r = new List { 0 }; if (pkm.GenNumber < 6) return r; @@ -707,7 +712,7 @@ internal static int GetMinLevelEncounter(PKM pkm) private static IEnumerable GetValidMoves(PKM pkm, GameVersion Version, IReadOnlyList> vs, int minLvLG1 = 1, int minLvLG2 = 1, bool LVL = false, bool Relearn = false, bool Tutor = false, bool Machine = false, bool MoveReminder = true, bool RemoveTransferHM = true) { - List r = new List { 0 }; + var r = new List { 0 }; if (Relearn && pkm.Format >= 6) r.AddRange(pkm.RelearnMoves); @@ -722,7 +727,7 @@ private static IEnumerable GetValidMoves(PKM pkm, GameVersion Version, IRea private static IEnumerable GetValidMoves(PKM pkm, GameVersion Version, IReadOnlyList vs, int generation, int minLvLG1 = 1, int minLvLG2 = 1, bool LVL = false, bool Relearn = false, bool Tutor = false, bool Machine = false, bool MoveReminder = true, bool RemoveTransferHM = true) { - List r = new List { 0 }; + var r = new List { 0 }; if (vs.Count == 0) return r; int species = pkm.Species; @@ -802,7 +807,7 @@ private static int GetEvoMoveMinLevel2(PKM pkm, int generation, int minLvLG2, Ev private static IEnumerable GetMoves(PKM pkm, int species, int minlvlG1, int minlvlG2, int lvl, int form, bool moveTutor, GameVersion Version, bool LVL, bool specialTutors, bool Machine, bool MoveReminder, bool RemoveTransferHM, int generation) { - List r = new List(); + var r = new List(); if (LVL) r.AddRange(MoveLevelUp.GetMovesLevelUp(pkm, species, minlvlG1, minlvlG2, lvl, form, Version, MoveReminder, generation)); if (Machine) diff --git a/PKHeX.Core/Legality/GBRestrictions.cs b/PKHeX.Core/Legality/GBRestrictions.cs index 2f20d0642..9519b945d 100644 --- a/PKHeX.Core/Legality/GBRestrictions.cs +++ b/PKHeX.Core/Legality/GBRestrictions.cs @@ -12,11 +12,11 @@ namespace PKHeX /// internal static class GBRestrictions { - internal static readonly int[] G1CaterpieMoves = { 33, 81 }; - internal static readonly int[] G1WeedleMoves = { 40, 81 }; - internal static readonly int[] G1MetapodMoves = G1CaterpieMoves.Concat(new[] { 106 }).ToArray(); - internal static readonly int[] G1KakunaMoves = G1WeedleMoves.Concat(new[] { 106 }).ToArray(); - internal static readonly int[] G1Exeggcute_IncompatibleMoves = { 78, 77, 79 }; + private static readonly int[] G1CaterpieMoves = { 33, 81 }; + private static readonly int[] G1WeedleMoves = { 40, 81 }; + private static readonly int[] G1MetapodMoves = { 33, 81, 106 }; + private static readonly int[] G1KakunaMoves = { 40, 81, 106 }; + private static readonly int[] G1Exeggcute_IncompatibleMoves = { 78, 77, 79 }; internal static readonly int[] Stadium_CatchRate = { @@ -24,7 +24,7 @@ internal static class GBRestrictions 168, // Gorgeous Box }; - internal static readonly HashSet Stadium_GiftSpecies = new HashSet + private static readonly HashSet Stadium_GiftSpecies = new HashSet { 001, // Bulbasaur 004, // Charmander @@ -37,12 +37,14 @@ internal static class GBRestrictions 140, // Kabuto }; - internal static readonly HashSet SpecialMinMoveSlots = new HashSet + private static readonly HashSet SpecialMinMoveSlots = new HashSet { 25, 26, 29, 30, 31, 32, 33, 34, 36, 38, 40, 59, 91, 103, 114, 121, }; - internal static readonly HashSet Types_Gen1 = new HashSet + internal static bool TypeIDExists(int type) => Types_Gen1.Contains(type); + + private static readonly HashSet Types_Gen1 = new HashSet { 0, 1, 2, 3, 4, 5, 7, 8, 20, 21, 22, 23, 24, 25, 26 }; diff --git a/PKHeX.Core/Legality/Structures/CheckResult.cs b/PKHeX.Core/Legality/Structures/CheckResult.cs index 1e252ccfe..874e2aa57 100644 --- a/PKHeX.Core/Legality/Structures/CheckResult.cs +++ b/PKHeX.Core/Legality/Structures/CheckResult.cs @@ -25,5 +25,8 @@ internal CheckResult(Severity s, string c, CheckIdentifier i) Comment = c; Identifier = i; } + + public string Format(string format) => string.Format(format, Rating, Comment); + public string Format(string format, int index) => string.Format(format, Rating, index, Comment); } } diff --git a/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs b/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs index 5e5a83bf4..18ee4d78f 100644 --- a/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs +++ b/PKHeX.Core/Legality/Verifiers/MiscVerifier.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using static PKHeX.Core.LegalityCheckStrings; +using static PKHeX.Core.CheckIdentifier; namespace PKHeX.Core { @@ -9,7 +10,7 @@ namespace PKHeX.Core /// public sealed class MiscVerifier : Verifier { - protected override CheckIdentifier Identifier => CheckIdentifier.Misc; + protected override CheckIdentifier Identifier => Misc; public override void Verify(LegalityAnalysis data) { @@ -19,21 +20,21 @@ public override void Verify(LegalityAnalysis data) VerifyMiscEggCommon(data); if (pkm is IContestStats s && s.HasContestStats()) - data.AddLine(GetInvalid(LEggContest, CheckIdentifier.Egg)); + data.AddLine(GetInvalid(LEggContest, Egg)); switch (pkm) { case PK5 pk5 when pk5.PokeStarFame != 0 && pk5.IsEgg: - data.AddLine(GetInvalid(LEggShinyPokeStar, CheckIdentifier.Egg)); + data.AddLine(GetInvalid(LEggShinyPokeStar, Egg)); break; case PK4 pk4 when pk4.ShinyLeaf != 0: - data.AddLine(GetInvalid(LEggShinyLeaf, CheckIdentifier.Egg)); + data.AddLine(GetInvalid(LEggShinyLeaf, Egg)); break; case PK4 pk4 when pk4.PokéathlonStat != 0: - data.AddLine(GetInvalid(LEggPokeathlon, CheckIdentifier.Egg)); + data.AddLine(GetInvalid(LEggPokeathlon, Egg)); break; case PK3 _ when pkm.Language != 1: // All Eggs are Japanese and flagged specially for localized string - data.AddLine(GetInvalid(string.Format(LOTLanguage, LanguageID.Japanese, (LanguageID)pkm.Language), CheckIdentifier.Egg)); + data.AddLine(GetInvalid(string.Format(LOTLanguage, LanguageID.Japanese, (LanguageID)pkm.Language), Egg)); break; } } @@ -53,7 +54,7 @@ public void VerifyMiscG1(LegalityAnalysis data) { VerifyMiscEggCommon(data); if (pkm.PKRS_Cured || pkm.PKRS_Infected) - data.AddLine(GetInvalid(LEggPokerus, CheckIdentifier.Egg)); + data.AddLine(GetInvalid(LEggPokerus, Egg)); } if (!(pkm is PK1 pk1)) @@ -67,14 +68,14 @@ private void VerifyMiscG1Types(LegalityAnalysis data, PK1 pk1) { var Type_A = pk1.Type_A; var Type_B = pk1.Type_B; - if (pk1.Species == 137) // Porygon + if (pk1.Species == (int)Species.Porygon) { // Can have any type combination of any species by using Conversion. - if (!GBRestrictions.Types_Gen1.Contains(Type_A)) + if (!GBRestrictions.TypeIDExists(Type_A)) { data.AddLine(GetInvalid(LG1TypePorygonFail1)); } - else if (!GBRestrictions.Types_Gen1.Contains(Type_B)) + if (!GBRestrictions.TypeIDExists(Type_B)) { data.AddLine(GetInvalid(LG1TypePorygonFail2)); } @@ -166,35 +167,35 @@ private static void VerifyMiscFatefulEncounter(LegalityAnalysis data) VerifyFatefulMysteryGift(data, g); return; case EncounterStatic s when s.Fateful: // ingame fateful - case EncounterSlot _ when pkm.Version == 15: // ingame pokespot + case EncounterSlot x when x.Version == GameVersion.XD: // ingame pokespot case EncounterTrade t when t.Fateful: VerifyFatefulIngameActive(data); return; } if (pkm.FatefulEncounter) - data.AddLine(GetInvalid(LFatefulInvalid, CheckIdentifier.Fateful)); + data.AddLine(GetInvalid(LFatefulInvalid, Fateful)); } private static void VerifyMiscEggCommon(LegalityAnalysis data) { var pkm = data.pkm; if (pkm.Move1_PPUps > 0 || pkm.Move2_PPUps > 0 || pkm.Move3_PPUps > 0 || pkm.Move4_PPUps > 0) - data.AddLine(GetInvalid(LEggPPUp, CheckIdentifier.Egg)); + data.AddLine(GetInvalid(LEggPPUp, Egg)); if (pkm.Move1_PP != pkm.GetMovePP(pkm.Move1, 0) || pkm.Move2_PP != pkm.GetMovePP(pkm.Move2, 0) || pkm.Move3_PP != pkm.GetMovePP(pkm.Move3, 0) || pkm.Move4_PP != pkm.GetMovePP(pkm.Move4, 0)) - data.AddLine(GetInvalid(LEggPP, CheckIdentifier.Egg)); + data.AddLine(GetInvalid(LEggPP, Egg)); var EncounterMatch = data.EncounterOriginal; var HatchCycles = (EncounterMatch as EncounterStatic)?.EggCycles; if (HatchCycles == 0 || HatchCycles == null) HatchCycles = pkm.PersonalInfo.HatchCycles; if (pkm.CurrentFriendship > HatchCycles) - data.AddLine(GetInvalid(LEggHatchCycles, CheckIdentifier.Egg)); + data.AddLine(GetInvalid(LEggHatchCycles, Egg)); if (pkm.Format >= 6 && EncounterMatch is EncounterEgg && !pkm.Moves.SequenceEqual(pkm.RelearnMoves)) { var moves = string.Join(", ", LegalityAnalysis.GetMoveNames(pkm.Moves)); var msg = string.Format(LMoveFExpect_0, moves); - data.AddLine(GetInvalid(msg, CheckIdentifier.Egg)); + data.AddLine(GetInvalid(msg, Egg)); } } @@ -206,12 +207,12 @@ private static void VerifyFatefulMysteryGift(LegalityAnalysis data, MysteryGift var Info = data.Info; Info.PIDIV = MethodFinder.Analyze(pkm); if (Info.PIDIV.Type != PIDType.G5MGShiny && pkm.Egg_Location != Locations.LinkTrade5) - data.AddLine(GetInvalid(LPIDTypeMismatch, CheckIdentifier.PID)); + data.AddLine(GetInvalid(LPIDTypeMismatch, PID)); } var result = pkm.FatefulEncounter != pkm.WasLink - ? GetValid(LFatefulMystery, CheckIdentifier.Fateful) - : GetInvalid(LFatefulMysteryMissing, CheckIdentifier.Fateful); + ? GetValid(LFatefulMystery, Fateful) + : GetInvalid(LFatefulMysteryMissing, Fateful); data.AddLine(result); } @@ -222,13 +223,13 @@ private static void VerifyReceivability(LegalityAnalysis data, MysteryGift g) { case WC6 wc6 when !wc6.CanBeReceivedByVersion(pkm.Version) && !pkm.WasTradedEgg: case WC7 wc7 when !wc7.CanBeReceivedByVersion(pkm.Version) && !pkm.WasTradedEgg: - data.AddLine(GetInvalid(LEncGiftVersionNotDistributed, CheckIdentifier.GameOrigin)); + data.AddLine(GetInvalid(LEncGiftVersionNotDistributed, GameOrigin)); return; case WC6 wc6 when wc6.RestrictLanguage != 0 && wc6.Language != wc6.RestrictLanguage: - data.AddLine(GetInvalid(string.Format(LOTLanguage, wc6.RestrictLanguage, pkm.Language), CheckIdentifier.Language)); + data.AddLine(GetInvalid(string.Format(LOTLanguage, wc6.RestrictLanguage, pkm.Language), Language)); return; case WC7 wc7 when wc7.RestrictLanguage != 0 && wc7.Language != wc7.RestrictLanguage: - data.AddLine(GetInvalid(string.Format(LOTLanguage, wc7.RestrictLanguage, pkm.Language), CheckIdentifier.Language)); + data.AddLine(GetInvalid(string.Format(LOTLanguage, wc7.RestrictLanguage, pkm.Language), Language)); return; } } @@ -237,7 +238,7 @@ private static void VerifyWC3Shiny(LegalityAnalysis data, WC3 g3) { // check for shiny locked gifts if (!g3.Shiny.IsValid(data.pkm)) - data.AddLine(GetInvalid(LEncGiftShinyMismatch, CheckIdentifier.Fateful)); + data.AddLine(GetInvalid(LEncGiftShinyMismatch, Fateful)); } private static void VerifyFatefulIngameActive(LegalityAnalysis data) @@ -247,14 +248,14 @@ private static void VerifyFatefulIngameActive(LegalityAnalysis data) { // can't have fateful until traded away, which clears ShadowID if (xk3.FatefulEncounter && xk3.ShadowID != 0 && data.EncounterMatch is EncounterStaticShadow) - data.AddLine(GetInvalid(LFatefulInvalid, CheckIdentifier.Fateful)); + data.AddLine(GetInvalid(LFatefulInvalid, Fateful)); return; // fateful is set when transferred away } var result = pkm.FatefulEncounter - ? GetValid(LFateful, CheckIdentifier.Fateful) - : GetInvalid(LFatefulMissing, CheckIdentifier.Fateful); + ? GetValid(LFateful, Fateful) + : GetInvalid(LFatefulMissing, Fateful); data.AddLine(result); } @@ -273,7 +274,7 @@ public void VerifyVersionEvolution(LegalityAnalysis data) bool Sun() => pkm.Version == (int)GameVersion.SN || pkm.Version == (int)GameVersion.US; bool Moon() => pkm.Version == (int)GameVersion.MN || pkm.Version == (int)GameVersion.UM; if (pkm.IsUntraded) - data.AddLine(GetInvalid(LEvoTradeRequired, CheckIdentifier.Evolution)); + data.AddLine(GetInvalid(LEvoTradeRequired, Evolution)); break; } } @@ -282,18 +283,18 @@ private static void VerifyBelugaStats(LegalityAnalysis data, PB7 pb7) { // ReSharper disable once CompareOfFloatsByEqualityOperator -- THESE MUST MATCH EXACTLY if (!IsCloseEnough(pb7.HeightAbsolute, pb7.CalcHeightAbsolute)) - data.AddLine(GetInvalid(LStatIncorrectHeight, CheckIdentifier.Encounter)); + data.AddLine(GetInvalid(LStatIncorrectHeight, Encounter)); // ReSharper disable once CompareOfFloatsByEqualityOperator -- THESE MUST MATCH EXACTLY if (!IsCloseEnough(pb7.WeightAbsolute, pb7.CalcWeightAbsolute)) - data.AddLine(GetInvalid(LStatIncorrectWeight, CheckIdentifier.Encounter)); + data.AddLine(GetInvalid(LStatIncorrectWeight, Encounter)); if (pb7.Stat_CP != pb7.CalcCP && !IsStarter(pb7)) - data.AddLine(GetInvalid(LStatIncorrectCP, CheckIdentifier.Encounter)); + data.AddLine(GetInvalid(LStatIncorrectCP, Encounter)); if (IsTradeEvoRequired7b(data.EncounterOriginal, pb7)) { var unevolved = LegalityAnalysis.SpeciesStrings[pb7.Species]; var evolved = LegalityAnalysis.SpeciesStrings[pb7.Species + 1]; - data.AddLine(GetInvalid(string.Format(LEvoTradeReqOutsider, unevolved, evolved), CheckIdentifier.Evolution)); + data.AddLine(GetInvalid(string.Format(LEvoTradeReqOutsider, unevolved, evolved), Evolution)); } } diff --git a/PKHeX.Core/Legality/VivillonTables.cs b/PKHeX.Core/Legality/VivillonTables.cs index 49a1d6e92..404602e8a 100644 --- a/PKHeX.Core/Legality/VivillonTables.cs +++ b/PKHeX.Core/Legality/VivillonTables.cs @@ -6,17 +6,17 @@ namespace PKHeX.Core { public static partial class Legal { - private struct CountryTable + private class CountryTable { - public byte countryID; - public byte mainform; - public FormSubregionTable[] otherforms; + public byte CountryID; + public byte BaseForm; + public FormSubregionTable[] SubRegionForms; } - private struct FormSubregionTable + private class FormSubregionTable { - public byte form; - public int[] region; + public byte Form; + public int[] Regions; } private static readonly int[][] VivillonCountryTable = @@ -45,204 +45,204 @@ private struct FormSubregionTable private static readonly CountryTable[] RegionFormTable = { new CountryTable{ - countryID = 001, // Japan - mainform = 05, // Elegant - otherforms = new[] + CountryID = 001, // Japan + BaseForm = 05, // Elegant + SubRegionForms = new[] { - new FormSubregionTable { form = 02, region = new[] {03,04} }, - new FormSubregionTable { form = 13, region = new[] {48} }, + new FormSubregionTable { Form = 02, Regions = new[] {03,04} }, + new FormSubregionTable { Form = 13, Regions = new[] {48} }, } }, new CountryTable{ - countryID = 049, // USA - mainform = 07, // Modern - otherforms = new[] + CountryID = 049, // USA + BaseForm = 07, // Modern + SubRegionForms = new[] { - new FormSubregionTable { form = 01, region = new[] {03,09,21,23,24,32,33,36,40,41,48,50} }, - new FormSubregionTable { form = 09, region = new[] {53} }, - new FormSubregionTable { form = 10, region = new[] {06,07,08,15,28,34,35,39,46,49} }, + new FormSubregionTable { Form = 01, Regions = new[] {03,09,21,23,24,32,33,36,40,41,48,50} }, + new FormSubregionTable { Form = 09, Regions = new[] {53} }, + new FormSubregionTable { Form = 10, Regions = new[] {06,07,08,15,28,34,35,39,46,49} }, } }, new CountryTable{ - countryID = 018, // Canada - mainform = 01, // Polar - otherforms = new[] + CountryID = 018, // Canada + BaseForm = 01, // Polar + SubRegionForms = new[] { - new FormSubregionTable { form = 00, region = new[] {12,13,14} }, - new FormSubregionTable { form = 07, region = new[] {05} }, - new FormSubregionTable { form = 10, region = new[] {04} }, + new FormSubregionTable { Form = 00, Regions = new[] {12,13,14} }, + new FormSubregionTable { Form = 07, Regions = new[] {05} }, + new FormSubregionTable { Form = 10, Regions = new[] {04} }, } }, new CountryTable{ - countryID = 016, // Brazil - mainform = 14, // Savanna - otherforms = new[] + CountryID = 016, // Brazil + BaseForm = 14, // Savanna + SubRegionForms = new[] { - new FormSubregionTable { form = 17, region = new[] {03,06} }, + new FormSubregionTable { Form = 17, Regions = new[] {03,06} }, } }, new CountryTable{ - countryID = 010, // Argentina - mainform = 14, // Savanna - otherforms = new[] + CountryID = 010, // Argentina + BaseForm = 14, // Savanna + SubRegionForms = new[] { - new FormSubregionTable { form = 01, region = new[] {21,24} }, - new FormSubregionTable { form = 03, region = new[] {16} }, + new FormSubregionTable { Form = 01, Regions = new[] {21,24} }, + new FormSubregionTable { Form = 03, Regions = new[] {16} }, } }, new CountryTable{ - countryID = 020, // Chile - mainform = 08, // Marine - otherforms = new[] + CountryID = 020, // Chile + BaseForm = 08, // Marine + SubRegionForms = new[] { - new FormSubregionTable { form = 01, region = new[] {12} }, + new FormSubregionTable { Form = 01, Regions = new[] {12} }, } }, new CountryTable{ - countryID = 036, // Mexico - mainform = 15, // Sun - otherforms = new[] + CountryID = 036, // Mexico + BaseForm = 15, // Sun + SubRegionForms = new[] { - new FormSubregionTable { form = 09, region = new[] {32} }, - new FormSubregionTable { form = 10, region = new[] {04,08,09,12,15,19,20,23,26,27,29} }, + new FormSubregionTable { Form = 09, Regions = new[] {32} }, + new FormSubregionTable { Form = 10, Regions = new[] {04,08,09,12,15,19,20,23,26,27,29} }, } }, new CountryTable{ - countryID = 052, // Venezuela - mainform = 09, // Archipelago - otherforms = new[] + CountryID = 052, // Venezuela + BaseForm = 09, // Archipelago + SubRegionForms = new[] { - new FormSubregionTable { form = 17, region = new[] {17} }, + new FormSubregionTable { Form = 17, Regions = new[] {17} }, } }, new CountryTable{ - countryID = 065, // Australia - mainform = 09, // River - otherforms = new[] + CountryID = 065, // Australia + BaseForm = 09, // River + SubRegionForms = new[] { - new FormSubregionTable { form = 04, region = new[] {07} }, - new FormSubregionTable { form = 15, region = new[] {04} }, + new FormSubregionTable { Form = 04, Regions = new[] {07} }, + new FormSubregionTable { Form = 15, Regions = new[] {04} }, } }, new CountryTable{ - countryID = 066, // Austria - mainform = 08, // Marine - otherforms = new[] + CountryID = 066, // Austria + BaseForm = 08, // Marine + SubRegionForms = new[] { - new FormSubregionTable { form = 06, region = new[] {10} }, + new FormSubregionTable { Form = 06, Regions = new[] {10} }, } }, new CountryTable{ - countryID = 073, // Czecg Republic - mainform = 08, // Marine - otherforms = new[] + CountryID = 073, // Czecg Republic + BaseForm = 08, // Marine + SubRegionForms = new[] { - new FormSubregionTable { form = 03, region = new[] {03} }, + new FormSubregionTable { Form = 03, Regions = new[] {03} }, } }, new CountryTable{ - countryID = 076, // Finland - mainform = 00, // Icy Snow - otherforms = new[] + CountryID = 076, // Finland + BaseForm = 00, // Icy Snow + SubRegionForms = new[] { - new FormSubregionTable { form = 01, region = new[] {27} }, + new FormSubregionTable { Form = 01, Regions = new[] {27} }, } }, new CountryTable{ - countryID = 077, // France - mainform = 06, // Meadow - otherforms = new[] + CountryID = 077, // France + BaseForm = 06, // Meadow + SubRegionForms = new[] { - new FormSubregionTable { form = 03, region = new[] {18} }, - new FormSubregionTable { form = 08, region = new[] {04,06,08,19} }, - new FormSubregionTable { form = 16, region = new[] {27} }, + new FormSubregionTable { Form = 03, Regions = new[] {18} }, + new FormSubregionTable { Form = 08, Regions = new[] {04,06,08,19} }, + new FormSubregionTable { Form = 16, Regions = new[] {27} }, } }, new CountryTable{ - countryID = 078, // Germany - mainform = 03, // Continental - otherforms = new[] + CountryID = 078, // Germany + BaseForm = 03, // Continental + SubRegionForms = new[] { - new FormSubregionTable { form = 06, region = new[] {04,13} }, - new FormSubregionTable { form = 08, region = new[] {05} }, + new FormSubregionTable { Form = 06, Regions = new[] {04,13} }, + new FormSubregionTable { Form = 08, Regions = new[] {05} }, } }, new CountryTable{ - countryID = 078, // Italy - mainform = 08, // Marine - otherforms = new[] + CountryID = 078, // Italy + BaseForm = 08, // Marine + SubRegionForms = new[] { - new FormSubregionTable { form = 06, region = new[] {04,06} }, + new FormSubregionTable { Form = 06, Regions = new[] {04,06} }, } }, new CountryTable{ - countryID = 085, // Lesotho - mainform = 09, // Archipelago ?? - otherforms = new[] + CountryID = 085, // Lesotho + BaseForm = 09, // Archipelago ?? + SubRegionForms = new[] { - new FormSubregionTable { form = 12, region = new[] {04} }, + new FormSubregionTable { Form = 12, Regions = new[] {04} }, } }, new CountryTable{ - countryID = 096, // Norway - mainform = 03, // Continental ?? - otherforms = new[] + CountryID = 096, // Norway + BaseForm = 03, // Continental ?? + SubRegionForms = new[] { - new FormSubregionTable { form = 00, region = new[] {11} }, - new FormSubregionTable { form = 01, region = new[] {12,15,16,17,20,22} }, - new FormSubregionTable { form = 02, region = new[] {13,14} }, + new FormSubregionTable { Form = 00, Regions = new[] {11} }, + new FormSubregionTable { Form = 01, Regions = new[] {12,15,16,17,20,22} }, + new FormSubregionTable { Form = 02, Regions = new[] {13,14} }, } }, new CountryTable{ - countryID = 097, // Poland - mainform = 03, // Continental - otherforms = new[] + CountryID = 097, // Poland + BaseForm = 03, // Continental + SubRegionForms = new[] { - new FormSubregionTable { form = 04, region = new[] {11} }, + new FormSubregionTable { Form = 04, Regions = new[] {11} }, } }, new CountryTable{ - countryID = 100, // Russia - mainform = 01, // Polar - otherforms = new[] + CountryID = 100, // Russia + BaseForm = 01, // Polar + SubRegionForms = new[] { - new FormSubregionTable { form = 00, region = new[] {14,22,34,38,40,52,66,88} }, - new FormSubregionTable { form = 03, region = new[] {29,46,51,69} }, - new FormSubregionTable { form = 10, region = new[] {20,24,25,28,33,71,73} }, + new FormSubregionTable { Form = 00, Regions = new[] {14,22,34,38,40,52,66,88} }, + new FormSubregionTable { Form = 03, Regions = new[] {29,46,51,69} }, + new FormSubregionTable { Form = 10, Regions = new[] {20,24,25,28,33,71,73} }, } }, new CountryTable{ - countryID = 104, //South Africa - mainform = 12, // River ?? - otherforms = new[] + CountryID = 104, //South Africa + BaseForm = 12, // River ?? + SubRegionForms = new[] { - new FormSubregionTable { form = 03, region = new[] {03,05} }, + new FormSubregionTable { Form = 03, Regions = new[] {03,05} }, } }, new CountryTable{ - countryID = 105, // Spain - mainform = 08, // Marine - otherforms = new[] + CountryID = 105, // Spain + BaseForm = 08, // Marine + SubRegionForms = new[] { - new FormSubregionTable { form = 06, region = new[] {11} }, - new FormSubregionTable { form = 12, region = new[] {07} }, + new FormSubregionTable { Form = 06, Regions = new[] {11} }, + new FormSubregionTable { Form = 12, Regions = new[] {07} }, } }, new CountryTable{ - countryID = 107, // Sweden - mainform = 03, // Continental - otherforms = new[] + CountryID = 107, // Sweden + BaseForm = 03, // Continental + SubRegionForms = new[] { - new FormSubregionTable { form = 00, region = new[] {11,21} }, - new FormSubregionTable { form = 01, region = new[] {09,13} }, + new FormSubregionTable { Form = 00, Regions = new[] {11,21} }, + new FormSubregionTable { Form = 01, Regions = new[] {09,13} }, } }, new CountryTable{ - countryID = 169, // India - mainform = 13, // Monsoon ?? - otherforms = new[] + CountryID = 169, // India + BaseForm = 13, // Monsoon ?? + SubRegionForms = new[] { - new FormSubregionTable { form = 17, region = new[] {12} }, + new FormSubregionTable { Form = 17, Regions = new[] {12} }, } }, }; @@ -259,14 +259,14 @@ public static bool CheckVivillonPattern(int form, int country, int region) if (!VivillonCountryTable[form].Contains(country)) return false; // Country mismatch - var ct = Array.Find(RegionFormTable, t => t.countryID == country); - if (ct.otherforms == null) // empty struct = no forms referenced + var ct = Array.Find(RegionFormTable, t => t.CountryID == country); + if (ct.SubRegionForms == null) // empty struct = no forms referenced return true; // No subregion table - if (ct.mainform == form) - return !ct.otherforms.Any(e => e.region.Contains(region)); //true if Mainform not in other specific region + if (ct.BaseForm == form) + return !ct.SubRegionForms.Any(e => e.Regions.Contains(region)); //true if Mainform not in other specific region - return ct.otherforms.Any(e => e.form == form && e.region.Contains(region)); + return ct.SubRegionForms.Any(e => e.Form == form && e.Regions.Contains(region)); } /// @@ -276,17 +276,17 @@ public static bool CheckVivillonPattern(int form, int country, int region) /// Console Region ID public static int GetVivillonPattern(int country, int region) { - var ct = Array.Find(RegionFormTable, t => t.countryID == country); - if (ct.otherforms == null) // empty struct = no forms referenced - return ct.mainform; // No subregion table + var ct = Array.Find(RegionFormTable, t => t.CountryID == country); + if (ct.SubRegionForms == null) // empty struct = no forms referenced + return ct.BaseForm; // No subregion table - foreach (var sub in ct.otherforms) + foreach (var sub in ct.SubRegionForms) { - if (sub.region.Contains(region)) - return sub.form; + if (sub.Regions.Contains(region)) + return sub.Form; } - return ct.mainform; + return ct.BaseForm; } /// diff --git a/PKHeX.Core/Saves/Substructures/Inventory/InventoryItem.cs b/PKHeX.Core/Saves/Substructures/Inventory/InventoryItem.cs index 95306958a..fd86f0479 100644 --- a/PKHeX.Core/Saves/Substructures/Inventory/InventoryItem.cs +++ b/PKHeX.Core/Saves/Substructures/Inventory/InventoryItem.cs @@ -1,4 +1,4 @@ -using System.Linq; +using System.Collections.Generic; namespace PKHeX.Core { @@ -10,7 +10,7 @@ public class InventoryItem public InventoryItem Clone() => (InventoryItem) MemberwiseClone(); // Check Pouch Compatibility - public bool Valid(ushort[] LegalItems, bool HaX, int MaxItemID) + public bool Valid(IList LegalItems, bool HaX, int MaxItemID) { if (Index == 0) return true;