updateItemList() 공개 메소드

public updateItemList ( ) : void
리턴 void
예제 #1
0
 // Update is called once per frame
 void Update()
 {
     if (_inventory != null && UserControl.PickupItem)
     {
         float distance = Vector2.Distance(new Vector2(this.gameObject.transform.position.x, this.gameObject.transform.position.y), new Vector2(_player.transform.position.x, _player.transform.position.y));
         print("distance: " + distance);
         if (distance <= 1.3)
         {
             sceneManager.GetComponent <MySceneManager>().removeFromGearList(this.gameObject);
             bool check = _inventory.checkIfItemAllreadyExist(item.itemID, item.itemValue);
             if (check)
             {
                 Destroy(this.gameObject);
             }
             else if (_inventory.ItemsInInventory.Count < (_inventory.width * _inventory.height))
             {
                 _inventory.addItemToInventory(item.itemID, item.itemValue);
                 _inventory.updateItemList();
                 _inventory.stackableSettings();
                 Destroy(this.gameObject);
             }
         }
     }
     if (_inventory != null && UserControl.GetGearsBack)
     {
         addItemToInv(item.itemID, item.itemValue);
     }
 }
예제 #2
0
 public void dropItem_re(Int32 itemIndex)
 {
     if (itemInventory == null)
     {
         itemInventory = this.transform.GetComponent <PlayerInventory>().inventory.GetComponent <Inventory>();
     }
     if (itemInventory != null)
     {
         itemInventory.deleteItemByIndex(itemIndex);
         itemInventory.updateItemList();
         itemInventory.stackableSettings();
         tooltip.deactivateTooltip();
     }
 }
예제 #3
0
    public void OnPointerDown(PointerEventData data)                    //splitting the item now
    {
        inv = transform.parent.parent.parent.GetComponent <Inventory>();
        if (transform.parent.parent.parent.GetComponent <Hotbar>() == null && data.button == PointerEventData.InputButton.Left && pressingButtonToSplit && inv.stackable && (inv.ItemsInInventory.Count < (inv.height * inv.width))) //if you press leftclick and and keycode
        {
            ItemOnObject itemOnObject = GetComponent <ItemOnObject>();                                                                                                                                                               //we take the ItemOnObject script of the item in the slot

            if (itemOnObject.item.itemValue > 1)                                                                                                                                                                                     //we split the item only when we have more than 1 in the stack
            {
                int splitPart = itemOnObject.item.itemValue;                                                                                                                                                                         //we take the value and store it in there
                itemOnObject.item.itemValue = (int)itemOnObject.item.itemValue / 2;                                                                                                                                                  //calculate the new value for the splitted item
                splitPart = splitPart - itemOnObject.item.itemValue;                                                                                                                                                                 //take the different

                inv.addItemToInventory(itemOnObject.item.itemID, splitPart);                                                                                                                                                         //and add a new item to the inventory
                inv.stackableSettings();

                if (GetComponent <ConsumeItem>().duplication != null)
                {
                    GameObject dup = GetComponent <ConsumeItem>().duplication;
                    dup.GetComponent <ItemOnObject>().item.itemValue = itemOnObject.item.itemValue;
                    dup.GetComponent <SplitItem>().inv.stackableSettings();
                }
                inv.updateItemList();
            }
        }
    }
예제 #4
0
    public void equipItemRequest_re(ITEM_INFO itemInfo, ITEM_INFO equipItemInfo)
    {
        Int32  itemIndex      = itemInfo.itemIndex;
        Int32  equipItemIndex = equipItemInfo.itemIndex;
        UInt64 itemUUid       = itemInfo.UUID;
        UInt64 equipItemUUid  = equipItemInfo.UUID;

        if (itemUUid > 0)
        {
            itemInventory.addItemToInventory(itemInfo.itemId, itemInfo.UUID, 1, itemInfo.itemIndex);
        }
        else
        {
            itemInventory.deleteItemByIndex(itemIndex);
        }

        if (equipItemUUid > 0)
        {
            equipInventory.addItemToInventory(equipItemInfo.itemId, equipItemInfo.UUID, 1, equipItemInfo.itemIndex);
        }
        else
        {
            equipInventory.deleteItemByIndex(equipItemIndex);
        }

        itemInventory.updateItemList();
        itemInventory.stackableSettings();
        equipInventory.updateItemList();
        equipInventory.stackableSettings();
    }
