/*
  * Creator: Yunzheng Zhou
  * Insert new potion into slot and interact with GUI
  * Parameter: slot - UIEquipSlot variable,
  *          id - an int variable indicating the item id
  *          testslot - Test_UIEquipSlot_Assign variable
  */
 public void fillinPotionslot(UIEquipSlot slot, int id, Test_UIEquipSlot_Assign testslot)
 {
     for (int i = 0; i < 40; i++)
     {
         if (Inventory.instance.items[i].itemID == id)
         {
             Inventory.instance.setdefault(i);
             slot.Assign(itemdatabase.GetByID(id));
             testslot.assignItem            = id;
             InventoryGUI.instance.items[i] = id;
             InventoryGUI.instance.gameslot[i].GetComponent <UIItemSlot>().Assign(itemdatabase.GetByID(0));
             InventoryGUI.instance.gameslot[i].GetComponent <Test_UIItemSlot_Assign>().assignItem = 0;
             return;
         }
     }
     testslot.assignItem = 0;
     slot.Assign(itemdatabase.GetByID(0));
     for (int i = 0; i < 5; i++)
     {
         if (EquipmentManager.instance.potionSlot[i].GetComponent <Test_UIEquipSlot_Assign>().assignItem == 0)
         {
             EquipmentManager.instance.Potions[i] = null;
         }
     }
 }
 /*
  * Creator: Yunzheng Zhou
  * Internal call for show tooltip.
  */
 protected void InternalShowTooltip()
 {
     // Call the on tooltip only if it's currently not shown
     if (!this.m_IsTooltipShown)
     {
         if (this is UIItemSlot)
         {
             Test_UIItemSlot_Assign tmp1 = this.GetComponent <Test_UIItemSlot_Assign>();
             if (tmp1.assignItem == 0)
             {
                 return;
             }
         }
         if (this is UIEquipSlot)
         {
             Test_UIEquipSlot_Assign tmp1 = this.GetComponent <Test_UIEquipSlot_Assign>();
             if (tmp1.assignItem == 0)
             {
                 return;
             }
         }
         this.m_IsTooltipShown = true;
         this.OnTooltip(true);
     }
 }
        /*
         * Creator: Yunzheng Zhou
         * Use potion from inventary and play sound effect
         */
        public void UsePotion()
        {
            playSFX(onConsumeSFX);
            Test_UIEquipSlot_Assign equipItem = this.GetComponent <Test_UIEquipSlot_Assign>();
            Item consumable = backupitemDataBase.GetItem(equipItem.assignItem);

            consumable.Use();
            (this as UIEquipSlot).Assign(itemdatabase.GetByID(0));
            fillinPotionslot((this as UIEquipSlot), equipItem.assignItem, equipItem);
        }
