2023-01-22 04:02:33 +00:00
|
|
|
using System;
|
|
|
|
|
2022-08-27 06:43:36 +00:00
|
|
|
namespace PKHeX.Core;
|
2022-05-07 03:38:55 +00:00
|
|
|
|
|
|
|
public static class EntityGender
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Translates a Gender string to Gender integer.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="s">Gender string</param>
|
|
|
|
/// <returns>Gender integer</returns>
|
2023-01-22 04:02:33 +00:00
|
|
|
public static int GetFromString(ReadOnlySpan<char> s)
|
2022-05-07 03:38:55 +00:00
|
|
|
{
|
|
|
|
if (s.Length != 1)
|
|
|
|
return 2;
|
|
|
|
return GetFromChar(s[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Translates a Gender char to Gender integer.
|
|
|
|
/// </summary>
|
|
|
|
public static int GetFromChar(char c) => c switch
|
|
|
|
{
|
|
|
|
'♂' or 'M' => 0,
|
|
|
|
'♀' or 'F' => 1,
|
|
|
|
_ => 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the gender ID of the species based on the Personality ID.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="species">National Dex ID.</param>
|
|
|
|
/// <param name="pid">Personality ID.</param>
|
|
|
|
/// <returns>Gender ID (0/1/2)</returns>
|
|
|
|
/// <remarks>This method should only be used for Generations 3-5 origin.</remarks>
|
2022-08-27 06:43:36 +00:00
|
|
|
public static int GetFromPID(ushort species, uint pid)
|
2022-05-07 03:38:55 +00:00
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
var gt = PKX.Personal[species].Gender;
|
2022-05-07 03:38:55 +00:00
|
|
|
return GetFromPIDAndRatio(pid, gt);
|
|
|
|
}
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
public static int GetFromPIDAndRatio(uint pid, byte gr) => gr switch
|
2022-05-07 03:38:55 +00:00
|
|
|
{
|
|
|
|
PersonalInfo.RatioMagicGenderless => 2,
|
|
|
|
PersonalInfo.RatioMagicFemale => 1,
|
|
|
|
PersonalInfo.RatioMagicMale => 0,
|
|
|
|
_ => (pid & 0xFF) < gr ? 1 : 0,
|
|
|
|
};
|
|
|
|
}
|