Esempio n. 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);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Takes a list of database items of a player and uses those to initialize the inventory
        /// </summary>
        /// <param name="clientContext">The client context to load extra item info from</param>
        /// <param name="items">The items to initialize the inventory with </param>
        public async Task LoadItems(IEnumerable <InventoryItem> items)
        {
            var initializeTasks = items.Select(async i =>
            {
                var item = await Item.Instantiate(i, ManagerComponent.GameObject, this);
                if (item != null)
                {
                    Object.Start(item);
                    item.Layer = StandardLayer.Hidden;
                }
            });

            await Task.WhenAll(initializeTasks);
        }
Esempio n. 3
0
        private void SpawnTarget(Player player)
        {
            // Create new target
            this._spawnedTarget = GameObject.Instantiate(new LevelObjectTemplate
            {
                Lot      = Targets[Math.Min(this._targetsDestroyed / 2, Targets.Length - 1)],
                Position = this.GameObject.Transform.Position,
                Rotation = this._targetRotation,
                Scale    = 1,
                LegoInfo = new LegoDataDictionary(),
            }, this.Zone);

            Object.Start(this._spawnedTarget);
            GameObject.Construct(this._spawnedTarget);

            var stats = this._spawnedTarget.GetComponent <DestroyableComponent>();

            // Whenever the target takes damage, increase score by the amount of damage dealt.
            // It also increases the score when other players damage the target.
            // This is intentional; according to the LU wiki, this is how it worked in Live as well.
            Listen(stats.OnHealthChanged, (u, i) =>
            {
                if (i >= 0) // Health gets reset to max when object dies
                {
                    return;
                }
                this.UpdateActivityValue(player, 0, -i);
                this.SetNetworkVar("totalDmg", this.GetActivityValue(player, 0));
            });

            // If the timer hasn't ended yet, spawn a new target when this one dies.
            var destructibleComponent = this._spawnedTarget.GetComponent <DestructibleComponent>();

            Listen(destructibleComponent.OnSmashed, (smasher, lootOwner) =>
            {
                Destroy(this._spawnedTarget);
                this._targetsDestroyed++;
                if (this._active)
                {
                    this.SpawnTarget(player);
                }
            });
        }