mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-27 14:30:56 +00:00
59fad0e8cf
Extract some logic (origin markings) Revise directives for NET7 targeting, remove old net5 refs
49 lines
1.6 KiB
C#
49 lines
1.6 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.Gen8b => ReleasedHeldItems_8b,
|
|
_ => Array.Empty<bool>(), // lgp/e, pla, etc
|
|
};
|
|
}
|