From d94fc65367a92c4e59d14d8b08b64c2f3712ca4e Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 10 Jun 2018 14:45:25 -0700 Subject: [PATCH] Refactoring continued reduction in Core size, simplify/clean up usages --- PKHeX.Core/Legality/Checks.cs | 2 +- PKHeX.Core/Legality/Core.cs | 78 ++++++++----------- .../Legality/Evolutions/EvolutionLineage.cs | 4 +- PKHeX.Core/Legality/Moves/EggInfoSource.cs | 4 +- PKHeX.Core/Legality/Moves/MoveLevelUp.cs | 30 +++---- 5 files changed, 52 insertions(+), 66 deletions(-) diff --git a/PKHeX.Core/Legality/Checks.cs b/PKHeX.Core/Legality/Checks.cs index 261b9e2cf..170b07419 100644 --- a/PKHeX.Core/Legality/Checks.cs +++ b/PKHeX.Core/Legality/Checks.cs @@ -73,7 +73,7 @@ private void VerifyGender() } private void VerifyItem() { - if (!Legal.IsHeldItemAllowed(pkm.HeldItem, pkm.Format)) + if (!Legal.IsHeldItemAllowed(pkm)) AddLine(Severity.Invalid, V204, CheckIdentifier.Form); if (pkm.Format == 3 && pkm.HeldItem == 175) VerifyEReaderBerry(); diff --git a/PKHeX.Core/Legality/Core.cs b/PKHeX.Core/Legality/Core.cs index ab64e71c6..a98596131 100644 --- a/PKHeX.Core/Legality/Core.cs +++ b/PKHeX.Core/Legality/Core.cs @@ -142,8 +142,8 @@ internal static int[] GetMaxLevelLearnMoveG1(int species, List moves) internal static List[] GetExclusiveMovesG1(int species1, int species2, IEnumerable tmhm, IEnumerable moves) { // Return from two species the exclusive moves that only one could learn and also the current pokemon have it in its current moveset - var moves1 = MoveLevelUp.AddMovesLevelUp1(species1, 1, 100); - var moves2 = MoveLevelUp.AddMovesLevelUp1(species2, 1, 100); + var moves1 = MoveLevelUp.GetMovesLevelUp1(species1, 1, 100); + var moves2 = MoveLevelUp.GetMovesLevelUp1(species2, 1, 100); // Remove common moves and remove tmhm, remove not learned moves var common = new HashSet(moves1.Intersect(moves2).Concat(tmhm)); @@ -607,7 +607,7 @@ private static List GetRequiredMoveCountLevel(PKM pk) if (minlevel > pk.CurrentLevel) return new List(); - return MoveLevelUp.AddMovesLevelUp1(basespecies, maxlevel, minlevel); + return MoveLevelUp.GetMovesLevelUp1(basespecies, maxlevel, minlevel); } internal static bool GetWasEgg23(PKM pkm) @@ -793,23 +793,15 @@ internal static ICollection GetWildBalls(PKM pkm) { switch (pkm.GenNumber) { - case 1: - return WildPokeBalls1; - case 2: - return WildPokeBalls2; - case 3: - return WildPokeBalls3; - case 4: - return pkm.HGSS ? WildPokeBalls4_HGSS : WildPokeBalls4_DPPt; - case 5: - return WildPokeBalls5; - case 6: - return WildPokeballs6; - case 7: - return WildPokeballs7; + case 1: return WildPokeBalls1; + case 2: return WildPokeBalls2; + case 3: return WildPokeBalls3; + case 4: return pkm.HGSS ? WildPokeBalls4_HGSS : WildPokeBalls4_DPPt; + case 5: return WildPokeBalls5; + case 6: return WildPokeballs6; + case 7: return WildPokeballs7; - default: - return null; + default: return null; } } internal static int GetEggHatchLevel(PKM pkm) => pkm.Format <= 3 ? 5 : 1; @@ -821,7 +813,7 @@ private static ICollection GetSplitBreedGeneration(int generation) { switch (generation) { - case 1: return Empty; + case 1: case 2: return Empty; case 3: return SplitBreed_3; case 4: return SplitBreed; @@ -867,8 +859,6 @@ internal static IEnumerable GetFutureGenEvolutions(int generation) } internal static int GetDebutGeneration(int species) { - if (species <= 0) - return 0; if (species <= MaxSpeciesID_1) return 1; if (species <= MaxSpeciesID_2) @@ -916,7 +906,11 @@ private static bool[] GetReleasedHeldItems(int generation) default: return new bool[0]; } } - internal static bool IsHeldItemAllowed(int item, int generation) + internal static bool IsHeldItemAllowed(PKM pkm) + { + return IsHeldItemAllowed(pkm.HeldItem, pkm.Format); + } + private static bool IsHeldItemAllowed(int item, int generation) { if (item < 0) return false; @@ -1073,14 +1067,18 @@ internal static bool GetCanBeCaptured(int species, int gen, GameVersion version switch (version) { case GameVersion.Any: - return GetCanBeCaptured(species, SlotsX, StaticX, XY:true) - || GetCanBeCaptured(species, SlotsY, StaticY, XY:true) + return FriendSafari.Contains(species) + || GetCanBeCaptured(species, SlotsX, StaticX) + || GetCanBeCaptured(species, SlotsY, StaticY) || GetCanBeCaptured(species, SlotsA, StaticA) || GetCanBeCaptured(species, SlotsO, StaticO); case GameVersion.X: - return GetCanBeCaptured(species, SlotsX, StaticX, XY:true); + return FriendSafari.Contains(species) + || GetCanBeCaptured(species, SlotsX, StaticX); case GameVersion.Y: - return GetCanBeCaptured(species, SlotsY, StaticY, XY:true); + return FriendSafari.Contains(species) + || GetCanBeCaptured(species, SlotsY, StaticY); + case GameVersion.AS: return GetCanBeCaptured(species, SlotsA, StaticA); case GameVersion.OR: @@ -1090,11 +1088,8 @@ internal static bool GetCanBeCaptured(int species, int gen, GameVersion version } return false; } - private static bool GetCanBeCaptured(int species, IEnumerable area, IEnumerable statics, bool XY = false) + private static bool GetCanBeCaptured(int species, IEnumerable area, IEnumerable statics) { - if (XY && FriendSafari.Contains(species)) - return true; - if (area.Any(loc => loc.Slots.Any(slot => slot.Species == species))) return true; if (statics.Any(enc => enc.Species == species && !enc.Gift)) @@ -1103,17 +1098,17 @@ private static bool GetCanBeCaptured(int species, IEnumerable are } internal static bool GetCanLearnMachineMove(PKM pkm, int move, int generation, GameVersion version = GameVersion.Any) { - return GetValidMoves(pkm, version, GetValidPreEvolutions(pkm).ToArray(), generation, Machine: true).Contains(move); + return GetValidMoves(pkm, version, GetValidPreEvolutions(pkm), generation, Machine: true).Contains(move); } internal static bool GetCanRelearnMove(PKM pkm, int move, int generation, GameVersion version = GameVersion.Any) { - return GetValidMoves(pkm, version, GetValidPreEvolutions(pkm).ToArray(), generation, LVL: true, Relearn: true).Contains(move); + return GetValidMoves(pkm, version, GetValidPreEvolutions(pkm), generation, LVL: true, Relearn: true).Contains(move); } internal static bool GetCanKnowMove(PKM pkm, int move, int generation, GameVersion version = GameVersion.Any) { if (pkm.Species == 235 && !InvalidSketch.Contains(move)) return true; - return GetValidMoves(pkm, version, GetValidPreEvolutions(pkm).ToArray(), generation, LVL: true, Relearn: true, Tutor: true, Machine: true).Contains(move); + return GetValidMoves(pkm, version, GetValidPreEvolutions(pkm), generation, LVL: true, Relearn: true, Tutor: true, Machine: true).Contains(move); } internal static int GetBaseEggSpecies(PKM pkm, int skipOption = 0) { @@ -1233,7 +1228,7 @@ internal static void SetTradebackStatusRBY(PKM pkm) internal static DexLevel[][] GetEvolutionChainsAllGens(PKM pkm, IEncounterable Encounter) { - var CompleteEvoChain = GetEvolutionChain(pkm, Encounter).ToArray(); + var CompleteEvoChain = GetEvolutionChain(pkm, Encounter); int maxgen = pkm.Format == 1 && !pkm.Gen1_NotTradeback ? 2 : pkm.Format; int mingen = (pkm.Format == 2 || pkm.VC2) && !pkm.Gen2_NotTradeback ? 1 : pkm.GenNumber; DexLevel[][] GensEvoChains = new DexLevel[maxgen + 1][]; @@ -1335,10 +1330,9 @@ private static DexLevel[] GetEvolutionChain(PKM pkm, IEncounterable Encounter) { return GetEvolutionChain(pkm, Encounter, pkm.Species, 100); } - private static DexLevel[] GetEvolutionChain(PKM pkm, IEncounterable Encounter, int maxspec, int maxlevel) { - DexLevel[] vs = GetValidPreEvolutions(pkm).ToArray(); + var vs = GetValidPreEvolutions(pkm).ToArray(); // Evolution chain is in reverse order (devolution) int minspec = Encounter.Species; @@ -1480,7 +1474,7 @@ private static IEnumerable GetMoves(PKM pkm, int species, int minlvlG1, int { List r = new List(); if (LVL) - r.AddRange(MoveLevelUp.GetLevelUpMoves(pkm, species, minlvlG1, minlvlG2, lvl, form, Version, MoveReminder, Generation)); + r.AddRange(MoveLevelUp.GetMovesLevelUp(pkm, species, minlvlG1, minlvlG2, lvl, form, Version, MoveReminder, Generation)); if (Machine) r.AddRange(MoveTechnicalMachine.GetTMHM(pkm, species, form, Generation, Version, RemoveTransferHM)); if (moveTutor) @@ -1491,14 +1485,6 @@ internal static int[] GetEggMoves(PKM pkm, int species, int formnum, GameVersion { return MoveEgg.GetEggMoves(pkm, species, formnum, version); } - internal static IEnumerable GetTMHM(PKM pkm, int species, int form, int generation, GameVersion Version = GameVersion.Any, bool RemoveTransferHM = true) - { - return MoveTechnicalMachine.GetTMHM(pkm, species, form, generation, Version, RemoveTransferHM); - } - internal static IEnumerable GetTutorMoves(PKM pkm, int species, int form, bool specialTutors, int generation) - { - return MoveTutor.GetTutorMoves(pkm, species, form, specialTutors, generation); - } internal static bool IsTradedKadabraG1(PKM pkm) { if (!(pkm is PK1 pk1) || pk1.Species != 64) diff --git a/PKHeX.Core/Legality/Evolutions/EvolutionLineage.cs b/PKHeX.Core/Legality/Evolutions/EvolutionLineage.cs index 1581a154e..9c78279c4 100644 --- a/PKHeX.Core/Legality/Evolutions/EvolutionLineage.cs +++ b/PKHeX.Core/Legality/Evolutions/EvolutionLineage.cs @@ -14,7 +14,7 @@ public void Insert(EvolutionMethod entry) { int matchChain = -1; for (int i = 0; i < Chain.Count; i++) - if (Enumerable.Any(Chain[i].StageEntryMethods, e => e.Species == entry.Species)) + if (Chain[i].StageEntryMethods.Any(e => e.Species == entry.Species)) matchChain = i; if (matchChain != -1) @@ -27,7 +27,7 @@ public void Insert(EvolutionStage evo) Chain.Insert(0, evo); } - public IList GetExplicitLineage(PKM pkm, int maxLevel, bool skipChecks, int maxSpeciesTree, int maxSpeciesOrigin, int minLevel) + public List GetExplicitLineage(PKM pkm, int maxLevel, bool skipChecks, int maxSpeciesTree, int maxSpeciesOrigin, int minLevel) { int lvl = maxLevel; List dl = new List { new DexLevel { Species = pkm.Species, Level = lvl, Form = pkm.AltForm } }; diff --git a/PKHeX.Core/Legality/Moves/EggInfoSource.cs b/PKHeX.Core/Legality/Moves/EggInfoSource.cs index 297c9fe68..6ae71e6fd 100644 --- a/PKHeX.Core/Legality/Moves/EggInfoSource.cs +++ b/PKHeX.Core/Legality/Moves/EggInfoSource.cs @@ -21,11 +21,11 @@ public EggInfoSource(PKM pkm, IEnumerable specialMoves, EncounterEgg e) ? Legal.GetBaseEggMoves(pkm, e.Species, e.Version, 100).Except(Base).ToList() : new List(); Tutor = e.Version == GameVersion.C - ? Legal.GetTutorMoves(pkm, pkm.Species, pkm.AltForm, false, 2).ToList() + ? MoveTutor.GetTutorMoves(pkm, pkm.Species, pkm.AltForm, false, 2).ToList() : new List(); // Only TM/HM moves from the source game of the egg, not any other games from the same generation - TMHM = Legal.GetTMHM(pkm, pkm.Species, pkm.AltForm, pkm.GenNumber, e.Version, false).ToList(); + TMHM = MoveTechnicalMachine.GetTMHM(pkm, pkm.Species, pkm.AltForm, pkm.GenNumber, e.Version).ToList(); // Non-Base moves that can magically appear in the regular movepool bool volt = notSpecial && (pkm.GenNumber > 3 || e.Version == GameVersion.E) && Legal.LightBall.Contains(pkm.Species); diff --git a/PKHeX.Core/Legality/Moves/MoveLevelUp.cs b/PKHeX.Core/Legality/Moves/MoveLevelUp.cs index 6b04af0a0..dc952fe03 100644 --- a/PKHeX.Core/Legality/Moves/MoveLevelUp.cs +++ b/PKHeX.Core/Legality/Moves/MoveLevelUp.cs @@ -256,22 +256,22 @@ private static Learnset GetDeoxysLearn3(int form) } } - public static IEnumerable GetLevelUpMoves(PKM pkm, int species, int minlvlG1, int minlvlG2, int lvl, int form, GameVersion version, bool MoveReminder, int Generation) + public static IEnumerable GetMovesLevelUp(PKM pkm, int species, int minlvlG1, int minlvlG2, int lvl, int form, GameVersion version, bool MoveReminder, int Generation) { switch (Generation) { - case 1: return AddMovesLevelUp1(species, lvl, minlvlG1); - case 2: return AddMovesLevelUp2(species, lvl, minlvlG2, pkm.Korean, pkm.Format); - case 3: return AddMovesLevelUp3(species, lvl, form); - case 4: return AddMovesLevelUp4(species, lvl, form); - case 5: return AddMovesLevelUp5(species, lvl, form); - case 6: return AddMovesLevelUp6(species, lvl, form, version); - case 7: return AddMovesLevelUp7(species, lvl, form, version, MoveReminder); + case 1: return GetMovesLevelUp1(species, lvl, minlvlG1); + case 2: return GetMovesLevelUp2(species, lvl, minlvlG2, pkm.Korean, pkm.Format); + case 3: return GetMovesLevelUp3(species, lvl, form); + case 4: return GetMovesLevelUp4(species, lvl, form); + case 5: return GetMovesLevelUp5(species, lvl, form); + case 6: return GetMovesLevelUp6(species, lvl, form, version); + case 7: return GetMovesLevelUp7(species, lvl, form, version, MoveReminder); } return null; } - internal static List AddMovesLevelUp1(int species, int max, int min) + internal static List GetMovesLevelUp1(int species, int max, int min) { List moves = new List(); int index = PersonalTable.RB.GetFormeIndex(species, 0); @@ -289,7 +289,7 @@ internal static List AddMovesLevelUp1(int species, int max, int min) moves.AddRange(LevelUpY[index].GetMoves(max, min)); return moves; } - private static List AddMovesLevelUp2(int species, int max, int min, bool korean, int format) + private static List GetMovesLevelUp2(int species, int max, int min, bool korean, int format) { var r = new List(); int index = PersonalTable.C.GetFormeIndex(species, 0); @@ -302,7 +302,7 @@ private static List AddMovesLevelUp2(int species, int max, int min, bool ko r = r.Where(m => m <= MaxMoveID_1).ToList(); return r; } - private static List AddMovesLevelUp3(int species, int lvl, int form) + private static List GetMovesLevelUp3(int species, int lvl, int form) { var moves = new List(); if (species == 386) @@ -324,7 +324,7 @@ private static List AddMovesLevelUp3(int species, int lvl, int form) moves.AddRange(LevelUpLG[index].GetMoves(lvl)); return moves; } - private static List AddMovesLevelUp4(int species, int lvl, int form) + private static List GetMovesLevelUp4(int species, int lvl, int form) { var moves = new List(); int index = PersonalTable.HGSS.GetFormeIndex(species, form); @@ -336,7 +336,7 @@ private static List AddMovesLevelUp4(int species, int lvl, int form) moves.AddRange(LevelUpHGSS[index].GetMoves(lvl)); return moves; } - private static List AddMovesLevelUp5(int species, int lvl, int form) + private static List GetMovesLevelUp5(int species, int lvl, int form) { var moves = new List(); int index1 = PersonalTable.BW.GetFormeIndex(species, form); @@ -348,7 +348,7 @@ private static List AddMovesLevelUp5(int species, int lvl, int form) moves.AddRange(LevelUpB2W2[index2].GetMoves(lvl)); return moves; } - private static List AddMovesLevelUp6(int species, int lvl, int form, GameVersion ver) + private static List GetMovesLevelUp6(int species, int lvl, int form, GameVersion ver) { var moves = new List(); switch (ver) @@ -384,7 +384,7 @@ private static void AddMovesLevelUp6AO(List moves, int species, int lvl, in return; moves.AddRange(LevelUpAO[index].GetMoves(lvl)); } - private static List AddMovesLevelUp7(int species, int lvl, int form, GameVersion ver, bool MoveReminder) + private static List GetMovesLevelUp7(int species, int lvl, int form, GameVersion ver, bool MoveReminder) { var moves = new List(); switch (ver)