132 lines
4.0 KiB
C#
132 lines
4.0 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using PkmnLibSharp.Utils;
|
|
using Interface = PkmnLibSharp.FFI.StaticData.Item;
|
|
|
|
namespace PkmnLibSharp.StaticData
|
|
{
|
|
/// <summary>
|
|
/// An item category defines which bag slot items are stored in.
|
|
/// </summary>
|
|
public enum ItemCategory : byte
|
|
{
|
|
/// <summary>
|
|
/// This is where most items should go.
|
|
/// </summary>
|
|
MiscItem,
|
|
|
|
/// <summary>
|
|
/// Pokeballs are used for capturing Pokemons.
|
|
/// </summary>
|
|
Pokeball,
|
|
|
|
/// <summary>
|
|
/// Medicine is used for healing HP, PP, and status effects
|
|
/// </summary>
|
|
Medicine,
|
|
|
|
/// <summary>
|
|
/// Berry is used for all berries.
|
|
/// </summary>
|
|
Berry,
|
|
|
|
/// <summary>
|
|
/// TMHM is used for Technical and Hidden Machines.
|
|
/// </summary>
|
|
TMHM,
|
|
|
|
/// <summary>
|
|
/// Form Changer is used for items that change forms, such as mega stones.
|
|
/// </summary>
|
|
FormChanger,
|
|
|
|
/// <summary>
|
|
/// Key Items are single stored items, generally used for story progression.
|
|
/// </summary>
|
|
KeyItem,
|
|
|
|
/// <summary>
|
|
/// Mail is used for mail items.
|
|
/// </summary>
|
|
Mail,
|
|
}
|
|
|
|
/// <summary>
|
|
/// A battle item category defines how the item is categorized when in battle.
|
|
/// </summary>
|
|
public enum BattleItemCategory : byte
|
|
{
|
|
/// <summary>
|
|
/// This item can't be used in battle.
|
|
/// </summary>
|
|
None,
|
|
|
|
/// <summary>
|
|
/// This item is used for healing Pokemon.
|
|
/// </summary>
|
|
Healing,
|
|
|
|
/// <summary>
|
|
/// This item is used for healing Pokemon from a status.
|
|
/// </summary>
|
|
StatusHealing,
|
|
|
|
/// <summary>
|
|
/// This item is used for capturing Pokemon.
|
|
/// </summary>
|
|
Pokeball,
|
|
|
|
/// <summary>
|
|
/// This item does not belong in above categories, but is still a battle item.
|
|
/// </summary>
|
|
MiscBattleItem,
|
|
}
|
|
|
|
/// <summary>
|
|
/// An item is an object which the player can pick up, keep in their Bag, and use in some manner
|
|
/// </summary>
|
|
public class Item : HandleType
|
|
{
|
|
/// <inheritdoc cref="Item"/>
|
|
protected Item(FFIHandle handle) : base(handle){}
|
|
|
|
/// <summary>
|
|
/// Instantiates an item.
|
|
/// </summary>
|
|
public static Item Create(string name, ItemCategory category, BattleItemCategory battleItemCategory, int price,
|
|
IEnumerable<string> flags)
|
|
{
|
|
var ptrArray = flags.Select(x => x.ToPtr()).ToArray();
|
|
var ptrToPtrArray = ptrArray.ArrayPtr();
|
|
var handle = Interface.item_new(name.ToPtr(), category, battleItemCategory, price, ptrToPtrArray,
|
|
(ulong)ptrArray.Length);
|
|
return Resolver.Instance.ResolveItem(handle.Result().Resolve());
|
|
}
|
|
|
|
private string? _name;
|
|
/// <summary>
|
|
/// The name of the item.
|
|
/// </summary>
|
|
public string Name => _name ??= Interface.item_name(Handle).Result().PtrString()!;
|
|
private ItemCategory? _category;
|
|
/// <summary>
|
|
/// Which bag slot items are stored in.
|
|
/// </summary>
|
|
public ItemCategory Category => _category ??= Interface.item_category(Handle);
|
|
private BattleItemCategory? _battleCategory;
|
|
/// <summary>
|
|
/// How the item is categorized when in battle.
|
|
/// </summary>
|
|
public BattleItemCategory BattleCategory => _battleCategory ??= Interface.item_battle_category(Handle);
|
|
private int? _price;
|
|
/// <summary>
|
|
/// The buying value of the item.
|
|
/// </summary>
|
|
public int Price => _price ??= Interface.item_price(Handle);
|
|
|
|
/// <summary>
|
|
/// Checks whether the item has a specific flag.
|
|
/// </summary>
|
|
public bool HasFlag(string flag) => Interface.item_has_flag(Handle, flag.ToPtr()) == 1;
|
|
}
|
|
} |