using System; using System.Collections.Generic; using System.Linq; using PkmnLibSharp.FFI; using PkmnLibSharp.Utils; using Interface = PkmnLibSharp.FFI.StaticData.Item; namespace PkmnLibSharp.StaticData { /// /// An item category defines which bag slot items are stored in. /// public enum ItemCategory : byte { /// /// This is where most items should go. /// MiscItem, /// /// Pokeballs are used for capturing Pokemons. /// Pokeball, /// /// Medicine is used for healing HP, PP, and status effects /// Medicine, /// /// Berry is used for all berries. /// Berry, /// /// TMHM is used for Technical and Hidden Machines. /// TMHM, /// /// Form Changer is used for items that change forms, such as mega stones. /// FormChanger, /// /// Key Items are single stored items, generally used for story progression. /// KeyItem, /// /// Mail is used for mail items. /// Mail, } /// /// A battle item category defines how the item is categorized when in battle. /// public enum BattleItemCategory : byte { /// /// This item can't be used in battle. /// None, /// /// This item is used for healing Pokemon. /// Healing, /// /// This item is used for healing Pokemon from a status. /// StatusHealing, /// /// This item is used for capturing Pokemon. /// Pokeball, /// /// This item does not belong in above categories, but is still a battle item. /// MiscBattleItem, } public class Item : ExternPointer { 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 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(); } } }