Ejemplo n.º 1
0
    /*public void RestoreItems(int[] restoredSlotID, int[] restoredValue, int[] restoredName){
     *      slotID [indexID] = item.itemID;
     *      slotValue [indexID] = item.itemValue;
     *      slotName [indexID] = item.itemName;
     *      slotDesc [indexID] = item.itemDesc;
     *      slotSprite [indexID] = item.itemSprite;
     *      slotType [indexID] = item.itemType;
     *      slotIcon[indexID].sprite = item.itemSprite;
     *      slotStack [indexID]++;
     *      EnableItem(ID);
     * }*/

    public void PurchaseItem(int ID)      //This method allows the player to purchase an item based on value of given item ID
    {
        BarController coinScript = this.gameObject.GetComponent <BarController>();

        if (InventoryFull() == false)
        {
            Debug.Log(coinScript.GetCoins());
            Item item = ItemDatabase.GetItem(storeItems[ID]);
            Debug.Log(item.itemValue);
            if (coinScript.GetCoins() >= item.itemValue)
            {
                //Subtract the correct amount of coins
                coinScript.SetCoins(coinScript.GetCoins() - item.itemValue);
                ItemClicked(storeItems[ID]);
                coinScript.InvokeSound(coinScript.craftSound);
                StartCoroutine(coinScript.InvokeMessage("+ITEM!", 1f));
            }
            else
            {
                //YOU DONT HAVE ENOUGH COINS
                coinScript.InvokeSound(coinScript.errorSound);
                StartCoroutine(coinScript.InvokeMessage("NOT ENOUGH COINS!", 1f));
            }
        }
        else
        {
            coinScript.InvokeSound(coinScript.errorSound);
            StartCoroutine(coinScript.InvokeMessage("INVENTORY FULL!", 1f));
        }
    }