mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-08-25 15:14:06 -05:00
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
This commit is contained in:
@@ -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<EncounterArea> 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<EncounterArea> 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<EncounterArea>();
|
||||
}
|
||||
}
|
||||
|
||||
internal static IEnumerable<int> 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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -109,7 +109,7 @@ private static IEnumerable<GBEncounterData> 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<int> species = new HashSet<int>(vs.Select(p => p.Species).ToList());
|
||||
|
||||
var deferred = new List<IEncounterable>();
|
||||
|
||||
@@ -375,8 +375,10 @@ internal static bool IsDexNavValid(PKM pkm)
|
||||
return false;
|
||||
|
||||
var vs = GetValidPreEvolutions(pkm);
|
||||
IEnumerable<EncounterArea> 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)
|
||||
|
||||
@@ -50,7 +50,7 @@ private static IEnumerable<MysteryGift> GetMatchingWC3(PKM pkm, IEnumerable<Myst
|
||||
yield break;
|
||||
|
||||
var validWC3 = new List<MysteryGift>();
|
||||
var vs = GetValidPreEvolutions(pkm, MaxSpeciesID_3).ToArray();
|
||||
var vs = GetValidPreEvolutions(pkm, MaxSpeciesID_3);
|
||||
var enumerable = DB.OfType<WC3>().Where(wc => vs.Any(dl => dl.Species == wc.Species));
|
||||
foreach (WC3 wc in enumerable)
|
||||
{
|
||||
@@ -78,7 +78,7 @@ private static IEnumerable<MysteryGift> GetMatchingPCD(PKM pkm, IEnumerable<Myst
|
||||
}
|
||||
|
||||
var deferred = new List<MysteryGift>();
|
||||
var vs = GetValidPreEvolutions(pkm).ToArray();
|
||||
var vs = GetValidPreEvolutions(pkm);
|
||||
var enumerable = DB.OfType<PCD>().Where(wc => vs.Any(dl => dl.Species == wc.Species));
|
||||
foreach (PCD mg in enumerable)
|
||||
{
|
||||
@@ -101,7 +101,7 @@ private static IEnumerable<MysteryGift> GetMatchingPGF(PKM pkm, IEnumerable<Myst
|
||||
yield break;
|
||||
|
||||
var deferred = new List<MysteryGift>();
|
||||
var vs = GetValidPreEvolutions(pkm).ToArray();
|
||||
var vs = GetValidPreEvolutions(pkm);
|
||||
var enumerable = DB.OfType<PGF>().Where(wc => vs.Any(dl => dl.Species == wc.Species));
|
||||
foreach (PGF wc in enumerable)
|
||||
{
|
||||
@@ -121,7 +121,7 @@ private static IEnumerable<MysteryGift> GetMatchingWC6(PKM pkm, IEnumerable<Myst
|
||||
if (DB == null)
|
||||
yield break;
|
||||
var deferred = new List<MysteryGift>();
|
||||
var vs = GetValidPreEvolutions(pkm).ToArray();
|
||||
var vs = GetValidPreEvolutions(pkm);
|
||||
var enumerable = DB.OfType<WC6>().Where(wc => vs.Any(dl => dl.Species == wc.Species));
|
||||
foreach (WC6 wc in enumerable)
|
||||
{
|
||||
@@ -148,7 +148,7 @@ private static IEnumerable<MysteryGift> GetMatchingWC7(PKM pkm, IEnumerable<Myst
|
||||
if (DB == null)
|
||||
yield break;
|
||||
var deferred = new List<MysteryGift>();
|
||||
var vs = GetValidPreEvolutions(pkm).ToArray();
|
||||
var vs = GetValidPreEvolutions(pkm);
|
||||
var enumerable = DB.OfType<WC7>().Where(wc => vs.Any(dl => dl.Species == wc.Species));
|
||||
foreach (WC7 wc in enumerable)
|
||||
{
|
||||
|
||||
@@ -201,7 +201,7 @@ private int GetIndex(EvolutionMethod evo)
|
||||
|
||||
return Personal.GetFormeIndex(evolvesToSpecies, evolvesToForm);
|
||||
}
|
||||
public IList<DexLevel> GetValidPreEvolutions(PKM pkm, int maxLevel, int maxSpeciesOrigin = -1, bool skipChecks = false, int minLevel = 1)
|
||||
public List<DexLevel> GetValidPreEvolutions(PKM pkm, int maxLevel, int maxSpeciesOrigin = -1, bool skipChecks = false, int minLevel = 1)
|
||||
{
|
||||
int index = GetIndex(pkm);
|
||||
if (maxSpeciesOrigin <= 0)
|
||||
|
||||
@@ -426,5 +426,17 @@ private static void AddMovesLevelUp7USUM(List<int> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user