Beispiel #1
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);
        }