Exemplo n.º 1
0
 /// <summary>Method called from button UI at a LootLocation to give one item to the player partyy</summary>
 /// <param name="selectionButton_">Reference to the LootSelectionButton that was used to call this method. It's required so we can get the correct item index</param>
 public void LootItemAtIndex(LootSelectionButton selectionButton_)
 {
     Debug.Log("Loot item at index " + selectionButton_.selectedItemIndex);
     if (this.lootUI.lootPanelObject.activeInHierarchy)
     {
         this.currentLocation.GetComponent <LootLocation>().GivePlayerItem(selectionButton_.selectedItemIndex);
         this.DisplayLootItems();
     }
 }
Exemplo n.º 2
0
    /// <summary>Method called from OpenLoot, LootItemAtIndex, and LootAllItems to update the display of items available</summary>
    private void DisplayLootItems()
    {
        //If for some reason the location isn't valid, we do nothing
        if (!this.lootUI.lootPanelObject.activeInHierarchy || !this.currentLocation.GetComponent <LootLocation>())
        {
            return;
        }

        //Deleting all selection buttons that aren't the main one
        Transform buttonParentTrans = this.lootUI.itemSelectionButton.transform.parent;

        for (int c = 0; c < buttonParentTrans.childCount; c++)
        {
            if (buttonParentTrans.GetChild(c) != this.lootUI.itemSelectionButton.transform)
            {
                Destroy(buttonParentTrans.GetChild(c).gameObject);
                c -= 1;
            }
        }

        //Looping through each item in the loot location and creating a new button for them
        LootLocation lootLoc = this.currentLocation.GetComponent <LootLocation>();

        for (int b = 0; b < lootLoc.spawnedItems.Length + 1; b++)
        {
            //For the first item, we don't create a new button but instead use the default one
            if (b == 0)
            {
                //If there are items that were spawned
                if (lootLoc.spawnedItems.Length > 0)
                {
                    if (lootLoc.spawnedItems[0] > 0)
                    {
                        this.lootUI.itemSelectionButton.gameObject.SetActive(true);
                        this.lootUI.itemSelectionButton.selectedItemIndex = 0;
                        this.lootUI.itemSelectionButton.itemNameText.text = lootLoc.lootTableItems[lootLoc.spawnedItems[b]].lootItem.itemNameID + "  x" + lootLoc.lootTableItems[lootLoc.spawnedItems[b]].stackQuantity;
                    }
                }
                //If the spawned items array is empty, this button can be used to store gold loot instead of items
                else if (lootLoc.spawnedItems.Length == 0 && lootLoc.spawnedGold > 0)
                {
                    this.lootUI.itemSelectionButton.gameObject.SetActive(true);
                    this.lootUI.itemSelectionButton.selectedItemIndex = 0;
                    this.lootUI.itemSelectionButton.itemNameText.text = lootLoc.spawnedGold + " Gold";
                }
                //Otherwise there's no loot at all and this button is hidden
                else
                {
                    this.lootUI.itemSelectionButton.gameObject.SetActive(false);
                }
            }
            //This index is technically out of bounds for the spawnedItems array, but it's used to hold the gold loot
            else if (b == lootLoc.spawnedItems.Length && lootLoc.spawnedGold > 0)
            {
                //Creating a new button to display the amount of gold in the location
                GameObject          newbutton       = GameObject.Instantiate(this.lootUI.itemSelectionButton.gameObject);
                LootSelectionButton newSelectButton = newbutton.GetComponent <LootSelectionButton>();
                newSelectButton.selectedItemIndex = b;
                newSelectButton.itemNameText.text = lootLoc.spawnedGold + " Gold";
            }
            //For all other loot items, we create a new selection button to display the item
            else
            {
                if (lootLoc.spawnedItems[b] > 0)
                {
                    GameObject          newbutton       = GameObject.Instantiate(this.lootUI.itemSelectionButton.gameObject);
                    LootSelectionButton newSelectButton = newbutton.GetComponent <LootSelectionButton>();
                    newSelectButton.selectedItemIndex = b;
                    newSelectButton.itemNameText.text = lootLoc.lootTableItems[lootLoc.spawnedItems[b]].lootItem.itemNameID + "  x" + lootLoc.lootTableItems[lootLoc.spawnedItems[b]].stackQuantity;
                }
            }
        }
    }