mirror of
https://github.com/kwsch/PKHeX
synced 2024-12-18 00:13:10 +00:00
58 lines
1.8 KiB
C#
58 lines
1.8 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
|
|||
|
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)
|
|||
|
{
|
|||
|
if (pk is PB7)
|
|||
|
return pk.HeldItem == 0;
|
|||
|
return IsHeldItemAllowed(pk.HeldItem, pk.Format);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Checks if an <see cref="item"/> is available to be held in <see cref="generation"/>.
|
|||
|
/// </summary>
|
|||
|
/// <param name="item">Held Item ID</param>
|
|||
|
/// <param name="generation">Generation Number</param>
|
|||
|
/// <returns>True if able to be held, false if not</returns>
|
|||
|
public static bool IsHeldItemAllowed(int item, int generation)
|
|||
|
{
|
|||
|
if (item == 0)
|
|||
|
return true;
|
|||
|
if (item < 0)
|
|||
|
return false;
|
|||
|
|
|||
|
var items = GetReleasedHeldItems(generation);
|
|||
|
return items.Count > item && items[item];
|
|||
|
}
|
|||
|
|
|||
|
private static IReadOnlyList<bool> GetReleasedHeldItems(int generation)
|
|||
|
{
|
|||
|
return 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<bool>()
|
|||
|
};
|
|||
|
}
|
|||
|
}
|
|||
|
}
|