private void PopulateSectionDictionary(Entity.EquipmentSlot slot)
    {
        EquipmentSlotFilter = slot;
        _playerInventory    = GameManager.Instance.Player.Inventory;
        _sortedItems        = new Dictionary <string, List <Item> >();

        foreach (var item in _playerInventory.Values)
        {
            if (!item.EquipmentSlots.Contains(EquipmentSlotFilter))
            {
                continue;
            }

            if (_sortedItems.ContainsKey(item.ItemType))
            {
                _sortedItems[item.ItemType].Add(item);
            }
            if (!_sortedItems.ContainsKey(item.ItemType))
            {
                _sortedItems.Add(item.ItemType, new List <Item> {
                    item
                });
            }
        }
    }
    public void DisplayAvailableEquipmentForSelectedEquipmentSlot(Entity.EquipmentSlot slot)
    {
        _itemSections = new List <GameObject>();
        _buttons      = new Dictionary <char, GameObject>();

        PopulateSectionDictionary(slot);

        _keyMapLetter = 'a';
        foreach (var section in _sortedItems.Keys)
        {
            var sectionHeader = Instantiate(SectionPrefab, new Vector3(0, 0), Quaternion.identity);
            sectionHeader.transform.SetParent(_sectionParent);
            _itemSections.Add(sectionHeader);

            var sectionHeaderText = sectionHeader.GetComponent <TextMeshProUGUI>();
            sectionHeaderText.text = FirstCharToUpper(section) + "s";

            var itemButtonsParent = sectionHeader.transform;

            foreach (var item in _sortedItems[section])
            {
                var itemButton = Instantiate(ButtonPrefab, new Vector3(0, 0), Quaternion.identity);
                itemButton.transform.SetParent(itemButtonsParent);
                _buttons.Add(_keyMapLetter, itemButton);

                var textFields = itemButton.GetComponentsInChildren <TextMeshProUGUI>(true);

                //todo come up with some kind of naming system based on material or legend
                if (item.ItemCategory.Equals("weapon"))
                {
                    textFields[1].text = "-  " + item.ItemType + "     [ " + item.ItemDice.NumDice + "d" + item.ItemDice.NumSides + " ]"; //todo add a sword icon
                    textFields[0].text = _keyMapLetter.ToString();
                }
                else if (item.ItemCategory.Equals("armor"))
                {
                    var defense = ((Armor)item).Defense;
                    textFields[1].text = "-  " + item.ItemType + "     [ " + defense + " def ]"; //todo replace def with a shield icon
                    textFields[0].text = _keyMapLetter.ToString();
                }
                textFields[2].text = item.Id.ToString();
                NextKeyMapLetter();
            }
        }

        UnequipButton.SetActive(GameManager.Instance.Player.Equipped[slot] != null);

        FilteredInventoryWindow.SetActive(true);
        TitleBar.SetActive(true);
        ActionBar.SetActive(true);
        gameObject.SetActive(true);
    }
Esempio n. 3
0
    public Item GetRandomItemByEquipmentSlot(Entity.EquipmentSlot slot, ItemRarity rarityCap = ItemRarity.Common)
    {
        var templatesForSlot = new List <ItemTemplate>();

        foreach (var templateType in _baseItemTemplateTypes)
        {
            var currentTemplate = ItemTemplateLoader.GetItemTemplate(templateType);

            var validSlots = GetEquipmentSlotsForSlotType(currentTemplate.EquipmentSlotType);

            if (validSlots.Contains(slot))
            {
                templatesForSlot.Add(currentTemplate);
            }
        }

        if (templatesForSlot.Count < 1)
        {
            return(null);
        }

        var itemTemplate = templatesForSlot[Random.Range(0, templatesForSlot.Count)];

        if (rarityCap == ItemRarity.Common)
        {
            return(GetItemFromTemplate(itemTemplate, rarityCap));
        }

        const int maxTries = 2;

        var rarity = GlobalHelper.GetRandomEnumValue <ItemRarity>();

        var currentTry = 1;

        while (currentTry <= maxTries && rarity > rarityCap)
        {
            rarity = GlobalHelper.GetRandomEnumValue <ItemRarity>();
            currentTry++;
        }

        return(GetItemFromTemplate(itemTemplate, rarity));
    }