Refactoring

pass identifier on cloning pkm
remove unnecessary ref for passing Data (not modifying array reference)
const some magic numbers
This commit is contained in:
Kurt 2017-12-27 16:36:24 -08:00
parent 61b65198f2
commit a1f2f8708a
24 changed files with 72 additions and 75 deletions

View file

@ -9,8 +9,11 @@ namespace PKHeX.Core
internal const int MaxSpeciesID_3 = 386;
internal const int MaxMoveID_3 = 354;
internal const int MaxItemID_3 = 374;
internal const int MaxItemID_3_COLO = 547;
internal const int MaxItemID_3_XD = 593;
internal const int MaxAbilityID_3 = 77;
internal const int MaxBallID_3 = 0xC;
internal const int MaxGameID_3 = 5; // LG
/// <summary>
/// Generation 3 -> Generation 4 Transfer Location (Pal Park)
/// </summary>

View file

@ -12,6 +12,7 @@ namespace PKHeX.Core
internal const int MaxItemID_4_HGSS = 536;
internal const int MaxAbilityID_4 = 123;
internal const int MaxBallID_4 = 0x18;
internal const int MaxGameID_4 = 15; // CXD
/// <summary> Generation 4 -> Generation 5 Transfer Location (Poké Transporter) </summary>
public const int Transfer4 = 30001;
/// <summary> Generation 4 -> Generation 5 Transfer Location (Crown Celebi - Event not activated in Gen 5) </summary>

View file

@ -33,7 +33,7 @@ namespace PKHeX.Core
if (Data.Length != SIZE_PARTY)
Array.Resize(ref Data, SIZE_PARTY);
}
public override PKM Clone() => new BK4((byte[])Encrypt().Clone());
public override PKM Clone() => new BK4((byte[])Encrypt().Clone(), Identifier);
public string GetString(int Offset, int Count) => StringConverter.GetBEString4(Data, Offset, Count);
public byte[] SetString(string value, int maxLength) => StringConverter.SetBEString4(value, maxLength);
@ -370,7 +370,7 @@ namespace PKHeX.Core
public override int MaxAbilityID => Legal.MaxAbilityID_4;
public override int MaxItemID => Legal.MaxItemID_4_HGSS;
public override int MaxBallID => Legal.MaxBallID_4;
public override int MaxGameID => 15; // Colo/XD
public override int MaxGameID => Legal.MaxGameID_4;
public override int MaxIV => 31;
public override int MaxEV => 252;
public override int OTLength => 7;

View file

@ -26,7 +26,7 @@ namespace PKHeX.Core
if (Data.Length != SIZE_PARTY)
Array.Resize(ref Data, SIZE_PARTY);
}
public override PKM Clone() => new CK3((byte[])Data.Clone());
public override PKM Clone() => new CK3((byte[])Data.Clone(), Identifier);
private string GetString(int Offset, int Count) => StringConverter.GetBEString3(Data, Offset, Count);
private byte[] SetString(string value, int maxLength) => StringConverter.SetBEString3(value, maxLength);
@ -203,7 +203,7 @@ namespace PKHeX.Core
public override int MaxAbilityID => Legal.MaxAbilityID_3;
public override int MaxItemID => Legal.MaxItemID_3;
public override int MaxBallID => Legal.MaxBallID_3;
public override int MaxGameID => 5;
public override int MaxGameID => Legal.MaxGameID_3;
public override int MaxIV => 31;
public override int MaxEV => 252;
public override int OTLength => 7;

View file

