void Start()
    {
        Storage_Manager storageManager = GameObject.Find("Storage_Manager").GetComponent <Storage_Manager>();

        textToDisplayLostItems.text += "\n";

        foreach (Lost_Item lostItem in items)
        {
            Item_And_Quantity stored = storageManager.GetStoredItemAndQuantity(lostItem.itemToLose);
            Item_And_Quantity toLose = new Item_And_Quantity(stored.item, 0);
            int randomAmount         = Random.Range(lostItem.minimumLost, lostItem.maximumLost);

            if (stored.quantity > randomAmount)
            {
                toLose.quantity = ( uint )randomAmount;
                storageManager.SubtractQuantity(toLose);
            }
            else if (stored.quantity == 0)
            {
            }
            else
            {
                // lose all
                storageManager.SubtractQuantity(stored);
            }

            textToDisplayLostItems.text += toLose.item.name + " x" + toLose.quantity.ToString() + '\n';
        }
    }
Example #2
0
    void OnClickCraftableItem(Item craftableItem)
    {
        selectedItemToCraft = craftableItem;

        foreach (GameObject craftItemScreen in requiredCraftItemsScreens)
        {
            GameObject.Destroy(craftItemScreen);
        }
        requiredCraftItemsScreens.Clear();

        craftDialog.SetActive(true);

        bool canCraft = true;

        foreach (Item_And_Quantity requiredItem in selectedItemToCraft.requiredMaterialsToCraft.requiredItems)
        {
            Item_And_Quantity storedRequiredItem = storageManager.GetStoredItemAndQuantity(requiredItem);

            GameObject newCraftItemScreen = GameObject.Instantiate(itemTemplate);
            newCraftItemScreen.transform.SetParent(craftMaterialRequirementsParent, false);
            requiredCraftItemsScreens.Add(newCraftItemScreen);

            Screen_Item_Manager newCraftItemManager = newCraftItemScreen.GetComponent <Screen_Item_Manager>();
            newCraftItemManager.nameText.text     = requiredItem.item.name;
            newCraftItemManager.quantityText.text = storedRequiredItem.quantity + "/" + requiredItem.quantity.ToString();
            newCraftItemManager.image.sprite      = requiredItem.item.storageSprite;

            if (storedRequiredItem.quantity >= requiredItem.quantity)
            {
                newCraftItemManager.quantityText.color = Color.green;
            }
            else
            {
                newCraftItemManager.quantityText.color = Color.red;
                canCraft = false;
            }
        }

        if (canCraft)
        {
            craftButton.interactable = true;
        }
        else
        {
            craftButton.interactable = false;
        }
    }
    void RefreshScreen()
    {
        // Clear screens
        foreach (GameObject itemScreen in itemScreens)
        {
            GameObject.Destroy(itemScreen);
        }
        itemScreens.Clear();

        foreach (GameObject perkScreen in perkScreens)
        {
            GameObject.Destroy(perkScreen);
        }
        perkScreens.Clear();

        // Level
        int homeLevel = homeManager.CurrentLevel();

        if (homeManager.HasUpgradeAvailable())
        {
            homeLevelText.text = "HOME UPGRADE " + (homeLevel + 1).ToString();

            canUpgrade = true;

            storedItems            = new List <Item_And_Quantity>();
            itemsRequiredToUpgrade = homeManager.GetRequiredItemsToUpgrade();
            foreach (Item_And_Quantity requiredItemAndQuantity in itemsRequiredToUpgrade)
            {
                // Get stored item
                Item_And_Quantity storedItem = storageManager.GetStoredItemAndQuantity(requiredItemAndQuantity);
                storedItems.Add(storedItem);

                // Add item to GUI
                GameObject newItemScreen = GameObject.Instantiate(itemTemplate);
                newItemScreen.transform.SetParent(itemPanelParent, false);
                itemScreens.Add(newItemScreen);

                Screen_Item_Manager itemScreen = newItemScreen.GetComponent <Screen_Item_Manager>();
                itemScreen.nameText.text     = requiredItemAndQuantity.item.name;
                itemScreen.quantityText.text = storedItem.quantity.ToString() + " / " + requiredItemAndQuantity.quantity.ToString();
                itemScreen.image.sprite      = requiredItemAndQuantity.item.storageSprite;

                // Determine if can upgrade
                if (storedItem.quantity < requiredItemAndQuantity.quantity)
                {
                    canUpgrade = false;
                    itemScreen.quantityText.color = Color.red;
                }
                else
                {
                    itemScreen.quantityText.color = Color.green;
                }
            }

            // Add perks
            List <string> perks = homeManager.GetPerksOfUpgrade();

            foreach (string perk in perks)
            {
                GameObject newPerkScreen = GameObject.Instantiate(perkTemplate, perkPanelParent, false);
                perkScreens.Add(newPerkScreen);

                Screen_Perk_Manager perkScreenManager = newPerkScreen.GetComponent <Screen_Perk_Manager>();
                perkScreenManager.perkText.text = perk;
            }
        }
        else
        {
            homeLevelText.text = "MAX HOME LEVEL REACHED";
            canUpgrade         = false;
            upgradeButton.gameObject.SetActive(false);
        }

        if (canUpgrade)
        {
            upgradeButton.interactable = true;
        }
        else
        {
            upgradeButton.interactable = false;
        }
    }