2018-05-13 01:11:47 +00:00
|
|
|
|
using System;
|
2018-06-15 23:00:28 +00:00
|
|
|
|
using System.Collections.Generic;
|
2018-05-13 01:11:47 +00:00
|
|
|
|
using System.Linq;
|
2018-06-15 23:00:28 +00:00
|
|
|
|
using static PKHeX.Core.GameVersion;
|
2018-05-13 01:11:47 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
2016-10-29 22:41:55 +00:00
|
|
|
|
{
|
2017-10-24 06:12:58 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Utility class for <see cref="GameVersion"/> logic.
|
|
|
|
|
/// </summary>
|
2016-10-29 22:41:55 +00:00
|
|
|
|
public static class GameUtil
|
|
|
|
|
{
|
2018-06-15 23:00:28 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// List of possible <see cref="GameVersion"/> values a <see cref="PKM.Version"/> can have.
|
|
|
|
|
/// </summary>
|
2018-07-12 02:19:19 +00:00
|
|
|
|
/// <remarks>Ordered roughly by most recent games first.</remarks>
|
2018-06-15 23:00:28 +00:00
|
|
|
|
public static readonly GameVersion[] GameVersions = ((GameVersion[])Enum.GetValues(typeof(GameVersion))).Where(z => z < RB && z > 0).Reverse().ToArray();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Indicates if the <see cref="GameVersion"/> value is a value used by the games or is an aggregate indicator.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="game">Game to check</param>
|
|
|
|
|
public static bool IsValidSavedVersion(this GameVersion game) => 0 < game && game <= RB;
|
|
|
|
|
|
2016-10-29 22:41:55 +00:00
|
|
|
|
/// <summary>Determines the Version Grouping of an input Version ID</summary>
|
|
|
|
|
/// <param name="Version">Version of which to determine the group</param>
|
|
|
|
|
/// <returns>Version Group Identifier or Invalid if type cannot be determined.</returns>
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public static GameVersion GetMetLocationVersionGroup(GameVersion Version)
|
2016-10-29 22:41:55 +00:00
|
|
|
|
{
|
|
|
|
|
switch (Version)
|
|
|
|
|
{
|
2018-06-15 23:00:28 +00:00
|
|
|
|
// Sidegame
|
|
|
|
|
case CXD:
|
|
|
|
|
return CXD;
|
|
|
|
|
case GO:
|
|
|
|
|
return GO;
|
|
|
|
|
|
|
|
|
|
// Gen1
|
|
|
|
|
case RBY: case RD: case BU: case YW: case GN:
|
|
|
|
|
return RBY;
|
|
|
|
|
|
|
|
|
|
// Gen2
|
|
|
|
|
case GS: case GD: case SV: case C:
|
|
|
|
|
return GSC;
|
|
|
|
|
|
|
|
|
|
// Gen3
|
|
|
|
|
case R: case S:
|
|
|
|
|
return RS;
|
|
|
|
|
case E:
|
|
|
|
|
return E;
|
|
|
|
|
case FR: case LG:
|
|
|
|
|
return FR;
|
|
|
|
|
|
|
|
|
|
// Gen4
|
|
|
|
|
case D: case P:
|
|
|
|
|
return DP;
|
|
|
|
|
case Pt:
|
|
|
|
|
return Pt;
|
|
|
|
|
case HG: case SS:
|
|
|
|
|
return HGSS;
|
|
|
|
|
|
|
|
|
|
// Gen5
|
|
|
|
|
case B: case W:
|
|
|
|
|
return BW;
|
|
|
|
|
case B2: case W2:
|
|
|
|
|
return B2W2;
|
|
|
|
|
|
|
|
|
|
// Gen6
|
|
|
|
|
case X: case Y:
|
|
|
|
|
return XY;
|
|
|
|
|
case OR: case AS:
|
|
|
|
|
return ORAS;
|
|
|
|
|
|
|
|
|
|
// Gen7
|
|
|
|
|
case SN: case MN:
|
|
|
|
|
return SM;
|
|
|
|
|
case US: case UM:
|
|
|
|
|
return USUM;
|
2018-07-15 04:55:45 +00:00
|
|
|
|
case GP: case GE:
|
|
|
|
|
return GG;
|
2017-09-02 15:41:36 +00:00
|
|
|
|
|
2016-10-29 22:41:55 +00:00
|
|
|
|
default:
|
2018-06-15 23:00:28 +00:00
|
|
|
|
return Invalid;
|
2016-10-29 22:41:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-01-14 21:10:36 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a Version ID from the end of that Generation
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="generation">Generation ID</param>
|
|
|
|
|
/// <returns>Version ID from requested generation. If none, return Unknown.</returns>
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public static GameVersion GetVersion(int generation)
|
2017-01-14 21:10:36 +00:00
|
|
|
|
{
|
|
|
|
|
switch (generation)
|
|
|
|
|
{
|
2018-06-15 23:00:28 +00:00
|
|
|
|
case 1: return RBY;
|
|
|
|
|
case 2: return C;
|
|
|
|
|
case 3: return E;
|
|
|
|
|
case 4: return SS;
|
|
|
|
|
case 5: return W2;
|
|
|
|
|
case 6: return AS;
|
|
|
|
|
case 7: return UM;
|
2017-01-14 21:10:36 +00:00
|
|
|
|
default:
|
2018-06-15 23:00:28 +00:00
|
|
|
|
return Invalid;
|
2017-01-14 21:10:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-19 00:17:21 +00:00
|
|
|
|
|
2018-06-15 23:00:28 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the Generation the <see cref="GameVersion"/> belongs to.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="game">Game to retrieve the generation for</param>
|
|
|
|
|
/// <returns>Generation ID</returns>
|
|
|
|
|
public static int GetGeneration(this GameVersion game)
|
|
|
|
|
{
|
|
|
|
|
if (Gen1.Contains(game)) return 1;
|
|
|
|
|
if (Gen2.Contains(game)) return 2;
|
|
|
|
|
if (Gen3.Contains(game)) return 3;
|
|
|
|
|
if (Gen4.Contains(game)) return 4;
|
|
|
|
|
if (Gen5.Contains(game)) return 5;
|
|
|
|
|
if (Gen6.Contains(game)) return 6;
|
|
|
|
|
if (Gen7.Contains(game)) return 7;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2017-12-19 00:17:21 +00:00
|
|
|
|
|
2018-06-18 04:52:52 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the Generation the <see cref="GameVersion"/> belongs to.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="game">Game to retrieve the generation for</param>
|
|
|
|
|
/// <returns>Generation ID</returns>
|
|
|
|
|
public static int GetMaxSpeciesID(this GameVersion game)
|
|
|
|
|
{
|
|
|
|
|
if (Gen1.Contains(game)) return Legal.MaxSpeciesID_1;
|
|
|
|
|
if (Gen2.Contains(game)) return Legal.MaxSpeciesID_2;
|
|
|
|
|
if (Gen3.Contains(game)) return Legal.MaxSpeciesID_3;
|
|
|
|
|
if (Gen4.Contains(game)) return Legal.MaxSpeciesID_4;
|
|
|
|
|
if (Gen5.Contains(game)) return Legal.MaxSpeciesID_5;
|
|
|
|
|
if (Gen6.Contains(game)) return Legal.MaxSpeciesID_6;
|
|
|
|
|
if (Gen7.Contains(game))
|
|
|
|
|
{
|
|
|
|
|
if (SM.Contains(game))
|
|
|
|
|
return Legal.MaxSpeciesID_7;
|
|
|
|
|
if (USUM.Contains(game))
|
|
|
|
|
return Legal.MaxSpeciesID_7_USUM;
|
|
|
|
|
return Legal.MaxSpeciesID_7_USUM;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-15 23:00:28 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Checks if the <see cref="g1"/> version (or subset versions) is equivalent to <see cref="g2"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="g1">Version (set)</param>
|
|
|
|
|
/// <param name="g2">Individual version</param>
|
|
|
|
|
public static bool Contains(this GameVersion g1, GameVersion g2)
|
|
|
|
|
{
|
|
|
|
|
if (g1 == g2 || g1 == Any)
|
|
|
|
|
return true;
|
2017-12-19 00:17:21 +00:00
|
|
|
|
|
2018-06-15 23:00:28 +00:00
|
|
|
|
switch (g1)
|
|
|
|
|
{
|
|
|
|
|
case RB:
|
|
|
|
|
return g2 == RD || g2 == BU || g2 == GN;
|
2018-08-28 03:44:26 +00:00
|
|
|
|
case Stadium:
|
|
|
|
|
case EventsGBGen1:
|
|
|
|
|
case VCEvents:
|
2018-06-15 23:00:28 +00:00
|
|
|
|
case RBY:
|
|
|
|
|
return RB.Contains(g2) || g2 == YW;
|
|
|
|
|
case Gen1:
|
|
|
|
|
return RBY.Contains(g2) || g2 == Stadium || g2 == EventsGBGen1 || g2 == VCEvents;
|
|
|
|
|
|
|
|
|
|
case GS: return g2 == GD || g2 == SV;
|
2018-08-28 03:44:26 +00:00
|
|
|
|
case Stadium2:
|
|
|
|
|
case EventsGBGen2:
|
2018-06-15 23:00:28 +00:00
|
|
|
|
case GSC:
|
|
|
|
|
return GS.Contains(g2) || g2 == C;
|
|
|
|
|
case Gen2:
|
|
|
|
|
return GSC.Contains(g2) || g2 == Stadium2 || g2 == EventsGBGen2;
|
|
|
|
|
case GBCartEraOnly:
|
|
|
|
|
return g2 == Stadium || g2 == Stadium2 || g2 == EventsGBGen1 || g2 == EventsGBGen2;
|
|
|
|
|
|
|
|
|
|
case RS: return g2 == R || g2 == S;
|
|
|
|
|
case RSE:
|
|
|
|
|
return RS.Contains(g2) || g2 == E;
|
|
|
|
|
case FRLG: return g2 == FR || g2 == LG;
|
|
|
|
|
case COLO:
|
|
|
|
|
case XD: return g2 == CXD;
|
|
|
|
|
case CXD: return g2 == COLO || g2 == XD;
|
|
|
|
|
case RSBOX: return RS.Contains(g2) || g2 == E || FRLG.Contains(g2);
|
|
|
|
|
case Gen3:
|
|
|
|
|
return RSE.Contains(g2) || FRLG.Contains(g2) || CXD.Contains(g2) || g2 == RSBOX;
|
|
|
|
|
|
|
|
|
|
case DP: return g2 == D || g2 == P;
|
|
|
|
|
case HGSS: return g2 == HG || g2 == SS;
|
|
|
|
|
case DPPt:
|
|
|
|
|
return DP.Contains(g2) || g2 == Pt;
|
|
|
|
|
case BATREV: return DP.Contains(g2) || g2 == Pt || HGSS.Contains(g2);
|
|
|
|
|
case Gen4:
|
|
|
|
|
return DPPt.Contains(g2) || HGSS.Contains(g2) || g2 == BATREV;
|
|
|
|
|
|
|
|
|
|
case BW: return g2 == B || g2 == W;
|
|
|
|
|
case B2W2: return g2 == B2 || g2 == W2;
|
|
|
|
|
case Gen5:
|
|
|
|
|
return BW.Contains(g2) || B2W2.Contains(g2);
|
|
|
|
|
|
|
|
|
|
case XY: return g2 == X || g2 == Y;
|
|
|
|
|
case ORAS: return g2 == OR || g2 == AS;
|
|
|
|
|
case Gen6:
|
|
|
|
|
return XY.Contains(g2) || ORAS.Contains(g2);
|
|
|
|
|
|
|
|
|
|
case SM:
|
|
|
|
|
return g2 == SN || g2 == MN;
|
|
|
|
|
case USUM:
|
|
|
|
|
return g2 == US || g2 == UM;
|
2018-07-12 02:19:19 +00:00
|
|
|
|
case GG:
|
|
|
|
|
return g2 == GP || g2 == GE;
|
2018-06-15 23:00:28 +00:00
|
|
|
|
case Gen7:
|
2018-07-12 02:19:19 +00:00
|
|
|
|
return SM.Contains(g2) || USUM.Contains(g2) || GG.Contains(g2);
|
2018-06-15 23:00:28 +00:00
|
|
|
|
|
|
|
|
|
default: return false;
|
2017-12-19 00:17:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-13 01:11:47 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// List of possible <see cref="GameVersion"/> values within the provided <see cref="generation"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="generation">Generation to look within</param>
|
|
|
|
|
public static GameVersion[] GetVersionsInGeneration(int generation) => GameVersions.Where(z => z.GetGeneration() == generation).ToArray();
|
2018-06-15 23:00:28 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// List of possible <see cref="GameVersion"/> values within the provided <see cref="IGameValueLimit"/> criteria.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="obj">Criteria for retrieving versions</param>
|
|
|
|
|
/// <param name="generation">Generation format minimum (necessary for the CXD/Gen4 swap etc)</param>
|
|
|
|
|
public static IEnumerable<GameVersion> GetVersionsWithinRange(IGameValueLimit obj, int generation = -1)
|
|
|
|
|
{
|
|
|
|
|
var vers = GameVersions.Where(z => z >= (GameVersion)obj.MinGameID && z <= (GameVersion)obj.MaxGameID);
|
|
|
|
|
if (generation == -1)
|
|
|
|
|
return vers;
|
|
|
|
|
return vers.Where(z => z.GetGeneration() <= generation);
|
|
|
|
|
}
|
2016-10-29 22:41:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|