@ -47,13 +47,11 @@ namespace PKHeX.Core
nick = Enumerable.Repeat((byte) 0x50, strLen).ToArray();
}
public override PKM Clone()
public override PKM Clone() => new PK1((byte[])Data.Clone(), Identifier, Japanese)
{
PK1 new_pk1 = new PK1((byte[])Data.Clone(), Identifier, Japanese);
Array.Copy(otname, 0, new_pk1.otname, 0, otname.Length);
Array.Copy(nick, 0, new_pk1.nick, 0, nick.Length);
return new_pk1;
}
otname = (byte[])otname.Clone(),
nick = (byte[])nick.Clone(),
};
public override string Nickname
{
get => StringConverter.GetString1(nick, 0, nick.Length, Japanese);

View file

@ -65,14 +65,12 @@ namespace PKHeX.Core
nick = Enumerable.Repeat((byte) 0x50, strLen).ToArray();
}
public override PKM Clone()
public override PKM Clone() => new PK2((byte[])Data.Clone(), Identifier, Japanese)
{
PK2 new_pk2 = new PK2((byte[])Data.Clone(), Identifier, Japanese);
Array.Copy(otname, 0, new_pk2.otname, 0, otname.Length);
Array.Copy(nick, 0, new_pk2.nick, 0, nick.Length);
new_pk2.IsEgg = IsEgg;
return new_pk2;
}
otname = (byte[])otname.Clone(),
nick = (byte[])nick.Clone(),
IsEgg = IsEgg,
};
public override string Nickname
{
get

View file

@ -22,7 +22,7 @@ namespace PKHeX.Core
if (Data.Length != SIZE_PARTY)
Array.Resize(ref Data, SIZE_PARTY);
}
public override PKM Clone() => new PK3((byte[])Data.Clone());
public override PKM Clone() => new PK3((byte[])Data.Clone(), Identifier);
private string GetString(int Offset, int Count) => StringConverter.GetString3(Data, Offset, Count, Japanese);
private byte[] SetString(string value, int maxLength) => StringConverter.SetString3(value, maxLength, Japanese);
@ -169,7 +169,7 @@ namespace PKHeX.Core
public override int MaxAbilityID => Legal.MaxAbilityID_3;
public override int MaxItemID => Legal.MaxItemID_3;
public override int MaxBallID => Legal.MaxBallID_3;
public override int MaxGameID => 5;
public override int MaxGameID => Legal.MaxGameID_3;
public override int MaxIV => 31;
public override int MaxEV => 255;
public override int OTLength => 7;

View file

@ -23,7 +23,7 @@ namespace PKHeX.Core
if (Data.Length != SIZE_PARTY)
Array.Resize(ref Data, SIZE_PARTY);
}
public override PKM Clone() => new PK4((byte[])Data.Clone());
public override PKM Clone() => new PK4((byte[])Data.Clone(), Identifier);
private string GetString(int Offset, int Count) => StringConverter.GetString4(Data, Offset, Count);
private byte[] SetString(string value, int maxLength) => StringConverter.SetString4(value, maxLength);
@ -357,7 +357,7 @@ namespace PKHeX.Core
public override int MaxAbilityID => Legal.MaxAbilityID_4;
public override int MaxItemID => Legal.MaxItemID_4_HGSS;
public override int MaxBallID => Legal.MaxBallID_4;
public override int MaxGameID => 15; // Colo/XD
public override int MaxGameID => Legal.MaxGameID_4;
public override int MaxIV => 31;
public override int MaxEV => 255;
public override int OTLength => 7;

View file

@ -23,7 +23,7 @@ namespace PKHeX.Core
if (Data.Length != SIZE_PARTY)
Array.Resize(ref Data, SIZE_PARTY);
}
public override PKM Clone() => new PK5((byte[])Data.Clone());
public override PKM Clone() => new PK5((byte[])Data.Clone(), Identifier);
private string GetString(int Offset, int Count) => StringConverter.GetString5(Data, Offset, Count);
private byte[] SetString(string value, int maxLength) => StringConverter.SetString5(value, maxLength);

View file

@ -24,7 +24,7 @@ namespace PKHeX.Core
if (Data.Length != SIZE_PARTY)
Array.Resize(ref Data, SIZE_PARTY);
}
public override PKM Clone() => new PK6((byte[])Data.Clone());
public override PKM Clone() => new PK6((byte[])Data.Clone(), Identifier);
private string GetString(int Offset, int Count) => StringConverter.GetString6(Data, Offset, Count);
private byte[] SetString(string value, int maxLength) => StringConverter.SetString6(value, maxLength);

