Split Pokemon4 class into separate box/party versions.

This commit is contained in:
Greg Edwards
2015-04-14 21:23:50 -04:00
parent caec6383d4
commit 222f8eba89
4 changed files with 104 additions and 56 deletions

View File

@@ -96,6 +96,7 @@
<Compile Include="Structures\Pokemon4.cs" />
<Compile Include="Structures\PokemonBase.cs" />
<Compile Include="Structures\IntStatValues.cs" />
<Compile Include="Structures\PokemonParty4.cs" />
<Compile Include="Structures\PokemonPartyBase.cs" />
<Compile Include="Structures\StatValues.cs" />
<Compile Include="Structures\StatValuesBase.cs" />

View File

@@ -166,36 +166,6 @@ namespace PkmnFoundations.Structures
Unknown4 = block[31];
}
// todo: split this class into separate box/party versions.
{
rand = (int)Personality;
byte[] block = reader.ReadBytes(100);
for (int pos = 0; pos < 100; pos += 2)
{
rand = DecryptRNG(rand);
block[pos] ^= (byte)(rand >> 16);
block[pos + 1] ^= (byte)(rand >> 24);
}
StatusAffliction = block[0];
Unknown5 = block[1];
Unknown6 = BitConverter.ToUInt16(block, 2);
Level = block[4];
CapsuleIndex = block[5];
HP = BitConverter.ToUInt16(block, 6);
m_stats = new IntStatValues(BitConverter.ToUInt16(block, 8),
BitConverter.ToUInt16(block, 10),
BitConverter.ToUInt16(block, 12),
BitConverter.ToUInt16(block, 14),
BitConverter.ToUInt16(block, 16),
BitConverter.ToUInt16(block, 18));
Unknown7 = new byte[56];
Array.Copy(block, 20, Unknown7, 0, 56);
Seals = new byte[24];
Array.Copy(block, 76, Seals, 0, 24);
}
byte[] ribbons = new byte[12];
Array.Copy(BitConverter.GetBytes(ribbons1), 0, ribbons, 0, 4);
Array.Copy(BitConverter.GetBytes(ribbons2), 0, ribbons, 4, 4);
@@ -349,34 +319,14 @@ namespace PkmnFoundations.Structures
/// </summary>
public HashSet<int> UnknownRibbons { get; private set; }
// party-only stuff. (todo: put in derived class)
public byte StatusAffliction { get; set; }
// todo: ball seals
public byte Unknown5 { get; set; }
public ushort Unknown6 { get; set; }
public byte CapsuleIndex { get; set; }
public ushort HP { get; set; }
//public IntStatValues Stats { get; set; } // cached stats (only refreshes per level on gen4)
public byte[] Unknown7 { get; set; } // 56 bytes
public byte[] Seals { get; set; }
private IntStatValues m_stats;
// todo: this should go into the derived class.
// the implementation here should auto-calculate the stats. (as in GenV)
public override IntStatValues Stats
{
get { return m_stats; }
}
private static int DecryptRNG(int prev)
protected static int DecryptRNG(int prev)
{
return prev * 0x41c64e6d + 0x6073;
}
public override int Size
{
get { return 236; }
get { return 136; }
}
}
}

View File

@@ -0,0 +1,97 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace PkmnFoundations.Structures
{
public class PokemonParty4 : Pokemon4
{
public PokemonParty4(Pokedex.Pokedex pokedex) : base(pokedex)
{
Initialize();
}
public PokemonParty4(Pokedex.Pokedex pokedex, BinaryReader data) : base(pokedex)
{
Initialize();
Load(data);
}
public PokemonParty4(Pokedex.Pokedex pokedex, byte[] data) : base(pokedex)
{
Initialize();
Load(data);
}
public PokemonParty4(Pokedex.Pokedex pokedex, byte[] data, int offset)
: base(pokedex)
{
Initialize();
Load(data, offset);
}
private void Initialize()
{
}
protected override void Load(BinaryReader reader)
{
base.Load(reader);
{
int rand = (int)Personality;
byte[] block = reader.ReadBytes(100);
for (int pos = 0; pos < 100; pos += 2)
{
rand = DecryptRNG(rand);
block[pos] ^= (byte)(rand >> 16);
block[pos + 1] ^= (byte)(rand >> 24);
}
StatusAffliction = block[0];
Unknown5 = block[1];
Unknown6 = BitConverter.ToUInt16(block, 2);
Level = block[4];
CapsuleIndex = block[5];
HP = BitConverter.ToUInt16(block, 6);
m_stats = new IntStatValues(BitConverter.ToUInt16(block, 8),
BitConverter.ToUInt16(block, 10),
BitConverter.ToUInt16(block, 12),
BitConverter.ToUInt16(block, 14),
BitConverter.ToUInt16(block, 16),
BitConverter.ToUInt16(block, 18));
Unknown7 = new byte[56];
Array.Copy(block, 20, Unknown7, 0, 56);
Seals = new byte[24];
Array.Copy(block, 76, Seals, 0, 24);
}
}
// todo: parse status afflictions (enum + sleep turns)
public byte StatusAffliction { get; set; }
// todo: Parse ball seals
public byte Unknown5 { get; set; }
public ushort Unknown6 { get; set; }
public byte CapsuleIndex { get; set; }
public ushort HP { get; set; } // remaining hp
public byte[] Unknown7 { get; set; } // 56 bytes
public byte[] Seals { get; set; } // 24 bytes
// cached stats on the party structure. This gives rise to the
// "box trick" on Gens 1-4 whereby putting the pokemon into the box
// recalculates its stats.
private IntStatValues m_stats;
public override IntStatValues Stats
{
get { return m_stats; }
}
public override int Size
{
get { return 236; }
}
}
}

View File

@@ -19,7 +19,7 @@ namespace PkmnFoundations.Web.gts
protected void Page_Load(object sender, EventArgs e)
{
m_pokedex = (Pokedex.Pokedex)Application["pkmncfPokedex"];
Pokemon4 pkmn = null;
PokemonParty4 pkmn = null;
if (Request.QueryString.Count == 0 || Request.QueryString.Count > 2) throw new WebException(400);
if (Request.QueryString["offer"] != null ||
@@ -55,13 +55,13 @@ namespace PkmnFoundations.Web.gts
case "4":
{
GtsRecord4 record = Database.Instance.GtsGetRecord4(tradeId, isExchanged, true);
if (record != null) pkmn = new Pokemon4(m_pokedex, record.Data);
if (record != null) pkmn = new PokemonParty4(m_pokedex, record.Data);
} break;
case "5":
{
GtsRecord5 record = Database.Instance.GtsGetRecord5(tradeId, isExchanged, true);
if (record != null) pkmn = new Pokemon4(m_pokedex, record.Data);
if (record != null) pkmn = new PokemonParty4(m_pokedex, record.Data);
} break;
default:
@@ -81,7 +81,7 @@ namespace PkmnFoundations.Web.gts
Bind(pkmn);
}
private void Bind(Pokemon4 pkmn)
private void Bind(PokemonParty4 pkmn)
{
litNickname.Text = pkmn.Nickname;
bool shiny = pkmn.IsShiny;