예제 #1
0
        internal Inventory(InventoryType inventoryType, InventoryManagerComponent managerComponent)
        {
            InventoryType    = inventoryType;
            ManagerComponent = managerComponent;

            using var ctx = new UchuContext();
            var playerCharacter = ctx.Characters
                                  .Include(c => c.Items)
                                  .First(c => c.CharacterId == managerComponent.GameObject.ObjectId);

            var inventoryItems = playerCharacter.Items
                                 .Where(item => (InventoryType)item.InventoryType == inventoryType)
                                 .ToList();

            _items = inventoryItems.Select(
                i => Item.Instantiate(i.InventoryItemId, this)
                ).Where(item => !ReferenceEquals(item, default)).ToList();

            _size = inventoryType != InventoryType.Items ? 1000 : playerCharacter.InventorySize;

            foreach (var item in _items)
            {
                Object.Start(item);
            }
        }
예제 #2
0
        /// <summary>
        /// Initializes a new inventory for a given type
        /// </summary>
        /// <param name="inventoryType">The type of inventory to initialize</param>
        /// <param name="managerComponent">The manager of this inventory</param>
        internal Inventory(InventoryType inventoryType, InventoryManagerComponent managerComponent)
        {
            InventoryType    = inventoryType;
            ManagerComponent = managerComponent;

            if (managerComponent.GameObject.TryGetComponent <CharacterComponent>(out var character))
            {
                switch (inventoryType)
                {
                case InventoryType.Items:
                    Size = character.InventorySize;
                    break;

                case InventoryType.VaultItems:
                case InventoryType.VaultModels:
                    Size = character.VaultInventorySize;
                    break;

                default:
                    Size = 1000;
                    break;
                }
            }
        }