/// <summary>
        /// Assign the slot by the passed source slot.
        /// </summary>
        /// <param name="source">Source.</param>
        public override bool Assign(Object source)
        {
            if (source is UIItemSlot)
            {
                UIItemSlot sourceSlot = source as UIItemSlot;

                // Check if the equipment type matches the target slot
                if (!this.CheckEquipType(sourceSlot.GetItemInfo()))
                {
                    return(false);
                }

                return(this.Assign(sourceSlot.GetItemInfo()));
            }
            else if (source is UIEquipSlot)
            {
                UIEquipSlot sourceSlot = source as UIEquipSlot;

                // Check if the equipment type matches the target slot
                if (!this.CheckEquipType(sourceSlot.GetItemInfo()))
                {
                    return(false);
                }

                return(this.Assign(sourceSlot.GetItemInfo()));
            }

            // Default
            return(false);
        }
Exemple #2
0
        /// <summary>
        /// Assign the slot by the passed source slot.
        /// </summary>
        /// <param name="source">Source.</param>
        public override bool Assign(Object source)
        {
            if (source is UIItemSlot)
            {
                UIItemSlot sourceSlot = source as UIItemSlot;

                if (sourceSlot != null)
                {
                    return(this.Assign(sourceSlot.GetItemInfo()));
                }
            }
            else if (source is UIEquipSlot)
            {
                UIEquipSlot sourceSlot = source as UIEquipSlot;

                if (sourceSlot != null)
                {
                    return(this.Assign(sourceSlot.GetItemInfo()));
                }
            }

            // Default
            return(false);
        }
        /*
         * Creator: Yunzheng Zhou
         * Retrieve and use item from inventary slot.
         * Parameter: item - RaycastResult variable referencing mouse postion and action
         */
        public void UseItem(RaycastResult item)    // right click. Use this!
        {
            if (this is UIEquipSlot && (int)(this as UIEquipSlot).equipType != 9)
            {
                return;
            }
            UIItemSlot              inventorySlot = item.gameObject.GetComponent <UIItemSlot>();
            UIEquipSlot             equipSlot     = item.gameObject.GetComponent <UIEquipSlot>();
            Test_UIItemSlot_Assign  tmpItem       = item.gameObject.GetComponent <Test_UIItemSlot_Assign>();
            Test_UIEquipSlot_Assign equipItem     = item.gameObject.GetComponent <Test_UIEquipSlot_Assign>();

            if (equipItem != null)
            {
                if (equipItem.assignItem == 0)
                {
                    return;
                }
            }
            UIItemInfo inven;
            Item       consumable;

            if (inventorySlot == null)
            {
                //equipSlot = item.gameObject.GetComponent<UIEquipSlot>();
                //equipItem = item.gameObject.GetComponent<Test_UIEquipSlot_Assign>();
                if (equipItem == null)
                {
                    return;
                }
                consumable = backupitemDataBase.GetItem(equipItem.assignItem);
                inven      = equipSlot.GetItemInfo();
            }
            else        //consumable
            {
                if (inventorySlot.isVendor)
                {
                    return;
                }
                tmpItem    = item.gameObject.GetComponent <Test_UIItemSlot_Assign>();
                inven      = inventorySlot.GetItemInfo();
                consumable = backupitemDataBase.GetItem(tmpItem.assignItem);
            }
            if (consumable.isconsumable)
            {
                playSFX(onConsumeSFX);
                consumable.Use();

                if (inventorySlot == null)
                {
                    equipSlot.Assign(itemdatabase.GetByID(0));
                    fillinPotionslot(equipSlot, equipItem.assignItem, equipItem);
                    return;
                }
                inventorySlot.Assign(itemdatabase.GetByID(0));
                tmpItem.assignItem = 0;
            }
            else        //equip
            {
                int i = (int)(itemdatabase.GetByID(tmpItem.assignItem).EquipType);
                if (i > 6 || i < 1)
                {
                    //Debug.Log("find gem");
                    return;
                }
                //this.InternalHideTooltip();
                UIEquipSlot EquipedSlot = EquipmentManager.instance.equipmentSlot[i].GetComponent <UIEquipSlot>();
                //Debug.Log(EquipedSlot);
                UIItemInfo currentEquiped = EquipedSlot.GetItemInfo();
                if (currentEquiped.EquipType == 0)
                {
                    //tmpItem.assignItem = 10;
                    playSFX(onEquipSFX);
                    inventorySlot.Assign(EquipedSlot);
                    if ((int)EquipedSlot.equipType == 1)
                    {
                        Player.instance.playerController.WeaponState = 1;
                    }
                }
                else
                {
                    playSFX(onEquipSFX);
                    inventorySlot.Assign(currentEquiped);
                }
                int tmpID = currentEquiped.ID;
                Test_UIEquipSlot_Assign equipedItem = EquipmentManager.instance.equipmentSlot[i].GetComponent <Test_UIEquipSlot_Assign>();
                equipedItem.assignItem   = tmpItem.assignItem;
                equipedItem.itemDatabase = itemdatabase;
                //equipedItem.slot = EquipedSlot;
                EquipedSlot.Assign(inven);
                //equipedItem.slot.Assign(inven);
                //EquipedSlot.Assign(itemdatabase.GetByID(equipedItem.assignItem));
                //equipedItem.slot.Assign(itemdatabase.GetByID(equipedItem.assignItem));
                tmpItem.assignItem = tmpID;
                Test_UIItemSlot_Assign inventoryitem = inventorySlot.GetComponent <Test_UIItemSlot_Assign>();
                inventoryitem.assignItem = tmpID;
                //Inventory.instance.UpdateInventory();
                for (int k = 4; k < 8; k++)
                {
                    EquipmentManager.instance.EquipmentUpdate(k);
                }
            }
        }