예제 #1
0
    public void MoveItem(InventorySlot toMove, InventorySlot destination)
    {
        if (toMove == destination)
        {
            return;
        }

        if (destination.IsEmpty())
        {
            Item temp     = toMove.item;
            int  numTemps = toMove.amount;
            toMove.ClearSlot();

            destination.AddItemToSlot(temp, numTemps);
        }
        else if (destination.item.isStackable && destination.item.itemName.Equals(toMove))
        {
            Item prevItem = toMove.item;
            int  numPrevs = toMove.amount;
            toMove.ClearSlot();

            destination.AddItemToSlot(prevItem, numPrevs);
        }
        else
        {
            Item prevItem = toMove.item;
            int  numPrevs = toMove.amount;

            Item destItem = destination.item;
            int  numDests = destination.amount;

            toMove.ClearSlot();
            destination.ClearSlot();

            destination.AddItemToSlot(prevItem, numPrevs);
            toMove.AddItemToSlot(destItem, numDests);
        }
    }
예제 #2
0
 public bool AddItemToInventory(Item item)
 {
     if (_inventoryItems.Count < _inventoryCapacity)
     {
         InventorySlot slot = _player.PlayerInventoryUI.GetFreeSlot();
         if (slot == null)
         {
             return(false);
         }
         slot.AddItemToSlot(item);
         slot.RightPointerClicked += OnItemUsed;
         _inventoryItems.Add(slot);
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #3
0
 /// <summary>
 /// Add item to the inventory
 /// </summary>
 /// <param name="itemPos">Index to add the item</param>
 /// <param name="item">Item to add</param>
 public virtual void AddItem(int itemPos, Item item, InventorySlot slot)
 {
     inventory[itemPos] = item;
     slot.AddItemToSlot(item);
     onInventoryChange.Invoke();
 }