diff --git a/PKHeX/PKM/PK2.cs b/PKHeX/PKM/PK2.cs index a6319b95c..fcd06f5dd 100644 --- a/PKHeX/PKM/PK2.cs +++ b/PKHeX/PKM/PK2.cs @@ -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; } } diff --git a/PKHeX/PKM/PKMConverter.cs b/PKHeX/PKM/PKMConverter.cs index 7ab96784a..55fd04f4d 100644 --- a/PKHeX/PKM/PKMConverter.cs +++ b/PKHeX/PKM/PKMConverter.cs @@ -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;