Esempio n. 1
0
    public void AddItem(IInventoryItem item)
    {
        ItemStack found = FindItem(item);

        if (found != null)
        {
            found.Increment();

            if (itemStacked != null)
            {
                itemStacked(this, new InventoryStackEventArgs(item.itemName, found.Quantity, true));
            }

            item.OnPickUp();
        }
        else if (mItems.Count < SLOTS)
        {
            mItems.Add(new ItemStack(item)); //Add the item to the inventory
            item.OnPickUp();                 //OnPickUp() method is called
            if (itemAdded != null)
            {
                itemAdded(this, new InventoryEventArgs(item)); //ItemAdded event raised and all the subscribers for this event are notified
            }
        }
    }
Esempio n. 2
0
 public void AddItem(IInventoryItem item, float rotZ, bool isSmall)
 {
     items.Add(item);
     item.OnPickUp();
     if (ItemAdded != null)
     {
         ItemAdded(this, new InventoryEventArgs(item, rotZ, isSmall));
     }
 }
Esempio n. 3
0
    private void OnMouseDown()
    {
        IInventoryItem item = this.GetComponent <IInventoryItem>();

        if (item != null)
        {
            inventory.AddItem(item);
            item.OnPickUp();
        }
        //Debug.Log(item);
    }
Esempio n. 4
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));
         *        }
         *    }
         * }
         */
    }
Esempio n. 5
0
        public void OnSelect(Transform selection)
        {
            if (itemList.Count < SLOTS)
            {
                Collider collider = selection.GetComponent <Collider>();
                if (collider.enabled)
                {
                    collider.enabled = false;
                    item             = selection.GetComponent <IInventoryItem>();
                    selection.gameObject.SetActive(false);

                    itemList.Add(item);
                    item.OnPickUp();

                    ItemAdded?.Invoke(this, new InventoryEventHandler(item));
                }
            }
        }
Esempio n. 6
0
    public void AddItem(IInventoryItem item)
    {
        if (Items.Count < SLOTS)
        {
            Collider collider = (item as MonoBehaviour).GetComponent <Collider>();

            if (collider.enabled)
            {
                collider.enabled = false;

                Items.Add(item);

                item.OnPickUp();

                if (ItemAdded != null)
                {
                    ItemAdded(this, new InventoryEventArgs(item));
                }
            }
        }
    }
Esempio n. 7
0
    private void RaycastItem()
    {
        player = FindObjectOfType <Player>();
        RaycastHit hit = CameraManager.GetCameraRaycast(player.GetStats().InteractRange);

        if (hit.transform)
        {
            if (Input.GetButtonDown("Collect"))
            {
                IInventoryItem item = hit.transform.GetComponent <IInventoryItem>();

                IInventoryItem rpg = null;
                for (int i = 0; i < inventory.wSlots.Count; i++)
                {
                    if (inventory.wSlots[i].mItemStack.Count != 0)
                    {
                        rpg = inventory.GetPeekItem(i, "Weapon");
                    }
                    if (rpg != null)
                    {
                        rpg = inventory.GetPeekItem(i, "Weapon");
                        if (rpg.Name == "Bazuka")
                        {
                            break;
                        }
                        else
                        {
                            rpg = null;
                        }
                    }
                }

                if (hit.transform.CompareTag("Ammo"))
                {
                    item.Collected = true;
                    SaveManager.instance.collected[item.Id] = true;

                    if (hit.transform.GetComponent <IInventoryItem>().Name == "Ammo 9mm")
                    {
                        WeaponManager.instance.GetComponent <Pistol>().CurrentSpare += item.Amount;
                    }
                    if (hit.transform.GetComponent <IInventoryItem>().Name == "Ammo Dart")
                    {
                        WeaponManager.instance.GetComponent <Sedat>().CurrentSpare += item.Amount;
                    }
                    if (hit.transform.GetComponent <IInventoryItem>().Name == "Ammo Shotgun")
                    {
                        WeaponManager.instance.GetComponent <Shotgun>().CurrentSpare += item.Amount;
                    }


                    if (SaveManager.instance.currentWeapon == WeaponEnum.Pistol)
                    {
                        UIManager.instance.UpdateAmmo(WeaponManager.instance.GetComponent <Pistol>().CurrentAmmo, WeaponManager.instance.GetComponent <Pistol>().CurrentSpare);
                    }
                    else if (SaveManager.instance.currentWeapon == WeaponEnum.Sedat)
                    {
                        UIManager.instance.UpdateAmmo(WeaponManager.instance.GetComponent <Sedat>().CurrentAmmo, WeaponManager.instance.GetComponent <Sedat>().CurrentSpare);
                    }
                    else if (SaveManager.instance.currentWeapon == WeaponEnum.Shotgun)
                    {
                        UIManager.instance.UpdateAmmo(WeaponManager.instance.GetComponent <Shotgun>().CurrentAmmo, WeaponManager.instance.GetComponent <Shotgun>().CurrentSpare);
                    }
                    else if (SaveManager.instance.currentWeapon == WeaponEnum.Bazuka)
                    {
                        UIManager.instance.UpdateAmmo(WeaponManager.instance.GetComponent <Bazuka>().CurrentAmmo, WeaponManager.instance.GetComponent <Bazuka>().CurrentSpare);
                    }
                    item.OnPickUp();
                }
                else if (hit.transform.CompareTag("Item"))
                {
                    item.Collected = true;
                    SaveManager.instance.collected[item.Id] = true;
                    inventory.AddItem(item, "Item");
                }
                else if (hit.transform.CompareTag("Weapon") && rpg != null)
                {
                    item.Collected = true;
                    SaveManager.instance.collected[item.Id] = true;
                    WeaponManager.instance.GetComponent <Bazuka>().CurrentSpare += 1;
                    if (SaveManager.instance.currentWeapon == WeaponEnum.Bazuka)
                    {
                        UIManager.instance.UpdateAmmo(WeaponManager.instance.GetComponent <Bazuka>().CurrentAmmo, WeaponManager.instance.GetComponent <Bazuka>().CurrentSpare);
                    }
                    item.OnPickUp();
                }
                else if (hit.transform.CompareTag("Weapon"))
                {
                    item.Collected = true;
                    SaveManager.instance.collected[item.Id] = true;
                    inventory.AddItem(item, "Weapon");
                }
            }
        }
    }