aboutsummaryrefslogtreecommitdiff
path: root/source/game/components/items/ItemStack.cs
blob: 360904baccff10d1d7ac900df14f205887d13ab5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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}";
        }
    }
}