public bool TryAddItem(Item item)
        {
            ItemBatch queriedBatch = itemBatches.FirstOrDefault(
                b =>
                b.item == item &&
                b.fillLevel <= maxBatchSize - item.stackWeight);
            IItemInstance itemInstance = default;

            if (queriedBatch != default(ItemBatch))
            {
                itemInstance = queriedBatch.AddNew(1)[0];
                ItemAdded?.Invoke(itemInstance);
                return(true);
            }
            else
            {
                if (!slotToItemBatch.Any(s => s.Value == null))
                {
                    return(false);
                }
                itemInstance = ItemManager.CreateItemInstance(item, null);
                CreateNewItemBatch(item, itemInstance);
                UpdateEmptyBatches();
                ItemAdded?.Invoke(itemInstance);
                return(true);
            }
        }
        public bool TryAddItemInstance(IItemInstance itemInstance)
        {
            ItemBatch queriedBatch = itemBatches.
                                     FirstOrDefault(
                b =>
                b.item == itemInstance.data &&
                b.fillLevel <= maxBatchSize - b.item.stackWeight);

            if (queriedBatch != default(ItemBatch))
            {
                if (queriedBatch.TryAdd(itemInstance))
                {
                    ItemAdded?.Invoke(itemInstance);
                    return(true);
                }
                return(false);
            }
            else
            {
                if (!slotToItemBatch.Any(s => s.Value == null))
                {
                    return(false);
                }
                CreateNewItemBatch(itemInstance.data, itemInstance);
                ItemAdded?.Invoke(itemInstance);
                return(true);
            }
        }
Пример #3
0
 public void UpdateItemSlot(ItemBatch batch)
 {
     if (batch == null)
     {
         image.sprite = null;
         stackSizeText.gameObject.SetActive(false);
         image.color = new Color(1, 1, 1, 0);
     }
     else
     {
         image.sprite = batch.item.Icon;
         image.color  = new Color(1, 1, 1, 1);
         stackSizeText.gameObject.SetActive(true);
         stackSizeText.text = batch.count.ToString();
     }
     updated?.Invoke(this);
 }
        public bool CanAddItem(Item item)
        {
            ItemBatch queriedBatch = itemBatches.FirstOrDefault(b => b.item == item && b.count + item.stackWeight <= maxBatchSize);

            return(queriedBatch != default(ItemBatch) || slotToItemBatch.Any(s => s.Value == null));
        }