Example #1
0
 void setShopDisplay()
 {
     shopDisplay.SetActive(true);
     shopTilesUI.shopItemList = sellingItems;
     shopTilesUI.prices       = sellingItemsPrices;
     shopTilesUI.updateUI();
     inventory.inventory.SetActive(true);
     Time.timeScale = 0;
     inventory.UpdateUI();
 }
Example #2
0
    public void purchaseItem()
    {
        if (isHubTile == false)
        {
            int gold      = tallyGold();
            int remainder = price;

            int goldStacks = Mathf.FloorToInt((float)gold / 1000);

            int goldStacksAfterPriceReduction = Mathf.FloorToInt((float)(gold - price) / 1000);

            if
            (
                gold >= price &&
                (inventory.itemList.Count < PlayerItems.maxInventorySize || goldStacksAfterPriceReduction < goldStacks) &&
                displayInfo != null
            )
            {
                inventory.itemList.Add(displayInfo.gameObject);
                int index = inventory.itemList.Count - 1;
                while (remainder > 0)
                {
                    while (inventory.itemList[index].GetComponent <DisplayItem>().goldValue == 0)
                    {
                        index--;
                    }

                    if (remainder >= inventory.itemList[index].GetComponent <DisplayItem>().goldValue)
                    {
                        remainder -= inventory.itemList[index].GetComponent <DisplayItem>().goldValue;
                        inventory.itemList.Remove(inventory.itemList[index]);
                    }
                    else
                    {
                        inventory.itemList[index].GetComponent <DisplayItem>().goldValue -= remainder;
                        remainder = 0;
                    }
                }
                int itemListIndex = shopTilesUI.shopItemList.IndexOf(displayInfo.gameObject);
                shopTilesUI.shopItemList.Remove(displayInfo.gameObject);
                shopTilesUI.prices.Remove(shopTilesUI.prices[itemListIndex]);
                deleteSlot();
                inventory.UpdateUI();
                FindObjectOfType <AudioManager>().PlaySound("Purchase Item");
            }
        }
        else
        {
            int gold = HubProperties.storeGold;
            if
            (
                gold >= price &&
                inventory.itemList.Count < GameObject.Find("PlayerShip").GetComponent <Inventory>().inventorySize &&
                displayInfo != null
            )
            {
                HubProperties.storeGold -= price;
                inventory.itemList.Add(displayInfo.gameObject);
                int itemListIndex = shopTilesUI.shopItemList.IndexOf(displayInfo.gameObject);
                shopTilesUI.shopItemList.Remove(displayInfo.gameObject);
                shopTilesUI.prices.Remove(shopTilesUI.prices[itemListIndex]);
                deleteSlot();
                inventory.UpdateUI();
                FindObjectOfType <AudioManager>().PlaySound("Purchase Item");
            }
        }
        shopTilesUI.updateUI();
    }