From 4b7f253a1ea90c22905ae976f82a9ccae93fe701 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Wed, 24 Feb 2016 16:36:26 -0800 Subject: [PATCH] Add DexNav move legality checking --- Legality/Analysis.cs | 12 ++++++++--- Legality/Core.cs | 9 ++++++++- Legality/Data.cs | 33 +++++++++++++++++++++++++++++++ PKHeX.csproj | 1 + Properties/Resources.Designer.cs | 10 ++++++++++ Properties/Resources.resx | 3 +++ Resources/byte/dexnav_ao.pkl | Bin 0 -> 1128 bytes 7 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 Resources/byte/dexnav_ao.pkl diff --git a/Legality/Analysis.cs b/Legality/Analysis.cs index eaed224d0..2f0337990 100644 --- a/Legality/Analysis.cs +++ b/Legality/Analysis.cs @@ -29,6 +29,7 @@ public class LegalityAnalysis public LegalityCheck EC, Nickname, PID, IDs, IVs, EVs; public int[] ValidMoves => Legal.getValidMoves(pk6.Species, pk6.CurrentLevel); public int[] ValidRelearnMoves => Legal.getValidRelearn(pk6.Species); + public bool DexNav => Legal.getDexNavValid(pk6.Species, pk6.Met_Location, pk6.CurrentLevel); public string Report => getLegalityReport(); private readonly PK6 pk6; @@ -78,15 +79,20 @@ public bool[] getRelearnValidity(int[] Moves) // Check Event Info // Not Implemented } - if (egg) + else if (egg) { for (int i = 0; i < 4; i++) res[i] &= relearnMoves.Contains(Moves[i]); return res; } - bool dexnav = false; - if (dexnav) // not implemented + else if (Moves[0] != 0) // DexNav only? { + // Check DexNav + for (int i = 1; i < 4; i++) + res[i] &= Moves[i] == 0; + if (DexNav) + res[0] = relearnMoves.Contains(Moves[0]); + return res; } diff --git a/Legality/Core.cs b/Legality/Core.cs index d97b78308..e628304ab 100644 --- a/Legality/Core.cs +++ b/Legality/Core.cs @@ -14,7 +14,14 @@ public static partial class Legal private static readonly EggMoves[] EggMoveAO = EggMoves.getArray(Util.unpackMini(Properties.Resources.eggmove_ao, "ao")); private static readonly Learnset[] LevelUpAO = Learnset.getArray(Util.unpackMini(Properties.Resources.lvlmove_ao, "ao")); private static readonly Evolutions[] Evolves = Evolutions.getArray(Util.unpackMini(Properties.Resources.evos_ao, "ao")); - + private static readonly DexNavLocations[] DexNavAO = DexNavLocations.getArray(Util.unpackMini(Properties.Resources.dexnav_ao, "ao")); + + internal static bool getDexNavValid(int species, int location, int level) + { + DexNavLocations[] locs = DexNavAO.Where(l => l.Location == location).ToArray(); + return locs.Any(loc => loc.Slots.Any(slot => slot.Species == species && slot.LevelMin <= level)); + } + internal static int[] getValidMoves(int species, int level) { int[] r = new int[1]; diff --git a/Legality/Data.cs b/Legality/Data.cs index f12593192..25d799f10 100644 --- a/Legality/Data.cs +++ b/Legality/Data.cs @@ -90,6 +90,39 @@ public static Evolutions[] getArray(byte[][] entries) return data; } } + + public class DexNavLocations + { + public readonly int Location; + public readonly EncounterSlot[] Slots = new EncounterSlot[3]; + public DexNavLocations(byte[] data) + { + Location = BitConverter.ToUInt16(data, 0); + for (int i = 0; i < Slots.Length; i++) + { + Slots[i] = new EncounterSlot + { + Species = BitConverter.ToUInt16(data, 2 + i*4), + LevelMin = BitConverter.ToUInt16(data, 4 + i*4) + }; + } + } + public static DexNavLocations[] getArray(byte[][] entries) + { + DexNavLocations[] data = new DexNavLocations[entries.Length]; + for (int i = 0; i < data.Length; i++) + data[i] = new DexNavLocations(entries[i]); + return data; + } + } + + public class EncounterSlot + { + public int Species; + public int Form; + public int LevelMin; + public int LevelMax; + } public class PersonalInfo { internal static int SizeAO = 0x50; diff --git a/PKHeX.csproj b/PKHeX.csproj index 56b3cc93e..548746b86 100644 --- a/PKHeX.csproj +++ b/PKHeX.csproj @@ -360,6 +360,7 @@ + diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index 3cad54fbb..ba5648511 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -9786,6 +9786,16 @@ internal class Resources { } } + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] dexnav_ao { + get { + object obj = ResourceManager.GetObject("dexnav_ao", resourceCulture); + return ((byte[])(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/Properties/Resources.resx b/Properties/Resources.resx index b4cc2f638..ea6718095 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -5761,4 +5761,7 @@ ..\Resources\img\warn.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Resources\byte\dexnav_ao.pkl;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + \ No newline at end of file diff --git a/Resources/byte/dexnav_ao.pkl b/Resources/byte/dexnav_ao.pkl new file mode 100644 index 0000000000000000000000000000000000000000..b89834619d387860f0fbb00a003690c67c6387a0 GIT binary patch literal 1128 zcmb`_ziSg=9LMp`^Q1`*NiKEI3ifKEpTrw(x_h=OJ*(t?mh1gH212>AmX z@)t8L_|uEQdC3^2~HxRi1eM*w)jxc!QsW_eb4uPXZ?PpMA8JFk!lDL zp@lX&=%R-{1{fm72ni*7+{DPBP5u>OL06xL};On4!Y=}j{$~= zF+zd~yg80XhzKpT(ZMV28>?k&wE*cgozhjCQWeshS#PrM38c5m+AOnKZJO-wPV+m> zzBK(#*KJ+Tu%SA=ROpHpA$_Gi-NYk#^q5Is*R0RHPk&>orpKnH zmu#i)TC;)H70?0wV|M?ssp|&sK-#AR{t*E^UH^I9w`TLdj{9(3=FfTS^qkWfr#+|7 zIGuCace-dE@?P#?ktdg?9nv8k{zKPH#pbkuJIXQtx1Kjmo6%)uw9Qru%&N{Q!Whzd zld}aasX!O#rdhKMJvR+4t8q$SG