126 lines
3.7 KiB
C#
126 lines
3.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using PkmnLibSharp.FFI;
|
|
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,
|
|
}
|
|
|
|
public class Item : ExternPointer<Item.CacheData>
|
|
{
|
|
public class CacheData
|
|
{
|
|
public string? Name { get; internal set; }
|
|
public ItemCategory? Category { get; internal set; }
|
|
public BattleItemCategory? BattleCategory { get; internal set; }
|
|
public int? Price { get; internal set; }
|
|
}
|
|
|
|
public Item(string name, ItemCategory category, BattleItemCategory battleItemCategory, int price,
|
|
IEnumerable<string> flags)
|
|
{
|
|
var ptrArray = flags.Select(x => x.ToPtr()).ToArray();
|
|
var ptrToPtrArray = ptrArray.ArrayPtr();
|
|
var ptr = Interface.item_new(name.ToPtr(), category, battleItemCategory, price, ptrToPtrArray,
|
|
(ulong)ptrArray.Length);
|
|
InitializePointer(ptr, true);
|
|
}
|
|
|
|
internal Item(IdentifiablePointer ptr) : base(ptr, true)
|
|
{
|
|
}
|
|
|
|
public string Name => Cache.Name ??= Interface.item_name(Ptr).PtrString()!;
|
|
public ItemCategory Category => Cache.Category ??= Interface.item_category(Ptr);
|
|
public BattleItemCategory BattleCategory => Cache.BattleCategory ??= Interface.item_battle_category(Ptr);
|
|
public int Price => Cache.Price ??= Interface.item_price(Ptr);
|
|
|
|
public bool HasFlag(string flag) => Interface.item_has_flag(Ptr, flag.ToPtr()) == 1;
|
|
|
|
protected override CacheData CreateCache() => new CacheData();
|
|
protected override void Destructor() => Interface.item_drop(Ptr);
|
|
|
|
~Item()
|
|
{
|
|
Dispose();
|
|
}
|
|
}
|
|
} |