InventoryItemSlot

 avatar
user_3183455
csharp
10 days ago
2.2 kB
1
Indexable
Never
using System;
 
namespace CuongMono.Item.Inventory
{
    [Serializable]
    public class InventoryItemSlot : IItemSlot<InventoryItem>
    {
        public Item item;
        public InventoryItem Item
        {
            get => this.item as InventoryItem;
            set => this.item = value;
        }
        public int quanity;
        public int Quanity
        {
            get => this.quanity;
            set
            {
                this.quanity = value;
                this.CheckQuanityToReset();
            }
        }
        public int duranceLeft;
        public int DuranceLeft
        {
            get => this.duranceLeft;
            set
            {
                this.duranceLeft = value;
                if (this.duranceLeft > this.Item?.MaxDurance) this.duranceLeft = this.item.MaxDurance;
                this.CheckDuranceLeftToReset();
            }
        }
        public InventoryItemSlot() { }
 
        public InventoryItemSlot(InventoryItem item, int quanity)
        {
            this.item = item;
            this.quanity = quanity;
            this.duranceLeft = this.item.MaxDurance;
        }
 
        public InventoryItemSlot(InventoryItem item, int quanity, int duranceLeft)
        {
            this.item = item;
            this.quanity = quanity;
            this.duranceLeft = duranceLeft;
        }
 
        public void CheckQuanityToReset()
        {
            if(this.quanity <= 0) this.ResetSlot();
        }
        public void CheckDuranceLeftToReset()
        {
            if(this.duranceLeft <= 0) this.ResetSlot();
        }
 
        public void ResetSlot()
        {
            this.item = null;
            this.quanity = 0;
            this.duranceLeft = 0;
        }
 
        public int GetRemainingSlot() => this.item.MaxStack - this.quanity;
 
        public int GetLostDurance() => this.item.MaxStack - this.duranceLeft;
 
        public IItemSlot<InventoryItem> Clone()
        {
            return new InventoryItemSlot(this.item as InventoryItem, this.quanity, this.duranceLeft);
        }
    }
}
Leave a Comment