using System; namespace PKHeX.Core; /// /// Interface that exposes a for allowing a Pokémon into ranked battles if it originated from a prior game. /// public interface IBattleVersion { /// /// Indicates which the Pokémon's moves were reset on. /// byte BattleVersion { get; set; } } public static class BattleVersionExtensions { /// /// Checks if the applied Battle Version value is valid based on visitation. /// public static bool IsBattleVersionValid(this T pk, EvolutionHistory h) where T : PKM, IBattleVersion => pk.BattleVersion switch { 0 => true, (int)GameVersion.SW or (int)GameVersion.SH => h.HasVisitedSWSH && !(pk.SWSH || pk.BDSP || pk.LA), _ => false, }; /// /// Resets the 's moves and sets the requested version. /// /// Reference to the object to set the /// Reference to the same object that gets moves reset /// Version to apply public static void AdaptToBattleVersion(this IBattleVersion v, PKM pk, GameVersion version) { var empty = new Moveset(); pk.SetMoves(empty); pk.SetRelearnMoves(empty); Span moves = stackalloc ushort[4]; MoveLevelUp.GetEncounterMoves(moves, pk, pk.CurrentLevel, version); pk.SetMoves(moves); pk.FixMoves(); v.BattleVersion = (byte)version; } /// /// Gets the minimum Generation ID that it was last reset in. /// public static int GetMinGeneration(this IBattleVersion v) { var ver = v.BattleVersion; if (ver == 0) return 1; var game = (GameVersion) ver; if (!game.IsValidSavedVersion()) return -1; var gen = game.GetGeneration(); if (gen >= 8) return gen; return -1; } }