Revert "Tweak 1<->2 conversion"

This reverts commit ce1202ead8.
This commit is contained in:
Kaphotics
2016-09-04 15:32:08 -07:00
2 changed files with 26 additions and 22 deletions

View File

@@ -337,13 +337,6 @@ public PK1 convertToPK1()
Array.Copy(otname, 0, pk1.otname, 0, otname.Length);
Array.Copy(nick, 0, pk1.nick, 0, nick.Length);
int[] newMoves = pk1.Moves;
for (int i = 0; i < 4; i++)
if (newMoves[i] > 165) // not present in Gen 1
newMoves[i] = 0;
pk1.Moves = newMoves;
pk1.FixMoves();
return pk1;
}
}

View File

@@ -100,32 +100,43 @@ public static PKM getPKMfromBytes(byte[] data, string ident = null)
}
internal static PKM convertToFormat(PKM pk, int Format, out string comment)
{
if (pk == null || pk.Species == 0)
string currentFormat = pk.Format.ToString();
PKM pkm = pk.Clone();
if (pk == null)
{
comment = "Null input. Aborting.";
return null;
}
string currentFormat = pk.Format.ToString();
PKM pkm = pk.Clone();
if (pk.Format == Format)
{
comment = "No need to convert, current format matches requested format.";
return pk;
}
if (pk.Format <= 2 && Format <= 2) // 1<->2, already checked not equal
if (pk.Format != Format && pk.Format <= 2 && Format <= 2)
{
switch (Format)
if (Format == 2) // pk.Format == 1
{
case 1:
if (pk.Species > 151)
{ comment = $"Cannot convert a {PKX.getSpeciesName(pk.Species, ((PK2)pk).Japanese ? 1 : 2)} to pk{Format}"; return null; }
pkm = ((PK2)pk).convertToPK1();
break;
case 2:
pkm = ((PK1)pk).convertToPK2();
break;
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;