public bool UseItemAtIndex(int index, int count, Vector3 pos)
        {
            if (index >= 0)
            {
                InteractItem item = GetItemByIndex(index);

                if (!System.Object.ReferenceEquals(null, item))
                {
                    if (!System.Object.ReferenceEquals(null, Owner))
                    {
                        Owner.UseItem(item.CfgID, pos);

                        item.Count -= count;

                        if (item.Count > 0)
                        {
                            OnItemChange(index);
                        }
                        else
                        {
                            RemoveBagItem(index);
                        }
                    }

                    return(true);
                }
            }
            return(false);
        }
 public void SelectRoleItem(InteractItem item)
 {
     ClearSelectItem();
     CurRoleInfoItem = item;
     CurInteractItem = item;
     HasItem         = true;
 }
        public bool UseItemAtIndex(int index, int count, BaseGameEntity target = null)
        {
            if (index >= 0)
            {
                InteractItem item = GetItemByIndex(index);

                if (!System.Object.ReferenceEquals(null, item))
                {
                    if (!System.Object.ReferenceEquals(null, Owner))
                    {
                        if (System.Object.ReferenceEquals(null, target))
                        {
                            target = Owner;
                        }
                        Owner.UseItem(item.CfgID, target);

                        item.Count -= count;

                        if (item.Count > 0)
                        {
                            OnItemChange(index);
                        }
                        else
                        {
                            RemoveBagItem(index);
                        }
                    }

                    return(true);
                }
            }
            return(false);
        }
 public void SelectBagItem(InteractItem item)
 {
     ClearSelectItem();
     CurBagItem      = item;
     CurInteractItem = item;
     HasItem         = true;
 }
 public void SelectShortcutItem(InteractItem item)
 {
     ClearSelectItem();
     CurShortcutItem = item;
     CurInteractItem = item;
     HasItem         = true;
 }
 public void ClearSelectItem()
 {
     CurBagItem      = null;
     CurShortcutItem = null;
     CurRoleInfoItem = null;
     CurInteractItem = null;
     UILord.Instance.CurItemUIType = InteractItemUIType.None;
     HasItem = false;
 }
        protected void HandleSelfItem(int index, int count = 0)
        {
            InteractItem item = Bag.GetItemByIndex(index);

            if (!System.Object.ReferenceEquals(null, item))
            {
                UILord.Instance.SelectBagItem(item);
                UILord.Instance.CurItemUIType = InteractItemUIType.Bag;
            }
        }
        /// <summary>
        /// Add ui show on bag ui of items.
        /// </summary>
        /// <param name="item"></param>
        public void AddItem(InteractItem item)
        {
            if (IsUIElementsReady)
            {
                ItemBtnImages[item.Index].sprite =
                    IconsAssetHolder.Instance.GetIconByID(item.IconID);

                Txts[item.Index].text = item.Count.ToString();
            }
        }
 public void OnItemChange(int index)
 {
     if (!System.Object.ReferenceEquals(null, Bag))
     {
         InteractItem bbi = Bag.GetItemByIndex(index);
         if (!System.Object.ReferenceEquals(null, bbi))
         {
             Txts[index].text = bbi.Count.ToString();
         }
     }
 }
 public void OnItemAdd(int index)
 {
     if (!System.Object.ReferenceEquals(null, Bag))
     {
         InteractItem bbi = Bag.GetItemByIndex(index);
         if (!System.Object.ReferenceEquals(null, bbi))
         {
             AddItem(bbi);
         }
     }
 }
        public void HandleShortcutItemJoin(InteractItem srcItem, int dstIndex)
        {
            if (srcItem.Index == dstIndex)
            {
                return;
            }

            if (Shortcut)
            {
                var InteractItem = Shortcut.GetItemByIndex(dstIndex);

                if (!System.Object.ReferenceEquals(null, InteractItem))
                {
                    if (InteractItem.CfgID == srcItem.CfgID)
                    {
                        int left = Shortcut.AddItemAtIndex(srcItem.Kind,
                                                           srcItem.CfgID, dstIndex, srcItem.Count);

                        if (left <= 0)
                        {
                            Shortcut.RemoveItem(srcItem.Index);
                        }
                        else
                        {
                            Shortcut.UpdateItemCount(srcItem.Index, left);
                        }
                        //UILord.Instance.CurBag.ChangeBagItem(srcItem.Index,
                        //    left);
                    }
                    else
                    {
                        Shortcut.RemoveItem(InteractItem.Index);
                        Shortcut.AddItemAtIndex(srcItem.Kind,
                                                srcItem.CfgID, dstIndex, srcItem.Count);
                        Shortcut.RemoveItem(srcItem.Index);
                        Shortcut.AddItemAtIndex(srcItem.Kind,
                                                InteractItem.CfgID, srcItem.Index,
                                                InteractItem.Count);
                    }
                }
                else
                {
                    Shortcut.AddItemAtIndex(0, srcItem.CfgID, dstIndex, srcItem.Count);
                    // remove the item in bag.
                    //UILord.Instance.CurBag.RemoveBagItem(srcItem.Index);
                    Shortcut.RemoveItem(srcItem.Index);
                }

                UILord.Instance.ClearSelectItem();
            }
        }
        public void HandleBagItemJoin(InteractItem srcItem, int dstIndex)
        {
            if (RoleInfo)
            {
                var InteractItem = RoleInfo.GetItemByIndex(dstIndex);

                if (!System.Object.ReferenceEquals(null, InteractItem))
                {
                    if (InteractItem.Kind == InteractItemType.Item)
                    {
                        if (InteractItem.CfgID == srcItem.CfgID)
                        {
                            int left = RoleInfo.AddItemAtIndex(0,
                                                               srcItem.CfgID, dstIndex, srcItem.Count);

                            UILord.Instance.CurBag.ChangeBagItem(srcItem.Index,
                                                                 left);
                        }
                        else
                        {
                            RoleInfo.RemoveItem(InteractItem.Index);
                            RoleInfo.AddItemAtIndex(0, srcItem.CfgID,
                                                    dstIndex, srcItem.Count);
                            UILord.Instance.CurBag.RemoveBagItem(srcItem.Index);
                            UILord.Instance.CurBag.AddItemAtIndex(
                                InteractItem.CfgID, srcItem.Index,
                                InteractItem.Count);
                        }
                    }
                    else
                    {
                        RoleInfo.RemoveItem(InteractItem.Index);
                        RoleInfo.AddItemAtIndex(0, srcItem.CfgID,
                                                dstIndex, srcItem.Count);
                        UILord.Instance.CurBag.RemoveBagItem(srcItem.Index);
                    }
                }
                else
                {
                    RoleInfo.AddItemAtIndex(0, srcItem.CfgID, dstIndex, srcItem.Count);
                    // remove the item in bag.
                    UILord.Instance.CurBag.RemoveBagItem(srcItem.Index);
                }

                UILord.Instance.ClearSelectItem();
            }
        }
        /// <summary>
        /// Add item to index, check the item must be the same type
        /// if there are already an item exist there.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="index"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public int AddItemAtIndex(int id, int index, int count)
        {
            if (!IsValidAtIndex(id, index))
            {
                return(0);
            }

            int countLeft = 0;

            InteractItem bbi = GetItemByIndex(index);

            if (!System.Object.ReferenceEquals(null, bbi))
            {
                bbi.Count += count;

                if (bbi.Count > bbi.MaxCount)
                {
                    countLeft = bbi.Count - bbi.MaxCount;
                    bbi.Count = bbi.MaxCount;
                }
            }
            else
            {
                bbi       = new InteractItem();
                bbi.CfgID = id;
                bbi.Index = index;

                ItemConfig ic = ConfigDataMgr.Instance.ItemCfgLoader.GetDataByID(id);
                bbi.IconID = ic.IconID;

                bbi.Count += count;
                bbi.Kind   = InteractItemType.Item;

                Items.Add(bbi);
            }

            IndexRecorder[index] = 1;

            if (!System.Object.ReferenceEquals(null, OnAddItem))
            {
                OnAddItem(index);
            }

            return(countLeft);
        }
        public void HandleBagItemJoin(InteractItem srcItem, int dstIndex)
        {
            if (srcItem.Index == dstIndex)
            {
                return;
            }

            var itemsrc = srcItem;
            var itemdst = Bag.GetItemByIndex(dstIndex);

            if (!System.Object.ReferenceEquals(null, itemdst))
            {
                bool isSame = itemsrc.CfgID == itemdst.CfgID;

                if (!isSame)
                {
                    Bag.RemoveBagItem(itemsrc.Index);
                    if (!System.Object.ReferenceEquals(null, itemdst))
                    {
                        Bag.RemoveBagItem(itemdst.Index);
                        Bag.AddItemAtIndex(itemdst.CfgID, itemsrc.Index, itemdst.Count);
                    }

                    Bag.AddItemAtIndex(itemsrc.CfgID, dstIndex, itemsrc.Count);
                }
                else
                {
                    int left = Bag.AddItemAtIndex(itemdst.CfgID, itemdst.Index, itemsrc.Count);
                    if (left <= 0)
                    {
                        Bag.RemoveBagItem(itemsrc.Index);
                    }
                    else
                    {
                        Bag.ChangeBagItem(itemsrc.Index, left);
                    }
                }
            }
            else
            {
                Bag.RemoveBagItem(itemsrc.Index);
                Bag.AddItemAtIndex(itemsrc.CfgID, dstIndex, itemsrc.Count);
            }
        }
        public void HandleShortcutItemJoin(InteractItem srcItem, int dstIndex)
        {
            var itemsrc = srcItem;
            var itemdst = Bag.GetItemByIndex(dstIndex);

            if (!System.Object.ReferenceEquals(null, itemdst))
            {
                bool isSame = itemsrc.CfgID == itemdst.CfgID;

                if (!isSame)
                {
                    //Bag.RemoveBagItem(itemsrc.Index);
                    UILord.Instance.CurShortcutUI.RemoveItem(itemsrc.Index);
                    if (!System.Object.ReferenceEquals(null, itemdst))
                    {
                        Bag.RemoveBagItem(itemdst.Index);
                        UILord.Instance.CurShortcut.AddItemAtIndex(itemdst.Kind,
                                                                   itemdst.CfgID, itemsrc.Index, itemdst.Count);
                    }

                    Bag.AddItemAtIndex(itemsrc.CfgID, dstIndex, itemsrc.Count);
                }
                else
                {
                    int left = Bag.AddItemAtIndex(itemdst.CfgID, itemdst.Index, itemsrc.Count);
                    if (left <= 0)
                    {
                        UILord.Instance.CurShortcut.RemoveItem(itemsrc.Index);
                    }
                    else
                    {
                        UILord.Instance.CurShortcut.UpdateItemCount(itemsrc.Index, left);
                    }
                }
            }
            else
            {
                //Bag.RemoveBagItem(itemsrc.Index);
                UILord.Instance.CurShortcutUI.RemoveItem(itemsrc.Index);
                Bag.AddItemAtIndex(itemsrc.CfgID, dstIndex, itemsrc.Count);
            }
        }
 public void Add(InteractItem item)
 {
 }
        public int AddItemAtIndex(InteractItemType kind, int id, int index, int count)
        {
            if (!IsValidAtIndex(id, index, count))
            {
                return(0);
            }

            InteractItem bbi = GetItemByIndex(index);

            int left = 0;

            if (kind == InteractItemType.Item) // item
            {
                if (!System.Object.ReferenceEquals(null, bbi))
                {
                    bbi.Count += count;

                    if (bbi.Count > bbi.MaxCount)
                    {
                        left      = bbi.Count - bbi.MaxCount;
                        bbi.Count = bbi.MaxCount;
                    }
                }
                else
                {
                    bbi       = new InteractItem();
                    bbi.CfgID = id;
                    bbi.Index = index;
                    bbi.Kind  = kind;

                    ItemConfig ic =
                        ConfigDataMgr.Instance.ItemCfgLoader.GetDataByID(id);
                    bbi.IconID = ic.IconID;

                    bbi.Count += count;

                    Items.Add(bbi);
                }
            }
            else if (kind == InteractItemType.Skill)  // skill
            {
                if (!System.Object.ReferenceEquals(null, bbi))
                {
                    // handle cool down.
                    bbi.Count = 1;
                }
                else
                {
                    bbi       = new InteractItem();
                    bbi.CfgID = id;
                    bbi.Index = index;
                    bbi.Kind  = kind;

                    //ItemConfig ic =
                    //    ConfigDataMgr.Instance.ItemCfgLoader.GetDataByID(id);

                    SkillConfig sc =
                        ConfigDataMgr.Instance.SkillCfgLoader.GetDataByID(id);
                    bbi.IconID = sc.IconID;

                    bbi.Count = 1;

                    Items.Add(bbi);
                }
            }

            IndexRecorder[index] = 1;

            if (!System.Object.ReferenceEquals(null, OnAddItem))
            {
                OnAddItem(index);
            }

            return(left);
        }