PKHeX/PKHeX.Core/PKM/Interfaces/ITrainerID.cs
Kurt fc754b346b
File scoped namespaces (#3529)
[Language Reference](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-10.0/file-scoped-namespaces)

Updates all the files, one less level of indentation.

Some small changes were made to API surfaces, renaming `PKM pkm` -> `PKM pk`, and `LegalityAnalysis.pkm` -> `LegalityAnalysis.Entity`
2022-06-18 11:04:24 -07:00

33 lines
809 B
C#

namespace PKHeX.Core;
/// <summary>
/// Object has Trainer ownership
/// </summary>
public interface ITrainerID
{
int TID { get; set; }
int SID { get; set; }
}
public static partial class Extensions
{
public static int GetTrainerIDFormat(this ITrainerID tr)
{
if (tr is PKM p)
{
var format = p.Generation;
if ((format < 3 && p.Format >= 7) || format <= 0) // VC or bad gen
return 4; // use TID/SID 16bit style
return format;
}
if (tr is SaveFile s)
return s.Generation;
return -1;
}
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);
}
}