PKHeX/PKHeX.Core/Legality/Verifiers/Egg/EggStateLegality.cs
Kurt cd5c220ddc Show correct HatchCounter value for BDSP traded eggs
Yay abstractions to hide away the quirks.

BDSP traded eggs set HT_Friendship and the CurrentHandler flag, but the HatchCounter is always the OT_Friendship value.

Trades always receive BaseFriendship, instead of a hardcoded 50. Necessary to not hardcode because it's immutable for eggs.

Clicking the hatch counter label now sets it to the legal minimum hatch counter (best), and control clicking sets it to the max (worst). Check the encounter template for the true maximum.
2021-11-21 19:53:13 -08:00

44 lines
1.4 KiB
C#

namespace PKHeX.Core
{
public static class EggStateLegality
{
public static bool GetIsEggHatchCyclesValid(PKM pk, IEncounterTemplate enc)
{
var hatchCounter = pk.OT_Friendship;
var max = GetMaximumEggHatchCycles(pk, enc);
if (hatchCounter > max)
return false;
var min = GetMinimumEggHatchCycles(pk);
if (hatchCounter < min)
return false;
return true;
}
public static int GetMinimumEggHatchCycles(PKM pk) => pk switch
{
PK7 => 0, // pelago can decrement to 0
_ => 1, // whenever it hits 0, it hatches, so anything above that is fine.
};
public static int GetMaximumEggHatchCycles(PKM pk)
{
var la = new LegalityAnalysis(pk);
var enc = la.EncounterMatch;
return GetMaximumEggHatchCycles(pk, enc);
}
public static int GetMaximumEggHatchCycles(PKM pk, IEncounterTemplate enc)
{
if (enc is EncounterStatic { EggCycles: not 0 } s)
return s.EggCycles;
return pk.PersonalInfo.HatchCycles;
}
public static bool IsValidHTEgg(PKM pk) => pk switch
{
PB8 { Met_Location: Locations.LinkTrade6NPC } pb8 when pb8.HT_Friendship == PersonalTable.BDSP[pb8.Species].BaseFriendship => true,
_ => false,
};
}
}