diff --git a/PKHeX/Legality/Checks.cs b/PKHeX/Legality/Checks.cs index ecae506e4..615b1df7a 100644 --- a/PKHeX/Legality/Checks.cs +++ b/PKHeX/Legality/Checks.cs @@ -72,8 +72,7 @@ namespace PKHeX.Core private void verifyItem() { - var unreleasedItems = Legal.getUnreleasedItems(pkm.Format); - if (unreleasedItems.Contains(pkm.HeldItem)) + if (!Legal.getHeldItemAllowed(pkm.Format, pkm.HeldItem)) AddLine(Severity.Invalid, "Held item is unreleased.", CheckIdentifier.Form); } diff --git a/PKHeX/Legality/Core.cs b/PKHeX/Legality/Core.cs index c61770c24..c18170507 100644 --- a/PKHeX/Legality/Core.cs +++ b/PKHeX/Legality/Core.cs @@ -656,6 +656,30 @@ namespace PKHeX.Core } } + internal static bool[] getReleasedHeldItems(int generation) + { + switch (generation) + { + case 2: return ReleasedHeldItems_2; + case 3: return ReleasedHeldItems_3; + case 4: return ReleasedHeldItems_4; + case 5: return ReleasedHeldItems_5; + case 6: return ReleasedHeldItems_6; + case 7: return ReleasedHeldItems_7; + default: return new bool[0]; + } + } + internal static bool getHeldItemAllowed(int generation, int item) + { + if (item < 0) + return false; + if (item == 0) + return true; + + var items = getReleasedHeldItems(generation); + return items.Length > item && items[item]; + } + internal static bool getDexNavValid(PKM pkm) { if (!pkm.AO || !pkm.InhabitedGeneration(6)) @@ -1493,14 +1517,5 @@ namespace PKHeX.Core // No tutors in G7 return moves.Distinct(); } - - public static int[] getUnreleasedItems(int generation) - { - switch (generation) - { - case 7: return UnreleasedItems_7; - default: return new int[0]; - } - } } } diff --git a/PKHeX/Legality/Tables2.cs b/PKHeX/Legality/Tables2.cs index 41f235172..ee87a02c2 100644 --- a/PKHeX/Legality/Tables2.cs +++ b/PKHeX/Legality/Tables2.cs @@ -59,5 +59,10 @@ namespace PKHeX.Core { // todo }; + internal static readonly int[] UnreleasedItems_2 = + { + // todo + }; + internal static readonly bool[] ReleasedHeldItems_2 = Enumerable.Range(1, MaxItemID_2).Select(i => HeldItems_GSC.Contains((ushort)i) && !UnreleasedItems_2.Contains(i)).ToArray(); } } diff --git a/PKHeX/Legality/Tables3.cs b/PKHeX/Legality/Tables3.cs index d661b701f..7dc734dfb 100644 --- a/PKHeX/Legality/Tables3.cs +++ b/PKHeX/Legality/Tables3.cs @@ -94,5 +94,10 @@ namespace PKHeX.Core }; // Ambipom Weavile Magnezone Lickilicky Tangrowth // Yanmega Leafeon Glaceon Mamoswine Gliscor Probopass + internal static readonly int[] UnreleasedItems_3 = + { + // todo + }; + internal static readonly bool[] ReleasedHeldItems_3 = Enumerable.Range(1, MaxItemID_3).Select(i => HeldItems_RS.Contains((ushort)i) && !UnreleasedItems_3.Contains(i)).ToArray(); } } diff --git a/PKHeX/Legality/Tables4.cs b/PKHeX/Legality/Tables4.cs index 83f1a9f6f..262629038 100644 --- a/PKHeX/Legality/Tables4.cs +++ b/PKHeX/Legality/Tables4.cs @@ -135,5 +135,10 @@ namespace PKHeX.Core { 700 }; + internal static readonly int[] UnreleasedItems_4 = + { + // todo + }; + internal static readonly bool[] ReleasedHeldItems_4 = Enumerable.Range(1, MaxItemID_4_HGSS).Select(i => HeldItems_HGSS.Contains((ushort)i) && !UnreleasedItems_4.Contains(i)).ToArray(); } } diff --git a/PKHeX/Legality/Tables5.cs b/PKHeX/Legality/Tables5.cs index 723d65860..244a62684 100644 --- a/PKHeX/Legality/Tables5.cs +++ b/PKHeX/Legality/Tables5.cs @@ -94,5 +94,10 @@ namespace PKHeX.Core { 700 }; + internal static readonly int[] UnreleasedItems_5 = + { + // todo + }; + internal static readonly bool[] ReleasedHeldItems_5 = Enumerable.Range(1, MaxItemID_5_B2W2).Select(i => HeldItems_BW.Contains((ushort)i) && !UnreleasedItems_5.Contains(i)).ToArray(); } } diff --git a/PKHeX/Legality/Tables6.cs b/PKHeX/Legality/Tables6.cs index c524618a9..5b4e32203 100644 --- a/PKHeX/Legality/Tables6.cs +++ b/PKHeX/Legality/Tables6.cs @@ -762,5 +762,10 @@ namespace PKHeX.Core 05, 10, 05, 05, 15, 10, 05, 05, 05, 10, 10, 10, 10, 20, 25, 10, 20, 30, 25, 20, 20, 15, 20, 15, 20, 20, 10, 10, 10, 10, 10, 20, 10, 30, 15, 10, 10, 10, 20, 20, 05, 05, 05, 20, 10, 10, 20, 15, 20, 20, 10, 20, 30, 10, 10, 40, 40, 30, 20, 40, 20, 20, 10, 10, 10, 10, 05, 10, 10, 05, 05, }; + internal static readonly int[] UnreleasedItems_6 = + { + // todo + }; + internal static readonly bool[] ReleasedHeldItems_6 = Enumerable.Range(0, MaxItemID_6_AO).Select(i => HeldItem_AO.Contains((ushort)i) && !UnreleasedItems_6.Contains(i)).ToArray(); } } diff --git a/PKHeX/Legality/Tables7.cs b/PKHeX/Legality/Tables7.cs index ed4cb26ca..5d9ced110 100644 --- a/PKHeX/Legality/Tables7.cs +++ b/PKHeX/Legality/Tables7.cs @@ -1252,7 +1252,7 @@ namespace PKHeX.Core #endregion #region Unreleased Items - internal static readonly int[] UnreleasedItems_7 = + internal static readonly int[] UnreleasedHeldItems_7 = { 016, // Cherish Ball 064, // Fluffy Tail @@ -1342,5 +1342,6 @@ namespace PKHeX.Core 836, // Pikashunium Z }; #endregion + internal static readonly bool[] ReleasedHeldItems_7 = Enumerable.Range(1, MaxItemID_7).Select(i => HeldItems_SM.Contains((ushort)i) && !UnreleasedHeldItems_7.Contains(i)).ToArray(); } }