Example #1
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);
        }
Example #2
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);
        }
Example #3
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);
                }
            }
        }