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)
This commit is contained in:
Kurt
2017-09-24 10:36:16 -07:00
parent e5d7a063af
commit 9ef2016d35
3 changed files with 27 additions and 15 deletions

View File

@@ -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()

View File

@@ -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)
{

View File

@@ -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<int>{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;
}
/// <summary>Returns the index of the lowest level move if the Pokémon were encountered at the specified level.</summary>