示例#1
0
        private void RestoreItems(bool restoreEquipped, ItemCollection itemCollection, InventoryBase inventory, HashSet <ItemType> alreadyAddedItemTypes)
        {
            for (int i = 0; i < data.items.Count; i++)
            {
                var itemData = data.items[i];
                if (itemData.count == 0)
                {
                    continue;
                }
                if (itemData.equipped != restoreEquipped)
                {
                    continue;
                }
                var itemType = UCCUtility.GetItemType(itemCollection, itemData.itemID);
                inventory.PickupItemType(itemType, itemData.count, itemData.slot, true, restoreEquipped);
                var item = inventory.GetItem(itemData.slot, itemType);
                if (item == null)
                {
                    continue;
                }
                for (int j = 0; j < item.ItemActions.Length; j++)
                {
                    var usableItem = item.ItemActions[j] as UsableItem;
                    if (usableItem == null)
                    {
                        continue;
                    }

                    for (int k = 0; k < itemData.itemActionData.Count; ++k)
                    {
                        if (usableItem.ID != itemData.itemActionData[k].id)
                        {
                            continue;
                        }

#if ULTIMATE_CHARACTER_CONTROLLER_SHOOTER
                        var shootableWeapon = usableItem as ShootableWeapon;
                        if (shootableWeapon != null)
                        {
                            // Temporarily fill clip so inventory.PickupItemType doesn't auto-reload:
                            usableItem.SetConsumableItemTypeCount(shootableWeapon.ClipSize);
                        }
#endif
                        if (debug)
                        {
                            Debug.Log("UCC Saver on " + name + " restoring item: " + usableItem.name +
                                      " (" + itemData.itemActionData[k].consumableCount + "/" + itemData.itemActionData[k].count + ")", this);
                        }
                        var consumableItemType = usableItem.GetConsumableItemType();
                        if (itemData.itemActionData[k].count > 0 && !alreadyAddedItemTypes.Contains(consumableItemType))
                        {
                            inventory.PickupItemType(consumableItemType, itemData.itemActionData[k].count, -1, true, false);
                            alreadyAddedItemTypes.Add(consumableItemType);
                        }
                        usableItem.SetConsumableItemTypeCount(itemData.itemActionData[k].consumableCount);
                    }
                }
            }
        }
示例#2
0
        private void PickupItemTypeRPC(int itemTypeID, float count)
        {
            var itemType = ItemTypeTracker.GetItemType(itemTypeID);

            if (itemType == null)
            {
                return;
            }

            m_Inventory.PickupItemType(itemType, count, -1, false, false, false);
        }
        /// <summary>
        /// Picks up the ItemType.
        /// </summary>
        /// <param name="character">The character that should pick up the ItemType.</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="forceEquip">Should the item be force equipped?</param>
        /// <returns>True if an ItemType was picked up.</returns>
        public bool DoItemTypePickup(GameObject character, InventoryBase inventory, int slotID, bool immediatePickup, bool forceEquip)
        {
            // Add the ItemTypes to the Inventory. This allows the character to pick up the actual item and any consumable ItemTypes (such as ammo).
            var pickedUp = false;

            EventHandler.ExecuteEvent(character, "OnItemPickupStartPickup");
            if (m_ItemTypeCounts != null)
            {
                for (int i = 0; i < m_ItemTypeCounts.Length; ++i)
                {
                    if (inventory.PickupItemType(m_ItemTypeCounts[i].ItemType, m_ItemTypeCounts[i].Count, slotID, immediatePickup, forceEquip))
                    {
                        pickedUp = true;
                    }
                }
            }
            EventHandler.ExecuteEvent(character, "OnItemPickupStopPickup");
            return(pickedUp);
        }