mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-09-08 18:36:21 -05:00
Handle some gen1/2 static generating easier
I should probably have slot1/2 and static1/2 and trade1/2 implement GetBlank so that they can flexibly return a japanese/int/(kor) from template rather than default int, but eh
This commit is contained in:
@@ -45,11 +45,13 @@ public abstract record EncounterStatic : IEncounterable, IMoveset, ILocation, IE
|
||||
|
||||
protected EncounterStatic(GameVersion game) => Version = game;
|
||||
|
||||
protected virtual PKM GetBlank(ITrainerInfo tr) => PKMConverter.GetBlank(Generation, Version);
|
||||
|
||||
public PKM ConvertToPKM(ITrainerInfo sav) => ConvertToPKM(sav, EncounterCriteria.Unrestricted);
|
||||
|
||||
public PKM ConvertToPKM(ITrainerInfo sav, EncounterCriteria criteria)
|
||||
{
|
||||
var pk = PKMConverter.GetBlank(Generation, Version);
|
||||
var pk = GetBlank(sav);
|
||||
sav.ApplyTo(pk);
|
||||
|
||||
ApplyDetails(sav, criteria, pk);
|
||||
|
||||
@@ -60,6 +60,13 @@ public override bool IsMatchExact(PKM pkm, DexLevel evo)
|
||||
_ => true
|
||||
};
|
||||
|
||||
protected override PKM GetBlank(ITrainerInfo tr) => Language switch
|
||||
{
|
||||
EncounterGBLanguage.Japanese => new PK1(true),
|
||||
EncounterGBLanguage.International => new PK1(),
|
||||
_ => new PK1(tr.Language == 1),
|
||||
};
|
||||
|
||||
protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk)
|
||||
{
|
||||
base.ApplyDetails(sav, criteria, pk);
|
||||
|
||||
@@ -71,6 +71,13 @@ public override bool IsMatchExact(PKM pkm, DexLevel evo)
|
||||
|
||||
protected override int GetMinimalLevel() => CurrentLevel == -1 ? base.GetMinimalLevel() : CurrentLevel;
|
||||
|
||||
protected override PKM GetBlank(ITrainerInfo tr) => Language switch
|
||||
{
|
||||
EncounterGBLanguage.Japanese => new PK1(true),
|
||||
EncounterGBLanguage.International => new PK1(),
|
||||
_ => new PK1(tr.Language == 1),
|
||||
};
|
||||
|
||||
protected override void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk)
|
||||
{
|
||||
base.ApplyDetails(sav, criteria, pk);
|
||||
|
||||
@@ -286,9 +286,6 @@ private static IEnumerable<MysteryGift> GetGifts(PKM pk, IReadOnlyCollection<int
|
||||
private static IEnumerable<EncounterStatic> GetStatic(PKM pk, IReadOnlyCollection<int> needs, IReadOnlyList<EvoCriteria> chain, GameVersion version)
|
||||
{
|
||||
var encounters = EncounterStaticGenerator.GetPossible(pk, chain, version);
|
||||
int gen = pk.Generation;
|
||||
if ((uint)gen <= 2)
|
||||
encounters = encounters.Concat(EncounterStaticGenerator.GetPossibleGBGifts(pk, chain, gen == 2 ? GameVersion.C : GameVersion.RBY));
|
||||
foreach (var enc in encounters)
|
||||
{
|
||||
if (enc.IsUnobtainable())
|
||||
@@ -310,10 +307,11 @@ private static IEnumerable<EncounterStatic> GetStatic(PKM pk, IReadOnlyCollectio
|
||||
yield return enc;
|
||||
}
|
||||
|
||||
int gen = version.GetGeneration();
|
||||
if ((uint)gen >= 3)
|
||||
yield break;
|
||||
|
||||
var gifts = EncounterStaticGenerator.GetPossibleGBGifts(pk, chain);
|
||||
var gifts = EncounterStaticGenerator.GetPossibleGBGifts(chain, version);
|
||||
foreach (var enc in gifts)
|
||||
{
|
||||
if (needs.Count == 0)
|
||||
|
||||
@@ -35,14 +35,11 @@ public static IEnumerable<EncounterStatic> GetPossible(PKM pkm, IReadOnlyList<De
|
||||
return table.Where(e => chain.Any(d => d.Species == e.Species));
|
||||
}
|
||||
|
||||
public static IEnumerable<EncounterStatic> GetPossibleGBGifts(PKM pkm, IReadOnlyList<DexLevel> chain, GameVersion gameSource = Any)
|
||||
public static IEnumerable<EncounterStatic> GetPossibleGBGifts(IReadOnlyList<DexLevel> chain, GameVersion gameSource)
|
||||
{
|
||||
if (gameSource == Any)
|
||||
gameSource = (GameVersion)pkm.Version;
|
||||
|
||||
static IEnumerable<EncounterStatic> GetEvents(GameVersion g)
|
||||
{
|
||||
if (g == RBY)
|
||||
if (g.GetGeneration() == 1)
|
||||
return !ParseSettings.AllowGBCartEra ? Encounters1.StaticEventsVC : Encounters1.StaticEventsGB;
|
||||
|
||||
return !ParseSettings.AllowGBCartEra ? Encounters2.StaticEventsVC : Encounters2.StaticEventsGB;
|
||||
@@ -54,18 +51,19 @@ static IEnumerable<EncounterStatic> GetEvents(GameVersion g)
|
||||
|
||||
public static IEnumerable<EncounterStatic> GetValidStaticEncounter(PKM pkm, IReadOnlyList<DexLevel> chain, GameVersion gameSource = Any)
|
||||
{
|
||||
var poss = GetPossible(pkm, chain, gameSource: gameSource);
|
||||
if (gameSource == Any)
|
||||
gameSource = (GameVersion)pkm.Version;
|
||||
|
||||
var table = GetEncounterStaticTable(pkm, gameSource);
|
||||
var poss = table.Where(e => chain.Any(d => d.Species == e.Species));
|
||||
|
||||
// Back Check against pkm
|
||||
return GetMatchingStaticEncounters(pkm, poss, chain);
|
||||
}
|
||||
|
||||
public static IEnumerable<EncounterStatic> GetValidGBGifts(PKM pkm, IReadOnlyList<DexLevel> chain, GameVersion gameSource = Any)
|
||||
public static IEnumerable<EncounterStatic> GetValidGBGifts(PKM pkm, IReadOnlyList<DexLevel> chain, GameVersion gameSource)
|
||||
{
|
||||
if (gameSource == Any)
|
||||
gameSource = (GameVersion)pkm.Version;
|
||||
|
||||
var poss = GetPossibleGBGifts(pkm, chain, gameSource: gameSource);
|
||||
var poss = GetPossibleGBGifts(chain, gameSource: gameSource);
|
||||
foreach (EncounterStatic e in poss)
|
||||
{
|
||||
foreach (var dl in chain)
|
||||
|
||||
Reference in New Issue
Block a user