Esempio n. 1
0
        private void RefreshCooking()
        {
            _firedWoods++;
            foreach (var holderObject in _sourceinventory.Slots)
            {
                if (holderObject != null && holderObject.Item != null && holderObject.Item is WoodResource)
                {
                    _destinationInventory.AddItem(HolderObjectFactory.GetItem(holderObject.Item.CookingResult.Key.GetType(), holderObject.Item.CookingResult.Value));
                    holderObject.ChangeAmount(1);
                }
                else if (holderObject != null &&
                         holderObject.Amount > 0 &&
                         holderObject.Item.CookingResult.Key != null &&
                         holderObject.Item.Converters.Contains(TypeConverter))
                {
                    if (_firedWoods % holderObject.Item.NeedWoodToCook == 0)
                    {
                        _destinationInventory.AddItem(HolderObjectFactory.GetItem(holderObject.Item.CookingResult.Key.GetType(), holderObject.Item.CookingResult.Value));
                        holderObject.ChangeAmount(1);
                    }
                }
            }

            if (_panel != null)
            {
                _panel.UpdateView(_sourceinventory, _destinationInventory);
            }

            if (!HasWood())
            {
                SnuffOut();
            }
        }
Esempio n. 2
0
    public void UnequipMainHand()
    {
        if (GetEquippedWeapon() != null && GetEquippedWeapon().GetWeaponType() != BaseWeapon.WEAPON_TYPE.WEAPON_FISTS)
        {
            inventory.AddItem(GetEquippedWeapon());
        }

        BaseWeapon emptyHand = new BaseWeapon();

        emptyHand.SetItemType(BaseItem.ITEM_TYPE.ITEM_EMPTY);

        equippedWeapon = emptyHand;
    }
Esempio n. 3
0
        public List <InventoryBase> GetInventoryList()
        {
            if (_currentItem != null)
            {
                _inventory.AddItem(HolderObjectFactory.GetItem(_currentItem.Item.GetType(), _currentItem.Amount, _currentItem.CurrentDurability));
            }

            var list = new List <InventoryBase> {
                _inventory
            };

            return(list);
        }
Esempio n. 4
0
        protected override void Init()
        {
            base.Init();

            if (!_slotInited)
            {
                _inventory = new InventoryBase();
                _inventory.Init(MaxSlots);
                foreach (var item in StartItems)
                {
                    _inventory.AddItem(HolderObjectFactory.GetItem(item.name, item.amount));
                }
            }
        }
Esempio n. 5
0
    public virtual bool MoveItem(int index, InventoryBase targetInventory, int targetIndex)
    {
        if (!IsValidIndex(index) ||
            targetInventory == null ||
            !targetInventory.IsValidIndex(targetIndex) ||
            !targetInventory.IsValidItemType(items[index]) ||
            (targetInventory.items[targetIndex] != null && !IsValidItemType(targetInventory.items[targetIndex])))
        {
            return(false);
        }

        // Add ExistingItem
        if (targetInventory.items[targetIndex]?.Info.AddCount(items[index].Info) ?? false)
        {
            if (items[index].Info.Count == 0)
            {
                DeleteItem(index);
            }

            // Update UI
            inventoryUI?.UpdateSlot(index);
            targetInventory.inventoryUI?.UpdateSlot(targetIndex);
            return(true);
        }

        // Move Item
        if (this != targetInventory && targetInventory.items[targetIndex] == null)
        {
            targetInventory.AddItem(items[index], targetIndex);
            DeleteItem(index, false);

            // On Item Move Callback
            targetInventory.items[targetIndex].OnMove();
        }
        // Swap Item
        else
        {
            Item fromBuffer = items[index];
            items[index] = targetInventory.items[targetIndex];
            targetInventory.items[targetIndex] = fromBuffer;

            if (this == targetInventory)
            {
                // Update UI
                inventoryUI?.MoveSlot(index, targetIndex);
            }
            else
            {
                items[index].OnAdd(this);
                targetInventory.items[targetIndex].OnAdd(targetInventory);

                // Update UI
                inventoryUI?.UpdateSlot(index);
                targetInventory.inventoryUI?.UpdateSlot(targetIndex);
            }

            // On Item Move Callback
            targetInventory.items[targetIndex].OnMove();
            items[index]?.OnMove();
        }

        return(true);
    }