예제 #5
0
    public void equipItemRequest_re(Dictionary <string, object> itemInfo, Dictionary <string, object> equipItemInfo)
    {
        Int32  itemIndex      = (Int32)itemInfo["itemIndex"];
        Int32  equipItemIndex = (Int32)equipItemInfo["itemIndex"];
        UInt64 itemUUid       = (UInt64)itemInfo["UUID"];
        UInt64 equipItemUUid  = (UInt64)equipItemInfo["UUID"];

        if (itemUUid > 0)
        {
            itemInventory.addItemToInventory((Int32)itemInfo["itemId"], (UInt64)itemInfo["UUID"], 1, (Int32)itemInfo["itemIndex"]);
        }
        else
        {
            itemInventory.deleteItemByIndex(itemIndex);
        }

        if (equipItemUUid > 0)
        {
            equipInventory.addItemToInventory((Int32)equipItemInfo["itemId"], (UInt64)equipItemInfo["UUID"], 1, (Int32)equipItemInfo["itemIndex"]);
        }
        else
        {
            equipInventory.deleteItemByIndex(equipItemIndex);
        }

        itemInventory.updateItemList();
        itemInventory.stackableSettings();
        equipInventory.updateItemList();
        equipInventory.stackableSettings();
    }
예제 #6
0
    // Update is called once per frame
    void Update()
    {
        if (_inventory != null && Input.GetKeyDown(KeyCode.E))
        {
            float distance = Vector3.Distance(this.gameObject.transform.position, _player.transform.position);

            if (distance <= 3)
            {
                if (playerIO.isNetwork)
                {
                    menuManager.Debuglog("Собранно " + item.itemName + " колличество " + item.itemValue);
                    //MenuManager.instance.Debuglog();
                    GameObject.Find("NetworkManager").GetComponent <NetworkLayerClient>().HarwestWood(item.itemID, item.itemValue);
                    Destroy(this.gameObject);
                }
                else
                {
                    Debug.Log("Собранно " + item.itemName + " колличество " + item.itemValue);
                    bool check = _inventory.checkIfItemAllreadyExist(item.itemID, item.itemValue);
                    if (check)
                    {
                        Destroy(this.gameObject);
                    }
                    else if (_inventory.ItemsInInventory.Count < (_inventory.width * _inventory.height))
                    {
                        _inventory.addItemToInventory(item.itemID, item.itemValue);
                        _inventory.updateItemList();
                        _inventory.stackableSettings();
                        Destroy(this.gameObject);
                    }
                }
            }
        }
    }
예제 #7
0
    private bool pressingButtonToSplit; //bool for pressing a item to split it

    #endregion Fields

    #region Methods

    //splitting the item now
    public void OnPointerDown(PointerEventData data)
    {
        inv = transform.parent.parent.parent.GetComponent<Inventory>();
        if (transform.parent.parent.parent.GetComponent<Hotbar>() == null && data.button == PointerEventData.InputButton.Left && pressingButtonToSplit && inv.stackable && (inv.ItemsInInventory.Count < (inv.height * inv.width))) //if you press leftclick and and keycode
        {
            ItemOnObject itemOnObject = GetComponent<ItemOnObject>();                                                   //we take the ItemOnObject script of the item in the slot

            if (itemOnObject.item.itemValue > 1)                                                                         //we split the item only when we have more than 1 in the stack
            {
                int splitPart = itemOnObject.item.itemValue;                                                           //we take the value and store it in there
                itemOnObject.item.itemValue = (int)itemOnObject.item.itemValue / 2;                                     //calculate the new value for the splitted item
                splitPart = splitPart - itemOnObject.item.itemValue;                                                   //take the different

                inv.addItemToInventory(itemOnObject.item.itemID, splitPart);                                            //and add a new item to the inventory
                inv.stackableSettings();

                if (GetComponent<ConsumeItem>().duplication != null)
                {
                    GameObject dup = GetComponent<ConsumeItem>().duplication;
                    dup.GetComponent<ItemOnObject>().item.itemValue = itemOnObject.item.itemValue;
                    dup.GetComponent<SplitItem>().inv.stackableSettings();
                }
                inv.updateItemList();

            }
        }
    }
