mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 20:43:07 +00:00
add overloads for GetPossible
Remove edge case handling for level 2 blissey; updates over the past 2 (yay 2 years of legality checking) can now handle that case without special handling.
This commit is contained in:
parent
9f8e86b2b5
commit
79b2576c31
8 changed files with 78 additions and 55 deletions
|
@ -1265,16 +1265,16 @@ namespace PKHeX.Core
|
|||
}
|
||||
internal static int GetBaseSpecies(PKM pkm, int skipOption = 0, int generation = -1)
|
||||
{
|
||||
if (pkm.Species == 292)
|
||||
return 290;
|
||||
if (pkm.Species == 242 && pkm.CurrentLevel < 3) // Never Cleffa
|
||||
return 113;
|
||||
|
||||
int tree = generation != -1 ? generation : pkm.Format;
|
||||
var table = EvolutionTree.GetEvolutionTree(tree);
|
||||
int maxSpeciesOrigin = generation != -1 ? GetMaxSpeciesOrigin(generation) : - 1;
|
||||
var evos = table.GetValidPreEvolutions(pkm, maxLevel: 100, maxSpeciesOrigin: maxSpeciesOrigin, skipChecks:true);
|
||||
|
||||
int maxSpeciesOrigin = generation != -1 ? GetMaxSpeciesOrigin(generation) : -1;
|
||||
var evos = table.GetValidPreEvolutions(pkm, maxLevel: 100, maxSpeciesOrigin: maxSpeciesOrigin, skipChecks: true);
|
||||
return GetBaseSpecies(pkm, evos, skipOption, generation);
|
||||
}
|
||||
internal static int GetBaseSpecies(PKM pkm, IList<DexLevel> evos, int skipOption = 0, int generation = -1)
|
||||
{
|
||||
if (pkm.Species == 292)
|
||||
return 290;
|
||||
switch (skipOption)
|
||||
{
|
||||
case -1: return pkm.Species;
|
||||
|
|
|
@ -8,6 +8,14 @@ namespace PKHeX.Core
|
|||
{
|
||||
// EncounterEgg
|
||||
public static IEnumerable<EncounterEgg> GenerateEggs(PKM pkm, bool all = false)
|
||||
{
|
||||
int tree = pkm.GenNumber;
|
||||
var table = EvolutionTree.GetEvolutionTree(tree);
|
||||
int maxSpeciesOrigin = GetMaxSpeciesOrigin(tree);
|
||||
var evos = table.GetValidPreEvolutions(pkm, maxLevel: 100, maxSpeciesOrigin: maxSpeciesOrigin, skipChecks: true);
|
||||
return GenerateEggs(pkm, evos, all);
|
||||
}
|
||||
public static IEnumerable<EncounterEgg> GenerateEggs(PKM pkm, IList<DexLevel> vs, bool all = false)
|
||||
{
|
||||
if (NoHatchFromEgg.Contains(pkm.Species))
|
||||
yield break;
|
||||
|
@ -21,7 +29,7 @@ namespace PKHeX.Core
|
|||
var ver = (GameVersion)pkm.Version;
|
||||
int max = GetMaxSpeciesOrigin(gen);
|
||||
|
||||
var baseSpecies = GetBaseSpecies(pkm, 0);
|
||||
var baseSpecies = GetBaseSpecies(pkm, vs, 0);
|
||||
int lvl = gen < 4 ? 5 : 1;
|
||||
if (baseSpecies <= max)
|
||||
{
|
||||
|
@ -33,7 +41,7 @@ namespace PKHeX.Core
|
|||
if (!GetSplitBreedGeneration(pkm).Contains(pkm.Species))
|
||||
yield break; // no other possible species
|
||||
|
||||
baseSpecies = GetBaseSpecies(pkm, 1);
|
||||
baseSpecies = GetBaseSpecies(pkm, vs, 1);
|
||||
if (baseSpecies <= max)
|
||||
{
|
||||
yield return new EncounterEgg { Version = ver, Level = lvl, Species = baseSpecies, SplitBreed = true };
|
||||
|
|
|
@ -112,7 +112,7 @@ namespace PKHeX.Core
|
|||
HashSet<int> species = new HashSet<int>(vs.Select(p => p.Species).ToList());
|
||||
|
||||
var deferred = new List<IEncounterable>();
|
||||
foreach (var t in GetValidEncounterTrades(pkm, game))
|
||||
foreach (var t in GetValidEncounterTrades(pkm, vs, game))
|
||||
{
|
||||
if (pkm.Format >= 7)
|
||||
{
|
||||
|
|
|
@ -11,6 +11,12 @@ namespace PKHeX.Core
|
|||
return Enumerable.Empty<EncounterLink>();
|
||||
return Encounters6.LinkGifts6.Where(g => g.Species == pkm.Species);
|
||||
}
|
||||
public static IEnumerable<EncounterLink> GetPossible(PKM pkm, IList<DexLevel> vs)
|
||||
{
|
||||
if (pkm.GenNumber != 6)
|
||||
return Enumerable.Empty<EncounterLink>();
|
||||
return Encounters6.LinkGifts6.Where(g => vs.Any(z => z.Species == g.Species));
|
||||
}
|
||||
public static IEnumerable<EncounterLink> GetValidLinkGifts(PKM pkm)
|
||||
{
|
||||
return GetPossible(pkm).Where(g => g.Level == pkm.Met_Level);
|
||||
|
|
|
@ -12,7 +12,10 @@ namespace PKHeX.Core
|
|||
{
|
||||
int maxspeciesorigin = GetMaxSpecies(gameSource);
|
||||
var vs = GetValidPreEvolutions(pkm, maxspeciesorigin: maxspeciesorigin);
|
||||
|
||||
return GetPossible(pkm, vs, gameSource);
|
||||
}
|
||||
public static IEnumerable<EncounterSlot> GetPossible(PKM pkm, IList<DexLevel> vs, GameVersion gameSource = GameVersion.Any)
|
||||
{
|
||||
var possibleAreas = GetEncounterSlots(pkm, gameSource);
|
||||
return possibleAreas.SelectMany(area => area.Slots).Where(z => vs.Any(v => v.Species == z.Species));
|
||||
}
|
||||
|
|
|
@ -8,11 +8,18 @@ namespace PKHeX.Core
|
|||
public static class EncounterStaticGenerator
|
||||
{
|
||||
public static IEnumerable<EncounterStatic> GetPossible(PKM pkm, GameVersion gameSource = GameVersion.Any)
|
||||
{
|
||||
int gen = pkm.GenNumber;
|
||||
int maxID = gen == 2 ? MaxSpeciesID_2 : gen == 1 ? MaxSpeciesID_1 : -1;
|
||||
var dl = GetValidPreEvolutions(pkm, maxID);
|
||||
return GetPossible(pkm, dl, gameSource);
|
||||
}
|
||||
public static IEnumerable<EncounterStatic> GetPossible(PKM pkm, IList<DexLevel> vs, GameVersion gameSource = GameVersion.Any)
|
||||
{
|
||||
if (gameSource == GameVersion.Any)
|
||||
gameSource = (GameVersion)pkm.Version;
|
||||
|
||||
var encs = GetStaticEncounters(pkm, gameSource: gameSource);
|
||||
var encs = GetStaticEncounters(pkm, vs, gameSource);
|
||||
return encs.Where(e => AllowGBCartEra || !GameVersion.GBCartEraOnly.Contains(e.Version));
|
||||
}
|
||||
public static IEnumerable<EncounterStatic> GetValidStaticEncounter(PKM pkm, GameVersion gameSource = GameVersion.Any)
|
||||
|
@ -171,25 +178,12 @@ namespace PKHeX.Core
|
|||
return false;
|
||||
return true;
|
||||
}
|
||||
private static IEnumerable<EncounterStatic> GetStaticEncounters(PKM pkm, GameVersion gameSource = GameVersion.Any)
|
||||
private static IEnumerable<EncounterStatic> GetStaticEncounters(PKM pkm, IList<DexLevel> dl, GameVersion gameSource = GameVersion.Any)
|
||||
{
|
||||
if (gameSource == GameVersion.Any)
|
||||
gameSource = (GameVersion)pkm.Version;
|
||||
|
||||
var table = GetEncounterStaticTable(pkm, gameSource);
|
||||
switch (pkm.GenNumber)
|
||||
{
|
||||
case 1:
|
||||
return GetStatic(pkm, table, maxspeciesorigin: MaxSpeciesID_1);
|
||||
case 2:
|
||||
return GetStatic(pkm, table, maxspeciesorigin: MaxSpeciesID_2);
|
||||
default:
|
||||
return GetStatic(pkm, table);
|
||||
}
|
||||
}
|
||||
private static IEnumerable<EncounterStatic> GetStatic(PKM pkm, IEnumerable<EncounterStatic> table, int maxspeciesorigin = -1, int lvl = -1, bool skip = false)
|
||||
{
|
||||
IEnumerable<DexLevel> dl = GetValidPreEvolutions(pkm, maxspeciesorigin: maxspeciesorigin, lvl: lvl, skipChecks: skip);
|
||||
return table.Where(e => dl.Any(d => d.Species == e.Species));
|
||||
}
|
||||
|
||||
|
@ -244,8 +238,8 @@ namespace PKHeX.Core
|
|||
case 2:
|
||||
return GetGSStaticTransfer(species, pkm.Met_Level);
|
||||
default:
|
||||
var table = GetEncounterStaticTable(pkm, (GameVersion)pkm.Version);
|
||||
return GetStatic(pkm, table, lvl: 100, skip: true).FirstOrDefault();
|
||||
var dl = GetValidPreEvolutions(pkm, lvl: 100, skipChecks: true);
|
||||
return GetPossible(pkm, dl).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,29 +9,49 @@ namespace PKHeX.Core
|
|||
{
|
||||
public static IEnumerable<EncounterTrade> GetPossible(PKM pkm, GameVersion gameSource = GameVersion.Any)
|
||||
{
|
||||
if (gameSource == GameVersion.Any)
|
||||
gameSource = (GameVersion)pkm.Version;
|
||||
|
||||
if (pkm.VC || pkm.Format <= 2)
|
||||
return GetPossibleVC(pkm, gameSource);
|
||||
return GetPossibleNonVC(pkm, gameSource);
|
||||
var p = GetValidPreEvolutions(pkm);
|
||||
return GetPossible(pkm, p, gameSource);
|
||||
}
|
||||
private static IEnumerable<EncounterTrade> GetPossibleNonVC(PKM pkm, GameVersion gameSource = GameVersion.Any)
|
||||
public static IEnumerable<EncounterTrade> GetPossible(PKM pkm, IList<DexLevel> vs, GameVersion gameSource = GameVersion.Any)
|
||||
{
|
||||
if (gameSource == GameVersion.Any)
|
||||
gameSource = (GameVersion)pkm.Version;
|
||||
|
||||
if (pkm.VC || pkm.Format <= 2)
|
||||
return GetValidEncounterTradesVC(pkm, gameSource);
|
||||
|
||||
return GetPossibleVC(pkm, vs, gameSource);
|
||||
return GetPossibleNonVC(pkm, vs, gameSource);
|
||||
}
|
||||
public static IEnumerable<EncounterTrade> GetValidEncounterTrades(PKM pkm, GameVersion gameSource = GameVersion.Any)
|
||||
{
|
||||
var p = GetValidPreEvolutions(pkm);
|
||||
return GetValidEncounterTrades(pkm, p, gameSource);
|
||||
}
|
||||
public static IEnumerable<EncounterTrade> GetValidEncounterTrades(PKM pkm, IList<DexLevel> p, GameVersion gameSource = GameVersion.Any)
|
||||
{
|
||||
if (GetIsFromGB(pkm))
|
||||
return GetValidEncounterTradesVC(pkm, p, gameSource);
|
||||
|
||||
int lvl = IsNotTrade(pkm);
|
||||
if (lvl <= 0)
|
||||
return Enumerable.Empty<EncounterTrade>();
|
||||
|
||||
var poss = GetPossibleNonVC(pkm, p, gameSource);
|
||||
return poss.Where(z => IsEncounterTradeValid(pkm, z, lvl));
|
||||
}
|
||||
private static IEnumerable<EncounterTrade> GetPossibleNonVC(PKM pkm, IList<DexLevel> p, GameVersion gameSource = GameVersion.Any)
|
||||
{
|
||||
if (gameSource == GameVersion.Any)
|
||||
gameSource = (GameVersion)pkm.Version;
|
||||
|
||||
if (pkm.VC || pkm.Format <= 2)
|
||||
return GetValidEncounterTradesVC(pkm, p, gameSource);
|
||||
|
||||
var table = GetEncounterTradeTable(pkm);
|
||||
return table?.Where(f => p.Any(r => r.Species == f.Species)) ?? Enumerable.Empty<EncounterTrade>();
|
||||
}
|
||||
private static IEnumerable<EncounterTrade> GetPossibleVC(PKM pkm, GameVersion gameSource = GameVersion.Any)
|
||||
private static IEnumerable<EncounterTrade> GetPossibleVC(PKM pkm, IList<DexLevel> p, GameVersion gameSource = GameVersion.Any)
|
||||
{
|
||||
var table = GetEncounterTradeTableVC(gameSource);
|
||||
var p = GetValidPreEvolutions(pkm);
|
||||
return table.Where(f => p.Any(r => r.Species == f.Species));
|
||||
}
|
||||
private static IEnumerable<EncounterTrade> GetEncounterTradeTableVC(GameVersion gameSource)
|
||||
|
@ -54,9 +74,9 @@ namespace PKHeX.Core
|
|||
}
|
||||
return null;
|
||||
}
|
||||
private static IEnumerable<EncounterTrade> GetValidEncounterTradesVC(PKM pkm, GameVersion gameSource)
|
||||
private static IEnumerable<EncounterTrade> GetValidEncounterTradesVC(PKM pkm, IList<DexLevel> p, GameVersion gameSource)
|
||||
{
|
||||
var poss = GetPossibleVC(pkm, gameSource);
|
||||
var poss = GetPossibleVC(pkm, p, gameSource);
|
||||
if (gameSource == GameVersion.RBY)
|
||||
return poss.Where(z => GetIsValidTradeVC1(pkm, z));
|
||||
return poss.Where(z => GetIsValidTradeVC2(pkm, z));
|
||||
|
@ -113,18 +133,6 @@ namespace PKHeX.Core
|
|||
}
|
||||
|
||||
private static bool GetIsFromGB(PKM pkm) => pkm.VC || pkm.Format <= 2;
|
||||
public static IEnumerable<EncounterTrade> GetValidEncounterTrades(PKM pkm, GameVersion gameSource = GameVersion.Any)
|
||||
{
|
||||
if (GetIsFromGB(pkm))
|
||||
return GetValidEncounterTradesVC(pkm, gameSource);
|
||||
|
||||
int lvl = IsNotTrade(pkm);
|
||||
if (lvl <= 0)
|
||||
return Enumerable.Empty<EncounterTrade>();
|
||||
|
||||
var poss = GetPossibleNonVC(pkm);
|
||||
return poss.Where(z => IsEncounterTradeValid(pkm, z, lvl));
|
||||
}
|
||||
private static bool IsEncounterTradeValid(PKM pkm, EncounterTrade z, int lvl)
|
||||
{
|
||||
if (z.IVs != null)
|
||||
|
|
|
@ -10,7 +10,11 @@ namespace PKHeX.Core
|
|||
public static IEnumerable<MysteryGift> GetPossible(PKM pkm)
|
||||
{
|
||||
int maxSpecies = GetMaxSpeciesOrigin(pkm.Format);
|
||||
var vs = GetValidPreEvolutions(pkm, maxSpecies).ToArray();
|
||||
var vs = GetValidPreEvolutions(pkm, maxSpecies);
|
||||
return GetPossible(pkm, vs);
|
||||
}
|
||||
public static IEnumerable<MysteryGift> GetPossible(PKM pkm, IList<DexLevel> vs)
|
||||
{
|
||||
var table = GetTable(pkm.GenNumber);
|
||||
return table.Where(wc => vs.Any(dl => dl.Species == wc.Species));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue