Ejemplo n.º 1
0
    public void AddToInventory(Item item, int amount)
    {
        for (int i = 0; i < amount; i++)
        {
            InventorySlot slot = GetValidSlotForItem(item);

            if (GetItemFromItemStorage(item).ThisItem != item)
            {
                StoredItem storedItem = new StoredItem(item);
                _inventoryItems.Add(storedItem);
            }
            else
            {
                GetItemFromItemStorage(item).CurrentAmount++;
            }

            if (slot == null)
            {
                slot = GetEmptySlot();
                if (slot == null)
                {
                    return;
                }
            }

            slot.AddItem(item);
        }
    }
Ejemplo n.º 2
0
    public override void Interact()
    {
        if (dirtSlot != null)
        {
            // TODO: Do it when you put items in the machine slot
            if (dirtSlot.ItemGO != null)
            {
                dirtCount = dirtSlot.Item.itemCount;

                dirtPercentage += 0.5f;

                if (dirtPercentage >= 100)
                {
                    dirtPercentage = 0;
                    dirtCount--;
                    dirtSlot.UpdateItemCount(-1);
                    sandSlot.AddItem(TileType.Sand, 1);
                }

                foreach (MachineBlock block in machineBlocks)
                {
                    WaterTank _waterTank = block.GetComponent <WaterTank>();
                    if (_waterTank != null)
                    {
                        if (_waterTank.AddWater(0.1f))
                        {
                            return;
                        }
                    }
                }
                Debug.LogError("No water tank found!");
            }
        }
    }
Ejemplo n.º 3
0
 private void PopulateStoreList()
 {
     for (int i = 0; i < merchant.listItems.Count; i++)
     {
         InventorySlot inventorySlot = Instantiate(inventorySlotPrefab, merchantUI.transform).GetComponent <InventorySlot>();
         inventorySlot.AddItem(merchant.listItems[i]);
         inventorySlot.ShowIcon(true);
         menuInGame.Add(inventorySlot.GetComponentInChildren <Button>());
         slots.Add(inventorySlot);
     }
 }
Ejemplo n.º 4
0
 protected override void UpdateUI()
 {
     if (inventory.items.Count > 0)
     {
         invSlot.AddItem(inventory.items[0]);
     }
     else
     {
         invSlot.ClearSlot();
     }
 }
Ejemplo n.º 5
0
    public void AddItem(Food food)
    {
        foreach (GameObject slot in inventorySlots)
        {
            InventorySlot inventorySlot = slot.GetComponent <InventorySlot>();

            if (!inventorySlot.HasItem())
            {
                inventorySlot.AddItem(food);
                return;
            }
        }

        Debug.Log("Inventory is full.");
    }
Ejemplo n.º 6
0
    public void AddItem(IInventoryItem item, string type)
    {
        InventorySlot freeSlot = FindStackkableSlot(item, type);

        if (freeSlot == null)
        {
            freeSlot = FindNextEmptySlot(type);
        }
        if (freeSlot != null)
        {
            freeSlot.AddItem(item);
            item.OnPickUp();

            if (type == "Item")
            {
                if (ItemAdded != null)
                {
                    ItemAdded(instance, new InventoryEventArgs(item));
                    Debug.Log("Added Item : " + item.Name);
                }
            }
            else if (type == "Weapon")
            {
                if (WeaponAdded != null)
                {
                    WeaponAdded(instance, new InventoryEventArgs(item));
                    Debug.Log("Added Weapon : " + item.Name);
                }
            }
        }

        /*
         * if(mItems.Count < SLOTS)
         * {
         *    Collider collider = (item as MonoBehaviour).GetComponent<Collider>();
         *    if(collider.enabled)
         *    {
         *        collider.enabled = false;
         *        mItems.Add(item);
         *        item.OnPickup();
         *        if(ItemAdded != null)
         *        {
         *            ItemAdded(this, new InventoryEventArgs(item));
         *        }
         *    }
         * }
         */
    }
Ejemplo n.º 7
0
    void UpdateUI()
    {
        foreach (Transform child in transform)
        {
            Destroy(child.gameObject);
        }

        for (int i = 0; i < inventory.veggies.Count; i++)
        {
            GameObject prefab = Instantiate(slotPrefab);
            prefab.transform.SetParent(transform);

            InventorySlot slot = prefab.GetComponent <InventorySlot>();
            slot.AddItem(inventory.veggies[i]);
        }
    }