Esempio n. 6
0
        /// <summary>
        /// Picks up the item.
        /// </summary>
        /// <param name="character">The character that should pick up the item.</param>
        /// <param name="inventory">The inventory belonging to the character.</param>
        /// <param name="slotID">The slot ID that picked up the item. A -1 value will indicate no specified slot.</param>
        /// <param name="immediatePickup">Should the item be picked up immediately?</param>
        /// <param name="pickupItemIdentifier">Should the ItemIdentifier be picked up? This should be false if the ItemIdentifier will later be picked up.</param>
        public void DoItemPickup(GameObject character, InventoryBase inventory, int slotID, bool immediatePickup, bool pickupItemIdentifier)
        {
            // Add any items to the character.
            if (m_ItemPickupSet != null && m_ItemPickupSet.Length > 0)
            {
                // Spawn the item under the character's ItemPlacement GameObject.
                var itemPlacement = character.GetComponentInChildren <ItemPlacement>(true);
                if (itemPlacement == null)
                {
                    Debug.LogError($"Error: ItemPlacement doesn't exist under the character {character.name}.");
                    return;
                }
                for (int i = 0; i < m_ItemPickupSet.Length; ++i)
                {
                    // If the Item is null then only the ItemSet should be added.
                    if (m_ItemPickupSet[i].Item == null)
                    {
                        var itemSetManager = character.GetCachedComponent <ItemSetManagerBase>();
                        if (itemSetManager == null)
                        {
                            continue;
                        }

                        IItemCategoryIdentifier category = null;
                        var addItemSetParents            = true;
                        // If no item is specified then the category should be retrieved from the Item Definition.
                        if (m_ItemPickupSet[i].CategoryID == 0)
                        {
                            for (int j = 0; j < m_ItemPickupSet[i].ItemSet.Slots.Length; ++j)
                            {
                                var itemDefinition = m_ItemPickupSet[i].ItemSet.Slots[j];
                                if (itemDefinition != null)
                                {
                                    category = itemDefinition.GetItemCategory();
                                }
                            }
                        }
                        else
                        {
                            // A specific category was specified.
                            if (itemSetManager.CategoryItemSets != null)
                            {
                                for (int j = 0; j < itemSetManager.CategoryItemSets.Length; ++j)
                                {
                                    if (itemSetManager.CategoryItemSets[j].CategoryID == m_ItemPickupSet[i].CategoryID)
                                    {
                                        category          = itemSetManager.CategoryItemSets[j].ItemCategory;
                                        addItemSetParents = false;
                                        break;
                                    }
                                }
                            }
                        }

                        if (category != null)
                        {
                            itemSetManager.AddItemSet(m_ItemPickupSet[i].ItemSet, m_ItemPickupSet[i].Default, category, addItemSetParents);
                        }

                        continue;
                    }

                    if (slotID != -1 && (slotID >= m_ItemPickupSet[i].ItemSet.Slots.Length || m_ItemPickupSet[i].ItemSet.Slots[slotID] == null))
                    {
                        continue;
                    }

                    var item = m_ItemPickupSet[i].Item.GetCachedComponent <Item>();
                    if (inventory.HasItem(item))
                    {
                        continue;
                    }

                    // Instantiate the item that will be added to the character.
                    item = Item.SpawnItem(character, item);

                    // Add the ItemSet before the item so the item can use the added ItemSet.
                    if (m_ItemPickupSet[i].ItemSet != null)
                    {
                        var itemSetManager = character.GetCachedComponent <ItemSetManager>();
                        if (itemSetManager != null)
                        {
                            m_ItemPickupSet[i].ItemSet.ItemIdentifiers = new Shared.Inventory.IItemIdentifier[m_ItemPickupSet[i].ItemSet.Slots.Length];
                            if (item.SlotID >= m_ItemPickupSet[i].ItemSet.ItemIdentifiers.Length)
                            {
                                Debug.LogError($"Error: Unable to assign the ItemIdentifier at slot {item.SlotID}. The Slot Count should be increased on the item pickup.");
                                continue;
                            }
                            m_ItemPickupSet[i].ItemSet.ItemIdentifiers[item.SlotID] = item.ItemIdentifier;
                            itemSetManager.AddItemSet(item, m_ItemPickupSet[i].ItemSet, m_ItemPickupSet[i].Default);
                        }
                    }

                    // All of the setup is complete - add the item to the inventory.
                    inventory.AddItem(item, false, false);
                }
            }

            m_PickedUp = m_AlwaysPickup;
            if (pickupItemIdentifier)
            {
                // Even if the ItemIdentifier doesn't have space it may be equipped by the inventory. The object should be considered as picked up in this situation.
                EventHandler.RegisterEvent <Item, int>(character, "OnAbilityWillEquipItem", OnWillEquipItem);
                if (DoItemIdentifierPickup(character, inventory, slotID, immediatePickup, true))
                {
                    m_PickedUp = true;
                }
                EventHandler.UnregisterEvent <Item, int>(character, "OnAbilityWillEquipItem", OnWillEquipItem);
            }
            else
            {
                // If pickup ItemIdentifier is false then the PickupItem ability will pick up the ItemIdentifier.
                m_PickedUp = true;
            }

            if (m_PickedUp)
            {
                ObjectPickedUp(character);
            }
        }
        /// <summary>
        /// Picks up the item.
        /// </summary>
        /// <param name="character">The character that should pick up the item.</param>
        /// <param name="inventory">The inventory belonging to the character.</param>
        /// <param name="slotID">The slot ID that picked up the item. A -1 value will indicate no specified slot.</param>
        /// <param name="immediatePickup">Should the item be picked up immediately?</param>
        /// <param name="pickupItemType">Should the ItemType be picked up? This should be false if the ItemType will later be picked up.</param>
        public void DoItemPickup(GameObject character, InventoryBase inventory, int slotID, bool immediatePickup, bool pickupItemType)
        {
            // Add any items to the character.
            if (m_ItemPickupSet != null && m_ItemPickupSet.Length > 0)
            {
                // Spawn the item under the character's ItemPlacement GameObject.
                var itemPlacement = character.GetComponentInChildren <ItemPlacement>(true);
                if (itemPlacement == null)
                {
                    Debug.LogError("Error: ItemPlacement doesn't exist under the character " + character.name);
                    return;
                }
                for (int i = 0; i < m_ItemPickupSet.Length; ++i)
                {
                    // The Item must exist.
                    if (m_ItemPickupSet[i].Item == null || (slotID != -1 && (slotID >= m_ItemPickupSet[i].ItemSet.Slots.Length || m_ItemPickupSet[i].ItemSet.Slots[slotID] == null)))
                    {
                        continue;
                    }

                    var item = m_ItemPickupSet[i].Item.GetCachedComponent <Item>();

                    // Add the ItemSet before the item so the item can use the added ItemSet.
                    if (m_ItemPickupSet[i].ItemSet != null)
                    {
                        var itemSetManager = character.GetCachedComponent <ItemSetManager>();
                        if (itemSetManager != null)
                        {
                            itemSetManager.AddItemSet(item, m_ItemPickupSet[i].ItemSet, m_ItemPickupSet[i].Default);
                        }
                    }

                    // Instantiate and add the item to the character.
                    if (!inventory.HasItem(item))
                    {
                        var itemGameObject = ObjectPool.Instantiate(m_ItemPickupSet[i].Item, Vector3.zero, Quaternion.identity, itemPlacement.transform);
                        itemGameObject.name = m_ItemPickupSet[i].Item.name;
                        itemGameObject.transform.localPosition = Vector3.zero;
                        itemGameObject.transform.localRotation = Quaternion.identity;
                        item = itemGameObject.GetComponent <Item>();
                        inventory.AddItem(item, false);
                    }
                }
            }

            m_PickedUp = m_AlwaysPickup;
            if (pickupItemType)
            {
                // Even if the ItemType doesn't have space it may be equipped by the inventory. The object should be considered as picked up in this situation.
                EventHandler.RegisterEvent <Item, int>(character, "OnAbilityWillEquipItem", OnWillEquipItem);
                if (DoItemTypePickup(character, inventory, slotID, immediatePickup, true))
                {
                    m_PickedUp = true;
                }
                EventHandler.UnregisterEvent <Item, int>(character, "OnAbilityWillEquipItem", OnWillEquipItem);
            }
            else
            {
                // If pickup ItemType is false then the PickupItem ability will pick up the ItemType.
                m_PickedUp = true;
            }

            if (m_PickedUp)
            {
                ObjectPickedUp(character);
            }
        }