Item Wrapper
This commit is contained in:
		
							
								
								
									
										44
									
								
								PkmnLibSharp/Library/Item.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								PkmnLibSharp/Library/Item.cs
									
									
									
									
									
										Normal 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); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user