using System;
using static PKHeX.Core.Legal;
namespace PKHeX.Core;
///
/// Information about Held Item Restrictions
///
public static class ItemRestrictions
{
///
/// Checks if a is available to be held in the current .
///
/// Entity data
/// True if able to be held, false if not
public static bool IsHeldItemAllowed(PKM pk)
{
return IsHeldItemAllowed(pk.HeldItem, pk.Context);
}
///
/// Checks if an is available to be held in .
///
/// Held Item ID
/// Entity context to check
/// True if able to be held, false if not
public static bool IsHeldItemAllowed(int item, EntityContext context)
{
if (item == 0)
return true;
var items = GetReleasedHeldItems(context);
return (uint)item < items.Length && items[item];
}
private static ReadOnlySpan GetReleasedHeldItems(EntityContext context) => context switch
{
EntityContext.Gen2 => ReleasedHeldItems_2,
EntityContext.Gen3 => ReleasedHeldItems_3,
EntityContext.Gen4 => ReleasedHeldItems_4,
EntityContext.Gen5 => ReleasedHeldItems_5,
EntityContext.Gen6 => ReleasedHeldItems_6,
EntityContext.Gen7 => ReleasedHeldItems_7,
EntityContext.Gen8 => ReleasedHeldItems_8,
EntityContext.Gen9 => ReleasedHeldItems_9,
EntityContext.Gen8b => ReleasedHeldItems_8b,
_ => Array.Empty(), // lgp/e, pla, etc
};
}