예제 #4
0
        /*
         * Creator: Yunzheng Zhou
         * Description:
         *          Performs a item swap from one slot to another slot
         *          The destination slot will varied. if the destination slot is vendor inventory
         *          then it means that the player is trading with vendor.
         *          otherwise swap the items.
         * Parameter: sourceObject object
         * Return a bool value indicating if slot swap was performed
         */
        public override bool PerformSlotSwap(Object sourceObject)
        {
            // Get the source slot
            UISlotBase sourceSlot = (sourceObject as UISlotBase);
            //Debug.Log("Itemslot!");
            // Get the source item info
            UIItemInfo sourceItemInfo = null;
            bool       assign1        = false;
            bool       sourceVendor   = false;
            bool       thisVendor     = false;

            // Check the type of the source slot
            if (sourceSlot is UIItemSlot)
            {
                sourceItemInfo = (sourceSlot as UIItemSlot).GetItemInfo();
                if ((sourceSlot as UIItemSlot).isVendor)
                {
                    sourceVendor = true;
                }
                if (this.isVendor)
                {
                    thisVendor = true;
                }
                Text gold = Inventory.instance.gold.GetComponent <Text>();
                if (sourceVendor && !thisVendor)
                {
                    gold.text = Convert.ToString(Convert.ToInt32(gold.text) + this.GetItemInfo().price);
                }
                if (!sourceVendor && thisVendor)
                {
                    if (gold.text == "0")
                    {
                        return(false);
                    }
                    if (this.GetItemInfo().price > Convert.ToInt32(gold.text))
                    {
                        return(false);
                    }
                    gold.text = Convert.ToString(Convert.ToInt32(gold.text) - this.GetItemInfo().price);
                }
                // Assign the source slot by this one
                assign1 = (sourceSlot as UIItemSlot).Assign(this.GetItemInfo());
                Test_UIItemSlot_Assign sourceItem = sourceSlot.GetComponent <Test_UIItemSlot_Assign>();
                Test_UIItemSlot_Assign Toitem     = this.GetComponent <Test_UIItemSlot_Assign>();
                int id = sourceItem.assignItem;
                sourceItem.assignItem = Toitem.assignItem;
                Toitem.assignItem     = id;

                /*if (sourceItem.assignItem == 0)
                 * {
                 * sourceSlot.Unassign();
                 * }
                 * if (Toitem.assignItem == 0)
                 * {
                 * this.Unassign();
                 * }*/
            }
            else if (sourceSlot is UIEquipSlot)
            {
                sourceItemInfo = (sourceSlot as UIEquipSlot).GetItemInfo();
                if (this.GetItemInfo().gemSlot != (sourceSlot as UIEquipSlot).slotindex)
                {
                    return(false);
                }

                if (this.GetItemInfo().EquipType == 0)
                {
                    return(false);
                }
                // Assign the source slot by this one
                assign1 = (sourceSlot as UIEquipSlot).Assign(this.GetItemInfo());
                if (!assign1)
                {
                    return(false);
                }
                Test_UIEquipSlot_Assign sourceItem = sourceSlot.GetComponent <Test_UIEquipSlot_Assign>();
                Test_UIItemSlot_Assign  Toitem     = this.GetComponent <Test_UIItemSlot_Assign>();
                int id = sourceItem.assignItem;
                sourceItem.assignItem = Toitem.assignItem;
                Toitem.assignItem     = id;
                if ((int)sourceSlot.GetComponent <UIEquipSlot>().equipType == 1)
                {
                    Player.instance.playerController.WeaponState = 1;
                }
                //Debug.Log("source is " + sourceItem.assignItem);
                //Debug.Log("this is " + this + " id is " + Toitem.assignItem);
            }
            //Debug.Log("perform swap");
            // Assign this slot by the source slot
            for (int i = 4; i < 8; i++)
            {
                EquipmentManager.instance.EquipmentUpdate(i);
            }
            bool assign2 = this.Assign(sourceItemInfo);

            //Debug.Log("assign1 is " + assign1 + "assign2 is " + assign2);
            // Return the status
            //Inventory.instance.UpdateInventory();
            return(assign1 && assign2);
        }
예제 #5
0
        /*
         * Creator: Yunzheng Zhou
         * Performs a slot swap.
         * Parameter: Source slot object
         * Return: a bool variable indicating if slot swap was performed
         */
        public override bool PerformSlotSwap(Object sourceObject)
        {
            // Get the source item info
            UIItemInfo sourceItemInfo = null;
            bool       assign1        = false;

            //Debug.Log(sourceObject + " equipment");
            // Check the type of the source slot
            if (sourceObject is UIItemSlot)
            {
                sourceItemInfo = (sourceObject as UIItemSlot).GetItemInfo();

                /*if (sourceItemInfo.EquipType == 0)
                 * {
                 *  Debug.Log("source is the ! " + sourceItemInfo);
                 *  (sourceObject as UIItemSlot).Unassign();
                 *  assign1 = true;
                 * }*/
                // Assign the source slot by this one
                //else
                //{
                assign1 = (sourceObject as UIItemSlot).Assign(this.GetItemInfo());
                Test_UIItemSlot_Assign  sourceitem = (sourceObject as UIItemSlot).GetComponent <Test_UIItemSlot_Assign>();
                Test_UIEquipSlot_Assign thisitem   = this.GetComponent <Test_UIEquipSlot_Assign>();
                Player.instance.playerStats.OnEquipmentChanged(null, backupitemDataBase.GetItem(thisitem.assignItem) as Equipment);
                if ((int)this.GetComponent <UIEquipSlot>().equipType == 1)
                {
                    Player.instance.playerController.WeaponState = 0;
                }
                int tmp = sourceitem.assignItem;
                sourceitem.assignItem = thisitem.assignItem;
                thisitem.assignItem   = tmp;

                //Debug.Log("source is " + sourceitem.assignItem);

                //Debug.Log("assign1 " + assign1);
                //}
            }
            else if (sourceObject is UIEquipSlot)
            {
                return(false);

                sourceItemInfo = (sourceObject as UIEquipSlot).GetItemInfo();

                // Assign the source slot by this one
                assign1 = (sourceObject as UIEquipSlot).Assign(this.GetItemInfo());
            }
            else
            {
                for (int i = 4; i < 8; i++)
                {
                    EquipmentManager.instance.EquipmentUpdate(i);
                }
                return(false);
            }
            for (int i = 4; i < 8; i++)
            {
                EquipmentManager.instance.EquipmentUpdate(i);
            }
            // Assign this slot by the source slot
            bool assign2 = this.Assign(sourceItemInfo);

            // Return the status
            return(assign1 && assign2);
        }
        /*
         * 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);
                }
            }
        }