diff --git a/PKHeX.Core/Legality/Encounters/Generator/EncounterMovesetGenerator.cs b/PKHeX.Core/Legality/Encounters/Generator/EncounterMovesetGenerator.cs
index 600d031e1..4574700d5 100644
--- a/PKHeX.Core/Legality/Encounters/Generator/EncounterMovesetGenerator.cs
+++ b/PKHeX.Core/Legality/Encounters/Generator/EncounterMovesetGenerator.cs
@@ -10,6 +10,22 @@ namespace PKHeX.Core
///
public static class EncounterMovesetGenerator
{
+ ///
+ /// Order in which objects are yielded from the generator.
+ ///
+ // ReSharper disable once AutoPropertyCanBeMadeGetOnly.Global
+ public static IEnumerable PriorityList { get; set; } = (EncounterOrder[])Enum.GetValues(typeof(EncounterOrder));
+
+ public enum EncounterOrder
+ {
+ Egg,
+ Mystery,
+ Link,
+ Static,
+ Trade,
+ Slot,
+ }
+
///
/// Gets possible objects that allow all moves requested to be learned.
///
@@ -104,8 +120,7 @@ public static IEnumerable GenerateVersionEncounters(PKM pk, IEnu
var dl = et.GetValidPreEvolutions(pk, maxLevel: 100, skipChecks: true);
int[] needs = GetNeededMoves(pk, moves, dl);
- foreach (var enc in GetPossible(pk, needs, version))
- yield return enc;
+ return PriorityList.SelectMany(type => GetPossibleOfType(pk, needs, version, type));
}
private static int[] GetNeededMoves(PKM pk, IEnumerable moves, IReadOnlyList dl)
@@ -118,47 +133,19 @@ private static int[] GetNeededMoves(PKM pk, IEnumerable moves, IReadOnlyLis
return moves.Except(canlearn).ToArray();
}
- ///
- /// Gets possible encounters that allow all moves requested to be learned.
- ///
- /// Rough Pokémon data which contains the requested species, gender, and form.
- /// Moves which cannot be taught by the player.
- /// Specific version to iterate for. Necessary for retrieving possible Egg Moves.
- /// A consumable list of possible encounters.
- private static IEnumerable GetPossible(PKM pk, IReadOnlyCollection needs, GameVersion version)
+ private static IEnumerable GetPossibleOfType(PKM pk, IReadOnlyCollection needs, GameVersion version, EncounterOrder type)
{
- // generate possible eggs
- var eggs = GetEggs(pk, needs, version);
- if (!GameVersion.CXD.Contains(version) && !GameVersion.GG.Contains(version))
+ switch (type)
{
- foreach (var egg in eggs)
- yield return egg;
+ case EncounterOrder.Egg: return GetEggs(pk, needs, version);
+ case EncounterOrder.Mystery: return GetGifts(pk, needs);
+ case EncounterOrder.Link: return GetLink(pk, needs);
+ case EncounterOrder.Static: return GetStatic(pk, needs);
+ case EncounterOrder.Trade: return GetTrades(pk, needs);
+ case EncounterOrder.Slot: return GetSlots(pk, needs);
+ default:
+ throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
-
- // mystery gifts next
- var gifts = GetGifts(pk, needs);
- foreach (var gift in gifts)
- yield return gift;
-
- // link stuff
- var links = GetLink(pk, needs);
- foreach (var link in links)
- yield return link;
-
- // static encounters last
- var statics = GetStatic(pk, needs);
- foreach (var enc in statics)
- yield return enc;
-
- // trades for kicks
- var trades = GetTrades(pk, needs);
- foreach (var trade in trades)
- yield return trade;
-
- // why not slots
- var slots = GetSlots(pk, needs);
- foreach (var slot in slots)
- yield return slot;
}
///
@@ -170,6 +157,9 @@ private static IEnumerable GetPossible(PKM pk, IReadOnlyCollecti
/// A consumable list of possible encounters.
private static IEnumerable GetEggs(PKM pk, IReadOnlyCollection needs, GameVersion version)
{
+ if (GameVersion.CXD.Contains(version) || GameVersion.GG.Contains(version))
+ yield break; // no eggs from these games
+
var eggs = EncounterEggGenerator.GenerateEggs(pk, all: true);
foreach (var egg in eggs)
{