Exemple #1
0
        public static void AddItemToPlayersInventory(TWEntity playerEntity, TWEntity itemOnEntity, ItemDropComponent itemDropComponent)
        {
            var inventoryComponent = playerEntity.GetComponentByType <InventoryComponent>();

            if (inventoryComponent != null)
            {
                var itemInInventory = inventoryComponent.Items.FirstOrDefault(x => x.Id == itemDropComponent.Item.Id);

                if (itemInInventory != null)
                {
                    itemInInventory.Quantity += itemDropComponent.Item.Quantity;
                }
                else
                {
                    inventoryComponent.AddItem(
                        new InventoryItem
                    {
                        Id       = itemDropComponent.Item.Id,
                        Name     = itemDropComponent.Item.Name,
                        Quantity = itemDropComponent.Item.Quantity
                    }
                        );
                }

                var itemToRemove = GetItemDropComponentOnEntity(itemOnEntity, itemDropComponent);

                if (itemToRemove != null)
                {
                    itemOnEntity.RemoveComponent(itemToRemove);
                }
            }
        }
Exemple #2
0
        public override void Run(TWEntity playerEntity, Action action)
        {
            var component = playerEntity.GetComponentByType <QuitComponent>();

            if (component != null)
            {
                action();

                playerEntity.RemoveComponent(component);
            }
        }
Exemple #3
0
        public void CanRemoveEntityComponent()
        {
            // Arrange
            var    entity        = new TWEntity("test entity");
            string componentName = "test description component";
            string description   = "This is a test description";

            entity.AddComponent(new DescriptionComponent(componentName, description));
            // Act
            var component = entity.GetComponentByName <DescriptionComponent>(componentName);

            if (component != null)
            {
                entity.RemoveComponent(component);
            }

            // Assert
            entity.Components.Should().BeEmpty();
        }