예제 #8
0
 // Update is called once per frame
 void Update()
 {
     if (_inventory != null && Input.GetKeyDown(KeyCode.E))
     {
         RaycastHit hit;
         if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, 3f))
         {
             if (!hit.transform.gameObject.GetComponent <PickUpItem>())
             {
                 return;
             }
             bool check = _inventory.checkIfItemAllreadyExist(item.itemID, item.itemValue);
             if (check)
             {
                 Destroy(this.gameObject);
             }
             else if (_inventory.ItemsInInventory.Count < (_inventory.width * _inventory.height))
             {
                 _inventory.addItemToInventory(item.itemID, item.itemValue);
                 _inventory.updateItemList();
                 _inventory.stackableSettings();
                 Destroy(this.gameObject);
             }
         }
     }
 }
예제 #9
0
    // Update is called once per frame
    void Update()
    {
        Vector3 newPos = this.gameObject.transform.position;
        // characPos = center of the player;
        Vector3 characPos = _player.transform.position;

        characPos.y += _player.transform.localScale.y / 2;
        float distance = Vector3.Distance(this.gameObject.transform.position, characPos);

        speedMultiplier = distance * 0.05f;

        if (distance <= 1)
        {
            pi.brokenItemID = this.gameObject.GetComponent <PickUpItem>().item.itemID;
            if (!pi.FullInventory())
            {
                // moving the item to the player
                if (newPos.x - characPos.x < 0)
                {
                    newPos.x += speedMultiplier;
                }
                else if (newPos.x - characPos.x > 0)
                {
                    newPos.x -= speedMultiplier;
                }

                if (newPos.y - characPos.y < 0)
                {
                    newPos.y += speedMultiplier;
                }
                else if (newPos.y - characPos.y > 0)
                {
                    newPos.y -= speedMultiplier;
                }
                this.gameObject.transform.position = newPos;

                // picking up the item
                if (_inventory != null && Mathf.Abs(this.gameObject.transform.position.x - characPos.x) <= 0.3f &&
                    Mathf.Abs(this.gameObject.transform.position.y - characPos.y) <= 0.3f * (_player.GetComponent <CapsuleCollider2D>().offset.y / _player.GetComponent <CapsuleCollider2D>().offset.x))
                {
                    bool check = _inventory.checkIfItemAllreadyExist(item.itemID, item.itemValue);
                    if (check)
                    {
                        Destroy(this.gameObject);
                    }
                    else if (_inventory.ItemsInInventory.Count < (_inventory.width * _inventory.height))
                    {
                        _inventory.addItemToInventory(item.itemID, item.itemValue);
                        _inventory.updateItemList();
                        _inventory.stackableSettings();
                        Destroy(this.gameObject);
                    }
                    if (!pi.currentLevel.Equals(pi.maxLevel))
                    {
                        pi.GainExp(item.expToGain);
                    }
                }
            }
        }
    }
예제 #10
0
    public void OnPointerDown(PointerEventData data)
    {
        inv = transform.parent.parent.parent.GetComponent<Inventory>();
        if (transform.parent.parent.parent.GetComponent<Hotbar>() == null && data.button == PointerEventData.InputButton.Left && pressingButtonToSplit && inv.stackable && (inv.ItemsInInventory.Count < (inv.height * inv.width)))
        {
            ItemOnObject itemOnObject = GetComponent<ItemOnObject>();

            if (itemOnObject.item.itemValue > 1)
            {
                int splitPart = itemOnObject.item.itemValue;
                itemOnObject.item.itemValue = (int)itemOnObject.item.itemValue / 2;
                splitPart = splitPart - itemOnObject.item.itemValue;

                inv.addItemToInventory(itemOnObject.item.itemID, splitPart);
                inv.stackableSettings();

                if (GetComponent<ConsumeItem>().duplication != null)
                {
                    GameObject dup = GetComponent<ConsumeItem>().duplication;
                    dup.GetComponent<ItemOnObject>().item.itemValue = itemOnObject.item.itemValue;
                    dup.GetComponent<SplitItem>().inv.stackableSettings();
                }
                inv.updateItemList();

            }
        }
    }
