summaryrefslogtreecommitdiff
path: root/source/game/components/items/ItemStack.cs
diff options
context:
space:
mode:
Diffstat (limited to 'source/game/components/items/ItemStack.cs')
-rw-r--r--source/game/components/items/ItemStack.cs34
1 files changed, 34 insertions, 0 deletions
diff --git a/source/game/components/items/ItemStack.cs b/source/game/components/items/ItemStack.cs
new file mode 100644
index 0000000..360904b
--- /dev/null
+++ b/source/game/components/items/ItemStack.cs
@@ -0,0 +1,34 @@
+using Celesteia.Resources;
+using Celesteia.Resources.Types;
+
+namespace Celesteia.Game.Components.Items {
+ public class ItemStack {
+ public byte ID;
+ public NamespacedKey Key;
+ public int Amount;
+ public readonly ItemType Type;
+
+ public ItemStack(NamespacedKey key, int amount) {
+ Key = key;
+ Amount = amount;
+
+ Type = ResourceManager.Items.GetResource(key) as ItemType;
+ }
+
+ public ItemStack NewStack() {
+ ItemStack stack = null;
+ if (Amount > Type.MaxStackSize) stack = new ItemStack(Key, Amount - Type.MaxStackSize);
+
+ return stack;
+ }
+
+ public ItemStack Clone() {
+ return new ItemStack(Key, Amount);
+ }
+
+ public override string ToString()
+ {
+ return $"{Amount}x {Type.Name}";
+ }
+ }
+} \ No newline at end of file