Condense into expression, add future-evo case

This commit is contained in:
Kurt 2021-08-22 00:06:02 -07:00
parent 5b42dc8ae4
commit 6112c9c91c

View file

@ -359,7 +359,7 @@ namespace PKHeX.Core
if (pid > 0xFF)
return GetNonMatch(out pidiv);
GetCuteCharmGenderSpecies(pk, pid, out int genderValue, out int species);
(int species, int genderValue) = GetCuteCharmGenderSpecies(pk, pid, pk.Species);
int getRatio() => PersonalTable.HGSS[species].Gender;
switch (genderValue)
{
@ -913,41 +913,32 @@ namespace PKHeX.Core
private static bool IsCuteCharmAzurillMale(uint pid) => pid is >= 0xC8 and <= 0xE0;
private static void GetCuteCharmGenderSpecies(PKM pk, uint pid, out int genderValue, out int species)
/// <summary>
/// There are some edge cases when the gender ratio changes across evolutions.
/// </summary>
private static (int Species, int Gender) GetCuteCharmGenderSpecies(PKM pk, uint pid, int currentSpecies) => currentSpecies switch
{
// There are some edge cases when the gender ratio changes across evolutions.
species = pk.Species;
if (species == (int)Species.Ninjask)
{
species = (int)Species.Nincada; // Nincada evo chain travels from M/F -> Genderless Shedinja
genderValue = PKX.GetGenderFromPID(species, pid);
return;
}
// Nincada evo chain travels from M/F -> Genderless Shedinja
(int)Species.Shedinja => ((int)Species.Nincada, PKX.GetGenderFromPID(currentSpecies, pid)),
switch (species)
{
// These evolved species cannot be encountered with cute charm.
// 100% fixed gender does not modify PID; override this with the encounter species for correct calculation.
// We can assume the re-mapped species's [gender ratio] is what was encountered.
// These evolved species cannot be encountered with cute charm.
// 100% fixed gender does not modify PID; override this with the encounter species for correct calculation.
// We can assume the re-mapped species's [gender ratio] is what was encountered.
(int)Species.Wormadam => ((int)Species.Burmy, 1),
(int)Species.Mothim => ((int)Species.Burmy, 0),
(int)Species.Vespiquen => ((int)Species.Combee, 1),
(int)Species.Gallade => ((int)Species.Kirlia, 0),
(int)Species.Froslass => ((int)Species.Snorunt, 1),
// Azurill & Marill/Azumarill collision
// Changed gender ratio (25% M -> 50% M) needs special treatment.
// Double check the encounter species with IsCuteCharm4Valid afterwards.
(int)Species.Marill or (int)Species.Azumarill when IsCuteCharmAzurillMale(pid) => ((int)Species.Azurill, 0),
case (int)Species.Wormadam or (int)Species.Mothim: species = (int)Species.Burmy; break;
case (int)Species.Vespiquen: species = (int)Species.Combee; break;
case (int)Species.Gallade: species = (int)Species.Kirlia; break;
case (int)Species.Froslass: species = (int)Species.Snorunt; break;
// Future evolutions
(int)Species.Sylveon => ((int)Species.Eevee, pk.Gender),
// Changed gender ratio (25% M -> 50% M) needs special treatment.
// Double check the encounter species with IsCuteCharm4Valid afterwards.
case (int)Species.Marill or (int)Species.Azumarill: // Azurill & Marill/Azumarill collision
if (IsCuteCharmAzurillMale(pid))
{
species = (int)Species.Azurill;
genderValue = 0;
return;
}
break;
}
genderValue = pk.Gender;
}
_ => (currentSpecies, pk.Gender),
};
private static readonly PIDType[] MethodH = { Method_1, Method_2, Method_3, Method_4 };
private static readonly PIDType[] MethodH14 = { Method_1, Method_4 };