From ea87140aea1cebbe8f4cd8eea766300a64f4fdde Mon Sep 17 00:00:00 2001 From: Kurt Date: Wed, 4 May 2022 22:28:39 -0700 Subject: [PATCH] Remove optional gameversion for enc generators Simplifies some of the logic a little. --- .../EncounterStatic/EncounterStatic.cs | 2 +- .../ByGeneration/EncounterGenerator3.cs | 4 +- .../ByGeneration/EncounterGenerator4.cs | 2 +- .../Specific/EncounterSlotGenerator.cs | 44 ++++--------------- .../Specific/EncounterStaticGenerator.cs | 20 ++++----- .../Specific/EncounterTradeGenerator.cs | 15 +++---- 6 files changed, 28 insertions(+), 59 deletions(-) diff --git a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic.cs b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic.cs index ffd9999e4..dd669e476 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic.cs @@ -43,7 +43,7 @@ public abstract record EncounterStatic(GameVersion Version) : IEncounterable, IM private const string _name = "Static Encounter"; public string Name => _name; - public string LongName => Version == GameVersion.Any ? _name : $"{_name} ({Version})"; + public string LongName => $"{_name} ({Version})"; public bool IsShiny => Shiny.IsShiny(); public bool IsRandomUnspecificForm => Form >= FormDynamic; diff --git a/PKHeX.Core/Legality/Encounters/Generator/ByGeneration/EncounterGenerator3.cs b/PKHeX.Core/Legality/Encounters/Generator/ByGeneration/EncounterGenerator3.cs index ce4f8baac..f874a55d2 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/ByGeneration/EncounterGenerator3.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/ByGeneration/EncounterGenerator3.cs @@ -110,7 +110,7 @@ private static IEnumerable GenerateRawEncounters3CXD(PKM pkm) } // Encounter Slots - foreach (var z in GetValidWildEncounters34(pkm, chain)) + foreach (var z in GetValidWildEncounters(pkm, chain)) { var match = z.GetMatchRating(pkm); if (match == PartialMatch) @@ -167,7 +167,7 @@ private static IEnumerable GenerateRawEncounters3(PKM pkm, Legal // Encounter Slots var slots = FrameFinder.GetFrames(info.PIDIV, pkm).ToList(); - foreach (var z in GetValidWildEncounters34(pkm, chain)) + foreach (var z in GetValidWildEncounters(pkm, chain)) { var match = z.GetMatchRating(pkm); if (match == PartialMatch) diff --git a/PKHeX.Core/Legality/Encounters/Generator/ByGeneration/EncounterGenerator4.cs b/PKHeX.Core/Legality/Encounters/Generator/ByGeneration/EncounterGenerator4.cs index 1ab325d9b..86319160b 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/ByGeneration/EncounterGenerator4.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/ByGeneration/EncounterGenerator4.cs @@ -74,7 +74,7 @@ private static IEnumerable GenerateRawEncounters4(PKM pkm, Legal } var slots = FrameFinder.GetFrames(info.PIDIV, pkm).ToList(); - foreach (var slot in GetValidWildEncounters34(pkm, chain)) + foreach (var slot in GetValidWildEncounters(pkm, chain)) { var z = (EncounterSlot4)slot; var match = z.GetMatchRating(pkm); diff --git a/PKHeX.Core/Legality/Encounters/Generator/Specific/EncounterSlotGenerator.cs b/PKHeX.Core/Legality/Encounters/Generator/Specific/EncounterSlotGenerator.cs index 83b44b9d9..8e654969b 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Specific/EncounterSlotGenerator.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Specific/EncounterSlotGenerator.cs @@ -23,7 +23,7 @@ namespace PKHeX.Core { public static class EncounterSlotGenerator { - public static IEnumerable GetPossible(PKM pkm, IReadOnlyList chain, GameVersion gameSource = Any) + public static IEnumerable GetPossible(PKM pkm, IReadOnlyList chain, GameVersion gameSource) { var possibleAreas = GetAreasByGame(pkm, gameSource); return possibleAreas.SelectMany(z => z.GetSpecies(chain)); @@ -40,7 +40,7 @@ public static IEnumerable GetPossible(PKM pkm, IReadOnlyList SlotsSV, C => SlotsC, - _ => GetEncounterSlots(pkm, gameSource), + _ => GetEncounterTable(pkm, gameSource), }; private static IEnumerable GetRawEncounterSlots(PKM pkm, IReadOnlyList chain, GameVersion gameSource) @@ -57,46 +57,20 @@ private static IEnumerable GetRawEncounterSlots(PKM pkm, IReadOnl } } - public static IEnumerable GetValidWildEncounters34(PKM pkm, IReadOnlyList chain, GameVersion gameSource = Any) + public static IEnumerable GetValidWildEncounters12(PKM pkm, IReadOnlyList chain, GameVersion gameSource) { - if (gameSource == Any) - gameSource = (GameVersion)pkm.Version; - - var slots = GetRawEncounterSlots(pkm, chain, gameSource); - - return slots; // defer deferrals to the method consuming this collection - } - - public static IEnumerable GetValidWildEncounters12(PKM pkm, IReadOnlyList chain, GameVersion gameSource = Any) - { - if (gameSource == Any) - gameSource = (GameVersion)pkm.Version; - return GetRawEncounterSlots(pkm, chain, gameSource); } - public static IEnumerable GetValidWildEncounters(PKM pkm, IReadOnlyList chain, GameVersion gameSource = Any) + public static IEnumerable GetValidWildEncounters(PKM pkm, IReadOnlyList chain) { - if (gameSource == Any) - gameSource = (GameVersion)pkm.Version; - + var gameSource = (GameVersion)pkm.Version; return GetRawEncounterSlots(pkm, chain, gameSource); } - public static IEnumerable GetEncounterSlots(PKM pkm, GameVersion gameSource = Any) + private static IEnumerable GetEncounterAreas(PKM pkm, GameVersion gameSource) { - if (gameSource == Any) - gameSource = (GameVersion)pkm.Version; - - return GetEncounterTable(pkm, gameSource); - } - - private static IEnumerable GetEncounterAreas(PKM pkm, GameVersion gameSource = Any) - { - if (gameSource == Any) - gameSource = (GameVersion)pkm.Version; - - var slots = GetEncounterSlots(pkm, gameSource: gameSource); + var slots = GetEncounterTable(pkm, gameSource); bool noMet = !pkm.HasOriginalMetLocation || (pkm.Format == 2 && gameSource != C); if (noMet) return slots; @@ -106,7 +80,7 @@ private static IEnumerable GetEncounterAreas(PKM pkm, GameVersion internal static EncounterSlot? GetCaptureLocation(PKM pkm, IReadOnlyList chain) { - return GetPossible(pkm, chain) + return GetPossible(pkm, chain, (GameVersion)pkm.Version) .OrderBy(z => !chain.Any(s => s.Species == z.Species && s.Form == z.Form)) .ThenBy(z => z.LevelMin) .FirstOrDefault(); @@ -157,7 +131,7 @@ private static IEnumerable GetEncounterAreas(PKM pkm, GameVersion _ => Array.Empty(), }; - private static IEnumerable GetEncounterTableGSC(PKM pkm) + private static EncounterArea[] GetEncounterTableGSC(PKM pkm) { if (!ParseSettings.AllowGen2Crystal(pkm)) return SlotsGS; diff --git a/PKHeX.Core/Legality/Encounters/Generator/Specific/EncounterStaticGenerator.cs b/PKHeX.Core/Legality/Encounters/Generator/Specific/EncounterStaticGenerator.cs index 1f80ec0cf..01c60a9f2 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Specific/EncounterStaticGenerator.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Specific/EncounterStaticGenerator.cs @@ -22,11 +22,8 @@ namespace PKHeX.Core { public static class EncounterStaticGenerator { - public static IEnumerable GetPossible(PKM pkm, IReadOnlyList chain, GameVersion gameSource = Any) + public static IEnumerable GetPossible(PKM pkm, IReadOnlyList chain, GameVersion gameSource) { - if (gameSource == Any) - gameSource = (GameVersion)pkm.Version; - var table = gameSource switch { RD or GN or BU or YW => StaticRBY.Where(z => z.Version.Contains(gameSource)), @@ -51,16 +48,15 @@ static IEnumerable GetEvents(GameVersion g) return table.Where(e => chain.Any(d => d.Species == e.Species)); } - public static IEnumerable GetValidStaticEncounter(PKM pkm, IReadOnlyList chain, GameVersion gameSource = Any) + public static IEnumerable GetValidStaticEncounter(PKM pkm, IReadOnlyList chain) { - if (gameSource == Any) - gameSource = (GameVersion)pkm.Version; + return GetValidStaticEncounter(pkm, chain, (GameVersion)pkm.Version); + } + public static IEnumerable GetValidStaticEncounter(PKM pkm, IReadOnlyList chain, GameVersion gameSource) + { var table = GetEncounterStaticTable(pkm, gameSource); - var poss = table.Where(e => chain.Any(d => d.Species == e.Species)); - - // Back Check against pkm - return GetMatchingStaticEncounters(pkm, poss, chain); + return GetMatchingStaticEncounters(pkm, table, chain); } public static IEnumerable GetValidGBGifts(PKM pkm, IReadOnlyList chain, GameVersion gameSource) @@ -142,7 +138,7 @@ private static int GetVCSpecies(IReadOnlyList chain, PKM pkm, int m case 2: return EncounterStatic7.GetVC2(MaxSpeciesID_2, (byte)pkm.Met_Level); default: - return GetPossible(pkm, chain) + return GetPossible(pkm, chain, (GameVersion)pkm.Version) .OrderBy(z => !chain.Any(s => s.Species == z.Species && s.Form == z.Form)) .ThenBy(z => z.LevelMin) .FirstOrDefault(); diff --git a/PKHeX.Core/Legality/Encounters/Generator/Specific/EncounterTradeGenerator.cs b/PKHeX.Core/Legality/Encounters/Generator/Specific/EncounterTradeGenerator.cs index d388fb17a..ec2db171d 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Specific/EncounterTradeGenerator.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Specific/EncounterTradeGenerator.cs @@ -42,22 +42,21 @@ public static IEnumerable GetValidEncounterTradesVC(PKM pkm, I } } - public static IEnumerable GetValidEncounterTrades(PKM pkm, IReadOnlyList chain, GameVersion game = Any) + public static IEnumerable GetValidEncounterTrades(PKM pkm, IReadOnlyList chain) { - if (game == Any) - game = (GameVersion)pkm.Version; - + // Pre-filter for some language scenarios int lang = pkm.Language; if (lang == (int)LanguageID.UNUSED_6) // invalid language return Array.Empty(); if (lang == (int)LanguageID.Hacked && !EncounterTrade5PID.IsValidMissingLanguage(pkm)) // Japanese trades in BW have no language ID return Array.Empty(); - var poss = GetPossible(chain, game); - return GetValidEncounterTrades(pkm, chain, poss); + var game = (GameVersion)pkm.Version; + var table = GetTable(game); + return GetValidEncounterTrades(pkm, chain, table); } - private static IEnumerable GetValidEncounterTrades(PKM pkm, IReadOnlyList chain, IEnumerable poss) + private static IEnumerable GetValidEncounterTrades(PKM pkm, IReadOnlyList chain, EncounterTrade[] poss) { foreach (var p in poss) { @@ -81,7 +80,7 @@ private static IEnumerable GetTableVC(GameVersion game) return Array.Empty(); } - private static IEnumerable GetTable(GameVersion game) => game switch + private static EncounterTrade[] GetTable(GameVersion game) => game switch { R or S or E => Encounters3.TradeGift_RSE, FR or LG => Encounters3.TradeGift_FRLG,