diff --git a/PKHeX.Core/Legality/Evolutions/EvolutionChain.cs b/PKHeX.Core/Legality/Evolutions/EvolutionChain.cs index 45ca659f1..532b04577 100644 --- a/PKHeX.Core/Legality/Evolutions/EvolutionChain.cs +++ b/PKHeX.Core/Legality/Evolutions/EvolutionChain.cs @@ -10,13 +10,13 @@ namespace PKHeX.Core { private static readonly List NONE = new(0); - internal static IReadOnlyList[] GetEvolutionChainsAllGens(PKM pkm, IEncounterTemplate Encounter) + internal static IReadOnlyList[] GetEvolutionChainsAllGens(PKM pkm, IEncounterTemplate enc) { - var CompleteEvoChain = GetEvolutionChain(pkm, Encounter, pkm.Species, pkm.CurrentLevel); - if (Encounter is EncounterInvalid || pkm.IsEgg || CompleteEvoChain.Count == 0) - return GetChainSingle(pkm, CompleteEvoChain); + var chain = GetEvolutionChain(pkm, enc, pkm.Species, pkm.CurrentLevel); + if (enc is EncounterInvalid || pkm.IsEgg || chain.Count == 0) + return GetChainSingle(pkm, chain); - return GetChainAll(pkm, Encounter, CompleteEvoChain); + return GetChainAll(pkm, enc, chain); } private static List[] GetChainBase(int maxgen) @@ -27,19 +27,19 @@ namespace PKHeX.Core return GensEvoChains; } - private static List[] GetChainSingle(PKM pkm, List CompleteEvoChain) + private static List[] GetChainSingle(PKM pkm, List fullChain) { var chain = GetChainBase(Math.Max(2, pkm.Format)); - chain[pkm.Format] = CompleteEvoChain; + chain[pkm.Format] = fullChain; return chain; } - private static List[] GetChainAll(PKM pkm, IEncounterTemplate enc, IReadOnlyList CompleteEvoChain) + private static List[] GetChainAll(PKM pkm, IEncounterTemplate enc, IReadOnlyList fullChain) { int maxgen = pkm is PK1 {Gen1_NotTradeback: false} ? 2 : pkm.Format; var GensEvoChains = GetChainBase(maxgen); - var queue = new Queue(CompleteEvoChain); + var queue = new Queue(fullChain); var mostEvolved = queue.Dequeue(); int lvl = pkm.CurrentLevel; @@ -143,10 +143,10 @@ namespace PKHeX.Core _ => false }; - private static void TrimVC1Transfer(PKM pkm, IList> GensEvoChains) + private static void TrimVC1Transfer(PKM pkm, IList> allChains) { - if (GensEvoChains[7].All(z => z.Species > MaxSpeciesID_1)) - GensEvoChains[pkm.Format] = NONE; // needed a Gen1 species present; invalidate the chain. + if (allChains[7].All(z => z.Species > MaxSpeciesID_1)) + allChains[pkm.Format] = NONE; // needed a Gen1 species present; invalidate the chain. } internal static int GetEvoChainSpeciesIndex(IReadOnlyList chain, int species) @@ -159,39 +159,39 @@ namespace PKHeX.Core return -1; } - private static List GetEvolutionChain(PKM pkm, IEncounterTemplate Encounter, int maxspec, int maxlevel) + private static List GetEvolutionChain(PKM pkm, IEncounterTemplate enc, int mostEvolvedSpecies, int maxlevel) { - var chain = GetValidPreEvolutions(pkm, minLevel: Encounter.LevelMin); - if (Encounter.Species == maxspec) + var chain = GetValidPreEvolutions(pkm, minLevel: enc.LevelMin); + if (enc.Species == mostEvolvedSpecies) { if (chain.Count != 1) { - chain.RemoveAll(z => z.Species != Encounter.Species); - chain[0].MinLevel = Encounter.LevelMin; + chain.RemoveAll(z => z.Species != enc.Species); + chain[0].MinLevel = enc.LevelMin; } return chain; } // Evolution chain is in reverse order (devolution) // Find the index of the minimum species to determine the end of the chain - int minindex = GetEvoChainSpeciesIndex(chain, Encounter.Species); - bool last = minindex < 0 || minindex == chain.Count - 1; + int minIndex = GetEvoChainSpeciesIndex(chain, enc.Species); + bool last = minIndex < 0 || minIndex == chain.Count - 1; // If we remove a pre-evolution, update the chain if appropriate. if (!last) { // Remove chain species after the encounter int count = chain.Count; - for (int i = minindex + 1; i < count; i++) + for (int i = minIndex + 1; i < count; i++) chain.RemoveAt(i); if (chain.Count == 0) return chain; // no species left in chain - CheckLastEncounterRemoval(Encounter, chain); + CheckLastEncounterRemoval(enc, chain); } // maxspec is used to remove future geneneration evolutions, to gather evolution chain of a pokemon in previous generations - int skip = Math.Max(0, GetEvoChainSpeciesIndex(chain, maxspec)); + int skip = Math.Max(0, GetEvoChainSpeciesIndex(chain, mostEvolvedSpecies)); for (int i = 0; i < skip; i++) chain.RemoveAt(0); diff --git a/PKHeX.Core/Legality/RNG/MethodFinder.cs b/PKHeX.Core/Legality/RNG/MethodFinder.cs index 9e84bd8f3..fb406ce3b 100644 --- a/PKHeX.Core/Legality/RNG/MethodFinder.cs +++ b/PKHeX.Core/Legality/RNG/MethodFinder.cs @@ -813,34 +813,32 @@ namespace PKHeX.Core _ => false }; - public static bool IsCompatible3(this PIDType val, IEncounterTemplate encounter, PKM pkm) + public static bool IsCompatible3(this PIDType val, IEncounterTemplate encounter, PKM pkm) => encounter switch { - switch (encounter) - { - case WC3 g: - if (val == g.Method) - return true; - if (val == CXDAnti && g.Shiny == Shiny.Never && g.Method == CXD) - return true; - // forced shiny eggs, when hatched, can lose their detectable correlation. - return g.IsEgg && !pkm.IsEgg && val == None && (g.Method is BACD_R_S or BACD_U_S); - case EncounterStaticShadow: - return pkm.Version == (int)GameVersion.CXD && (val is CXD or CXDAnti); - case EncounterStatic3 s: - return pkm.Version switch - { - (int)GameVersion.CXD => val is CXD or CXD_ColoStarter or CXDAnti, - (int)GameVersion.E => val == Method_1, // no roamer glitch - (int)GameVersion.FR or (int)GameVersion.LG => s.Roaming ? val.IsRoamerPIDIV(pkm) : val == Method_1, // roamer glitch - _ => s.Roaming ? val.IsRoamerPIDIV(pkm) : MethodH14.Contains(val), // RS, roamer glitch && RSBox s/w emulation => method 4 available - }; - case EncounterSlot w: - if (pkm.Version == 15) - return val == PokeSpot; - return (w.Species == (int)Species.Unown ? MethodH_Unown : MethodH).Contains(val); - default: - return val == None; - } + WC3 g => IsCompatible3Mystery(val, pkm, g), + EncounterStatic3 s => IsCompatible3Static(val, pkm, s), + EncounterSlot3 w => (w.Species == (int)Species.Unown ? MethodH_Unown : MethodH).Contains(val), + EncounterStaticShadow => val is CXD or CXDAnti, + EncounterSlot3PokeSpot => val == PokeSpot, + _ => val == None + }; + + private static bool IsCompatible3Static(PIDType val, PKM pkm, EncounterStatic3 s) => pkm.Version switch + { + (int)GameVersion.CXD => val is CXD or CXD_ColoStarter or CXDAnti, + (int)GameVersion.E => val == Method_1, // no roamer glitch + (int)GameVersion.FR or (int) GameVersion.LG => s.Roaming ? val.IsRoamerPIDIV(pkm) : val == Method_1, // roamer glitch + _ => s.Roaming ? val.IsRoamerPIDIV(pkm) : MethodH14.Contains(val), // RS, roamer glitch && RSBox s/w emulation => method 4 available + }; + + private static bool IsCompatible3Mystery(PIDType val, PKM pkm, WC3 g) + { + if (val == g.Method) + return true; + if (val == CXDAnti && g.Shiny == Shiny.Never && g.Method == CXD) + return true; + // forced shiny eggs, when hatched, can lose their detectable correlation. + return g.IsEgg && !pkm.IsEgg && val == None && (g.Method is BACD_R_S or BACD_U_S); } private static bool IsRoamerPIDIV(this PIDType val, PKM pkm) diff --git a/PKHeX.Core/PKHeX.Core.csproj b/PKHeX.Core/PKHeX.Core.csproj index 3cf9e9977..9cf5b2a8c 100644 --- a/PKHeX.Core/PKHeX.Core.csproj +++ b/PKHeX.Core/PKHeX.Core.csproj @@ -12,6 +12,7 @@ https://github.com/kwsch/PKHeX 9 enable + true