2022-09-02 17:20:19 +00:00
|
|
|
using System;
|
|
|
|
|
2022-08-04 01:17:46 +00:00
|
|
|
namespace PKHeX.Core;
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Interface that exposes a <see cref="BattleVersion"/> for allowing a Pokémon into ranked battles if it originated from a prior game.
|
|
|
|
/// </summary>
|
|
|
|
public interface IBattleVersion
|
2020-06-19 23:51:15 +00:00
|
|
|
{
|
|
|
|
/// <summary>
|
2022-06-18 18:04:24 +00:00
|
|
|
/// Indicates which <see cref="GameVersion"/> the Pokémon's moves were reset on.
|
2020-06-19 23:51:15 +00:00
|
|
|
/// </summary>
|
2022-06-18 18:04:24 +00:00
|
|
|
byte BattleVersion { get; set; }
|
|
|
|
}
|
2020-06-19 23:51:15 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public static class BattleVersionExtensions
|
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Checks if the applied Battle Version value is valid based on visitation.
|
|
|
|
/// </summary>
|
2022-06-18 18:04:24 +00:00
|
|
|
public static bool IsBattleVersionValid<T>(this T pk, EvolutionHistory h) where T : PKM, IBattleVersion => pk.BattleVersion switch
|
2020-06-19 23:51:15 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
0 => true,
|
2023-01-22 04:02:33 +00:00
|
|
|
(int)GameVersion.SW or (int)GameVersion.SH => h.HasVisitedSWSH && !(pk.SWSH || pk.BDSP || pk.LA),
|
2022-06-18 18:04:24 +00:00
|
|
|
_ => false,
|
|
|
|
};
|
2022-05-31 04:43:52 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Resets the <see cref="PKM"/>'s moves and sets the requested version.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="v">Reference to the object to set the <see cref="version"/></param>
|
|
|
|
/// <param name="pk">Reference to the same object that gets moves reset</param>
|
|
|
|
/// <param name="version">Version to apply</param>
|
|
|
|
public static void AdaptToBattleVersion(this IBattleVersion v, PKM pk, GameVersion version)
|
|
|
|
{
|
2022-09-02 17:20:19 +00:00
|
|
|
var empty = new Moveset();
|
|
|
|
pk.SetMoves(empty);
|
|
|
|
pk.SetRelearnMoves(empty);
|
|
|
|
|
|
|
|
Span<ushort> moves = stackalloc ushort[4];
|
|
|
|
MoveLevelUp.GetEncounterMoves(moves, pk, pk.CurrentLevel, version);
|
2022-06-18 18:04:24 +00:00
|
|
|
pk.SetMoves(moves);
|
|
|
|
pk.FixMoves();
|
2023-01-22 04:02:33 +00:00
|
|
|
v.BattleVersion = (byte)version;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2020-06-27 18:06:28 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the minimum Generation ID that it was last reset in.
|
|
|
|
/// </summary>
|
2022-06-18 18:04:24 +00:00
|
|
|
public static int GetMinGeneration(this IBattleVersion v)
|
|
|
|
{
|
|
|
|
var ver = v.BattleVersion;
|
|
|
|
if (ver == 0)
|
|
|
|
return 1;
|
|
|
|
var game = (GameVersion) ver;
|
|
|
|
if (!game.IsValidSavedVersion())
|
2021-01-29 17:56:31 +00:00
|
|
|
return -1;
|
2022-06-18 18:04:24 +00:00
|
|
|
var gen = game.GetGeneration();
|
|
|
|
if (gen >= 8)
|
|
|
|
return gen;
|
|
|
|
return -1;
|
2020-06-19 23:51:15 +00:00
|
|
|
}
|
|
|
|
}
|