Add encounter tables

This commit is contained in:
Kaphotics
2016-02-25 16:19:59 -08:00
parent 4b7f253a1e
commit cb6a3394d5
13 changed files with 104 additions and 30 deletions

View File

@@ -29,7 +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 bool DexNav => Legal.getDexNavValid(pk6.Species, pk6.Met_Location, pk6.Met_Level, pk6.Version);
public string Report => getLegalityReport();
private readonly PK6 pk6;
@@ -71,16 +71,21 @@ public bool[] getRelearnValidity(int[] Moves)
if (!pk6.Gen6)
goto noRelearn;
bool egg = pk6.Egg_Location > 1000 || pk6.Egg_Location == 318;
bool evnt = pk6.Met_Location > 40000 || pk6.Egg_Location > 40000;
bool egg = Legal.EggLocations.Contains(pk6.Egg_Location) && pk6.Met_Level == 1;
bool evnt = pk6.FatefulEncounter && pk6.Met_Location > 40000;
bool eventEgg = pk6.FatefulEncounter && (pk6.Egg_Location > 40000 || pk6.Egg_Location == 30002) && pk6.Met_Level == 1;
int[] relearnMoves = ValidRelearnMoves;
if (evnt)
if (evnt || eventEgg)
{
// Check Event Info
// Not Implemented
}
else if (egg)
{
if (new[] {25, 26, 172}.Contains(pk6.Species)) //
{
relearnMoves = relearnMoves.Concat(new[] {344}).ToArray();
}
for (int i = 0; i < 4; i++)
res[i] &= relearnMoves.Contains(Moves[i]);
return res;
@@ -88,7 +93,7 @@ public bool[] getRelearnValidity(int[] Moves)
else if (Moves[0] != 0) // DexNav only?
{
// Check DexNav
for (int i = 1; i < 4; i++)
for (int i = 0; i < 4; i++)
res[i] &= Moves[i] == 0;
if (DexNav)
res[0] = relearnMoves.Contains(Moves[0]);

View File

@@ -14,11 +14,29 @@ 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)
private static readonly EncounterArea[] SlotsA = EncounterArea.getArray(Util.unpackMini(Properties.Resources.encounter_a, "ao"));
private static readonly EncounterArea[] SlotsO = EncounterArea.getArray(Util.unpackMini(Properties.Resources.encounter_o, "ao"));
private static readonly EncounterArea[] SlotsX = EncounterArea.getArray(Util.unpackMini(Properties.Resources.encounter_x, "xy"));
private static readonly EncounterArea[] SlotsY = EncounterArea.getArray(Util.unpackMini(Properties.Resources.encounter_y, "xy"));
private static readonly EncounterArea[] DexNavA = getDexNavSlots(SlotsA);
private static readonly EncounterArea[] DexNavO = getDexNavSlots(SlotsO);
private static EncounterArea[] getDexNavSlots(EncounterArea[] GameSlots)
{
DexNavLocations[] locs = DexNavAO.Where(l => l.Location == location).ToArray();
EncounterArea[] eA = new EncounterArea[GameSlots.Length];
for (int i = 0; i < eA.Length; i++)
{
eA[i] = GameSlots[i];
eA[i].Slots = eA[i].Slots.Take(20).Concat(eA[i].Slots.Skip(25)).ToArray(); // Skip 5 Rock Smash slots.
}
return eA;
}
internal static bool getDexNavValid(int species, int location, int level, int Version)
{
bool alpha = Version == 26;
if (!alpha && Version != 27)
return false;
EncounterArea[] locs = (alpha ? DexNavA : DexNavO).Where(l => l.Location == location).ToArray();
return locs.Any(loc => loc.Slots.Any(slot => slot.Species == species && slot.LevelMin <= level));
}
@@ -55,7 +73,6 @@ internal static int[] getValidRelearn(int species)
moves = moves.Concat(getEggMoves(species)).ToArray();
moves = moves.Concat(getLVLMoves(species, 100)).ToArray();
return moves.Concat(new int[1]).Distinct().ToArray();
// Not implemented: DexNav exclusive moves, Wonder Cards
}
private static int[] getEggMoves(int species)

