Пример #1
0
        public override void Run(TWEntity outputEntity)
        {
            foreach (var component in outputEntity.GetComponentsByType <OutputComponent>())
            {
                if (component.OutputType == OutputType.Regular)
                {
                    Console.WriteLine(component.Value);
                    Console.WriteLine();
                }
                //else if (component.OutputType == OutputType.Command)
                //{
                //    Console.WriteLine($"command: {component.Value}");
                //    Console.WriteLine();
                //}
                else if (component.OutputType == OutputType.Separator)
                {
                    Console.WriteLine();
                }
                else if (component.OutputType == OutputType.MessageOfTheDay)
                {
                    Console.WriteLine($"-[ {component.Value} ]-");
                    Console.WriteLine();
                }
            }

            outputEntity.Components.Clear();
        }
Пример #2
0
        public override void Run(TWEntity commandEntity, TWEntity playerEntity, TWEntity outputEntity)
        {
            var processedComponents = new List <CommandComponent>();

            foreach (var commandComponent in commandEntity.GetComponentsByType <CommandComponent>())
            {
                var command = commandComponent.Command !.ToLower();

                if (command == "inv" || command == "inventory")
                {
                    processedComponents.Add(commandComponent);

                    // get the players inventory component
                    var inventoryComponent = playerEntity.GetComponentByType <InventoryComponent>();

                    if (inventoryComponent != null)
                    {
                        var itemsAsString = inventoryComponent.GetItemsAsString();

                        if (string.IsNullOrEmpty(itemsAsString))
                        {
                            outputEntity.AddComponent(new OutputComponent("show player inventory", "You don't have any items in your inventory", OutputType.Regular));
                        }
                        else
                        {
                            outputEntity.AddComponent(new OutputComponent("show player inventory", $"inventory: {itemsAsString}", OutputType.Regular));
                        }
                    }
                }
            }

            commandEntity.RemoveComponents(processedComponents);
        }
Пример #3
0
        public override void Run(TWEntity playerEntity, List <TWEntity> itemEntities, List <TWEntity> roomEntities, TWEntity outputEntity)
        {
            var processedComponents = new List <TWComponent>();

            foreach (var component in playerEntity.GetComponentsByType <ItemActionComponent>())
            {
                processedComponents.Add(component);
                component.Action !(roomEntities, itemEntities, playerEntity, outputEntity, component);
            }

            playerEntity.RemoveComponents(processedComponents);
        }
Пример #4
0
        public void CanGetEntityComponentsByType()
        {
            // Arrange
            var entity = new TWEntity("test entity");

            entity.AddComponent(new TestComponent("test component 1"));
            entity.AddComponent(new TestComponent("test component 2"));
            // Act
            var components = entity.GetComponentsByType <TestComponent>();

            // Assert
            components.Should().HaveCount(2);
        }
Пример #5
0
        public static ItemDropComponent?GetItemDropComponentFromEntity(TWEntity entity, string itemName)
        {
            var items = entity.GetComponentsByType <ItemDropComponent>();

            if (items.Count > 0)
            {
                var takeItem = items.FirstOrDefault(x => x.Item.Name == itemName);

                if (takeItem != null)
                {
                    return(takeItem);
                }
            }

            return(null);
        }
Пример #6
0
        public override void Run(TWEntity commandEntity, TWEntity outputEntity)
        {
            var unknownCommandComponents = new List <UnknownCommandComponent>();

            commandEntity.GetComponentsByType <CommandComponent>().ForEach(x =>
            {
                unknownCommandComponents.Add(new UnknownCommandComponent("unknown command", x.Command !));
            });

            commandEntity.Components.Clear();

            if (unknownCommandComponents.Count > 0)
            {
                commandEntity.Components.AddRange(unknownCommandComponents);

                unknownCommandComponents.ForEach(x =>
                {
                    outputEntity.AddComponent(new OutputComponent("output for unknown command", $"I don't know how to do: {x.Command}", OutputType.Regular));
                });
            }
        }
Пример #7
0
        public override void Run(TWEntity commandEntity, TWEntity playerEntity, List <TWEntity> roomEntities, TWEntity outputEntity)
        {
            TextInfo myTI = new CultureInfo("en-US", false).TextInfo;
            var      processedComponents = new List <CommandComponent>();

            foreach (var commandComponent in commandEntity.GetComponentsByType <CommandComponent>())
            {
                var commandAsTitleCase = myTI.ToTitleCase(commandComponent.Command !);

                if (Enum.TryParse <Direction>(commandAsTitleCase, out Direction direction))
                {
                    processedComponents.Add(commandComponent);

                    var currentRoomComponent = playerEntity.GetComponentByName <IdComponent>("player current room");
                    var currentRoomEntity    = roomEntities.FirstOrDefault(x => x.Id == currentRoomComponent !.Id);
                    var currentRoomExits     = currentRoomEntity !.GetComponentsByType <ExitComponent>();
                    var exit = currentRoomExits.FirstOrDefault(x => x.Direction.ToString() == commandAsTitleCase);

                    if (exit != null)
                    {
                        var newRoomEntity = roomEntities.FirstOrDefault(x => x.Id == exit.RoomId);

                        if (newRoomEntity != null)
                        {
                            currentRoomComponent !.Id = newRoomEntity.Id;

                            playerEntity.AddComponent(new ShowDescriptionComponent("player new room", newRoomEntity, DescriptionType.Room));
                            playerEntity.AddComponent(Helper.GetRoomExitInfoForRoom(playerEntity, roomEntities, newRoomEntity));
                        }
                    }
                    else
                    {
                        outputEntity.AddComponent(new OutputComponent("output for inaccessible direction", "I cannot go in that direction", OutputType.Regular));
                    }

                    commandEntity.RemoveComponents(processedComponents);
                }
            }
        }
Пример #8
0
 public static ItemDropComponent?GetItemDropComponentOnEntity(TWEntity entity, ItemDropComponent itemDropComponent)
 {
     return(entity.GetComponentsByType <ItemDropComponent>().FirstOrDefault(x => x.Item.Id == itemDropComponent.Item.Id));
 }