diff --git a/PKHeX/Legality/Analysis.cs b/PKHeX/Legality/Analysis.cs index a715680f7..cf9f59b36 100644 --- a/PKHeX/Legality/Analysis.cs +++ b/PKHeX/Legality/Analysis.cs @@ -203,7 +203,6 @@ private void updateChecks() verifyRibbons(); verifyAbility(); verifyBall(); - verifyRegion(); verifyForm(); verifyMisc(); verifyGender(); @@ -217,8 +216,9 @@ private void updateChecks() verifyHTMemory(); verifyHyperTraining(); verifyMedals(); + verifyRegion(); } - if (pkm.GenNumber < 5 || pkm.VC) + if (pkm.GenNumber < 5) verifyEggMoves(); verifyVersionEvolution(); diff --git a/PKHeX/Legality/Checks.cs b/PKHeX/Legality/Checks.cs index ce5f0c63d..477949b9e 100644 --- a/PKHeX/Legality/Checks.cs +++ b/PKHeX/Legality/Checks.cs @@ -1924,6 +1924,16 @@ private void verifyMisc() } if (pkm.FatefulEncounter) AddLine(Severity.Invalid, "Fateful Encounter should not be checked.", CheckIdentifier.Fateful); + if (pkm.Format == 5) + { + var enc = EncounterMatch as EncounterStatic; + bool req = enc?.NSparkle ?? false; + bool has = ((PK5) pkm).NPokémon; + if (req && !has) + AddLine(Severity.Invalid, "Special ingame N's Sparkle flag missing.", CheckIdentifier.Fateful); + if (!req && has) + AddLine(Severity.Invalid, "Special ingame N's Sparkle flag should not be checked.", CheckIdentifier.Fateful); + } } } private void verifyVersionEvolution() diff --git a/PKHeX/Legality/Core.cs b/PKHeX/Legality/Core.cs index 3f78a24b8..6731fa0cd 100644 --- a/PKHeX/Legality/Core.cs +++ b/PKHeX/Legality/Core.cs @@ -173,8 +173,7 @@ private static void MarkG3Slots_FRLG(ref EncounterArea[] Areas) Areas = Areas.Where(a => (a.Location < 188 || a.Location > 194)). GroupBy(a => a.Location). Select(a => - new EncounterArea() - { Location = a.First().Location, Slots = a.SelectMany(m => m.Slots).ToArray() }). + new EncounterArea { Location = a.First().Location, Slots = a.SelectMany(m => m.Slots).ToArray() }). ToArray(); } @@ -183,8 +182,7 @@ private static void MarkG3Slots_RSE(ref EncounterArea[] Areas) // Group areas by location id, the raw data have areas with different slots but the same location id Areas = Areas.GroupBy(a => a.Location). Select(a => - new EncounterArea() - { Location = a.First().Location, Slots = a.SelectMany(m => m.Slots).ToArray() }). + new EncounterArea { Location = a.First().Location, Slots = a.SelectMany(m => m.Slots).ToArray() }). ToArray(); } private static void MarkG4Slots(ref EncounterArea[] Areas) @@ -192,8 +190,7 @@ private static void MarkG4Slots(ref EncounterArea[] Areas) // Group areas by location id, the raw data have areas with different slots but the same location id Areas = Areas.GroupBy(a => a.Location). Select(a => - new EncounterArea() - { Location = a.First().Location, Slots = a.SelectMany(m => m.Slots).ToArray() }). + new EncounterArea { Location = a.First().Location, Slots = a.SelectMany(m => m.Slots).ToArray() }). ToArray(); } private static void MarkG5Slots(ref EncounterArea[] Areas) @@ -229,8 +226,7 @@ private static void MarkG5Slots(ref EncounterArea[] Areas) // Group areas by location id, the raw data have areas with different slots but the same location id Areas = Areas.GroupBy(a => a.Location). Select(a => - new EncounterArea() - { Location = a.First().Location, Slots = a.SelectMany(m => m.Slots).ToArray() }). + new EncounterArea { Location = a.First().Location, Slots = a.SelectMany(m => m.Slots).ToArray() }). ToArray(); } private static void MarkG6XYSlots(ref EncounterArea[] Areas) diff --git a/PKHeX/Legality/Structures/EncounterArea.cs b/PKHeX/Legality/Structures/EncounterArea.cs index 9c18d50ec..4ed23fea3 100644 --- a/PKHeX/Legality/Structures/EncounterArea.cs +++ b/PKHeX/Legality/Structures/EncounterArea.cs @@ -259,7 +259,7 @@ private static IEnumerable getSlots3(byte[] data, ref int ofs, in int levelmax = data[ofs + 3 + i * 4]; int Species = PKX.getG4Species(BitConverter.ToUInt16(data, ofs + 4 + i * 4)); if (Species > 0) - slots.Add(new EncounterSlot() + slots.Add(new EncounterSlot { LevelMin = levelmin, LevelMax = levelmax, @@ -285,7 +285,7 @@ private static IEnumerable getSlots3_F(byte[] data, ref int ofs, int levelmax = data[ofs + 3 + i * 4]; int Species = PKX.getG4Species(BitConverter.ToUInt16(data, ofs + 4 + i * 4)); if (Species > 0) - slots.Add(new EncounterSlot() + slots.Add(new EncounterSlot { LevelMin = levelmin, LevelMax = levelmax, @@ -304,13 +304,9 @@ private static EncounterSlot[] getSlots4_DPPt_G(byte[] data, ref int ofs, int nu for (int i = 0; i < numslots; i++) { - int levelmin = data[ofs + 2 + i * 4]; - int levelmax = data[ofs + 3 + i * 4]; - int Species = BitConverter.ToUInt16(data, ofs + 4 + i * 4); - int level = (int)BitConverter.ToUInt32(data, ofs + i * 8); int species = (int)BitConverter.ToUInt32(data, ofs + i * 8); - slots[i] = new EncounterSlot() + slots[i] = new EncounterSlot { LevelMax = level, LevelMin = level, @@ -331,7 +327,7 @@ private static EncounterSlot[] getSlots4_HGSS_G(byte[] data, ref int ofs, int nu { int level = data[ofs + i]; int species = BitConverter.ToUInt16(data, ofs + numslots + i * 2); - slots[i] = new EncounterSlot() + slots[i] = new EncounterSlot { LevelMin = level, LevelMax = level, @@ -342,13 +338,13 @@ private static EncounterSlot[] getSlots4_HGSS_G(byte[] data, ref int ofs, int nu for (int i = 0; i < numslots; i++) { slots[numslots + i] = slots[i].Clone(); - slots[numslots + i].Species = (int)BitConverter.ToUInt16(data, ofs + numslots * 3 + i * 2); + slots[numslots + i].Species = BitConverter.ToUInt16(data, ofs + numslots * 3 + i * 2); slots[numslots + i].Type = t; } for (int i = 0; i < numslots; i++) { slots[numslots * 2 + i] = slots[i].Clone(); - slots[numslots * 2 + i].Species = (int)BitConverter.ToUInt16(data, ofs + numslots * 5 + i * 2); + slots[numslots * 2 + i].Species = BitConverter.ToUInt16(data, ofs + numslots * 5 + i * 2); slots[numslots * 2 + i].Type = t; } @@ -443,7 +439,7 @@ private static IEnumerable getSlots4DPPt_WFR(byte[] data, ref int //2 bytes padding int Species = (int)BitConverter.ToUInt32(data, ofs + 4 + i * 8); if (Species > 0) - slots.Add(new EncounterSlot() + slots.Add(new EncounterSlot { LevelMin = levelmin, LevelMax = levelmax, @@ -462,9 +458,9 @@ private static IEnumerable getSlots4HGSS_WFR(byte[] data, ref int { int levelmin = data[ofs + 0 + i * 4]; int levelmax = data[ofs + 1 + i * 4]; - int Species = (int)BitConverter.ToUInt16(data, ofs + 2 + i * 4); + int Species = BitConverter.ToUInt16(data, ofs + 2 + i * 4); if (Species > 0) - slots.Add(new EncounterSlot() + slots.Add(new EncounterSlot { LevelMin = levelmin, LevelMax = levelmax, @@ -480,19 +476,15 @@ private static IEnumerable getSlots4HGSS_WFR(byte[] data, ref int private static EncounterArea getArea3(byte[] data) { EncounterArea Area3 = new EncounterArea(); - bool HaveGrassSlots = false; - bool HaveSurfSlots = false; - bool HaveRockSmashSlots = false; - bool HaveFishingSlots = false; - + if (data.Length < 6) { Area3.Location = 0; Area3.Slots = new EncounterSlot[0]; return Area3; } Area3.Location = data[0]; - HaveGrassSlots = data[1] == 1; - HaveSurfSlots = data[2] == 1; - HaveRockSmashSlots = data[3] == 1; - HaveFishingSlots = data[4] == 1; + var HaveGrassSlots = data[1] == 1; + var HaveSurfSlots = data[2] == 1; + var HaveRockSmashSlots = data[3] == 1; + var HaveFishingSlots = data[4] == 1; int offset = 5; var slots = new List(); @@ -510,12 +502,6 @@ private static EncounterArea getArea3(byte[] data) private static EncounterArea getArea4DPPt(byte[] data) { - int ofs = 0; - int GrassRatio = 0; - int SurfRatio = 0; - int OldRodRatio = 0; - int GoodRodRatio = 0; - int SuperRodRatio = 0; EncounterArea Area4 = new EncounterArea(); if (data.Length != 426) { Area4.Location = 0; Area4.Slots = new EncounterSlot[0]; return Area4; } @@ -523,8 +509,8 @@ private static EncounterArea getArea4DPPt(byte[] data) var Slots = new List(); Area4.Location = BitConverter.ToUInt16(data, 0); - GrassRatio = (int)BitConverter.ToUInt32(data, 2); - ofs = 6; + var GrassRatio = (int)BitConverter.ToUInt32(data, 2); + var ofs = 6; if (GrassRatio > 0) { EncounterSlot[] GrassSlots = getSlots4_DPPt_G(data, ref ofs, 12, SlotType.Grass); @@ -545,7 +531,7 @@ private static EncounterArea getArea4DPPt(byte[] data) else ofs = 206; - SurfRatio = (int)BitConverter.ToUInt32(data, ofs); + var SurfRatio = (int)BitConverter.ToUInt32(data, ofs); ofs += 4; if (SurfRatio > 0) Slots.AddRange(getSlots4DPPt_WFR(data, ref ofs, 5, SlotType.Surf)); @@ -553,21 +539,21 @@ private static EncounterArea getArea4DPPt(byte[] data) ofs += 40; ofs += 44; //44 bytes padding - OldRodRatio = (int)BitConverter.ToUInt32(data, 294); + var OldRodRatio = (int)BitConverter.ToUInt32(data, 294); ofs += 4; if (OldRodRatio > 0) Slots.AddRange(getSlots4DPPt_WFR(data, ref ofs, 5, SlotType.Old_Rod)); else ofs += 40; - GoodRodRatio = (int)BitConverter.ToUInt32(data, 338); + var GoodRodRatio = (int)BitConverter.ToUInt32(data, 338); ofs += 4; if (GoodRodRatio > 0) Slots.AddRange(getSlots4DPPt_WFR(data, ref ofs, 5, SlotType.Good_Rod)); else ofs += 40; - SuperRodRatio = (int)BitConverter.ToUInt32(data, 382); + var SuperRodRatio = (int)BitConverter.ToUInt32(data, 382); ofs += 4; if (SuperRodRatio > 0) Slots.AddRange(getSlots4DPPt_WFR(data, ref ofs, 5, SlotType.Super_Rod)); @@ -580,12 +566,6 @@ private static EncounterArea getArea4DPPt(byte[] data) private static EncounterArea getArea4HGSS(byte[] data) { - int GrassRatio = 0; - int SurfRatio = 0; - int OldRodRatio = 0; - int GoodRodRatio = 0; - int SuperRodRatio = 0; - int RockSmashRatio = 0; EncounterArea Area4 = new EncounterArea(); if (data.Length != 198) { Area4.Location = 0; Area4.Slots = new EncounterSlot[0]; return Area4; } @@ -593,12 +573,12 @@ private static EncounterArea getArea4HGSS(byte[] data) var Slots = new List(); Area4.Location = BitConverter.ToUInt16(data, 0); - GrassRatio = data[2]; - SurfRatio = data[3]; - RockSmashRatio = data[4]; - OldRodRatio = data[5]; - GoodRodRatio = data[6]; - SuperRodRatio = data[7]; + int GrassRatio = data[2]; + int SurfRatio = data[3]; + int RockSmashRatio = data[4]; + int OldRodRatio = data[5]; + int GoodRodRatio = data[6]; + int SuperRodRatio = data[7]; // 2 bytes padding int ofs = 10; @@ -669,7 +649,7 @@ private static EncounterArea getArea4HGSS_Headbutt(byte[] data) int Species = BitConverter.ToUInt16(data, 6 + i * 4); if (Species > 0) { - Slots.Add(new EncounterSlot() + Slots.Add(new EncounterSlot { Species = Species, LevelMin = data[8 + i * 4], @@ -844,9 +824,9 @@ public static EncounterArea[] getArray3(byte[][] entries) return null; var Areas = new List(); - for (int i = 0; i < entries.Length; i++) + foreach (byte[] t in entries) { - EncounterArea Area = getArea3(entries[i]); + EncounterArea Area = getArea3(t); if (Area.Slots.Any()) Areas.Add(Area); } diff --git a/PKHeX/Legality/Structures/EncounterStatic.cs b/PKHeX/Legality/Structures/EncounterStatic.cs index 66184458f..6d83f0bec 100644 --- a/PKHeX/Legality/Structures/EncounterStatic.cs +++ b/PKHeX/Legality/Structures/EncounterStatic.cs @@ -25,6 +25,7 @@ public class EncounterStatic : IEncounterable public bool Fateful = false; public bool RibbonWishing = false; public bool SkipFormCheck = false; + public bool NSparkle = false; public string Name { diff --git a/PKHeX/Legality/Tables4.cs b/PKHeX/Legality/Tables4.cs index 3329d44e9..a7ed8ff06 100644 --- a/PKHeX/Legality/Tables4.cs +++ b/PKHeX/Legality/Tables4.cs @@ -322,8 +322,8 @@ public static partial class Legal //Gift new EncounterStatic { Gift = true, Species = 133, Level = 5, Location = 131, }, // Eevee @ Goldenrod Cityx - new EncounterStatic { Gift = true, Species = 147, Level = 15, Location = 222, Moves = new int[] {245, 086, 239, 082}, }, // Dratini @ Dragon's Den (ExtremeSpeed) - new EncounterStatic { Gift = true, Species = 147, Level = 15, Location = 222, Moves = new int[] {043, 086, 239, 082}, }, // Dratini @ Dragon's Den (Non-ExtremeSpeed) + new EncounterStatic { Gift = true, Species = 147, Level = 15, Location = 222, Moves = new[] {245, 086, 239, 082}, }, // Dratini @ Dragon's Den (ExtremeSpeed) + new EncounterStatic { Gift = true, Species = 147, Level = 15, Location = 222, Moves = new[] {043, 086, 239, 082}, }, // Dratini @ Dragon's Den (Non-ExtremeSpeed) new EncounterStatic { Gift = true, Species = 236, Level = 10, Location = 216, }, // Tyrogue @ Mt. Mortar new EncounterStatic { Gift = true, Species = 175, Level = 1, EggLocation = 128,}, // Togepi Egg @ Violet City new EncounterStatic { Gift = true, Species = 179, Level = 1, EggLocation = 128,}, // Mareep Egg @ Violet City @@ -399,27 +399,27 @@ public static partial class Legal }; internal static readonly EncounterTrade[] TradeGift_DPPt = { - new EncounterTrade { Species = 063, Ability = 1, TID = 25643, SID = 00000, OTGender = 1, Gender = 0, IVs = new int[] {15,15,15,25,25,20}, Nature = Nature.Quiet,}, // Abra - new EncounterTrade { Species = 441, Ability = 2, TID = 44142, SID = 00000, OTGender = 0, Gender = 1, IVs = new int[] {15,20,15,25,15,25}, Nature = Nature.Lonely, }, // Chatot - new EncounterTrade { Species = 093, Ability = 1, TID = 19248, SID = 00000, OTGender = 1, Gender = 0, IVs = new int[] {20,25,15,15,15,25}, Nature = Nature.Hasty,}, // Haunter - new EncounterTrade { Species = 129, Ability = 1, TID = 53277, SID = 00000, OTGender = 0, Gender = 1, IVs = new int[] {15,25,15,25,15,20}, Nature = Nature.Mild}, // Magikarp + new EncounterTrade { Species = 063, Ability = 1, TID = 25643, SID = 00000, OTGender = 1, Gender = 0, IVs = new[] {15,15,15,25,25,20}, Nature = Nature.Quiet,}, // Abra + new EncounterTrade { Species = 441, Ability = 2, TID = 44142, SID = 00000, OTGender = 0, Gender = 1, IVs = new[] {15,20,15,25,15,25}, Nature = Nature.Lonely, }, // Chatot + new EncounterTrade { Species = 093, Ability = 1, TID = 19248, SID = 00000, OTGender = 1, Gender = 0, IVs = new[] {20,25,15,15,15,25}, Nature = Nature.Hasty,}, // Haunter + new EncounterTrade { Species = 129, Ability = 1, TID = 53277, SID = 00000, OTGender = 0, Gender = 1, IVs = new[] {15,25,15,25,15,20}, Nature = Nature.Mild}, // Magikarp }; internal static readonly EncounterTrade[] TradeGift_HGSS = { - new EncounterTrade { Species = 095, Ability = 2, TID = 48926, SID = 00000, OTGender = 0, Gender = 0, IVs = new int[] {25,20,25,15,15,15}, Nature = Nature.Hasty,}, // Onix - new EncounterTrade { Species = 066, Ability = 1, TID = 37460, SID = 00000, OTGender = 0, Gender = 1, IVs = new int[] {15,25,20,15,15,20}, Nature = Nature.Lonely,}, // Machop - new EncounterTrade { Species = 100, Ability = 2, TID = 29189, SID = 00000, OTGender = 0, Gender = 2, IVs = new int[] {15,20,15,25,15,25}, Nature = Nature.Hardy,}, // Voltorb - new EncounterTrade { Species = 085, Ability = 1, TID = 00283, SID = 00000, OTGender = 1, Gender = 1, IVs = new int[] {20,20,20,15,15,15}, Nature = Nature.Impish,}, // Dodrio - new EncounterTrade { Species = 082, Ability = 1, TID = 50082, SID = 00000, OTGender = 0, Gender = 2, IVs = new int[] {15,20,15,20,20,20}, Nature = Nature.Impish,}, // Magneton - new EncounterTrade { Species = 178, Ability = 1, TID = 15616, SID = 00000, OTGender = 0, Gender = 0, IVs = new int[] {15,20,15,20,20,20}, Nature = Nature.Modest,}, // Xatu - new EncounterTrade { Species = 025, Ability = 1, TID = 33038, SID = 00000, OTGender = 0, Gender = 1, IVs = new int[] {20,25,18,25,13,31}, Nature = Nature.Jolly,}, // Pikachu - new EncounterTrade { Species = 374, Ability = 1, TID = 23478, SID = 00000, OTGender = 0, Gender = 2, IVs = new int[] {28,29,24,24,25,23}, Nature = Nature.Brave,}, // Beldum - new EncounterTrade { Species = 111, Ability = 1, TID = 06845, SID = 00000, OTGender = 0, Gender = 1, IVs = new int[] {22,31,13,22,9,0}, Nature = Nature.Relaxed, Moves= new int[]{422,-1,-1,-1} }, // Rhyhorn - new EncounterTrade { Species = 208, Ability = 1, TID = 26491, SID = 00000, OTGender = 1, Gender = 0, IVs = new int[] {8,30,28,18,20,6}, Nature = Nature.Brave,}, // Steelix + new EncounterTrade { Species = 095, Ability = 2, TID = 48926, SID = 00000, OTGender = 0, Gender = 0, IVs = new[] {25,20,25,15,15,15}, Nature = Nature.Hasty,}, // Onix + new EncounterTrade { Species = 066, Ability = 1, TID = 37460, SID = 00000, OTGender = 0, Gender = 1, IVs = new[] {15,25,20,15,15,20}, Nature = Nature.Lonely,}, // Machop + new EncounterTrade { Species = 100, Ability = 2, TID = 29189, SID = 00000, OTGender = 0, Gender = 2, IVs = new[] {15,20,15,25,15,25}, Nature = Nature.Hardy,}, // Voltorb + new EncounterTrade { Species = 085, Ability = 1, TID = 00283, SID = 00000, OTGender = 1, Gender = 1, IVs = new[] {20,20,20,15,15,15}, Nature = Nature.Impish,}, // Dodrio + new EncounterTrade { Species = 082, Ability = 1, TID = 50082, SID = 00000, OTGender = 0, Gender = 2, IVs = new[] {15,20,15,20,20,20}, Nature = Nature.Impish,}, // Magneton + new EncounterTrade { Species = 178, Ability = 1, TID = 15616, SID = 00000, OTGender = 0, Gender = 0, IVs = new[] {15,20,15,20,20,20}, Nature = Nature.Modest,}, // Xatu + new EncounterTrade { Species = 025, Ability = 1, TID = 33038, SID = 00000, OTGender = 0, Gender = 1, IVs = new[] {20,25,18,25,13,31}, Nature = Nature.Jolly,}, // Pikachu + new EncounterTrade { Species = 374, Ability = 1, TID = 23478, SID = 00000, OTGender = 0, Gender = 2, IVs = new[] {28,29,24,24,25,23}, Nature = Nature.Brave,}, // Beldum + new EncounterTrade { Species = 111, Ability = 1, TID = 06845, SID = 00000, OTGender = 0, Gender = 1, IVs = new[] {22,31,13,22,9,0}, Nature = Nature.Relaxed, Moves= new[]{422,-1,-1,-1} }, // Rhyhorn + new EncounterTrade { Species = 208, Ability = 1, TID = 26491, SID = 00000, OTGender = 1, Gender = 0, IVs = new[] {8,30,28,18,20,6}, Nature = Nature.Brave,}, // Steelix //Gift - new EncounterTrade { Species = 021, Ability = 1, TID = 01001, SID = 00000, OTGender = 0, Gender = 1, Nature = Nature.Hasty, Level = 20, Location = 183, Moves= new int[]{043,031,228,332}},//Webster's Spearow - new EncounterTrade { Species = 213, Ability = 2, TID = 04336, SID = 00000, OTGender = 0, Gender = 1, Nature = Nature.Relaxed, Level = 20, Location = 130, Moves= new int[]{132,117,227,219}},//Kirk's Shuckle + new EncounterTrade { Species = 021, Ability = 1, TID = 01001, SID = 00000, OTGender = 0, Gender = 1, Nature = Nature.Hasty, Level = 20, Location = 183, Moves= new[]{043,031,228,332}},//Webster's Spearow + new EncounterTrade { Species = 213, Ability = 2, TID = 04336, SID = 00000, OTGender = 0, Gender = 1, Nature = Nature.Relaxed, Level = 20, Location = 130, Moves= new[]{132,117,227,219}},//Kirk's Shuckle }; #region Alt Slots @@ -520,7 +520,7 @@ public static partial class Legal private static readonly EncounterArea SlotsD_HoneyTree = new EncounterArea { - Slots = SlotsPt_HoneyTree.Slots.Concat( new EncounterSlot[] + Slots = SlotsPt_HoneyTree.Slots.Concat( new[] { new EncounterSlot { Species = 266, LevelMin = 5, LevelMax = 15, Type = SlotType.HoneyTree }, // Silcoon }).ToArray() @@ -529,13 +529,13 @@ public static partial class Legal private static readonly EncounterArea SlotsP_HoneyTree = new EncounterArea { - Slots = SlotsPt_HoneyTree.Slots.Concat(new EncounterSlot[] + Slots = SlotsPt_HoneyTree.Slots.Concat(new[] { new EncounterSlot { Species = 268, LevelMin = 5, LevelMax = 15, Type = SlotType.HoneyTree }, // Cascoon }).ToArray() }; - private static readonly int[] HoneyTreesLocation = new int[] + private static readonly int[] HoneyTreesLocation = new[] { 20, // Route 205 21, // Route 206