View file

@ -25,7 +25,7 @@ namespace PKHeX.Core
if (Data.Length != SIZE_PARTY)
Array.Resize(ref Data, SIZE_PARTY);
}
public override PKM Clone() => new PK7((byte[])Data.Clone());
public override PKM Clone() => new PK7((byte[])Data.Clone(), Identifier);
private string GetString(int Offset, int Count) => StringConverter.GetString7(Data, Offset, Count);
private byte[] SetString(string value, int maxLength, bool chinese = false) => StringConverter.SetString7(value, maxLength, Language, chinese: chinese);

View file

@ -24,7 +24,7 @@ namespace PKHeX.Core
if (Data.Length != SIZE_PARTY)
Array.Resize(ref Data, SIZE_PARTY);
}
public override PKM Clone() => new XK3((byte[])Data.Clone()) {Purification = Purification};
public override PKM Clone() => new XK3((byte[])Data.Clone(), Identifier) {Purification = Purification};
private string GetString(int Offset, int Count) => StringConverter.GetBEString3(Data, Offset, Count);
private byte[] SetString(string value, int maxLength) => StringConverter.SetBEString3(value, maxLength);
@ -208,7 +208,7 @@ namespace PKHeX.Core
public override int MaxAbilityID => Legal.MaxAbilityID_3;
public override int MaxItemID => Legal.MaxItemID_3;
public override int MaxBallID => Legal.MaxBallID_3;
public override int MaxGameID => 5;
public override int MaxGameID => Legal.MaxGameID_3;
public override int MaxIV => 31;
public override int MaxEV => 252;
public override int OTLength => 7;

View file

@ -358,7 +358,7 @@ namespace PKHeX.Core
};
foreach (var p in pouch)
{
p.GetPouchG1(ref Data);
p.GetPouchG1(Data);
}
return pouch;
}
@ -374,8 +374,8 @@ namespace PKHeX.Core
p.Items[i] = p.Items[ofs++];
}
while (ofs < p.Items.Length)
p.Items[ofs++] = new InventoryItem { Count = 0, Index = 0 };
p.SetPouchG1(ref Data);
p.Items[ofs++] = new InventoryItem();
p.SetPouchG1(Data);
}
}
}

View file

@ -206,7 +206,7 @@ namespace PKHeX.Core
public override int SIZE_STORED => Japanese ? PKX.SIZE_2JLIST : PKX.SIZE_2ULIST;
protected override int SIZE_PARTY => Japanese ? PKX.SIZE_2JLIST : PKX.SIZE_2ULIST;
public override PKM BlankPKM => new PK2(null, null, Japanese);
public override PKM BlankPKM => new PK2(jp: Japanese);
public override Type PKMType => typeof(PK2);
private int SIZE_BOX => BoxSlotCount*SIZE_STORED;
@ -384,7 +384,7 @@ namespace PKHeX.Core
};
foreach (var p in pouch)
{
p.GetPouchG1(ref Data);
p.GetPouchG1(Data);
}
return pouch;
}
@ -401,7 +401,7 @@ namespace PKHeX.Core
}
while (ofs < p.Items.Length)
p.Items[ofs++] = new InventoryItem();
p.SetPouchG1(ref Data);
p.SetPouchG1(Data);
}
}
}

View file

@ -200,7 +200,7 @@ namespace PKHeX.Core
public override int MaxAbilityID => Legal.MaxAbilityID_3;
public override int MaxItemID => Legal.MaxItemID_3;
public override int MaxBallID => Legal.MaxBallID_3;
public override int MaxGameID => 5;
public override int MaxGameID => Legal.MaxGameID_3;
public override int BoxCount => 14;
public override int MaxEV => 255;
@ -417,14 +417,14 @@ namespace PKHeX.Core
{
if (p.Type != InventoryType.PCItems)
p.SecurityKey = SecurityKey;
p.GetPouch(ref Data);
p.GetPouch(Data);
}
return pouch;
}
set
{
foreach (var p in value)
p.SetPouch(ref Data);
p.SetPouch(Data);
}
}

