From e105f2b589d0c16fdecc0ccf0c0f155fabd65a0d Mon Sep 17 00:00:00 2001 From: Kurt Date: Sun, 10 Jun 2018 17:55:03 -0700 Subject: [PATCH] Refactoring fix b2w2 egg base levelup reference (not bw, b2w2!), doesn't really matter much except for better indication (possibly?) remove some unnecessary linq ToArray() calls continue relocating code out of Core --- PKHeX.Core/Legality/Core.cs | 22 +------------------ .../Legality/Encounters/EncounterEgg.cs | 2 +- .../Legality/Encounters/EncounterSlot.cs | 2 +- .../Legality/Encounters/EncounterStatic.cs | 4 ++-- .../Legality/Encounters/EncounterTrade.cs | 2 +- .../Generator/EncounterGenerator.cs | 2 +- .../Generator/EncounterSlotGenerator.cs | 6 +++-- .../Generator/MysteryGiftGenerator.cs | 10 ++++----- .../Legality/Evolutions/EvolutionTree.cs | 2 +- PKHeX.Core/Legality/Moves/MoveLevelUp.cs | 12 ++++++++++ 10 files changed, 29 insertions(+), 35 deletions(-) diff --git a/PKHeX.Core/Legality/Core.cs b/PKHeX.Core/Legality/Core.cs index a98596131..b2014f357 100644 --- a/PKHeX.Core/Legality/Core.cs +++ b/PKHeX.Core/Legality/Core.cs @@ -289,7 +289,7 @@ internal static int[] GetBaseEggMoves(PKM pkm, int species, GameVersion gameSour case GameVersion.W2: case GameVersion.B2W2: if (pkm.InhabitedGeneration(5)) - return LevelUpBW[species].GetMoves(lvl); + return LevelUpB2W2[species].GetMoves(lvl); break; case GameVersion.X: @@ -767,18 +767,6 @@ private static IEnumerable GetEncounterTableGSC(PKM pkm) // or it can be a Crystal pokemon that lost met location after being tradeback to gen 1 games return SlotsGSC; } - internal static IEnumerable GetDexNavAreas(PKM pkm) - { - switch (pkm.Version) - { - case (int)GameVersion.AS: - return SlotsA.Where(l => l.Location == pkm.Met_Location); - case (int)GameVersion.OR: - return SlotsO.Where(l => l.Location == pkm.Met_Location); - default: - return Enumerable.Empty(); - } - } internal static IEnumerable GetLineage(PKM pkm) { @@ -1536,14 +1524,6 @@ internal static bool IsOutsider(PKM pkm) internal static bool HasVisitedORAS(this PKM pkm) => pkm.InhabitedGeneration(6) && (pkm.AO || !pkm.IsUntraded); internal static bool HasVisitedUSUM(this PKM pkm) => pkm.InhabitedGeneration(7) && (pkm.USUM || !pkm.IsUntraded); - public static int[] GetEncounterMoves(PKM pk, int level, GameVersion version) - { - var learn = GameData.GetLearnsets(version); - var table = GameData.GetPersonal(version); - var index = table.GetFormeIndex(pk.Species, pk.AltForm); - return learn[index].GetEncounterMoves(level); - } - public static LanguageID GetSafeLanguage(int generation, LanguageID prefer, GameVersion game = GameVersion.Any) { switch (generation) diff --git a/PKHeX.Core/Legality/Encounters/EncounterEgg.cs b/PKHeX.Core/Legality/Encounters/EncounterEgg.cs index 29f274e5a..42c81b67e 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterEgg.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterEgg.cs @@ -103,7 +103,7 @@ private int[] GetCurrentEggMoves(PKM pk) { var moves = Legal.GetEggMoves(pk, Species, pk.AltForm, Version); if (moves.Length == 0) - moves = Legal.GetEncounterMoves(pk, Level, Version); + moves = MoveLevelUp.GetEncounterMoves(pk, Level, Version); else if (moves.Length < 4 && pk.Format >= 6) { // Sprinkle in some default level up moves diff --git a/PKHeX.Core/Legality/Encounters/EncounterSlot.cs b/PKHeX.Core/Legality/Encounters/EncounterSlot.cs index 07388deff..a72f4e892 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterSlot.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterSlot.cs @@ -133,7 +133,7 @@ public PKM ConvertToPKM(ITrainerInfo SAV) break; } - var moves = this is EncounterSlotMoves m ? m.Moves : Legal.GetEncounterMoves(pk, level, version); + var moves = this is EncounterSlotMoves m ? m.Moves : MoveLevelUp.GetEncounterMoves(pk, level, version); if (pk.Format == 1 && moves.All(z => z == 0)) moves = ((PersonalInfoG1)PersonalTable.RB[Species]).Moves; else if (Version == GameVersion.XD) diff --git a/PKHeX.Core/Legality/Encounters/EncounterStatic.cs b/PKHeX.Core/Legality/Encounters/EncounterStatic.cs index 6a7c84563..5d9e81a5a 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterStatic.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterStatic.cs @@ -157,9 +157,9 @@ public PKM ConvertToPKM(ITrainerInfo SAV) if (pk is IContestStats s) this.CopyContestStatsTo(s); - var moves = Moves ?? Legal.GetEncounterMoves(pk, level, version); + var moves = Moves ?? MoveLevelUp.GetEncounterMoves(pk, level, version); if (pk.Format == 1 && moves.All(z => z == 0)) - moves = (PersonalTable.RB[Species] as PersonalInfoG1).Moves; + moves = ((PersonalInfoG1) PersonalTable.RB[Species]).Moves; pk.HeldItem = HeldItem; pk.Moves = moves; pk.SetMaximumPPCurrent(moves); diff --git a/PKHeX.Core/Legality/Encounters/EncounterTrade.cs b/PKHeX.Core/Legality/Encounters/EncounterTrade.cs index dd90a3fc5..176c13fc0 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterTrade.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterTrade.cs @@ -126,7 +126,7 @@ public PKM ConvertToPKM(ITrainerInfo SAV) if (pk is IContestStats s) this.CopyContestStatsTo(s); - var moves = Moves ?? Legal.GetEncounterMoves(pk, level, version); + var moves = Moves ?? MoveLevelUp.GetEncounterMoves(pk, level, version); if (pk.Format == 1 && moves.All(z => z == 0)) moves = ((PersonalInfoG1)PersonalTable.RB[Species]).Moves; pk.Moves = moves; diff --git a/PKHeX.Core/Legality/Encounters/Generator/EncounterGenerator.cs b/PKHeX.Core/Legality/Encounters/Generator/EncounterGenerator.cs index fb4bda908..684046a22 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/EncounterGenerator.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/EncounterGenerator.cs @@ -109,7 +109,7 @@ private static IEnumerable GenerateRawEncounters12(PKM pkm, Gam // Calculate all 3 at the same time and pick the best result (by species). // Favor special event move gifts as Static Encounters when applicable var maxspeciesorigin = gsc ? MaxSpeciesID_2 : MaxSpeciesID_1; - DexLevel[] vs = GetValidPreEvolutions(pkm, maxspeciesorigin: maxspeciesorigin).ToArray(); + var vs = GetValidPreEvolutions(pkm, maxspeciesorigin: maxspeciesorigin); HashSet species = new HashSet(vs.Select(p => p.Species).ToList()); var deferred = new List(); diff --git a/PKHeX.Core/Legality/Encounters/Generator/EncounterSlotGenerator.cs b/PKHeX.Core/Legality/Encounters/Generator/EncounterSlotGenerator.cs index 924e4f445..9c9b285a3 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/EncounterSlotGenerator.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/EncounterSlotGenerator.cs @@ -375,8 +375,10 @@ internal static bool IsDexNavValid(PKM pkm) return false; var vs = GetValidPreEvolutions(pkm); - IEnumerable locs = GetDexNavAreas(pkm); - var d_areas = locs.Select(loc => GetValidEncounterSlots(pkm, loc, vs, DexNav: true)); + var table = pkm.Version == (int) GameVersion.AS ? Encounters6.SlotsA : Encounters6.SlotsO; + int loc = pkm.Met_Location; + var areas = table.Where(l => l.Location == loc); + var d_areas = areas.Select(area => GetValidEncounterSlots(pkm, area, vs, DexNav: true)); return d_areas.Any(slots => slots.Any(slot => slot.Permissions.AllowDexNav && slot.Permissions.DexNav)); } internal static EncounterArea GetCaptureLocation(PKM pkm) diff --git a/PKHeX.Core/Legality/Encounters/Generator/MysteryGiftGenerator.cs b/PKHeX.Core/Legality/Encounters/Generator/MysteryGiftGenerator.cs index bb7d6c77d..6992c6f32 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/MysteryGiftGenerator.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/MysteryGiftGenerator.cs @@ -50,7 +50,7 @@ private static IEnumerable GetMatchingWC3(PKM pkm, IEnumerable(); - var vs = GetValidPreEvolutions(pkm, MaxSpeciesID_3).ToArray(); + var vs = GetValidPreEvolutions(pkm, MaxSpeciesID_3); var enumerable = DB.OfType().Where(wc => vs.Any(dl => dl.Species == wc.Species)); foreach (WC3 wc in enumerable) { @@ -78,7 +78,7 @@ private static IEnumerable GetMatchingPCD(PKM pkm, IEnumerable(); - var vs = GetValidPreEvolutions(pkm).ToArray(); + var vs = GetValidPreEvolutions(pkm); var enumerable = DB.OfType().Where(wc => vs.Any(dl => dl.Species == wc.Species)); foreach (PCD mg in enumerable) { @@ -101,7 +101,7 @@ private static IEnumerable GetMatchingPGF(PKM pkm, IEnumerable(); - var vs = GetValidPreEvolutions(pkm).ToArray(); + var vs = GetValidPreEvolutions(pkm); var enumerable = DB.OfType().Where(wc => vs.Any(dl => dl.Species == wc.Species)); foreach (PGF wc in enumerable) { @@ -121,7 +121,7 @@ private static IEnumerable GetMatchingWC6(PKM pkm, IEnumerable(); - var vs = GetValidPreEvolutions(pkm).ToArray(); + var vs = GetValidPreEvolutions(pkm); var enumerable = DB.OfType().Where(wc => vs.Any(dl => dl.Species == wc.Species)); foreach (WC6 wc in enumerable) { @@ -148,7 +148,7 @@ private static IEnumerable GetMatchingWC7(PKM pkm, IEnumerable(); - var vs = GetValidPreEvolutions(pkm).ToArray(); + var vs = GetValidPreEvolutions(pkm); var enumerable = DB.OfType().Where(wc => vs.Any(dl => dl.Species == wc.Species)); foreach (WC7 wc in enumerable) { diff --git a/PKHeX.Core/Legality/Evolutions/EvolutionTree.cs b/PKHeX.Core/Legality/Evolutions/EvolutionTree.cs index 345aacc66..416b4a5ce 100644 --- a/PKHeX.Core/Legality/Evolutions/EvolutionTree.cs +++ b/PKHeX.Core/Legality/Evolutions/EvolutionTree.cs @@ -201,7 +201,7 @@ private int GetIndex(EvolutionMethod evo) return Personal.GetFormeIndex(evolvesToSpecies, evolvesToForm); } - public IList GetValidPreEvolutions(PKM pkm, int maxLevel, int maxSpeciesOrigin = -1, bool skipChecks = false, int minLevel = 1) + public List GetValidPreEvolutions(PKM pkm, int maxLevel, int maxSpeciesOrigin = -1, bool skipChecks = false, int minLevel = 1) { int index = GetIndex(pkm); if (maxSpeciesOrigin <= 0) diff --git a/PKHeX.Core/Legality/Moves/MoveLevelUp.cs b/PKHeX.Core/Legality/Moves/MoveLevelUp.cs index dc952fe03..630912cd4 100644 --- a/PKHeX.Core/Legality/Moves/MoveLevelUp.cs +++ b/PKHeX.Core/Legality/Moves/MoveLevelUp.cs @@ -426,5 +426,17 @@ private static void AddMovesLevelUp7USUM(List moves, int species, int lvl, moves.AddRange(LevelUpUSUM[index].GetMoves(lvl)); } + + public static int[] GetEncounterMoves(PKM pk, int level, GameVersion version) + { + return GetEncounterMoves(pk.Species, pk.AltForm, level, version); + } + public static int[] GetEncounterMoves(int species, int form, int level, GameVersion version) + { + var learn = GameData.GetLearnsets(version); + var table = GameData.GetPersonal(version); + var index = table.GetFormeIndex(species, form); + return learn[index].GetEncounterMoves(level); + } } }