From 2b00e310aefccb06023ec1bfbd29636206b37a15 Mon Sep 17 00:00:00 2001 From: Kurt Date: Tue, 2 Feb 2021 22:14:33 -0800 Subject: [PATCH] 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 --- .../EncounterStatic/EncounterStatic.cs | 4 +++- .../EncounterStatic/EncounterStatic1E.cs | 7 +++++++ .../EncounterStatic/EncounterStatic2E.cs | 7 +++++++ .../Moveset/EncounterMovesetGenerator.cs | 6 ++---- .../Specific/EncounterStaticGenerator.cs | 20 +++++++++---------- 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic.cs b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic.cs index d021e1a66..718e8bffc 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic.cs @@ -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); diff --git a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic1E.cs b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic1E.cs index 96e0261f0..0a2562c8d 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic1E.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic1E.cs @@ -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); diff --git a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic2E.cs b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic2E.cs index 5d3cf6d29..512d80a9f 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic2E.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterStatic/EncounterStatic2E.cs @@ -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); diff --git a/PKHeX.Core/Legality/Encounters/Generator/Moveset/EncounterMovesetGenerator.cs b/PKHeX.Core/Legality/Encounters/Generator/Moveset/EncounterMovesetGenerator.cs index 991673a87..ea67648a3 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Moveset/EncounterMovesetGenerator.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Moveset/EncounterMovesetGenerator.cs @@ -286,9 +286,6 @@ private static IEnumerable GetGifts(PKM pk, IReadOnlyCollection GetStatic(PKM pk, IReadOnlyCollection needs, IReadOnlyList 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 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) diff --git a/PKHeX.Core/Legality/Encounters/Generator/Specific/EncounterStaticGenerator.cs b/PKHeX.Core/Legality/Encounters/Generator/Specific/EncounterStaticGenerator.cs index fb9c20ac4..8c1a397e6 100644 --- a/PKHeX.Core/Legality/Encounters/Generator/Specific/EncounterStaticGenerator.cs +++ b/PKHeX.Core/Legality/Encounters/Generator/Specific/EncounterStaticGenerator.cs @@ -35,14 +35,11 @@ public static IEnumerable GetPossible(PKM pkm, IReadOnlyList chain.Any(d => d.Species == e.Species)); } - public static IEnumerable GetPossibleGBGifts(PKM pkm, IReadOnlyList chain, GameVersion gameSource = Any) + public static IEnumerable GetPossibleGBGifts(IReadOnlyList chain, GameVersion gameSource) { - if (gameSource == Any) - gameSource = (GameVersion)pkm.Version; - static IEnumerable 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 GetEvents(GameVersion g) public static IEnumerable GetValidStaticEncounter(PKM pkm, IReadOnlyList 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 GetValidGBGifts(PKM pkm, IReadOnlyList chain, GameVersion gameSource = Any) + public static IEnumerable GetValidGBGifts(PKM pkm, IReadOnlyList 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)