示例#1
0
        public ICommand GetCommand()
        {
            Type[] gameCommands = ScriptFactory.GetTypesWithInterface("ICommand");
            var    input        = currentPlayer.ReceiveInput().ToLower();

            string[] args = input.Split(' ');

            if (args.Length >= 1)
            {
                input = args[0];
            }

            if (string.IsNullOrEmpty(input))
            {
                return(new InvalidCommand());
            }

            foreach (Type command in gameCommands)
            {
                string correctedCommand = command.Name.ToLower();

                if (correctedCommand.StartsWith("command"))
                {
                    correctedCommand = correctedCommand.Substring("command".Length);
                }

                if (correctedCommand.EndsWith("command"))
                {
                    correctedCommand = correctedCommand.Substring(0, correctedCommand.Length - "command".Length);
                }

                if (correctedCommand == input)
                {
                    var commandToExecute = ScriptFactory.GetScript(command.FullName);

                    if (commandToExecute != null)
                    {
                        return((ICommand)commandToExecute);
                    }
                }
            }

            return(new InvalidCommand());
        }
示例#2
0
        /// <summary>
        /// Adds a doorway to the Room, linking it to another Room in the world.
        /// </summary>
        /// <param name="direction">The direction that the player must travel in order to move through the doorway</param>
        /// <param name="arrivalRoom">The room that the player will enter, once they walk through the doorway</param>
        /// <param name="autoAddReverseDirection">If true, the arrival room will have the opposite doorway automatically linked back to this Room</param>
        /// <param name="forceOverwrite">If true, if a doorway already exists for the specified direction, it will overwrite it.</param>
        public virtual void AddDoorway(AvailableTravelDirections direction, IRoom arrivalRoom, bool autoAddReverseDirection = true, bool forceOverwrite = true)
        {
            // Check if room is null.
            if (arrivalRoom == null)
            {
                return; // No null references within our collections!
            }
            // If this direction already exists, overwrite it
            // but only if 'forceOverwrite' is true
            if (Doorways.ContainsKey(direction))
            {
                // Remove the old door
                RemoveDoorway(direction);
                // Get a scripted Door instance to add back to the collection
                var door = (Door)ScriptFactory.GetScript(MudDesigner.Engine.Properties.EngineSettings.Default.DoorScript);
                door.SetArrivalRoom(arrivalRoom);
                door.SetDepartingRoom(this);
                door.SetFacingDirection(direction);

                Doorways.Add(direction, door);
            }
            // Direction does not exist, so lets add a new doorway
            else
            {
                // Get a scripted instance of a Door.
                var door = (Door)ScriptFactory.GetScript(MudDesigner.Engine.Properties.EngineSettings.Default.DoorScript);
                door.SetFacingDirection(direction);
                door.SetArrivalRoom(arrivalRoom);
                door.SetDepartingRoom(this);


                // Add the new doorway to this rooms collection.
                Doorways.Add(direction, door);

                // If autoreverse is enabled, add the doorway to the arrival room too.
                if (autoAddReverseDirection)
                {
                    arrivalRoom.AddDoorway(TravelDirections.GetReverseDirection(direction), this, false, forceOverwrite);
                }
            }
        }