Add&Split out PersonalTable

Will eventually have more complex operations associated with it, as the
PersonalInfo[] could not do that sort of logic.
This commit is contained in:
Kaphotics 2016-07-17 22:39:18 -07:00
parent 07e4483ef7
commit f5bacf236c
18 changed files with 137 additions and 126 deletions

View file

@ -30,7 +30,7 @@ namespace PKHeX
{
private LegalityCheck verifyGender()
{
if (PersonalInfo.AO[pk6.Species].Gender == 255 && pk6.Gender != 2)
if (PersonalTable.AO[pk6.Species].Gender == 255 && pk6.Gender != 2)
return new LegalityCheck(Severity.Invalid, "Genderless Pokémon should not have a gender.");
return new LegalityCheck();
@ -431,8 +431,8 @@ namespace PKHeX
}
private LegalityCheck verifyAbility()
{
int index = PersonalInfo.AO[pk6.Species].FormeIndex(pk6.Species, pk6.AltForm);
int[] abilities = PersonalInfo.AO[index].Abilities;
int index = PersonalTable.AO[pk6.Species].FormeIndex(pk6.Species, pk6.AltForm);
int[] abilities = PersonalTable.AO[index].Abilities;
int abilval = Array.IndexOf(abilities, pk6.Ability);
if (abilval < 0)
return new LegalityCheck(Severity.Invalid, "Ability is not valid for species/form.");

View file

@ -405,8 +405,8 @@ namespace PKHeX
}
private static IEnumerable<int> getLVLMoves(int species, int lvl, int formnum)
{
int ind_XY = PersonalInfo.XY[species].FormeIndex(species, formnum);
int ind_AO = PersonalInfo.AO[species].FormeIndex(species, formnum);
int ind_XY = PersonalTable.XY[species].FormeIndex(species, formnum);
int ind_AO = PersonalTable.AO[species].FormeIndex(species, formnum);
return LevelUpXY[ind_XY].getMoves(lvl).Concat(LevelUpAO[ind_AO].getMoves(lvl));
}
private static IEnumerable<EncounterArea> getEncounterSlots(PK6 pk6)
@ -543,7 +543,7 @@ namespace PKHeX
bool ORASTutors = Version == -1 || pk6.AO || !pk6.IsUntraded;
if (FormChangeMoves.Contains(species)) // Deoxys & Shaymin & Giratina (others don't have extra but whatever)
{
int formcount = PersonalInfo.AO[species].FormeCount;
int formcount = PersonalTable.AO[species].FormeCount;
for (int i = 0; i < formcount; i++)
r.AddRange(getMoves(species, lvl, i, ORASTutors, Version, LVL, Tutor, Machine));
if (Relearn) r.AddRange(pk6.RelearnMoves);
@ -568,8 +568,8 @@ namespace PKHeX
List<int> r = new List<int> { 0 };
if (Version < 0 || Version == 0)
{
int index = PersonalInfo.XY[species].FormeIndex(species, form);
PersonalInfo pi = PersonalInfo.XY[index];
int index = PersonalTable.XY[species].FormeIndex(species, form);
PersonalInfo pi = PersonalTable.XY[index];
if (LVL) r.AddRange(LevelUpXY[index].getMoves(lvl));
if (Tutor) r.AddRange(getTutorMoves(species, form, ORASTutors));
@ -577,8 +577,8 @@ namespace PKHeX
}
if (Version < 0 || Version == 1)
{
int index = PersonalInfo.AO[species].FormeIndex(species, form);
PersonalInfo pi = PersonalInfo.AO[index];
int index = PersonalTable.AO[species].FormeIndex(species, form);
PersonalInfo pi = PersonalTable.AO[index];
if (LVL) r.AddRange(LevelUpAO[index].getMoves(lvl));
if (Tutor) r.AddRange(getTutorMoves(species, form, ORASTutors));
@ -588,13 +588,13 @@ namespace PKHeX
}
private static IEnumerable<int> getEggMoves(int species, int formnum)
{
int ind_XY = PersonalInfo.XY[species].FormeIndex(species, formnum);
int ind_AO = PersonalInfo.AO[species].FormeIndex(species, formnum);
int ind_XY = PersonalTable.XY[species].FormeIndex(species, formnum);
int ind_AO = PersonalTable.AO[species].FormeIndex(species, formnum);
return EggMoveAO[ind_AO].Moves.Concat(EggMoveXY[ind_XY].Moves);
}
private static IEnumerable<int> getTutorMoves(int species, int formnum, bool ORASTutors)
{
PersonalInfoORAS pkAO = (PersonalInfoORAS) PersonalInfo.AO[PersonalInfo.AO[species].FormeIndex(species, formnum)];
PersonalInfoORAS pkAO = (PersonalInfoORAS)PersonalTable.AO[PersonalTable.AO[species].FormeIndex(species, formnum)];
// Type Tutor
List<int> moves = TypeTutor.Where((t, i) => pkAO.TypeTutors[i]).ToList();

View file

@ -181,7 +181,7 @@ namespace PKHeX
try { return SpeciesLang.All(list => list[species].ToUpper() != nick); }
catch { return false; }
}
internal static PersonalInfo[] Personal = PersonalInfo.AO;
internal static PersonalTable Personal = PersonalTable.AO;
// Stat Fetching
internal static int getMovePP(int move, int ppup)

View file

@ -1,28 +1,7 @@
using System;
namespace PKHeX
namespace PKHeX
{
public abstract class PersonalInfo
{
internal static readonly PersonalInfo[] AO = getArray(Properties.Resources.personal_ao, GameVersion.ORAS);
internal static readonly PersonalInfo[] XY = getArray(Properties.Resources.personal_xy, GameVersion.XY);
internal static readonly PersonalInfo[] B2W2 = getArray(Properties.Resources.personal_b2w2, GameVersion.B2W2);
internal static readonly PersonalInfo[] BW = getArray(Properties.Resources.personal_bw, GameVersion.BW);
internal static readonly PersonalInfo[] HGSS = getArray(Properties.Resources.personal_hgss, GameVersion.HGSS);
internal static readonly PersonalInfo[] Pt = getArray(Properties.Resources.personal_pt, GameVersion.Pt);
internal static readonly PersonalInfo[] DP = getArray(Properties.Resources.personal_dp, GameVersion.DP);
internal static readonly PersonalInfo[] LG = getArray(Properties.Resources.personal_lg, GameVersion.LG);
internal static readonly PersonalInfo[] FR = getArray(Properties.Resources.personal_fr, GameVersion.FR);
internal static readonly PersonalInfo[] E = getArray(Properties.Resources.personal_e, GameVersion.E);
internal static readonly PersonalInfo[] RS = getArray(Properties.Resources.personal_rs, GameVersion.RS);
protected const int SIZE_G3 = 0x1C;
protected const int SIZE_G4 = 0x2C;
protected const int SIZE_BW = 0x3C;
protected const int SIZE_B2W2 = 0x4C;
protected const int SIZE_XY = 0x40;
protected const int SIZE_AO = 0x50;
protected byte[] Data;
public abstract byte[] Write();
public abstract int HP { get; set; }
@ -108,76 +87,5 @@ namespace PKHeX
}
public bool HasFormes => FormeCount > 1;
public int BST => HP + ATK + DEF + SPE + SPA + SPD;
// Array Retrieval
internal static PersonalInfo[] getArray(byte[] data, GameVersion format)
{
int size = 0;
switch (format)
{
case GameVersion.RS:
case GameVersion.E:
case GameVersion.FR:
case GameVersion.LG: size = SIZE_G3; break;
case GameVersion.DP:
case GameVersion.Pt:
case GameVersion.HGSS: size = SIZE_G4; break;
case GameVersion.BW: size = SIZE_BW; break;
case GameVersion.B2W2: size = SIZE_B2W2; break;
case GameVersion.XY: size = SIZE_XY; break;
case GameVersion.ORAS: size = SIZE_AO; break;
}
if (size == 0)
return null;
byte[][] entries = splitBytes(data, size);
PersonalInfo[] d = new PersonalInfo[data.Length / size];
switch (format)
{
case GameVersion.RS:
case GameVersion.E:
case GameVersion.FR:
case GameVersion.LG:
Array.Resize(ref d, 387);
for (int i = 0; i < d.Length; i++) // entries are not in order of natdexID
d[i] = new PersonalInfoG3(entries[PKX.getG3Species(i)]);
break;
case GameVersion.DP:
case GameVersion.Pt:
case GameVersion.HGSS:
for (int i = 0; i < d.Length; i++)
d[i] = new PersonalInfoG4(entries[i]);
break;
case GameVersion.BW:
for (int i = 0; i < d.Length; i++)
d[i] = new PersonalInfoBW(entries[i]);
break;
case GameVersion.B2W2:
for (int i = 0; i < d.Length; i++)
d[i] = new PersonalInfoB2W2(entries[i]);
break;
case GameVersion.XY:
for (int i = 0; i < d.Length; i++)
d[i] = new PersonalInfoXY(entries[i]);
break;
case GameVersion.ORAS:
for (int i = 0; i < d.Length; i++)
d[i] = new PersonalInfoORAS(entries[i]);
break;
}
return d;
}
private static byte[][] splitBytes(byte[] data, int size)
{
byte[][] r = new byte[data.Length/size][];
for (int i = 0; i < data.Length; i += size)
{
r[i/size] = new byte[size];
Array.Copy(data, i, r[i/size], 0, size);
}
return r;
}
}
}

View file

@ -4,9 +4,10 @@ namespace PKHeX
{
public class PersonalInfoB2W2 : PersonalInfoBW
{
public new const int SIZE = 0x4C;
public PersonalInfoB2W2(byte[] data)
{
if (data.Length != SIZE_B2W2)
if (data.Length != SIZE)
return;
Data = data;

View file

@ -6,9 +6,10 @@ namespace PKHeX
public class PersonalInfoBW : PersonalInfo
{
protected PersonalInfoBW() { }
public const int SIZE = 0x3C;
public PersonalInfoBW(byte[] data)
{
if (data.Length != SIZE_BW)
if (data.Length != SIZE)
return;
Data = data;

View file

@ -5,9 +5,10 @@ namespace PKHeX
public class PersonalInfoG3 : PersonalInfo
{
protected PersonalInfoG3() { }
public const int SIZE = 0x1C;
public PersonalInfoG3(byte[] data)
{
if (data.Length != SIZE_G3)
if (data.Length != SIZE)
return;
Data = data;

View file

@ -4,9 +4,10 @@ namespace PKHeX
{
public class PersonalInfoG4 : PersonalInfoG3
{
public new const int SIZE = 0x2C;
public PersonalInfoG4(byte[] data)
{
if (data.Length != SIZE_G4)
if (data.Length != SIZE)
return;
Data = data;

View file

@ -4,9 +4,10 @@ namespace PKHeX
{
public class PersonalInfoORAS : PersonalInfoXY
{
public new const int SIZE = 0x50;
public PersonalInfoORAS(byte[] data)
{
if (data.Length != SIZE_AO)
if (data.Length != SIZE)
return;
Data = data;

View file

@ -5,9 +5,10 @@ namespace PKHeX
public class PersonalInfoXY : PersonalInfoBW
{
protected PersonalInfoXY() { } // For ORAS
public new const int SIZE = 0x40;
public PersonalInfoXY(byte[] data)
{
if (data.Length != SIZE_XY)
if (data.Length != SIZE)
return;
Data = data;

View file

@ -0,0 +1,97 @@
using System;
namespace PKHeX
{
public class PersonalTable
{
internal static readonly PersonalTable AO = new PersonalTable(Properties.Resources.personal_ao, GameVersion.ORAS);
internal static readonly PersonalTable XY = new PersonalTable(Properties.Resources.personal_xy, GameVersion.XY);
internal static readonly PersonalTable B2W2 = new PersonalTable(Properties.Resources.personal_b2w2, GameVersion.B2W2);
internal static readonly PersonalTable BW = new PersonalTable(Properties.Resources.personal_bw, GameVersion.BW);
internal static readonly PersonalTable HGSS = new PersonalTable(Properties.Resources.personal_hgss, GameVersion.HGSS);
internal static readonly PersonalTable Pt = new PersonalTable(Properties.Resources.personal_pt, GameVersion.Pt);
internal static readonly PersonalTable DP = new PersonalTable(Properties.Resources.personal_dp, GameVersion.DP);
internal static readonly PersonalTable LG = new PersonalTable(Properties.Resources.personal_lg, GameVersion.LG);
internal static readonly PersonalTable FR = new PersonalTable(Properties.Resources.personal_fr, GameVersion.FR);
internal static readonly PersonalTable E = new PersonalTable(Properties.Resources.personal_e, GameVersion.E);
internal static readonly PersonalTable RS = new PersonalTable(Properties.Resources.personal_rs, GameVersion.RS);
private static byte[][] splitBytes(byte[] data, int size)
{
byte[][] r = new byte[data.Length / size][];
for (int i = 0; i < data.Length; i += size)
{
r[i / size] = new byte[size];
Array.Copy(data, i, r[i / size], 0, size);
}
return r;
}
private PersonalTable(byte[] data, GameVersion format)
{
int size = 0;
switch (format)
{
case GameVersion.RS:
case GameVersion.E:
case GameVersion.FR:
case GameVersion.LG: size = PersonalInfoG3.SIZE; break;
case GameVersion.DP:
case GameVersion.Pt:
case GameVersion.HGSS: size = PersonalInfoG4.SIZE; break;
case GameVersion.BW: size = PersonalInfoBW.SIZE; break;
case GameVersion.B2W2: size = PersonalInfoB2W2.SIZE; break;
case GameVersion.XY: size = PersonalInfoXY.SIZE; break;
case GameVersion.ORAS: size = PersonalInfoORAS.SIZE; break;
}
if (size == 0)
{ Table = null; return; }
byte[][] entries = splitBytes(data, size);
PersonalInfo[] d = new PersonalInfo[data.Length / size];
switch (format)
{
case GameVersion.RS:
case GameVersion.E:
case GameVersion.FR:
case GameVersion.LG:
Array.Resize(ref d, 387);
for (int i = 0; i < d.Length; i++) // entries are not in order of natdexID
d[i] = new PersonalInfoG3(entries[PKX.getG3Species(i)]);
break;
case GameVersion.DP:
case GameVersion.Pt:
case GameVersion.HGSS:
for (int i = 0; i < d.Length; i++)
d[i] = new PersonalInfoG4(entries[i]);
break;
case GameVersion.BW:
for (int i = 0; i < d.Length; i++)
d[i] = new PersonalInfoBW(entries[i]);
break;
case GameVersion.B2W2:
for (int i = 0; i < d.Length; i++)
d[i] = new PersonalInfoB2W2(entries[i]);
break;
case GameVersion.XY:
for (int i = 0; i < d.Length; i++)
d[i] = new PersonalInfoXY(entries[i]);
break;
case GameVersion.ORAS:
for (int i = 0; i < d.Length; i++)
d[i] = new PersonalInfoORAS(entries[i]);
break;
}
Table = d;
}
private readonly PersonalInfo[] Table;
public PersonalInfo this[int index]
{
get { return Table[index]; }
set { Table[index] = value; }
}
}
}

View file

@ -77,7 +77,7 @@ namespace PKHeX
OFS_PouchBalls = BlockOfs[1] + 0x0600;
OFS_PouchTMHM = BlockOfs[1] + 0x0640;
OFS_PouchBerry = BlockOfs[1] + 0x0740;
Personal = PersonalInfo.RS;
Personal = PersonalTable.RS;
break;
case GameVersion.FRLG:
LegalKeyItems = Legal.Pouch_Key_FRLG;
@ -86,7 +86,7 @@ namespace PKHeX
OFS_PouchBalls = BlockOfs[1] + 0x0430;
OFS_PouchTMHM = BlockOfs[1] + 0x0464;
OFS_PouchBerry = BlockOfs[1] + 0x054C;
Personal = PersonalInfo.FR; // todo split FR & LG
Personal = PersonalTable.FR; // todo split FR & LG
break;
case GameVersion.E:
LegalKeyItems = Legal.Pouch_Key_E;
@ -95,7 +95,7 @@ namespace PKHeX
OFS_PouchBalls = BlockOfs[1] + 0x0650;
OFS_PouchTMHM = BlockOfs[1] + 0x0690;
OFS_PouchBerry = BlockOfs[1] + 0x0790;
Personal = PersonalInfo.E;
Personal = PersonalTable.E;
break;
}
LegalItems = Legal.Pouch_Items_RS;

View file

@ -28,9 +28,9 @@ namespace PKHeX
switch (Version)
{
case GameVersion.DP: Personal = PersonalInfo.DP; break;
case GameVersion.Pt: Personal = PersonalInfo.Pt; break;
case GameVersion.HGSS: Personal = PersonalInfo.HGSS; break;
case GameVersion.DP: Personal = PersonalTable.DP; break;
case GameVersion.Pt: Personal = PersonalTable.Pt; break;
case GameVersion.HGSS: Personal = PersonalTable.HGSS; break;
}
if (!Exportable)

View file

@ -55,7 +55,7 @@ namespace PKHeX
LegalMedicine = Legal.Pouch_Medicine_BW;
LegalBerries = Legal.Pouch_Berries_BW;
Personal = PersonalInfo.BW;
Personal = PersonalTable.BW;
break;
case GameVersion.B2W2: // B2W2
BattleBox = 0x20900;
@ -78,7 +78,7 @@ namespace PKHeX
LegalMedicine = Legal.Pouch_Medicine_BW;
LegalBerries = Legal.Pouch_Berries_BW;
Personal = PersonalInfo.B2W2;
Personal = PersonalTable.B2W2;
break;
}
HeldItems = Legal.HeldItems_BW;

View file

@ -21,7 +21,7 @@ namespace PKHeX
getSAVOffsets();
HeldItems = ORAS ? Legal.HeldItem_AO : Legal.HeldItem_XY;
Personal = ORAS ? PersonalInfo.AO : PersonalInfo.XY;
Personal = ORAS ? PersonalTable.AO : PersonalTable.XY;
if (!Exportable)
resetBoxes();
}

View file

@ -45,7 +45,7 @@ namespace PKHeX
public abstract bool ChecksumsValid { get; }
public abstract string ChecksumInfo { get; }
public abstract int Generation { get; }
public PersonalInfo[] Personal { get; protected set; }
public PersonalTable Personal { get; protected set; }
public bool ORASDEMO => Data.Length == SaveUtil.SIZE_G6ORASDEMO;
public bool ORAS => Version == GameVersion.OR || Version == GameVersion.AS;

View file

@ -363,7 +363,7 @@ namespace PKHeX
private void setForms()
{
int species = Util.getIndex(CB_Species);
bool hasForms = PersonalInfo.AO[species].HasFormes || new[] { 664, 665, 414 }.Contains(species);
bool hasForms = PersonalTable.AO[species].HasFormes || new[] { 664, 665, 414 }.Contains(species);
CB_Form.Enabled = CB_Form.Visible = hasForms;
CB_Form.DisplayMember = "Text";

View file

@ -411,7 +411,7 @@ namespace PKHeX
int newabil = Convert.ToInt16(MT_AbilNo.Text) >> 1;
int species = Util.getIndex(CB_Species);
int formnum = CB_Form.SelectedIndex;
int[] abils = PersonalInfo.AO[PersonalInfo.AO[species].FormeIndex(species, formnum)].Abilities;
int[] abils = PersonalTable.AO[PersonalTable.AO[species].FormeIndex(species, formnum)].Abilities;
// Build Ability List
List<string> ability_list = new List<string>
@ -428,7 +428,7 @@ namespace PKHeX
private void setForms()
{
int species = Util.getIndex(CB_Species);
bool hasForms = PersonalInfo.AO[species].HasFormes || new[] { 664, 665, 414 }.Contains(species);
bool hasForms = PersonalTable.AO[species].HasFormes || new[] { 664, 665, 414 }.Contains(species);
CB_Form.Enabled = CB_Form.Visible = hasForms;
CB_Form.DisplayMember = "Text";