Exemplo n.º 1
0
        /// <summary>
        /// Returns true if the specified ItemSet is valid. A valid ItemSet means the character has all of the items specified in the inventory.
        /// </summary>
        /// <param name="categoryIndex">The index of the ItemSet category.</param>
        /// <param name="itemSetIndex">The ItemSet within the category.</param>
        /// <param name="checkIfCanSwitchTo">Should the ItemSet be checked if it can be switched to?</param>
        /// <param name="allowedSlotsMask">The bitwise mask indicating which slots are allowed.</param>
        /// <returns>True if the specified ItemSet is valid.</returns>
        public bool IsItemSetValid(int categoryIndex, int itemSetIndex, bool checkIfCanSwitchTo, int allowedSlotsMask = -1)
        {
            if (itemSetIndex == -1 || itemSetIndex >= m_CategoryItemSets[categoryIndex].ItemSetList.Count)
            {
                return(false);
            }

            var itemSet = m_CategoryItemSets[categoryIndex].ItemSetList[itemSetIndex];

            // The ItemSet isn't valid if it isn't enabled.
            if (!itemSet.Enabled)
            {
                return(false);
            }

            // The ItemSet may not be able to be switched to.
            if (checkIfCanSwitchTo && !itemSet.CanSwitchTo)
            {
                return(false);
            }

            for (int i = 0; i < itemSet.Slots.Length; ++i)
            {
                if (itemSet.Slots[i] == null)
                {
                    continue;
                }

                // It only takes one item for the ItemSet not to be valid.
                var item = m_Inventory.GetItem(i, itemSet.Slots[i]);
                if (item == null)
                {
                    return(false);
                }

                // The item may not be in the allowed layer mask.
                if (allowedSlotsMask != -1 && m_CategoryItemSets[categoryIndex].DefaultItemSetIndex != itemSetIndex && !MathUtility.InLayerMask(i, allowedSlotsMask))
                {
                    return(false);
                }

                // Ensure the inventory has the number of items required for the current ItemSet.
                var requiredCount = 0;
                for (int j = 0; j < itemSet.Slots.Length; ++j)
                {
                    if (itemSet.Slots[j] == item.ItemType)
                    {
                        requiredCount++;
                    }
                }
                if (m_Inventory.GetItemTypeCount(item.ItemType) < requiredCount)
                {
                    return(false);
                }

                // Usable items may not be able to be equipped if they don't have any consumable ItemTypes left.
                for (int j = 0; j < item.ItemActions.Length; ++j)
                {
                    var usableItem = item.ItemActions[j] as IUsableItem;
                    if (usableItem != null)
                    {
                        if (!usableItem.CanEquipEmptyItem && usableItem.GetConsumableItemType() != null && m_Inventory.GetItemTypeCount(usableItem.GetConsumableItemType()) == 0)
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns true if the specified ItemSet is valid. A valid ItemSet means the character has all of the items specified in the inventory.
        /// </summary>
        /// <param name="categoryIndex">The index of the ItemSet category.</param>
        /// <param name="itemSetIndex">The ItemSet within the category.</param>
        /// <param name="checkIfCanSwitchTo">Should the ItemSet be checked if it can be switched to?</param>
        /// <param name="allowedSlotsMask">The bitwise mask indicating which slots are allowed.</param>
        /// <returns>True if the specified ItemSet is valid.</returns>
        public bool IsItemSetValid(int categoryIndex, int itemSetIndex, bool checkIfCanSwitchTo, int allowedSlotsMask = -1)
        {
            if (itemSetIndex == -1 || itemSetIndex >= m_CategoryItemSets[categoryIndex].ItemSetList.Count)
            {
                return(false);
            }

            var itemSet = m_CategoryItemSets[categoryIndex].ItemSetList[itemSetIndex];

            // The ItemSet isn't valid if it isn't enabled.
            if (!itemSet.Enabled)
            {
                return(false);
            }

            // The ItemSet may not be able to be switched to.
            if (checkIfCanSwitchTo && !itemSet.CanSwitchTo)
            {
                return(false);
            }

            var requiredCount  = 0;
            var availableCount = 0;

            m_CheckedItemIdentifiers.Clear();
            for (int i = 0; i < itemSet.Slots.Length; ++i)
            {
                if (itemSet.Slots[i] == null)
                {
                    continue;
                }

                // If the ItemIdentifier is null then the item hasn't been added yet.
                if (itemSet.ItemIdentifiers[i] == null)
                {
                    return(false);
                }

                // The item may not be in the allowed layer mask.
                if (allowedSlotsMask != -1 && m_CategoryItemSets[categoryIndex].DefaultItemSetIndex != itemSetIndex && !MathUtility.InLayerMask(i, allowedSlotsMask))
                {
                    return(false);
                }

                // It only takes one item for the ItemSet not to be valid.
                var item = m_Inventory.GetItem(itemSet.ItemIdentifiers[i], i);
                if (item == null)
                {
                    return(false);
                }

                // Usable items may not be able to be equipped if they don't have any consumable ItemIdentifiers left.
                for (int j = 0; j < item.ItemActions.Length; ++j)
                {
                    var usableItem = item.ItemActions[j] as IUsableItem;
                    if (usableItem != null)
                    {
                        if (!usableItem.CanEquipEmptyItem && usableItem.GetConsumableItemIdentifier() != null && m_Inventory.GetItemIdentifierAmount(usableItem.GetConsumableItemIdentifier()) == 0)
                        {
                            return(false);
                        }
                    }
                }

                // Remember the count to ensure the correct number of items exist within the inventory.
                requiredCount++;
                if (!m_CheckedItemIdentifiers.Contains(item.ItemIdentifier))
                {
                    availableCount += m_Inventory.GetItemIdentifierAmount(item.ItemIdentifier);
                    m_CheckedItemIdentifiers.Add(item.ItemIdentifier);
                }
            }

            // Ensure the inventory has the number of items required for the current ItemSet.
            if (availableCount < requiredCount)
            {
                return(false);
            }

            return(true);
        }