Item Wrapper

This commit is contained in:
Deukhoofd 2020-05-04 21:50:14 +02:00
parent a8709f2b05
commit 6c0d320656
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
1 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,44 @@
using System;
using System.Linq;
using PkmnLibSharp.Utilities;
using BattleItemCategory = Pkmnlib.BattleItemCategory;
using ItemCategory = Pkmnlib.ItemCategory;
namespace PkmnLibSharp.Library
{
public class Item : PointerWrapper
{
private string _name;
public string Name => _name ??= Creatureliblibrary.Generated.Item.GetName(Ptr).PtrString();
public ItemCategory Category => (ItemCategory) Creatureliblibrary.Generated.Item.GetCategory(Ptr);
public BattleItemCategory BattleCategory =>
(BattleItemCategory) Creatureliblibrary.Generated.Item.GetBattleCategory(Ptr);
public int Price => Creatureliblibrary.Generated.Item.GetPrice(Ptr);
public byte FlingPower => Pkmnlib.Generated.Item.GetFlingPower(Ptr);
public bool HasFlag(string s)
{
return Creatureliblibrary.Generated.Item.HasFlag(Ptr, s.ToPtr()) == MarshalHelper.True;
}
internal Item(IntPtr ptr) : base(ptr)
{
}
public static Item Create(string name, ItemCategory category, BattleItemCategory battleCategory,
int price,
string[] flags, byte flingPower)
{
var convertedFlags = flags.Select(x => x.ToPtr()).ToArray().ArrayPtr();
var p = Pkmnlib.Generated.Item.Construct(name.ToPtr(), category, battleCategory, price, convertedFlags,
(ulong) flags.Length, flingPower);
return new Item(p);
}
protected override void DeletePtr()
{
Pkmnlib.Generated.Item.Destruct(Ptr);
}
}
}