コード例 #1
0
    private void sellDecoration(uint id, int count)
    {
        if (grabbedSlot == null)
        {
            int toSell = count;
            try
            {
                if (homeDecorationsBought[id] < toSell)
                {
                    toSell = homeDecorationsBought[id];
                }
                homeDecorationsBought[id] -= toSell;
                fpc.money += (int)(toSell * decorationValue[(uint)id] * 0.75f);
            }
            catch { }
            //todo decrease item's count by count

            MenuSlot sellSlot = GameObject.Find("sellFlowerSlot").GetComponent <MenuSlot>();

            //Reduce flower count by "adding" a negative value
            addHomeInventoryItem(id, -count, false);
            sellSlot.setCount(sellSlot.getCount() - count);//this is neg for some reason
            updateMoneyText();


            updateFlowerDisplaySlot(sellSlot.getItem());
        }
    }
コード例 #2
0
    //Sell the flower the given number of times
    private void sellFlower(uint flowerID, int sellAmount)
    {
        if (grabbedSlot == null)
        {
            MenuSlot sellSlot = GameObject.Find("sellFlowerSlot").GetComponent <MenuSlot>();
            //this was for multiple sells since processflowersell allways sells one
            //fpc.money += HomeBaseController.instance.getFlowerValue(flowerID) * (sellAmount-1);
            HomeBaseController.instance.processFlowerSell(flowerID);

            //Reduce flower count by "adding" a negative value
            addHomeInventoryItem(flowerID, -sellAmount, true);
            sellSlot.setCount(sellSlot.getCount() - sellAmount);
            updateMoneyText();
            updateFlowerDisplaySlot(sellSlot.getItem());
        }
    }
コード例 #3
0
 private void purchaseDecoration(uint id, MenuSlot item)
 {
     if (grabbedSlot == null)
     {
         if (fpc.money >= decorationValue[(uint)id])
         {
             if (!homeDecorationsBought.ContainsKey(id))
             {
                 homeDecorationsBought.Add(id, 0);
             }
             homeDecorationsBought[id] += 1;
             fpc.money -= decorationValue[(uint)id];
             updateMoneyText();
             bool      pushedToInventory    = false;
             Transform playerInventoryPanel = GameObject.Find("playerInventoryPanel").transform;
             for (int i = 0; i < 10 && pushedToInventory == false; i++)
             {
                 if (playerInventoryPanel.GetChild(i).childCount != 0)
                 {
                     MenuSlotItem msi = playerInventoryPanel.GetChild(i).GetChild(0).GetComponent <MenuSlotItem>();
                     if (msi.isFlower == false && msi.id == id)
                     {
                         msi.setCount(msi.count + 1);
                         pushedToInventory = true;
                     }
                 }
             }
             if (!pushedToInventory)
             {
                 item.setCount(item.getCount() + 1);
                 addHomeInventoryItem(id, 1, false);
             }
             for (int i = 0; i < 10 && pushedToInventory == false; i++)
             {
                 if (playerInventoryPanel.GetChild(i).childCount == 0)
                 {
                     item.releaseItem(playerInventoryPanel.GetChild(i).GetComponent <MenuSlot>());
                     pushedToInventory = true;
                 }
             }
         }
     }
 }
コード例 #4
0
    /// <summary>
    /// Releases the item to the given slot, if it's null then nothing happens
    /// </summary>
    public void releaseItem(MenuSlot releaseTo)
    {
        Debug.Log("vvvvvvvvv Start releasing vvvvvvvvvv");
        //Note: "this" always refers to the item slot that holds the grabbed item

        HomeBaseUIController hbuic = GetComponentInParent <HomeBaseUIController>();

        GetComponent <Image>().color = Color.white;
        isGrabbed = false;

        //If the item is actually dropped onto a slot
        //And the slot is different than the one it was picked up in
        if (releaseTo != null && releaseTo != this)
        {
            //First thing to do is see if the player is "splitting" items
            //If there is a visible item with the same id in the player inventory or the home inventory then merge the two items together
            if (releaseTo.type == SlotType.HomeInventory || releaseTo.type == MenuSlot.SlotType.DisplaySlot)
            {
                //Get a matching slot
                MenuSlot matchingSlot = hbuic.findSlotWithItem(this.getItem());
                //Make sure there is a matching slot and it's not this one and it has more than 0 items
                if (matchingSlot != null && matchingSlot != this && matchingSlot.getCount() > 0)
                {
                    //If the player didn't already try to merge the items
                    if (matchingSlot != releaseTo)
                    {
                        if (releaseTo.slotIndex != 0 || releaseTo.type == SlotType.DisplaySlot)
                        {
                            //Pretend the player clicked on the matching slot
                            matchingSlot.swapWith(releaseTo);
                        }
                        else
                        {
                            releaseTo = matchingSlot;
                        }
                    }
                }
            }

            //This only happens if the player is moving something to a slot
            bool iCanMove, uCanMove, weSwap;
            iCanMove = canMoveToSlot(releaseTo);
            uCanMove = releaseTo.canMoveToSlot(this);
            Debug.Log("iCanMove: " + iCanMove + " uCanMove: " + uCanMove);
            weSwap = (iCanMove && uCanMove);
            if (weSwap)
            {
                this.swapWith(releaseTo);
            }
            else //It can't be a straight up swap
            {
                //If my item can move to the given slot
                if (iCanMove)
                {
                    //If it can't combine them then
                    if (!combineSuccess(releaseTo))
                    {
                        //Store the other one in its respective inventory
                        releaseTo.storeItem(false);
                        //Make this one empty by swapping the two items
                        this.swapWith(releaseTo);
                    }
                }
                else
                {
                    //If this item isn't a decoration slot
                    if (this.type != SlotType.DecorationSlot)
                    {
                        //Store this item into its proper home inventory (and set it to null)
                        this.storeItem(true);
                    }
                    else
                    {
                        //The the player is trying to store an item that was picked up from a decoration slot
                        returnItemToSlot();
                    }
                    //If the item in the released slot can move
                    if (uCanMove)
                    {
                        //Only swap the items if the other slot isn't a decoration slot
                        if (releaseTo.type != SlotType.DecorationSlot)
                        {
                            this.swapWith(releaseTo);
                        }
                    }
                }
            }
        }
        else //If the item was dropped somewhere that's not a slot (or dropped back onto itself)
        {
            this.returnItemToSlot();
        }

        Debug.Log("^^^^^^^^^^ Done releasing ^^^^^^^^^^");
    }