diff --git a/PKHeX.Core/Legality/Analysis.cs b/PKHeX.Core/Legality/Analysis.cs index 964c3a0b9..aa9902178 100644 --- a/PKHeX.Core/Legality/Analysis.cs +++ b/PKHeX.Core/Legality/Analysis.cs @@ -212,23 +212,23 @@ private void UpdateTradebackG12() { if (pkm.Format == 1) { - Legal.GetTradebackStatusRBY(pkm); + Legal.SetTradebackStatusRBY(pkm); return; } if (pkm.Format == 2 || pkm.VC2) { - // check for impossible tradeback scenarios - // Korean gen2 games can't tradeback because there is no gen1 korean games released - if (pkm.Korean || pkm.IsEgg || pkm.HasOriginalMetLocation || pkm.Species > Legal.MaxSpeciesID_1 && !Legal.FutureEvolutionsGen1.Contains(pkm.Species)) - pkm.TradebackStatus = TradebackType.Gen2_NotTradeback; - else - pkm.TradebackStatus = TradebackType.Any; + // Check for impossible tradeback scenarios + // Korean Gen2 games can't tradeback because there are no Gen1 Korean games released + bool g2only = pkm.Korean || pkm.IsEgg || pkm.HasOriginalMetLocation || + pkm.Species > Legal.MaxSpeciesID_1 && !Legal.FutureEvolutionsGen1.Contains(pkm.Species); + pkm.TradebackStatus = g2only ? TradebackType.Gen2_NotTradeback : TradebackType.Any; + return; } // VC2 is released, we can assume it will be TradebackType.Any. - // Met date cannot be used definitively as the player can change their system clock. - // Is impossible to difference between a VC1 pokemon trade to gen7 after or before VC2 release. + // Is impossible to differentiate a VC1 pokemon traded to Gen7 after VC2 is available. + // Met Date cannot be used definitively as the player can change their system clock. pkm.TradebackStatus = TradebackType.Any; } private void UpdateTypeInfo() diff --git a/PKHeX.Core/Legality/Core.cs b/PKHeX.Core/Legality/Core.cs index c721d11ab..88ec58f75 100644 --- a/PKHeX.Core/Legality/Core.cs +++ b/PKHeX.Core/Legality/Core.cs @@ -1431,7 +1431,7 @@ private static bool GetCatchRateMatchesPreEvolution(PKM pkm, int catch_rate) bool IsCatchRateTrade() => (pkm.Species == 098 || pkm.Species == 099) && catch_rate == 204; bool IsCatchRateStadium() => Stadium_GiftSpecies.Contains(pkm.Species) && Stadium_CatchRate.Contains(catch_rate); } - internal static void GetTradebackStatusRBY(PKM pkm) + internal static void SetTradebackStatusRBY(PKM pkm) { if (!AllowGen1Tradeback) { diff --git a/PKHeX.Core/Legality/Structures/Learnset.cs b/PKHeX.Core/Legality/Structures/Learnset.cs index 8ffedb82c..a7c9d355c 100644 --- a/PKHeX.Core/Legality/Structures/Learnset.cs +++ b/PKHeX.Core/Legality/Structures/Learnset.cs @@ -44,11 +44,23 @@ public int[] GetEncounterMoves(int level, int count = 4) int end = Array.FindLastIndex(Levels, z => z <= level); if (end < 0) return new int[0]; - count = Math.Min(count, 4); - int start = end - count + 1; - if (start < 0) start = 0; - int[] result = new int[end - start + 1]; - Array.Copy(Moves, start, result, 0, result.Length); + + // Moves can be duplicated in the learnset. + // When generating the encounter, loop backwards until all moves are filled or no moves are left. + // Insert moves in reverse so that the first move is from the earliest position in the learnset. + int[] result = new int[count]; + var list = new List{Moves[end]}; + while (end-- > 0) + { + int move = Moves[end]; + if (list.Contains(move)) + continue; + + list.Insert(0, move); + if (list.Count == count) + break; + } + list.CopyTo(result); return result; } /// Returns the index of the lowest level move if the Pokémon were encountered at the specified level.