예제 #11
0
    public override void Interact()
    {
        base.Interact();
        bool check = _inventory.checkIfItemAllreadyExist(item.itemID, item.itemValue);

        if (check)
        {
            Destroy(this.gameObject);
        }
        else if (_inventory.ItemsInInventory.Count < (_inventory.width * _inventory.height))
        {
            _inventory.addItemToInventory(item.itemID, item.itemValue);
            _inventory.updateIconSize();
            _inventory.updateItemList();
            _inventory.stackableSettings();
            Destroy(this.gameObject);
            GameManager.NotifyPickedUpItem(item);
        }
    }
예제 #12
0
    public void onReqItemList(Dictionary <UInt64, ITEM_INFO> itemList, Dictionary <UInt64, ITEM_INFO> equipItemDict)
    {
        UnityEngine.GameObject _player = UnityEngine.GameObject.FindGameObjectWithTag("Player");
        Inventory _inventory           = null;
        Inventory _equipInventory      = null;

        if (_player != null)
        {
            _inventory      = _player.GetComponent <PlayerInventory>().inventory.GetComponent <Inventory>();
            _equipInventory = _player.GetComponent <PlayerInventory>().characterSystem.GetComponent <Inventory>();
        }
        if (_inventory != null)
        {
            foreach (UInt64 dbid in itemList.Keys)
            {
                ITEM_INFO info  = itemList[dbid];
                Int32     id    = info.itemId;
                UInt64    uid   = info.UUID;
                Int32     index = info.itemIndex;
                UInt32    count = info.itemCount;
                _inventory.addItemToInventory(id, uid, (int)count, index);
                _inventory.updateItemList();
                _inventory.stackableSettings();
            }
        }
        if (_equipInventory != null)
        {
            foreach (UInt64 dbid in equipItemDict.Keys)
            {
                ITEM_INFO info  = equipItemDict[dbid];
                Int32     id    = info.itemId;
                UInt64    uid   = info.UUID;
                Int32     index = info.itemIndex;
                _equipInventory.addItemToInventory(id, uid, 1, index);
                _equipInventory.updateItemList();
                _equipInventory.stackableSettings();
            }
        }
    }
예제 #13
0
    // Update is called once per frame
    void Update()
    {
        if (_inventory != null && Input.GetKeyDown(KeyCode.E))
        {
            float distance = Vector3.Distance(this.gameObject.transform.position, _player.transform.position);

            if (distance <= 3)
            {
                bool check = _inventory.checkIfItemAllreadyExist(item.itemID, item.itemValue);
                if (check)
                {
                    Destroy(this.gameObject);
                }
                else if (_inventory.ItemsInInventory.Count < (_inventory.width * _inventory.height))
                {
                    _inventory.addItemToInventory(item.itemID, item.itemValue);
                    _inventory.updateItemList();
                    _inventory.stackableSettings();
                    Destroy(this.gameObject);
                }
            }
        }
    }
