using System;
using System.Collections.Generic;
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)
{
if (pk is PB7)
return pk.HeldItem == 0;
return IsHeldItemAllowed(pk.HeldItem, pk.Format);
}
///
/// Checks if an is available to be held in .
///
/// Held Item ID
/// Generation Number
/// True if able to be held, false if not
public static bool IsHeldItemAllowed(int item, int generation)
{
if (item == 0)
return true;
var items = GetReleasedHeldItems(generation);
return (uint)item < items.Count && items[item];
}
private static IReadOnlyList GetReleasedHeldItems(int generation) => generation switch
{
2 => ReleasedHeldItems_2,
3 => ReleasedHeldItems_3,
4 => ReleasedHeldItems_4,
5 => ReleasedHeldItems_5,
6 => ReleasedHeldItems_6,
7 => ReleasedHeldItems_7,
8 => ReleasedHeldItems_8,
_ => Array.Empty()
};
}
}