Пример #1
0
 //The player right clicked the item - add it to the inventory
 void OnMouseOver()
 {
     if (Input.GetMouseButtonDown(1))
     {
         if (item.stackable)
         {
             inventory.AddStackableItem(item);
         }
         else
         {
             inventory.AddItem(item);
         }
         DestroyObject(gameObject);
     }
 }
Пример #2
0
 //The item was created now add it to the inventory
 public void AddItem()
 {
     for (int i = 0; i < inventory.items.Count; i++)
     {
         if (inventory.CheckItemFit(selectedItem.item, inventory.items[i], false))
         {
             RemoveItem();
             inventory.AddItem(selectedItem.item);
             crafting = false;
             return;
         }
         if (i == inventory.items.Count - 1)
         {
             //Display message
         }
     }
     crafting = false;
 }
Пример #3
0
    //Buy the item of the slot
    public void BuyItem(uGUIMerchantSlot slot, out bool succes, out string failMessage, out AudioClip sound)
    {
        ItemClass item = uGUIInventory.DeepCopy(slot.item);

        sound       = item.itemSound;
        succes      = false;
        failMessage = "";
        //If the player has enough gold
        if (player.money >= slot.item.buyPrice)
        {
            //If the item is stackable then add the stackable item
            if (item.stackable)
            {
                item.stackSize = 1;
                if (inventory.AddStackableItem(item))
                {
                    player.money -= slot.item.buyPrice;
                    if (removeStackableItemsWhenBought)
                    {
                        for (int i = 0; i < selectedMerchant.tabs.Count; i++)
                        {
                            for (int j = 0; j < selectedMerchant.tabs[i].items.Count; j++)
                            {
                                if (selectedMerchant.tabs[i].items[j] == slot.item)
                                {
                                    selectedMerchant.tabs[i].items.Remove(slot.item);
                                }
                            }
                        }
                        for (int i = 0; i < item.height; i++)
                        {
                            for (int j = 0; j < item.width; j++)
                            {
                                items[slot.itemStartNumber + merchantWidth * i + j].item          = new ItemClass();
                                items[slot.itemStartNumber + merchantWidth * i + j].item.itemName = "";
                                items[slot.itemStartNumber + merchantWidth * i + j].GetComponent <Image>().color = Color.white;
                                items[slot.itemStartNumber + merchantWidth * i + j].transform.Find("ItemIcon").gameObject.SetActive(false);
                                items[slot.itemStartNumber + merchantWidth * i + j].transform.Find("ItemFrame").gameObject.SetActive(false);
                            }
                        }
                    }
                    avaliableGoldText.text = player.money.ToString();
                    succes      = true;
                    failMessage = "";
                    return;
                }
                //There's no open slots in the inventory so display a fail message
                else
                {
                    succes      = false;
                    failMessage = "I need more space!";
                }
            }
            //Add the item to the inventory
            else if (inventory.AddItem(uGUIInventory.DeepCopy(slot.item)))
            {
                player.money -= slot.item.buyPrice;
                for (int i = 0; i < selectedMerchant.tabs.Count; i++)
                {
                    for (int j = 0; j < selectedMerchant.tabs[i].items.Count; j++)
                    {
                        if (selectedTab.tabType == selectedMerchant.tabs[i].tabType)
                        {
                            if (selectedMerchant.tabs[i].items[j].itemName == slot.item.itemName)
                            {
                                selectedMerchant.tabs[i].items.Remove(selectedMerchant.tabs[i].items[j]);
                                for (int k = 0; k < item.height; k++)
                                {
                                    for (int l = 0; l < item.width; l++)
                                    {
                                        items[slot.itemStartNumber + merchantWidth * k + l].item          = new ItemClass();
                                        items[slot.itemStartNumber + merchantWidth * k + l].item.itemName = "";
                                        items[slot.itemStartNumber + merchantWidth * k + l].GetComponent <Image>().color = Color.white;
                                        items[slot.itemStartNumber + merchantWidth * k + l].transform.Find("ItemIcon").gameObject.SetActive(false);
                                        items[slot.itemStartNumber + merchantWidth * k + l].transform.Find("ItemFrame").gameObject.SetActive(false);
                                    }
                                }
                                avaliableGoldText.text = player.money.ToString();
                                succes      = true;
                                failMessage = "";
                                return;
                            }
                        }
                    }
                }
            }
            //There's no open slots in the inventory so display a fail message
            else
            {
                succes      = false;
                failMessage = "I need more space!";
            }
            ResetTabs();
        }
        //The player doesn't have enough gold to purchase the item
        else
        {
            //Display a fail message
            succes      = false;
            failMessage = "Not enough gold!";
        }
    }