예제 #14
0
    public void consumeIt()
    {
        Inventory inventory = transform.parent.parent.parent.GetComponent <Inventory>();

        bool gearable = false;

        if (GameObject.FindGameObjectWithTag("EquipmentSystem") != null)
        {
            eS = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerInventory>().characterSystem.GetComponent <EquipmentSystem>();
        }

        if (eS != null)
        {
            itemTypeOfSlot = eS.itemTypeOfSlots;
        }

        Item itemFromDup = null;

        if (duplication != null)
        {
            itemFromDup = duplication.GetComponent <ItemOnObject>().item;
        }

        bool stop = false;

        if (eS != null)
        {
            for (int i = 0; i < eS.slotsInTotal; i++)
            {
                if (itemTypeOfSlot[i].Equals(item.itemType))
                {
                    if (eS.transform.GetChild(1).GetChild(i).childCount == 0)
                    {
                        stop = true;
                        this.gameObject.transform.SetParent(eS.transform.GetChild(1).GetChild(i));
                        this.gameObject.GetComponent <RectTransform>().localPosition = Vector3.zero;
                        eS.gameObject.GetComponent <Inventory>().updateItemList();
                        inventory.updateItemList();
                        inventory.EquiptItem(item);
                        gearable = true;
                        if (duplication != null)
                        {
                            Destroy(duplication.gameObject);
                        }
                        break;
                    }
                }
            }

            if (!stop)
            {
                for (int i = 0; i < eS.slotsInTotal; i++)
                {
                    if (itemTypeOfSlot[i].Equals(item.itemType))
                    {
                        if (eS.transform.GetChild(1).GetChild(i).childCount != 0)
                        {
                            GameObject otherItemFromCharacterSystem = eS.transform.GetChild(1).GetChild(i).GetChild(0).gameObject;
                            Item       otherSlotItem = otherItemFromCharacterSystem.GetComponent <ItemOnObject>().item;
                            if (item.itemType == ItemType.UFPS_Weapon)
                            {
                                inventory.UnEquipItem1(otherItemFromCharacterSystem.GetComponent <ItemOnObject>().item);
                                inventory.EquiptItem(item);
                            }
                            else
                            {
                                inventory.EquiptItem(item);
                                if (item.itemType != ItemType.Backpack)
                                {
                                    inventory.UnEquipItem1(otherItemFromCharacterSystem.GetComponent <ItemOnObject>().item);
                                }
                            }
                            if (this == null)
                            {
                                GameObject dropItem = (GameObject)Instantiate(otherSlotItem.itemModel);
                                dropItem.AddComponent <PickUpItem>();
                                dropItem.GetComponent <PickUpItem>().item = otherSlotItem;
                                dropItem.transform.localPosition          = GameObject.FindGameObjectWithTag("Player").transform.localPosition;
                                inventory.OnUpdateItemList();
                            }
                            else
                            {
                                otherItemFromCharacterSystem.transform.SetParent(this.transform.parent);
                                otherItemFromCharacterSystem.GetComponent <RectTransform>().localPosition = Vector3.zero;
                                if (this.gameObject.transform.parent.parent.parent.GetComponent <Hotbar>() != null)
                                {
                                    createDuplication(otherItemFromCharacterSystem);
                                }

                                this.gameObject.transform.SetParent(eS.transform.GetChild(1).GetChild(i));
                                this.gameObject.GetComponent <RectTransform>().localPosition = Vector3.zero;
                            }

                            gearable = true;
                            if (duplication != null)
                            {
                                Destroy(duplication.gameObject);
                            }
                            eS.gameObject.GetComponent <Inventory>().updateItemList();
                            inventory.OnUpdateItemList();
                            break;
                        }
                    }
                }
            }
        }
        if (!gearable && item.itemType != ItemType.UFPS_Ammo && item.itemType != ItemType.UFPS_Grenade)
        {
            if (duplication != null)
            {
                itemFromDup = duplication.GetComponent <ItemOnObject>().item;
            }

            inventory.ConsumeItem(item);

            item.itemValue--;
            if (itemFromDup != null)
            {
                duplication.GetComponent <ItemOnObject>().item.itemValue--;
                if (itemFromDup.itemValue <= 0)
                {
                    if (tooltip != null)
                    {
                        tooltip.deactivateTooltip();
                    }
                    inventory.deleteItemFromInventory(item);
                    Destroy(duplication.gameObject);
                }
            }
            if (item.itemValue <= 0)
            {
                if (tooltip != null)
                {
                    tooltip.deactivateTooltip();
                }
                inventory.deleteItemFromInventory(item);
                Destroy(this.gameObject);
            }
        }
    }
