2023-07-06 04:14:09 +00:00
|
|
|
using System;
|
2024-02-23 03:20:54 +00:00
|
|
|
using static PKHeX.Core.GameVersion;
|
2023-07-06 04:14:09 +00:00
|
|
|
|
2023-06-04 01:19:16 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Logic for SW/SH met locations from HOME.
|
|
|
|
/// </summary>
|
|
|
|
public static class LocationsHOME
|
|
|
|
{
|
|
|
|
// 60000 - (version - PLA)
|
2023-09-11 04:17:47 +00:00
|
|
|
private const int RemapCount = 5; // Count of future game version IDs that can transfer back into SW/SH.
|
2023-06-04 01:19:16 +00:00
|
|
|
public const ushort SHVL = 59996; // VL traded to (SW)SH
|
|
|
|
public const ushort SWSL = 59997; // SL traded to SW(SH)
|
|
|
|
public const ushort SHSP = 59998; // SP traded to (SW)SH
|
|
|
|
public const ushort SWBD = 59999; // BD traded to SW(SH)
|
|
|
|
public const ushort SWLA = 60000; // PLA traded to SW(SH)
|
|
|
|
|
|
|
|
public const ushort SWSHEgg = 65534; // -2 = 8bNone-1..
|
|
|
|
|
|
|
|
/// <summary>
|
2023-12-04 04:13:20 +00:00
|
|
|
/// Gets the external entity version needs to be remapped into a location for SW/SH.
|
2023-06-04 01:19:16 +00:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="version"></param>
|
|
|
|
/// <returns>True if a known remap exists.</returns>
|
2024-02-23 03:20:54 +00:00
|
|
|
public static bool IsVersionRemapNeeded(GameVersion version) => GetRemapIndex(version) < RemapCount;
|
2023-06-04 01:19:16 +00:00
|
|
|
|
2024-02-23 03:20:54 +00:00
|
|
|
private static int GetRemapIndex(GameVersion version) => version - PLA;
|
2023-06-04 01:19:16 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Checks if the SW/SH-context Met Location is one of the remapped HOME locations.
|
|
|
|
/// </summary>
|
2024-02-23 03:20:54 +00:00
|
|
|
public static bool IsLocationSWSH(ushort met) => met switch
|
2023-06-04 01:19:16 +00:00
|
|
|
{
|
|
|
|
SHVL or SWSL or SHSP or SWBD or SWLA => true,
|
|
|
|
_ => false,
|
|
|
|
};
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Checks if the SW/SH-context Egg Location is valid with respect to the <see cref="original"/> location.
|
|
|
|
/// </summary>
|
2024-02-23 03:20:54 +00:00
|
|
|
public static bool IsLocationSWSHEgg(GameVersion version, ushort met, int egg, ushort original)
|
2023-06-04 01:19:16 +00:00
|
|
|
{
|
|
|
|
if (original > SWLA && egg == SWSHEgg)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// >60000 can be reset to Link Trade (30001), then altered differently.
|
2024-02-23 03:20:54 +00:00
|
|
|
var expect = GetMetSWSH(original, version);
|
2023-06-04 01:19:16 +00:00
|
|
|
return expect == met && expect == egg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2024-02-23 03:20:54 +00:00
|
|
|
/// Gets the SW/SH-context Egg Location when an external entity from the input <see cref="version"/> resides in SW/SH.
|
2023-06-04 01:19:16 +00:00
|
|
|
/// </summary>
|
2024-02-23 03:20:54 +00:00
|
|
|
public static ushort GetLocationSWSHEgg(GameVersion version, ushort egg)
|
2023-06-04 01:19:16 +00:00
|
|
|
{
|
|
|
|
if (egg == 0)
|
|
|
|
return 0;
|
|
|
|
if (egg > SWLA)
|
|
|
|
return SWSHEgg;
|
|
|
|
// >60000 can be reset to Link Trade (30001), then altered differently.
|
2024-02-23 03:20:54 +00:00
|
|
|
return GetMetSWSH(egg, version);
|
2023-06-04 01:19:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2024-02-23 03:20:54 +00:00
|
|
|
/// Gets the SW/SH-context <see cref="GameVersion"/> when an external entity from the input <see cref="version"/> resides in SW/SH.
|
2023-06-04 01:19:16 +00:00
|
|
|
/// </summary>
|
2024-02-23 03:20:54 +00:00
|
|
|
public static GameVersion GetVersionSWSH(GameVersion version) => version switch
|
2023-06-04 01:19:16 +00:00
|
|
|
{
|
2024-02-23 03:20:54 +00:00
|
|
|
GameVersion.PLA => GameVersion.SW,
|
|
|
|
GameVersion.BD => GameVersion.SW,
|
|
|
|
GameVersion.SP => GameVersion.SH,
|
|
|
|
GameVersion.SL => GameVersion.SW,
|
|
|
|
GameVersion.VL => GameVersion.SH,
|
|
|
|
_ => version,
|
2023-06-04 01:19:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// <summary>
|
2024-02-23 03:20:54 +00:00
|
|
|
/// Gets the SW/SH-context Met Location when an external entity from the input <see cref="version"/> resides in SW/SH.
|
2023-06-04 01:19:16 +00:00
|
|
|
/// </summary>
|
2024-02-23 03:20:54 +00:00
|
|
|
public static ushort GetMetSWSH(ushort loc, GameVersion version) => version switch
|
2023-06-04 01:19:16 +00:00
|
|
|
{
|
|
|
|
GameVersion.PLA => SWLA,
|
|
|
|
GameVersion.BD => SWBD,
|
|
|
|
GameVersion.SP => SHSP,
|
|
|
|
GameVersion.SL => SWSL,
|
|
|
|
GameVersion.VL => SHVL,
|
|
|
|
_ => loc,
|
|
|
|
};
|
|
|
|
|
2024-02-23 03:20:54 +00:00
|
|
|
public static GameVersion GetVersionSWSHOriginal(ushort loc) => loc switch
|
2023-07-11 20:26:57 +00:00
|
|
|
{
|
2024-02-23 03:20:54 +00:00
|
|
|
SWLA => GameVersion.PLA,
|
|
|
|
SWBD => GameVersion.BD,
|
|
|
|
SHSP => GameVersion.SP,
|
|
|
|
SWSL => GameVersion.SL,
|
|
|
|
SHVL => GameVersion.VL,
|
|
|
|
_ => GameVersion.SW,
|
2023-07-11 20:26:57 +00:00
|
|
|
};
|
|
|
|
|
2023-06-04 01:19:16 +00:00
|
|
|
/// <summary>
|
2024-02-23 03:20:54 +00:00
|
|
|
/// Checks if the met location is a valid location for the input <see cref="version"/>.
|
2023-06-04 01:19:16 +00:00
|
|
|
/// </summary>
|
2023-12-04 04:13:20 +00:00
|
|
|
/// <remarks>Relevant when an entity from BD/SP is transferred to SW/SH.</remarks>
|
2024-02-23 03:20:54 +00:00
|
|
|
public static bool IsValidMetBDSP(ushort loc, GameVersion version) => loc switch
|
2023-06-04 01:19:16 +00:00
|
|
|
{
|
2024-02-23 03:20:54 +00:00
|
|
|
SHSP when version == SH => true,
|
|
|
|
SWBD when version == SW => true,
|
2023-06-04 01:19:16 +00:00
|
|
|
_ => false,
|
|
|
|
};
|
|
|
|
|
|
|
|
/// <summary>
|
2024-02-23 03:20:54 +00:00
|
|
|
/// Checks if the met location is a valid location for the input <see cref="version"/>.
|
2023-06-04 01:19:16 +00:00
|
|
|
/// </summary>
|
2023-12-04 04:13:20 +00:00
|
|
|
/// <remarks>Relevant when an entity from S/V is transferred to SW/SH.</remarks>
|
2024-02-23 03:20:54 +00:00
|
|
|
public static bool IsValidMetSV(ushort loc, GameVersion version) => loc switch
|
2023-06-04 01:19:16 +00:00
|
|
|
{
|
2024-02-23 03:20:54 +00:00
|
|
|
SHVL when version == SH => true,
|
|
|
|
SWSL when version == SW => true,
|
2023-06-04 01:19:16 +00:00
|
|
|
_ => false,
|
|
|
|
};
|
2023-07-06 04:14:09 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Checks if the location is (potentially) remapped based on visitation options.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>Relevant when a side data yields SW/SH side data with a higher priority than the original (by version) side data.</remarks>
|
|
|
|
/// <param name="original">Original context</param>
|
|
|
|
/// <param name="current">Current context</param>
|
|
|
|
public static LocationRemapState GetRemapState(EntityContext original, EntityContext current)
|
|
|
|
{
|
|
|
|
if (current == original)
|
|
|
|
return LocationRemapState.Original;
|
|
|
|
if (current == EntityContext.Gen8)
|
|
|
|
return LocationRemapState.Remapped;
|
|
|
|
return original.Generation() switch
|
|
|
|
{
|
|
|
|
< 8 => LocationRemapState.Original,
|
|
|
|
8 => LocationRemapState.Either,
|
|
|
|
_ => current is (EntityContext.Gen8a or EntityContext.Gen8b) // down
|
|
|
|
? LocationRemapState.Either
|
|
|
|
: LocationRemapState.Original,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-02-23 03:20:54 +00:00
|
|
|
public static bool IsMatchLocation(EntityContext original, EntityContext current, ushort met, int expect, GameVersion version)
|
2023-07-06 04:14:09 +00:00
|
|
|
{
|
|
|
|
var state = GetRemapState(original, current);
|
|
|
|
return state switch
|
|
|
|
{
|
|
|
|
LocationRemapState.Original => met == expect,
|
|
|
|
LocationRemapState.Remapped => met == GetMetSWSH((ushort)expect, version),
|
|
|
|
LocationRemapState.Either => met == expect || met == GetMetSWSH((ushort)expect, version),
|
|
|
|
_ => false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Flags]
|
|
|
|
public enum LocationRemapState
|
|
|
|
{
|
|
|
|
None,
|
|
|
|
Original = 1 << 0,
|
|
|
|
Remapped = 1 << 1,
|
|
|
|
Either = Original | Remapped,
|
2023-06-04 01:19:16 +00:00
|
|
|
}
|