2022-12-04 05:00:25 +00:00
|
|
|
namespace PKHeX.Core;
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Object has Trainer ownership
|
|
|
|
/// </summary>
|
|
|
|
public interface ITrainerID
|
2018-04-28 18:06:58 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
int TID { get; set; }
|
|
|
|
int SID { get; set; }
|
|
|
|
}
|
2018-07-27 02:34:27 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public static partial class Extensions
|
|
|
|
{
|
|
|
|
public static int GetTrainerIDFormat(this ITrainerID tr)
|
2018-07-27 02:34:27 +00:00
|
|
|
{
|
2022-12-04 05:00:25 +00:00
|
|
|
if (tr is PKM pk)
|
2018-07-27 02:34:27 +00:00
|
|
|
{
|
2022-12-04 05:00:25 +00:00
|
|
|
if (pk.Version is 0)
|
|
|
|
return pk.Format;
|
|
|
|
|
|
|
|
var format = pk.Generation;
|
|
|
|
if (format < 3 && pk.Format >= 7) // VC or bad gen
|
|
|
|
return 4; // use TID/SID 16bit style
|
|
|
|
if (format <= 0)
|
2022-06-18 18:04:24 +00:00
|
|
|
return 4; // use TID/SID 16bit style
|
|
|
|
return format;
|
2018-07-27 02:34:27 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
if (tr is SaveFile s)
|
|
|
|
return s.Generation;
|
|
|
|
return -1;
|
|
|
|
}
|
2020-09-25 02:26:21 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public static bool IsShiny(this ITrainerID tr, uint pid, int gen = 7)
|
|
|
|
{
|
|
|
|
var xor = tr.SID ^ tr.TID ^ (pid >> 16) ^ (pid & 0xFFFF);
|
|
|
|
return xor < (gen >= 7 ? 16 : 8);
|
2018-07-27 02:34:27 +00:00
|
|
|
}
|
2018-04-28 18:06:58 +00:00
|
|
|
}
|