mirror of
https://github.com/kwsch/PKHeX
synced 2024-12-24 03:13:18 +00:00
3c232505e5
In this pull request I've changed a ton of method signatures to reflect the more-narrow types of Species, Move# and Form; additionally, I've narrowed other large collections that stored lists of species / permitted values, and reworked them to be more performant with the latest API spaghetti that PKHeX provides. Roamer met locations, usually in a range of [max-min]<64, can be quickly checked using a bitflag operation on a UInt64. Other collections (like "Is this from Colosseum or XD") were eliminated -- shadow state is not transferred COLO<->XD, so having a Shadow ID or matching the met location from a gift/wild encounter is a sufficient check for "originated in XD".
47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
namespace PKHeX.Core;
|
|
|
|
public static class EntityGender
|
|
{
|
|
/// <summary>
|
|
/// Translates a Gender string to Gender integer.
|
|
/// </summary>
|
|
/// <param name="s">Gender string</param>
|
|
/// <returns>Gender integer</returns>
|
|
public static int GetFromString(string s)
|
|
{
|
|
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>
|
|
public static int GetFromPID(ushort species, uint pid)
|
|
{
|
|
int gt = PKX.Personal[species].Gender;
|
|
return GetFromPIDAndRatio(pid, gt);
|
|
}
|
|
|
|
public static int GetFromPIDAndRatio(uint pid, int gr) => gr switch
|
|
{
|
|
PersonalInfo.RatioMagicGenderless => 2,
|
|
PersonalInfo.RatioMagicFemale => 1,
|
|
PersonalInfo.RatioMagicMale => 0,
|
|
_ => (pid & 0xFF) < gr ? 1 : 0,
|
|
};
|
|
}
|