View file

@ -144,12 +144,12 @@ namespace PKHeX.Core
public override PKM BlankPKM => new CK3();
public override Type PKMType => typeof(CK3);
public override int MaxMoveID => 354;
public override int MaxMoveID => Legal.MaxMoveID_3;
public override int MaxSpeciesID => Legal.MaxSpeciesID_3;
public override int MaxAbilityID => 77;
public override int MaxItemID => 547;
public override int MaxBallID => 0xC;
public override int MaxGameID => 5;
public override int MaxAbilityID => Legal.MaxAbilityID_3;
public override int MaxBallID => Legal.MaxBallID_3;
public override int MaxItemID => Legal.MaxItemID_3_COLO;
public override int MaxGameID => Legal.MaxGameID_3;
public override int MaxEV => 255;
public override int Generation => 3;

View file

@ -98,13 +98,13 @@ namespace PKHeX.Core
public override PKM BlankPKM => new PK3();
public override Type PKMType => typeof(PK3);
public override int MaxMoveID => 354;
public override int MaxMoveID => Legal.MaxMoveID_3;
public override int MaxSpeciesID => Legal.MaxSpeciesID_3;
public override int MaxAbilityID => 77;
public override int MaxItemID => 374;
public override int MaxBallID => 0xC;
public override int MaxGameID => 5;
public override int MaxAbilityID => Legal.MaxAbilityID_3;
public override int MaxItemID => Legal.MaxItemID_3;
public override int MaxBallID => Legal.MaxBallID_3;
public override int MaxGameID => Legal.MaxGameID_3;
public override int MaxEV => 255;
public override int Generation => 3;
protected override int GiftCountMax => 1;

View file

@ -157,13 +157,13 @@ namespace PKHeX.Core
public override PKM BlankPKM => new XK3();
public override Type PKMType => typeof(XK3);
public override int MaxMoveID => 354;
public override int MaxMoveID => Legal.MaxMoveID_3;
public override int MaxSpeciesID => Legal.MaxSpeciesID_3;
public override int MaxAbilityID => 77;
public override int MaxItemID => 593;
public override int MaxBallID => 0xC;
public override int MaxGameID => 5;
public override int MaxAbilityID => Legal.MaxAbilityID_3;
public override int MaxBallID => Legal.MaxBallID_3;
public override int MaxItemID => Legal.MaxItemID_3_XD;
public override int MaxGameID => Legal.MaxGameID_3;
public override int MaxEV => 255;
public override int Generation => 3;
protected override int GiftCountMax => 1;

View file

@ -65,7 +65,7 @@ namespace PKHeX.Core
public override int MaxItemID => Version == GameVersion.HGSS ? Legal.MaxItemID_4_HGSS : Version == GameVersion.Pt ? Legal.MaxItemID_4_Pt : Legal.MaxItemID_4_DP;
public override int MaxAbilityID => Legal.MaxAbilityID_4;
public override int MaxBallID => Legal.MaxBallID_4;
public override int MaxGameID => 15; // Colo/XD
public override int MaxGameID => Legal.MaxGameID_4; // Colo/XD
// Checksums
private static int[][] GetChecksumOffsets(GameVersion g)
@ -308,13 +308,13 @@ namespace PKHeX.Core
new InventoryPouch(InventoryType.MailItems, LegalMailItems, 999, OFS_MailItems),
};
foreach (var p in pouch)
p.GetPouch(ref Data);
p.GetPouch(Data);
return pouch;
}
set
{
foreach (var p in value)
p.SetPouch(ref Data);
p.SetPouch(Data);
}
}

View file

@ -82,10 +82,10 @@ namespace PKHeX.Core
public override int MaxMoveID => 467;
public override int MaxSpeciesID => Legal.MaxSpeciesID_4;
public override int MaxAbilityID => 123;
public override int MaxItemID => 536;
public override int MaxBallID => 0x18;
public override int MaxGameID => 15;
public override int MaxAbilityID => Legal.MaxAbilityID_4;
public override int MaxItemID => Legal.MaxItemID_4_HGSS;
public override int MaxBallID => Legal.MaxBallID_4;
public override int MaxGameID => Legal.MaxGameID_4;
public override int MaxEV => 255;
public override int Generation => 4;

