Initial work on battle side.

This commit is contained in:
2020-07-18 16:49:11 +02:00
parent 5ad3e2e040
commit 049eb480c0
39 changed files with 835 additions and 88 deletions

View File

@@ -6,6 +6,6 @@ namespace PkmnLibSharp.Library.Items
Healing = 1,
StatusHealing = 2,
Pokeball = 3,
MiscBattleItem = 4,
MiscBattleItem = 4
}
}

View File

@@ -8,6 +8,10 @@ namespace PkmnLibSharp.Library.Items
{
private string _name;
internal Item(IntPtr ptr) : base(ptr)
{
}
public string Name => _name ??= Creatureliblibrary.Generated.Item.GetName(Ptr).PtrString();
public ItemCategory Category => (ItemCategory) Creatureliblibrary.Generated.Item.GetCategory(Ptr);
@@ -22,10 +26,6 @@ namespace PkmnLibSharp.Library.Items
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)

View File

@@ -9,6 +9,6 @@ namespace PkmnLibSharp.Library
TechnicalMachine = 4,
FormeChanger = 5,
KeyItem = 6,
Mail = 7,
Mail = 7
}
}

View File

@@ -6,7 +6,18 @@ namespace PkmnLibSharp.Library.Items
{
public class ItemLibrary : PointerWrapper
{
private readonly Dictionary<string, Item> _cache = new Dictionary<string, Item>(StringComparer.InvariantCultureIgnoreCase);
private readonly Dictionary<string, Item> _cache =
new Dictionary<string, Item>(StringComparer.InvariantCultureIgnoreCase);
internal ItemLibrary(IntPtr ptr) : base(ptr)
{
}
public ItemLibrary(ulong initialCapacity) : base(
Creatureliblibrary.Generated.ItemLibrary.Construct(initialCapacity))
{
}
public ulong Count => Creatureliblibrary.Generated.ItemLibrary.GetCount(Ptr);
public void Insert(string key, Item item)
@@ -26,13 +37,14 @@ namespace PkmnLibSharp.Library.Items
if (_cache.TryGetValue(key, out item))
return true;
var ptr = IntPtr.Zero;
if (Creatureliblibrary.Generated.ItemLibrary.TryGet(Ptr, key.ToPtr(), ref ptr) != MarshalHelper.True)
if (Creatureliblibrary.Generated.ItemLibrary.TryGet(Ptr, key.ToPtr(), ref ptr) != MarshalHelper.True)
return false;
if (TryResolvePointer(ptr, out item))
{
_cache.Add(key, item);
return true;
}
item = new Item(ptr);
_cache.Add(key, item);
return true;
@@ -49,33 +61,21 @@ namespace PkmnLibSharp.Library.Items
_cache.Add(key, item);
return item;
}
item = new Item(ptr);
_cache.Add(key, item);
return item;
}
internal ItemLibrary(IntPtr ptr) : base(ptr)
{
}
public ItemLibrary(ulong initialCapacity) : base(
Creatureliblibrary.Generated.ItemLibrary.Construct(initialCapacity))
{
}
protected internal override void MarkAsDeleted()
{
base.MarkAsDeleted();
foreach (var item in _cache)
{
item.Value.MarkAsDeleted();
}
foreach (var item in _cache) item.Value.MarkAsDeleted();
}
protected override void DeletePtr()
{
Creatureliblibrary.Generated.ItemLibrary.Destruct(Ptr);
}
}
}