mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-27 14:30:56 +00:00
03182ebd3d
Adds support for Scarlet & Violet. Co-Authored-By: SciresM <8676005+SciresM@users.noreply.github.com> Co-Authored-By: Matt <17801814+sora10pls@users.noreply.github.com> Co-Authored-By: Lusamine <30205550+Lusamine@users.noreply.github.com>
50 lines
1.7 KiB
C#
50 lines
1.7 KiB
C#
using System;
|
|
|
|
using static PKHeX.Core.Legal;
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
/// <summary>
|
|
/// Information about Held Item Restrictions
|
|
/// </summary>
|
|
public static class ItemRestrictions
|
|
{
|
|
/// <summary>
|
|
/// Checks if a <see cref="PKM.HeldItem"/> is available to be held in the current <see cref="PKM.Format"/>.
|
|
/// </summary>
|
|
/// <param name="pk">Entity data</param>
|
|
/// <returns>True if able to be held, false if not</returns>
|
|
public static bool IsHeldItemAllowed(PKM pk)
|
|
{
|
|
return IsHeldItemAllowed(pk.HeldItem, pk.Context);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks if an <see cref="item"/> is available to be held in <see cref="context"/>.
|
|
/// </summary>
|
|
/// <param name="item">Held Item ID</param>
|
|
/// <param name="context">Entity context to check</param>
|
|
/// <returns>True if able to be held, false if not</returns>
|
|
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<bool> 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<bool>(), // lgp/e, pla, etc
|
|
};
|
|
}
|