Exemplo n.º 1
0
    private void OnSlot_Click(ItemKind type)
    {
        itemSlotSelected   = null;
        _curItemTypeSelect = type;
        uiEquipmentRoot.SetActive(false);
        uiInventoryRoot.SetActive(true);

        List <UserItem> items;

        if (type == ItemKind.Consume)
        {
            items = GameManager.GameUser.UserItems.Where(p => p.GameItem.Kind == (int)type &&
                                                         (p.RoleUId == 0 || p.RoleUId == heroSlotSelected.userRole.Id) &&
                                                         p.GameItem.Kind == (int)ItemKind.Consume).ToList();
        }
        else
        {
            items = GameManager.GameUser.UserItems.Where(p => p.GameItem.Kind == (int)type &&
                                                         (p.RoleUId == 0 || p.RoleUId == heroSlotSelected.userRole.Id)).ToList();
            //.OrderByDescending(p => p.RoleUId == heroSlotSelected.userRole.Id).ThenByDescending(p => p.GameItem.Level).ThenByDescending(p => p.Grade).ToList();
        }

        for (int i = 0; i < items.Count; i++)
        {
            GameObject            go   = NGUITools.AddChild(uiItemSlotRoot, uiItemSlotPrefab);
            UIHeroItemSlotManager slot = go.GetComponent <UIHeroItemSlotManager>();
            slot.SetItem(items[i], this);
            _itemSet.Add(slot);
        }

        uiItemSlotRoot.GetComponent <UIGrid>().Reposition();
    }
Exemplo n.º 2
0
    public void OnEquip()
    {
        if (MessageBox.isShow)
        {
            return;
        }

        if (itemSlotSelected == null)
        {
            return;
        }


        UserItem item = itemSlotSelected.itemContain;

        if (heroSlotSelected.userRole.Id != item.RoleUId)
        {
            //Euip
            UserItem oldItemEquiped = GameManager.GameUser.UserItems.FirstOrDefault(p => p.RoleUId == heroSlotSelected.userRole.Id && p.GameItem.Kind == item.GameItem.Kind);
            Debug.Log("OnEquip " + itemSlotSelected.itemContain.Name);
            if (oldItemEquiped != null)
            {
                GameManager.GameUser.SetItemForRole(null, oldItemEquiped);
                //  _heroMenuController.SendRequestEquipItem(0, oldItemEquiped.Id);

                UIHeroItemSlotManager uiSlot = _itemSet.FirstOrDefault(p => p.itemContain.Id == oldItemEquiped.Id);
                if (uiSlot != null)
                {
                    uiSlot.Refresh();
                }
            }

            /* if (!GameManager.GameUser.SetItemForRole(heroSlotSelected.userRole, item))
             * {
             *   MessageBox.ShowDialog(GameManager.localization.GetText("Equip_CantEuqip"), UINoticeManager.NoticeType.Message);
             *   return;
             * }
             *
             * _heroMenuController.SendRequestEquipItem(heroSlotSelected.userRole.Id, item.Id);*/
        }
        else
        {
            //EnEquip
            Debug.Log("EnEquip " + itemSlotSelected.itemContain.Name);
            GameManager.GameUser.SetItemForRole(null, item);
            _heroMenuController.SendRequestEquipItem(0, item.Id);
        }
    }