diff --git a/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot8b.cs b/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot8b.cs index a290ec398..69c67f9c3 100644 --- a/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot8b.cs +++ b/PKHeX.Core/Legality/Encounters/EncounterSlot/EncounterSlot8b.cs @@ -12,10 +12,13 @@ public sealed record EncounterSlot8b : EncounterSlot public override int Generation => 8; public bool IsUnderground => Area.Location is (>= 508 and <= 617); public bool IsMarsh => Area.Location is (>= 219 and <= 224); + public readonly bool IsBCAT; - public EncounterSlot8b(EncounterArea area, int species, int form, int min, int max) : base(area, species, form, min, max) + public EncounterSlot8b(EncounterArea area, int species, int form, int min, int max, bool isBCAT = false) : base(area, species, form, min, max) { + IsBCAT = isBCAT; } + protected override void SetFormatSpecificData(PKM pk) { if (IsUnderground) @@ -32,42 +35,48 @@ protected override void SetFormatSpecificData(PKM pk) public bool CanBeUndergroundMove(int move) { - var et = EvolutionTree.Evolves8b; - var sf = et.GetBaseSpeciesForm(Species, Form); - var species = sf & 0x7FF; - var form = sf >> 11; - if (IgnoreEggMoves.TryGetValue(species, out var exclude) && Array.IndexOf(exclude, move) != -1) + var et = PersonalTable.BDSP; + var sf = (PersonalInfoBDSP)et.GetFormEntry(Species, Form); + var species = sf.HatchSpecies; + if (IsBCAT && IgnoreEggMoves.TryGetValue(species, out var exclude) && Array.IndexOf(exclude, move) != -1) return false; - var baseEgg = MoveEgg.GetEggMoves(8, species, form, Version); - return baseEgg.Length == 0 || Array.IndexOf(baseEgg, move) >= 0; + var baseEgg = Legal.EggMovesBDSP[species].Moves; + if (baseEgg.Length == 0) + return move == 0; + return Array.IndexOf(baseEgg, move) >= 0; } public bool GetBaseEggMove(out int move) { - var et = EvolutionTree.Evolves8b; - var sf = et.GetBaseSpeciesForm(Species, Form); - var species = sf & 0x7FF; - var form = sf >> 11; + var et = PersonalTable.BDSP; + var sf = (PersonalInfoBDSP)et.GetFormEntry(Species, Form); + var species = sf.HatchSpecies; int[] Exclude = IgnoreEggMoves.TryGetValue(species, out var exclude) ? exclude : Array.Empty(); - var baseEgg = MoveEgg.GetEggMoves(8, species, form, Version); + var baseEgg = Legal.EggMovesBDSP[species].Moves; if (baseEgg.Length == 0) { move = 0; return false; } + // Official method creates a new List() with all the egg moves, removes all ignored, then picks a random index. + // We'll just loop instead to not allocate, and because it's a >50% chance the move won't be ignored, thus faster. var rnd = Util.Rand; while (true) { var index = rnd.Next(baseEgg.Length); move = baseEgg[index]; - if (Array.IndexOf(Exclude, move) == -1) + if (IsBCAT && Array.IndexOf(Exclude, move) == -1) return true; } } + /// + /// Unreferenced in v1.0, so all egg moves are possible for ROM encounters. + /// Since the Underground supports BCAT distributions, we will keep this around on the off chance they do utilize that method of distribution. + /// private static readonly Dictionary IgnoreEggMoves = new() { {004, new[] {394}}, // Charmander diff --git a/PKHeX.Core/Legality/Evolutions/EvolutionTree.cs b/PKHeX.Core/Legality/Evolutions/EvolutionTree.cs index 387839add..b4a56a555 100644 --- a/PKHeX.Core/Legality/Evolutions/EvolutionTree.cs +++ b/PKHeX.Core/Legality/Evolutions/EvolutionTree.cs @@ -23,7 +23,7 @@ public sealed class EvolutionTree private static readonly EvolutionTree Evolves7 = new(Unpack("uu"), Gen7, PersonalTable.USUM, MaxSpeciesID_7_USUM); private static readonly EvolutionTree Evolves7b = new(Unpack("gg"), Gen7, PersonalTable.GG, MaxSpeciesID_7b); private static readonly EvolutionTree Evolves8 = new(Unpack("ss"), Gen8, PersonalTable.SWSH, MaxSpeciesID_8); - internal static readonly EvolutionTree Evolves8b = new(Unpack("bs"), Gen8, PersonalTable.BDSP, MaxSpeciesID_8b); + private static readonly EvolutionTree Evolves8b = new(Unpack("bs"), Gen8, PersonalTable.BDSP, MaxSpeciesID_8b); private static byte[] Get(string resource) => Util.GetBinaryResource($"evos_{resource}.pkl"); private static byte[][] Unpack(string resource) => BinLinker.Unpack(Get(resource), resource);