From 9ef2016d35f39733abd74292ff135d11377b9d50 Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 24 Sep 2017 10:36:16 -0700 Subject: [PATCH] Encounter Learnset move duplication fix a level 15/16 magmar has leer/smog twice in its learnset (at level 1 and at actual levels); returning just the 4 previous learned moves at level 15/16 yields duplicates for Smog. [Smog, Leer, Fire Punch, Smog | Leer, Ember]. By ignoring moves already added, the true movepool is acquired also fix TradebackType getting overwritten at the end of the method (in case of nontradeback like korean/egg) --- PKHeX.Core/Legality/Analysis.cs | 18 +++++++++--------- PKHeX.Core/Legality/Core.cs | 2 +- PKHeX.Core/Legality/Structures/Learnset.cs | 22 +++++++++++++++++----- 3 files changed, 27 insertions(+), 15 deletions(-) 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.