View File

@@ -91,27 +91,31 @@ public static Evolutions[] getArray(byte[][] entries)
}
}
public class DexNavLocations
public class EncounterArea
{
public readonly int Location;
public readonly EncounterSlot[] Slots = new EncounterSlot[3];
public DexNavLocations(byte[] data)
public EncounterSlot[] Slots;
public EncounterArea(byte[] data)
{
Location = BitConverter.ToUInt16(data, 0);
Slots = new EncounterSlot[(data.Length-2)/4];
for (int i = 0; i < Slots.Length; i++)
{
ushort SpecForm = BitConverter.ToUInt16(data, 2 + i*4);
Slots[i] = new EncounterSlot
{
Species = BitConverter.ToUInt16(data, 2 + i*4),
LevelMin = BitConverter.ToUInt16(data, 4 + i*4)
Species = SpecForm & 0x7FF,
Form = SpecForm >> 11,
LevelMin = data[4 + i*4],
LevelMax = data[5 + i*4],
};
}
}
public static DexNavLocations[] getArray(byte[][] entries)
public static EncounterArea[] getArray(byte[][] entries)
{
DexNavLocations[] data = new DexNavLocations[entries.Length];
EncounterArea[] data = new EncounterArea[entries.Length];
for (int i = 0; i < data.Length; i++)
data[i] = new DexNavLocations(entries[i]);
data[i] = new EncounterArea(entries[i]);
return data;
}
}

View File

@@ -209,5 +209,6 @@ public static partial class Legal
internal static readonly int Struggle = 165;
internal static readonly int Chatter = 448;
internal static readonly int[] InvalidSketch = {Struggle, Chatter};
internal static readonly int[] EggLocations = {318, 60002, 30002};
}
}

View File

@@ -363,6 +363,12 @@
<None Include="Resources\byte\dexnav_ao.pkl" />
<None Include="Resources\byte\eggmove_ao.pkl" />
<None Include="Resources\byte\eggmove_xy.pkl" />
<None Include="Resources\byte\encounter_a.pkl" />
<None Include="Resources\byte\encounter_ao.pkl" />
<None Include="Resources\byte\encounter_o.pkl" />
<None Include="Resources\byte\encounter_x.pkl" />
<None Include="Resources\byte\encounter_xy.pkl" />
<None Include="Resources\byte\encounter_y.pkl" />
<None Include="Resources\byte\evos_ao.pkl" />
<None Include="Resources\byte\lvlmove_ao.pkl" />
<None Include="Resources\byte\lvlmove_xy.pkl" />

View File

@@ -1854,6 +1854,8 @@ private void updateOriginGame(object sender, EventArgs e)
CB_EncounterType.SelectedValue = 0;
setMarkings(); // Set/Remove KB marking
pk6.Met_Location = Util.getIndex(CB_MetLocation);
pk6.Egg_Location = Util.getIndex(CB_EggLocation);
updateValidMoves();
}
private void updateExtraByteValue(object sender, EventArgs e)

View File

@@ -9786,16 +9786,6 @@ internal class Resources {
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] dexnav_ao {
get {
object obj = ResourceManager.GetObject("dexnav_ao", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
@@ -9866,6 +9856,46 @@ internal class Resources {
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] encounter_a {
get {
object obj = ResourceManager.GetObject("encounter_a", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] encounter_o {
get {
object obj = ResourceManager.GetObject("encounter_o", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] encounter_x {
get {
object obj = ResourceManager.GetObject("encounter_x", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] encounter_y {
get {
object obj = ResourceManager.GetObject("encounter_y", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>

View File

@@ -5761,7 +5761,16 @@
<data name="warn" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\img\warn.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="dexnav_ao" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\byte\dexnav_ao.pkl;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<data name="encounter_a" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\byte\encounter_a.pkl;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="encounter_o" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\byte\encounter_o.pkl;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="encounter_x" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\byte\encounter_x.pkl;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="encounter_y" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\byte\encounter_y.pkl;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.