View file

@ -419,13 +419,13 @@ namespace PKHeX.Core
new InventoryPouch(InventoryType.Berries, LegalBerries, 999, OFS_PouchBerry),
};
foreach (var p in pouch)
p.GetPouch(ref Data);
p.GetPouch(Data);
return pouch;
}
set
{
foreach (var p in value)
p.SetPouch(ref Data);
p.SetPouch(Data);
}
}

View file

@ -726,13 +726,13 @@ namespace PKHeX.Core
new InventoryPouch(InventoryType.Berries, Legal.Pouch_Berry_XY, 999, OFS_PouchBerry),
};
foreach (var p in pouch)
p.GetPouch(ref Data);
p.GetPouch(Data);
return pouch;
}
set
{
foreach (var p in value)
p.SetPouch(ref Data);
p.SetPouch(Data);
}
}

View file

@ -932,13 +932,13 @@ namespace PKHeX.Core
new InventoryPouch(InventoryType.BattleItems, Legal.Pouch_Roto_USUM, 999, OFS_BattleItems),
};
foreach (var p in pouch)
p.GetPouch7(ref Data);
p.GetPouch7(Data);
return pouch;
}
set
{
foreach (var p in value)
p.SetPouch7(ref Data);
p.SetPouch7(Data);
}
}

View file

@ -22,10 +22,7 @@ namespace PKHeX.Core
public bool New;
public bool FreeSpace;
public int Index, Count;
public InventoryItem Clone()
{
return new InventoryItem {Count = Count, Index = Index, New = New};
}
public InventoryItem Clone() => (InventoryItem) MemberwiseClone();
// Check Pouch Compatibility
public bool Valid(ushort[] LegalItems, bool HaX, int MaxItemID)
@ -60,7 +57,7 @@ namespace PKHeX.Core
PouchDataSize = size > -1 ? size : legal.Length;
}
public void GetPouch(ref byte[] Data)
public void GetPouch(byte[] Data)
{
InventoryItem[] items = new InventoryItem[PouchDataSize];
for (int i = 0; i < items.Length; i++)
@ -73,7 +70,7 @@ namespace PKHeX.Core
}
Items = items;
}
public void SetPouch(ref byte[] Data)
public void SetPouch(byte[] Data)
{
if (Items.Length != PouchDataSize)
throw new ArgumentException("Item array length does not match original pouch size.");
@ -84,7 +81,7 @@ namespace PKHeX.Core
BitConverter.GetBytes((ushort)((ushort)Items[i].Count ^ (ushort)SecurityKey)).CopyTo(Data, Offset + i*4 + 2);
}
}
public void GetPouch7(ref byte[] Data)
public void GetPouch7(byte[] Data)
{
InventoryItem[] items = new InventoryItem[PouchDataSize];
for (int i = 0; i < items.Length; i++)
@ -104,7 +101,7 @@ namespace PKHeX.Core
Items = items;
OriginalItems = Items.Select(i => i.Clone()).ToArray();
}
public void SetPouch7(ref byte[] Data, bool setNEW = false)
public void SetPouch7(byte[] Data, bool setNEW = false)
{
if (Items.Length != PouchDataSize)
throw new ArgumentException("Item array length does not match original pouch size.");
@ -150,7 +147,7 @@ namespace PKHeX.Core
}
}
public void GetPouchG1(ref byte[] Data)
public void GetPouchG1(byte[] Data)
{
InventoryItem[] items = new InventoryItem[PouchDataSize];
if (Type == InventoryType.TMHMs)
@ -209,7 +206,7 @@ namespace PKHeX.Core
Items = items;
}
public void SetPouchG1(ref byte[] Data)
public void SetPouchG1(byte[] Data)
{
if (Items.Length != PouchDataSize)
throw new ArgumentException("Item array length does not match original pouch size.");