PK1 <-> PK2 Conversion

This commit is contained in:
Michael Scire 2016-09-04 15:03:40 -07:00
parent 387ed9cbcc
commit 1bb5388b4b
4 changed files with 88 additions and 5 deletions

View file

@ -19,7 +19,7 @@ namespace PKHeX
191, 192, 193, 194, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249
};
internal static readonly ushort[] HeldItems_GSC = new ushort[1].Concat(Pouch_Items_GSC).Concat(Pouch_Ball_GSC).ToArray();
internal static readonly ushort[] HeldItems_GSC = new ushort[1].Concat(Pouch_Items_GSC).Concat(Pouch_Ball_GSC).Concat(Pouch_TMHM_GSC).ToArray();
internal static readonly int[] MovePP_GSC =
{

View file

@ -120,8 +120,8 @@ namespace PKHeX
get { return PKX.getG1Species(Data[0]); }
set
{
// Before updating catch rate, check if Special Yellow Version Pikachu
if (!(PKX.getG1Species(Data[0]) == 25 && value == 25 && Catch_Rate == 163))
// Before updating catch rate, check if non-standard
if (Catch_Rate == PersonalTable.RBY[Species].CatchRate)
Catch_Rate = PersonalTable.RBY[value].CatchRate;
Data[0] = (byte)PKX.setG1Species(value);
Type_A = PersonalTable.RBY[value].Types[0];
@ -250,6 +250,46 @@ namespace PKHeX
public override int CNT_Tough { get { return 0; } set { } }
public override int CNT_Sheen { get { return 0; } set { } }
#endregion
public PK2 convertToPK2()
{
PK2 pk2 = new PK2(null, Identifier, Japanese);
pk2.Species = Species;
Array.Copy(Data, 0x7, pk2.Data, 0x1, 0x1A);
// https://github.com/pret/pokecrystal/blob/master/engine/link.asm#L1132
if (!Legal.HeldItems_GSC.Contains((ushort)pk2.HeldItem))
switch (pk2.HeldItem)
{
case 0x19:
pk2.HeldItem = 0x92; // Leftovers
break;
case 0x2D:
pk2.HeldItem = 0x53; // Bitter Berry
break;
case 0x32:
pk2.HeldItem = 0xAE; // Leftovers
break;
case 0x5A:
case 0x64:
case 0x78:
case 0x87:
case 0xBE:
case 0xC3:
case 0xDC:
case 0xFA:
case 0xFF:
pk2.HeldItem = 0xAD; // Berry
break;
}
pk2.CurrentFriendship = PersonalTable.C[Species].BaseFriendship;
// Pokerus = 0
// Caught Data = 0
pk2.Stat_Level = Stat_Level;
Array.Copy(otname, 0, pk2.otname, 0, otname.Length);
Array.Copy(nick, 0, pk2.nick, 0, nick.Length);
return pk2;
}
}
public class PokemonList1

View file

@ -325,6 +325,20 @@ public override int Stat_Level
public override int CNT_Tough { get { return 0; } set { } }
public override int CNT_Sheen { get { return 0; } set { } }
#endregion
public PK1 convertToPK1()
{
PK1 pk1 = new PK1(null, Identifier, Japanese);
Array.Copy(Data, 0x1, pk1.Data, 0x7, 0x1A);
pk1.Species = Species; // This will take care of Typing :)
pk1.Stat_HPCurrent = Stat_HPCurrent;
pk1.Stat_Level = Stat_Level;
// Status = 0
Array.Copy(otname, 0, pk1.otname, 0, otname.Length);
Array.Copy(nick, 0, pk1.nick, 0, nick.Length);
return pk1;
}
}
public class PokemonList2

View file

@ -100,6 +100,9 @@ namespace PKHeX
}
internal static PKM convertToFormat(PKM pk, int Format, out string comment)
{
string currentFormat = pk.Format.ToString();
PKM pkm = pk.Clone();
if (pk == null)
{
comment = "Null input. Aborting.";
@ -110,6 +113,34 @@ namespace PKHeX
comment = "No need to convert, current format matches requested format.";
return pk;
}
if (pk.Format != Format && pk.Format <= 2 && Format <= 2)
{
if (Format == 2) // pk.Format == 1
{
pkm = ((PK1) pk).convertToPK2();
}
if (Format == 1) // pk.Format == 2
{
// Only convert if it's legal to do so.
if (1 <= pk.Species && pk.Species <= 151)
{
foreach (var move in new[] { pk.Move1, pk.Move2, pk.Move3, pk.Move4})
if (move < 1 || move > 165)
{
comment = $"Pokemon cannot be converted due to invalid move: {Main.movelist[move]}";
return null;
}
pkm = ((PK2) pk).convertToPK1();
}
else
{
comment =$"Cannot convert a {PKX.getSpeciesName(pk.Species, ((PK2)pk).Japanese ? 1 : 2)} to pk{Format}";
return null;
}
}
comment = $"Converted from pk{pk.Format} to pk{Format}";
return pkm;
}
if (pk.Format > Format)
{
comment = "Cannot convert a PKM backwards." + Environment.NewLine
@ -128,8 +159,6 @@ namespace PKHeX
+ "Please wait for Sun/Moon to release and documentation to occur.";
return null;
}
string currentFormat = pk.Format.ToString();
PKM pkm = pk.Clone();
if (pkm.IsEgg) // force hatch
{
pkm.IsEgg = false;