2022-08-20 05:37:27 +00:00
using static PKHeX . Core . LegalityCheckStrings ;
2018-06-24 05:00:01 +00:00
2022-06-18 18:04:24 +00:00
namespace PKHeX.Core ;
2018-07-27 02:34:27 +00:00
2022-06-18 18:04:24 +00:00
/// <summary>
/// Verifies the <see cref="PKM.HeldItem"/>.
/// </summary>
public sealed class ItemVerifier : Verifier
{
protected override CheckIdentifier Identifier = > CheckIdentifier . HeldItem ;
2018-06-24 05:00:01 +00:00
2022-06-18 18:04:24 +00:00
public override void Verify ( LegalityAnalysis data )
{
var pk = data . Entity ;
2022-08-20 05:37:27 +00:00
var item = pk . HeldItem ;
if ( pk . IsEgg & & item ! = 0 )
2022-06-18 18:04:24 +00:00
data . AddLine ( GetInvalid ( LItemEgg ) ) ;
2022-08-20 05:37:27 +00:00
if ( ! ItemRestrictions . IsHeldItemAllowed ( item , context : pk . Context ) )
{
data . AddLine ( GetInvalid ( LItemUnreleased ) ) ;
}
else if ( pk . Format = = 3 & & item = = 175 ) // Enigma Berry
{
// A Pokémon holding this Berry cannot be traded to Pokémon Colosseum or Pokémon XD: Gale of Darkness, nor can it be stored in Pokémon Box Ruby & Sapphire.
if ( pk is CK3 or XK3 )
data . AddLine ( GetInvalid ( LItemUnreleased ) ) ;
else
VerifyEReaderBerry ( data ) ;
}
2022-06-18 18:04:24 +00:00
}
2018-06-24 05:00:01 +00:00
2022-06-18 18:04:24 +00:00
private void VerifyEReaderBerry ( LegalityAnalysis data )
{
var status = EReaderBerrySettings . GetStatus ( ) ;
var chk = GetEReaderCheckResult ( status ) ;
2023-04-23 23:04:04 +00:00
if ( chk ! = default )
2022-06-18 18:04:24 +00:00
data . AddLine ( chk ) ;
2018-06-24 05:00:01 +00:00
}
2022-06-18 18:04:24 +00:00
2023-04-23 23:04:04 +00:00
private CheckResult GetEReaderCheckResult ( EReaderBerryMatch status ) = > status switch
2022-06-18 18:04:24 +00:00
{
EReaderBerryMatch . NoMatch = > GetInvalid ( LEReaderInvalid ) ,
EReaderBerryMatch . NoData = > GetInvalid ( LItemUnreleased ) ,
EReaderBerryMatch . InvalidUSA = > GetInvalid ( LEReaderAmerica ) ,
EReaderBerryMatch . InvalidJPN = > GetInvalid ( LEReaderJapan ) ,
2023-04-23 23:04:04 +00:00
_ = > default ,
2022-06-18 18:04:24 +00:00
} ;
2018-06-24 05:00:01 +00:00
}