mirror of
https://github.com/kwsch/PKHeX
synced 2024-12-12 13:42:36 +00:00
Tweak 1<->2 conversion
Delete gen2 only moves on 2->1 instead of refusing to convert; fix moves afterwards. Simplify PKMConverter checks
This commit is contained in:
parent
1bb5388b4b
commit
ce1202ead8
2 changed files with 22 additions and 26 deletions
|
@ -337,6 +337,13 @@ public override int Stat_Level
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,43 +100,32 @@ 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)
|
||||
if (pk == null || pk.Species == 0)
|
||||
{
|
||||
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 != Format && pk.Format <= 2 && Format <= 2)
|
||||
if (pk.Format <= 2 && Format <= 2) // 1<->2, already checked not equal
|
||||
{
|
||||
if (Format == 2) // pk.Format == 1
|
||||
switch (Format)
|
||||
{
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
comment = $"Converted from pk{pk.Format} to pk{Format}";
|
||||
return pkm;
|
||||
|
|
Loading…
Reference in a new issue