- Deleted the following commands from the engine: Exit, GetTime, LinkRoom, Load, Look, Save and Walk. These are now part of the MudGame script library. - Revised all of the Commands prior to moving them to the Script Library. They are now very well commented. - Optimized the player login code. - All commands now support the Help command. - Game now has a MinimumPasswordSize property for setting the required minimum characters for a players password. - System.Linq and System.Text using statements added to scripts when they are compiled. Script writers no longer need to type out the fully qualified name of a Type within those namespaces. MudGame: - Added the following commands to the script library: Exit, GetTime, LinkRoom, Load, Look, Save, Walk. - Added 76 lines of comments to WorldCalifornia to better help new users understand how to create their game worlds via script. - The Clear, Help, Say and Create commands have been given better commenting. - Existing scripts have been given some better optimizations.
113 lines
5.6 KiB
C#
113 lines
5.6 KiB
C#
/// <summary>
|
|
/// The Walk command allows players to walk from Room to Room, traversing the Mud world.
|
|
/// The command supports all of the available travel directions found within the
|
|
/// MudEngine.GameObjects.Environment.AvailableTravelDirections enum.
|
|
/// </summary>
|
|
public class CommandWalk : IGameCommand
|
|
{
|
|
/// <summary>
|
|
/// Used by the Command Engine to allow for overriding any other commands that contain the same name.
|
|
/// TODO: Does Overriding Commands still work? This is part of some old code I wrote several years back and might be broke.
|
|
/// </summary>
|
|
public Boolean Override { get; set; }
|
|
|
|
/// <summary>
|
|
/// The name of the command.
|
|
/// If Override is set to true, this command will override any other command that contains the same name.
|
|
/// </summary>
|
|
public String Name { get; set; }
|
|
|
|
/// <summary>
|
|
/// A collection of strings that contains helpfull information for this Command.
|
|
/// When the user enteres 'Help Exit' the game will print the content of this collection.
|
|
/// This is treated like a virtual book, each entry in the collection is printed as a new line.
|
|
/// </summary>
|
|
public List<String> Help { get; set; }
|
|
|
|
/// <summary>
|
|
/// Constructor for the class.
|
|
/// </summary>
|
|
public CommandWalk()
|
|
{
|
|
Help = new List<String>();
|
|
Help.Add("Allows you to traverse through the world.");
|
|
Help.Add("You may walk in any direction available within the current Room.");
|
|
Help.Add("You may use the Look command to see a description of the current Room, and decide where you would like to walk.");
|
|
Help.Add("Usage: Walk 'Direction' where Direction may equal one of the following:");
|
|
|
|
//We will construct a string that contains all of the available travel directions for the player.
|
|
StringBuilder directions = new StringBuilder();
|
|
|
|
//Store a array of existing values within the AvailableTravelDirection enum.
|
|
//These values are the legal travel directions that are supported by the game.
|
|
Array values = Enum.GetValues(typeof(AvailableTravelDirections));
|
|
|
|
//Loop through the array, printing each travel direction we found in the enum array collection
|
|
//to the screen for the user to see and select from.
|
|
foreach (Int32 v in values)
|
|
{
|
|
//Since enum values are not strings, we can't simply assign a string value to the enum.
|
|
//The enum needs to be queried to retrieve a value that matches that of 'v' and convert it to a String
|
|
String displayName = Enum.GetName(typeof(AvailableTravelDirections), v);
|
|
|
|
//Add the current travel direction to our string for later use.
|
|
directions.Append(displayName + ", ");
|
|
}
|
|
|
|
//Place the newly constructed String with all of our available travel directions into the help collection.
|
|
Help.Add(directions.ToString());
|
|
|
|
//Note that you could have placed each direction in manually "Help.Add("West")" etc. however this would
|
|
//prove an issue with maintanence if directions were changed within the engine, new ones added or old ones removed.
|
|
//Getting the travel directions the way we did always ensures that the help command will always every
|
|
//available travel direction contained within the engine, regardless if we add or remove directions internally or not.
|
|
//It's a dynamic way of storing our directions.
|
|
}
|
|
|
|
/// <summary>
|
|
/// Constructor for the class.
|
|
/// </summary>
|
|
public void Execute(String command, BaseCharacter player)
|
|
{
|
|
//Since the walk command requires a second word (ex: walk north)
|
|
//we split the words into an array so they are seperate.
|
|
String[] words = command.Split(' ');
|
|
List<String> directions = new List<String>();
|
|
|
|
//We only 1 word was found within the array, then the user failed to provide a second word
|
|
//which would be the travel direction they are wanting to go.
|
|
if (words.Length == 1)
|
|
{
|
|
player.Send("No direction provided!");
|
|
return;
|
|
}
|
|
//The user supplied a traveling direction for us, lets ensure it's a valid one.
|
|
else
|
|
{
|
|
//iterate through each door within the current Room and see if we have a Door that
|
|
//contains a exit in the direction that the player supplied.
|
|
foreach (Door door in player.CurrentRoom.Doorways)
|
|
{
|
|
//See if the current door has the same travel direction value as that of the users entered direction.
|
|
if (door.TravelDirection == TravelDirections.GetTravelDirectionValue(words[1]))
|
|
{
|
|
//The matches the users direction, so move the player in the direction supplied by the user.
|
|
player.Move(door.TravelDirection);
|
|
|
|
//Use the Look command to print the contents of the new Room to the Player.
|
|
player.CommandSystem.ExecuteCommand("Look", player);
|
|
|
|
//If the current Active Game has Auto-Save enabled, we will save the player.
|
|
if (player.ActiveGame.AutoSave)
|
|
player.Save(player.ActiveGame.DataPaths.Players);
|
|
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
//If the user entered a travel direction that does not exist within the current Room, they will be told so
|
|
//and no moving will be performed.
|
|
player.Send("Unable to travel in that direction.");
|
|
}
|
|
}
|