예제 #15
0
    public void OnPointerDown(PointerEventData data)
    {
        if (this.gameObject.transform.parent.parent.parent.GetComponent <EquipmentSystem>() == null)
        {
            bool      gearable  = false;
            Inventory inventory = transform.parent.parent.parent.GetComponent <Inventory>();

            if (eS != null)
            {
                itemTypeOfSlot = eS.itemTypeOfSlots;
            }

            if (data.button == PointerEventData.InputButton.Right)
            {
                //item from craft system to inventory
                if (transform.parent.GetComponent <CraftResultSlot>() != null)
                {
                    bool check = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerInventory>().inventory.GetComponent <Inventory>().checkIfItemAllreadyExist(item.itemID, item.itemValue);

                    if (!check)
                    {
                        GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerInventory>().inventory.GetComponent <Inventory>().addItemToInventory(item.itemID, item.itemValue);
                        GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerInventory>().inventory.GetComponent <Inventory>().stackableSettings();
                    }
                    CraftSystem cS = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerInventory>().craftSystem.GetComponent <CraftSystem>();
                    cS.deleteItems(item);
                    CraftResultSlot result = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerInventory>().craftSystem.transform.GetChild(3).GetComponent <CraftResultSlot>();
                    result.temp = 0;
                    //tooltip.deactivateTooltip();
                    gearable = true;
                    GameObject.FindGameObjectWithTag("MainInventory").GetComponent <Inventory>().updateItemList();
                }
                else
                {
                    bool stop = false;
                    if (eS != null)
                    {
                        for (int i = 0; i < eS.slotsInTotal; i++)
                        {
                            if (itemTypeOfSlot[i].Equals(item.itemType))
                            {
                                if (eS.transform.GetChild(1).GetChild(i).childCount == 0)
                                {
                                    stop = true;
                                    if (eS.transform.GetChild(1).GetChild(i).parent.parent.GetComponent <EquipmentSystem>() != null && this.gameObject.transform.parent.parent.parent.GetComponent <EquipmentSystem>() != null)
                                    {
                                    }
                                    else
                                    {
                                        inventory.EquiptItem(item);
                                    }

                                    this.gameObject.transform.SetParent(eS.transform.GetChild(1).GetChild(i));
                                    this.gameObject.GetComponent <RectTransform>().localPosition = Vector3.zero;
                                    eS.gameObject.GetComponent <Inventory>().updateItemList();
                                    inventory.updateItemList();
                                    gearable = true;
                                    if (duplication != null)
                                    {
                                        Destroy(duplication.gameObject);
                                    }
                                    break;
                                }
                            }
                        }


                        if (!stop)
                        {
                            for (int i = 0; i < eS.slotsInTotal; i++)
                            {
                                if (itemTypeOfSlot[i].Equals(item.itemType))
                                {
                                    if (eS.transform.GetChild(1).GetChild(i).childCount != 0)
                                    {
                                        GameObject otherItemFromCharacterSystem = eS.transform.GetChild(1).GetChild(i).GetChild(0).gameObject;
                                        Item       otherSlotItem = otherItemFromCharacterSystem.GetComponent <ItemOnObject>().item;
                                        if (item.itemType == ItemType.UFPS_Weapon)
                                        {
                                            inventory.UnEquipItem1(otherItemFromCharacterSystem.GetComponent <ItemOnObject>().item);
                                            inventory.EquiptItem(item);
                                        }
                                        else
                                        {
                                            inventory.EquiptItem(item);
                                            if (item.itemType != ItemType.Backpack)
                                            {
                                                inventory.UnEquipItem1(otherItemFromCharacterSystem.GetComponent <ItemOnObject>().item);
                                            }
                                        }
                                        if (this == null)
                                        {
                                            GameObject dropItem = (GameObject)Instantiate(otherSlotItem.itemModel);
                                            dropItem.AddComponent <PickUpItem>();
                                            dropItem.GetComponent <PickUpItem>().item = otherSlotItem;
                                            dropItem.transform.localPosition          = GameObject.FindGameObjectWithTag("Player").transform.localPosition;
                                            inventory.OnUpdateItemList();
                                        }
                                        else
                                        {
                                            otherItemFromCharacterSystem.transform.SetParent(this.transform.parent);
                                            otherItemFromCharacterSystem.GetComponent <RectTransform>().localPosition = Vector3.zero;
                                            if (this.gameObject.transform.parent.parent.parent.GetComponent <Hotbar>() != null)
                                            {
                                                createDuplication(otherItemFromCharacterSystem);
                                            }

                                            this.gameObject.transform.SetParent(eS.transform.GetChild(1).GetChild(i));
                                            this.gameObject.GetComponent <RectTransform>().localPosition = Vector3.zero;
                                        }

                                        gearable = true;
                                        if (duplication != null)
                                        {
                                            Destroy(duplication.gameObject);
                                        }
                                        eS.gameObject.GetComponent <Inventory>().updateItemList();
                                        inventory.OnUpdateItemList();
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                if (!gearable && item.itemType != ItemType.UFPS_Ammo && item.itemType != ItemType.UFPS_Grenade)
                {
                    Item itemFromDup = null;
                    if (duplication != null)
                    {
                        itemFromDup = duplication.GetComponent <ItemOnObject>().item;
                    }

                    inventory.ConsumeItem(item);

                    item.itemValue--;
                    if (itemFromDup != null)
                    {
                        duplication.GetComponent <ItemOnObject>().item.itemValue--;
                        if (itemFromDup.itemValue <= 0)
                        {
                            if (tooltip != null)
                            {
                                tooltip.deactivateTooltip();
                            }
                            inventory.deleteItemFromInventory(item);
                            Destroy(duplication.gameObject);
                        }
                    }
                    if (item.itemValue <= 0)
                    {
                        if (tooltip != null)
                        {
                            tooltip.deactivateTooltip();
                        }
                        inventory.deleteItemFromInventory(item);
                        Destroy(this.gameObject);
                    }
                }
            }
        }
    }
예제 #16
0
    public void OnPointerDown(PointerEventData data)
    {
        if (this.gameObject.transform.parent.parent.parent.GetComponent <EquipmentSystem>() == null)
        {
            bool      gearable  = false;
            Inventory inventory = transform.parent.parent.parent.GetComponent <Inventory>();

            if (eS != null)
            {
                itemTypeOfSlot = eS.itemTypeOfSlots;
            }

            if (data.button == PointerEventData.InputButton.Left && DoubleClick() && item.itemType == ItemType.Consumable)     // if we doubleClick with the mouse's left button
            {
                //item from craft system to inventory
                if (transform.parent.GetComponent <CraftResultSlot>() != null)
                {
                    bool check = inv.GetComponent <Inventory>().checkIfItemAllreadyExist(item.itemID, item.itemValue);

                    if (!check)
                    {
                        for (int j = 0; j < inv.transform.GetChild(1).transform.childCount; j++)
                        {
                            if (inv.transform.GetChild(1).transform.GetChild(j).childCount != 0)
                            {
                                //if the item we're crafting has a slot filled in the main inventory and there are some places
                                if (item.itemID.Equals(inv.transform.GetChild(1).transform.GetChild(j).GetChild(0).GetComponent <ItemOnObject>().item.itemID) && inv.transform.GetChild(1).transform.GetChild(j).GetChild(0).GetComponent <ItemOnObject>().item.itemValue != inv.transform.GetChild(1).transform.GetChild(j).GetChild(0).GetComponent <ItemOnObject>().item.maxStack)
                                {
                                    //filling the remaining places before adding the rest through the normal add
                                    if (inv.transform.GetChild(1).transform.GetChild(j).GetChild(0).GetComponent <ItemOnObject>().item.itemValue + item.itemValue > inv.transform.GetChild(1).transform.GetChild(j).GetChild(0).GetComponent <ItemOnObject>().item.maxStack)
                                    {
                                        item.itemValue -= (inv.transform.GetChild(1).transform.GetChild(j).GetChild(0).GetComponent <ItemOnObject>().item.maxStack - inv.transform.GetChild(1).transform.GetChild(j).GetChild(0).GetComponent <ItemOnObject>().item.itemValue);
                                        inv.transform.GetChild(1).transform.GetChild(j).GetChild(0).GetComponent <ItemOnObject>().item.itemValue = inv.transform.GetChild(1).transform.GetChild(j).GetChild(0).GetComponent <ItemOnObject>().item.maxStack;
                                    }
                                }
                            }
                        }
                        //normal add
                        numberOfItems = item.itemValue / item.maxStack;
                        for (int i = 0; i < numberOfItems; i++)
                        {
                            inv.GetComponent <Inventory>().addItemToInventory(item.itemID, item.maxStack);
                            inv.GetComponent <Inventory>().stackableSettings();
                        }
                        if (item.itemValue % item.maxStack != 0)
                        {
                            inv.GetComponent <Inventory>().addItemToInventory(item.itemID, item.itemValue % item.maxStack);
                            inv.GetComponent <Inventory>().stackableSettings();
                        }
                    }
                    CraftSystem cS = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerInventory>().craftSystem.GetComponent <CraftSystem>();
                    cS.deleteItems(item);
                    CraftResultSlot result = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerInventory>().craftSystem.transform.GetChild(3).GetComponent <CraftResultSlot>();
                    tooltip.deactivateTooltip();
                    gearable = true;
                    inv.GetComponent <Inventory>().updateItemList();
                }
                else
                {
                    bool stop = false;
                    if (eS != null)
                    {
                        for (int i = 0; i < eS.slotsInTotal; i++)
                        {
                            if (itemTypeOfSlot[i].Equals(item.itemType))
                            {
                                if (eS.transform.GetChild(1).GetChild(i).childCount == 0)
                                {
                                    stop = true;
                                    if (eS.transform.GetChild(1).GetChild(i).parent.parent.GetComponent <EquipmentSystem>() != null && this.gameObject.transform.parent.parent.parent.GetComponent <EquipmentSystem>() != null)
                                    {
                                    }
                                    else
                                    {
                                        inventory.EquiptItem(item);
                                    }

                                    this.gameObject.transform.SetParent(eS.transform.GetChild(1).GetChild(i));
                                    this.gameObject.GetComponent <RectTransform>().localPosition = Vector3.zero;
                                    eS.gameObject.GetComponent <Inventory>().updateItemList();
                                    inventory.updateItemList();
                                    gearable = true;
                                    if (duplication != null)
                                    {
                                        Destroy(duplication.gameObject);
                                    }
                                    break;
                                }
                            }
                        }

                        if (!stop)
                        {
                            for (int i = 0; i < eS.slotsInTotal; i++)
                            {
                                if (itemTypeOfSlot[i].Equals(item.itemType))
                                {
                                    if (eS.transform.GetChild(1).GetChild(i).childCount != 0)
                                    {
                                        GameObject otherItemFromCharacterSystem = eS.transform.GetChild(1).GetChild(i).GetChild(0).gameObject;
                                        Item       otherSlotItem = otherItemFromCharacterSystem.GetComponent <ItemOnObject>().item;
                                        if (item.itemType == ItemType.UFPS_Weapon)
                                        {
                                            inventory.UnEquipItem1(otherItemFromCharacterSystem.GetComponent <ItemOnObject>().item);
                                            inventory.EquiptItem(item);
                                        }
                                        else
                                        {
                                            inventory.EquiptItem(item);
                                            if (item.itemType != ItemType.Backpack)
                                            {
                                                inventory.UnEquipItem1(otherItemFromCharacterSystem.GetComponent <ItemOnObject>().item);
                                            }
                                        }
                                        if (this == null)
                                        {
                                            GameObject dropItem = (GameObject)Instantiate(otherSlotItem.itemModel);
                                            dropItem.AddComponent <PickUpItem>();
                                            dropItem.GetComponent <PickUpItem>().item = otherSlotItem;
                                            dropItem.transform.localPosition          = GameObject.FindGameObjectWithTag("Player").transform.localPosition;
                                            inventory.OnUpdateItemList();
                                        }
                                        else
                                        {
                                            otherItemFromCharacterSystem.transform.SetParent(this.transform.parent);
                                            otherItemFromCharacterSystem.GetComponent <RectTransform>().localPosition = Vector3.zero;
                                            if (this.gameObject.transform.parent.parent.parent.GetComponent <Hotbar>() != null)
                                            {
                                                createDuplication(otherItemFromCharacterSystem);
                                            }

                                            this.gameObject.transform.SetParent(eS.transform.GetChild(1).GetChild(i));
                                            this.gameObject.GetComponent <RectTransform>().localPosition = Vector3.zero;
                                        }

                                        gearable = true;
                                        if (duplication != null)
                                        {
                                            Destroy(duplication.gameObject);
                                        }
                                        eS.gameObject.GetComponent <Inventory>().updateItemList();
                                        inventory.OnUpdateItemList();
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                if (!gearable && item.itemType != ItemType.UFPS_Ammo && item.itemType != ItemType.UFPS_Grenade)
                {
                    Item itemFromDup = null;
                    if (duplication != null)
                    {
                        itemFromDup = duplication.GetComponent <ItemOnObject>().item;
                    }

                    inventory.ConsumeItem(item);

                    item.itemValue--;
                    if (itemFromDup != null)
                    {
                        duplication.GetComponent <ItemOnObject>().item.itemValue--;
                        if (itemFromDup.itemValue <= 0)
                        {
                            if (tooltip != null)
                            {
                                tooltip.deactivateTooltip();
                            }
                            inventory.deleteItemFromInventory(item);
                            Destroy(duplication.gameObject);
                        }
                    }
                    if (item.itemValue <= 0)
                    {
                        if (tooltip != null)
                        {
                            tooltip.deactivateTooltip();
                        }
                        inventory.deleteItemFromInventory(item);
                        Destroy(this.gameObject);
                    }
                }
            }
        }
    }
예제 #17
0
 public void addItemToInventory(int id)
 {
     mainInventory.addItemToInventory(id);
     mainInventory.updateItemList();
     mainInventory.stackableSettings();
 }