MudEngine:

- Improvements to the EditRealm command. Bug fixes and tweaks
 - EditRealm command now updates All Zones and Rooms within other Realms when its Realm.name is changed instead of only child Zones/Rooms.
 - Realms, Zones and Rooms will now append a file extension if no file extension is supplied during GetRealm(), GetZone() and GetRoom() method invokes.
 - Realm.InitialZone is no longer read-only
 - Zone.InitialRoom is no longer read-only.
 - Added EditZone command. Allows for editing pre-existing Zones. Zones can be created via the Create command.
 - Added EditRoom command. Allows for editing pre-existing Rooms. Rooms can be created via the Create command.

MudGame:
 - Re-organized the Scripts directory. All Admin commands are now placed within a 'AdminCommands' folder while the player based commands are in a 'PlayerCommands' folder. All remaining scripts reside within the Scripts root folder.
This commit is contained in:
Scionwest_cp 2010-09-05 16:28:35 -07:00
parent 1f21892c36
commit b3238d0227
23 changed files with 1617 additions and 26 deletions

View file

@ -0,0 +1,42 @@
/// <summary>
/// The Clear command is used to clear the players terminal screen of all text.
/// </summary>
public class CommandClear : 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 CommandClear()
{
Help = new List<String>();
Help.Add("The Clear command is used to clear the screen of all text.");
}
/// <summary>
/// Constructor for the class.
/// </summary>
public void Execute(String command, BaseCharacter player)
{
//Call the flush method to clear the players console screen of all text.
player.FlushConsole();
}
}

View file

@ -0,0 +1,72 @@
/// <summary>
/// The Exit command is used to exit the MUD game.
/// Using this command while connected to a MUD server will perform a disconnect from the server.
/// Using the command while running the game in offline mode will simply shut down the game.
/// </summary>
public class CommandExit : 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 CommandExit()
{
//Instance the help collection and add our help information to it.
//Typically the Help content is placed within the constructor, but this particular help document
//needs to access information from the player, so we will build our Help collection in the Execute command.
Help = new List<string>();
Help.Add("Exits the game.");
}
/// <summary>
/// Executes the command.
/// This method is called from the Command Engine, it is not recommended that you call this method directly.
/// </summary>
/// <param name="command"></param>
/// <param name="player"></param>
public void Execute(String command, BaseCharacter player)
{
//Check if the game is multiplayer.
//Multiplayer games require disconnecting from the server and letting other players in the same Room know
//that this player has left.
if (player.ActiveGame.IsMultiplayer)
{
//Query the Active Games Player collection so that we can build a collection of Players that need to be
//informed of the Player disconnecting from the Server.
var playerQuery =
from p in player.ActiveGame.GetPlayerCollection()
where !p.Name.StartsWith("New") && p.Name != player.Name && p.CurrentWorldLocation == player.CurrentWorldLocation
select p;
//Inform each player found in our LINQ query that the player has disconnected from the Server.
foreach (BaseCharacter p in playerQuery)
p.Send(player.Name + " has left."); ;
//TODO: If a player is in a Group then s/he needs to be removed upon disconnecting.
player.Disconnect();
}
else
{
//Call the game's shutdown method which will save all objects and exit the game gracefully.
player.ActiveGame.Shutdown();
}
}
}

View file

@ -0,0 +1,47 @@
/// <summary>
/// The GetTime command is used to print the current in-game time to the player.
/// This command will print the day, month and year along with hour, minute and seconds.
/// </summary>
public class CommandGetTime : 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 CommandGetTime()
{
//Instance the help collection and add our help information to it.
Help = new List<string>();
Help.Add("Gives you the current time and date in the game world.");
}
/// <summary>
/// Executes the Command.
/// This method is called from the Command Engine, it is not recommended that you call this method directly.
/// </summary>
/// <param name="command"></param>
/// <param name="player"></param>
public void Execute(String command, BaseCharacter player)
{
//Send the returned String containing the World Time to the player.
player.Send(player.ActiveGame.WorldTime.GetCurrentWorldTime());
}
}

View file

@ -0,0 +1,81 @@
/// <summary>
/// Help command provides information on all the existing game commands, including script based commands.
/// </summary>
public class CommandHelp : 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 CommandHelp()
{
Help = new List<String>();
Help.Add("Provides help on various topics.");
Help.Add("You may ask for help on any game command.");
Help.Add("Usage: Help");
Help.Add("Usage: Help 'command' where command = a game command");
Help.Add("Example: Help Look");
}
/// <summary>
/// Constructor for the class.
/// </summary>
public void Execute(String command, BaseCharacter player)
{
//Check if we have a topic that the player wants help with. If there is nothing after the Help word
//in the command, then the user didn't supply us with a topic.
string topic = command.Substring("Help".Length);
//if the user did not supply us with a topic, we will print every command currently loaded in the engine
//and tell the user how they can access help information regarding that command.
//TODO: Help command should have self contained help topics.
if (topic.Length == 0)
{
player.Send("Available commands: ", false);
//Print each command found within the command engine.
foreach (String cmd in CommandEngine.GetCommands())
{
//We will get a reference to the current command in the iteration
IGameCommand g = CommandEngine.GetCommand(cmd);
//Print the name of the command to the user, place a comma after the command
//so that the next command can be placed afterwards.
player.Send(CommandEngine.GetCommandName(g) + ", ", false);
}
//Let the player know how to use the help command to access help regarding any of the aformentioned commands.
player.Send("");
player.Send("Usage: Help 'Command'");
return;
}
//The player supplied a topic, lets trip out all the white spaces from it caused by the Substring method
else
topic = topic.Trim();
//Get a reference to the command the player wants help with. We must insert the 'Command' string into the topic,
//as all Commands start with the word Command, however the player never sees the word Command. It's internal only.
IGameCommand gc = CommandEngine.GetCommand("Command" + topic);
//Iterate through each entry in the commands help collection and print it to the player.
foreach (String help in gc.Help)
player.Send(help);
}
}

View file

@ -0,0 +1,64 @@
/// <summary>
/// The Look command is used to print the contents of the players current Room to the screen.
/// The Room.Description property is printed to the players screen if it contains content.
/// If the Room.DetailedDescription collection property contains content, it will be printed to the screen
/// after the Room.Description property is printed (provided Room.Description is not empty.)
/// </summary>
public class CommandLook : 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 CommandLook()
{
Help = new List<String>();
Help.Add("Prints a description of the current Room and the objects that reside within it.");
}
/// <summary>
/// Constructor for the class.
/// </summary>
public void Execute(String command, BaseCharacter player)
{
//If the players Room is null, then we need to let them know that they are
//currently not residing within a Room. If this occures for some reason, the player will
//need to be moved into an existing Room by an Admin.
//TODO: Allow Admins to move Characters from one Room to another.
if (player.CurrentRoom == null)
{
player.Send("You are not within any Room.");
return;
}
//Check if the players current Room has a blank Description. If not, we print it for the player to read.
if (!String.IsNullOrEmpty(player.CurrentRoom.Description))
player.Send(player.CurrentRoom.Description);
//Check if the players current Room has a detailed description.
//If the collection contains content, it will loop through each entry and print it to the screen as a new line.
if (player.CurrentRoom.DetailedDescription.Count != 0)
{
foreach (String entry in player.CurrentRoom.DetailedDescription)
player.Send(entry);
}
}
}

View file

@ -0,0 +1,42 @@
/// <summary>
/// The Save command will save the current player to a hard-disk file.
/// </summary>
public class CommandSave : 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 CommandSave()
{
Help = new List<String>();
Help.Add("Saves your character immediately.");
}
/// <summary>
/// Constructor for the class.
/// </summary>
public void Execute(String command, BaseCharacter player)
{
//Save the player to the hard-disk.
player.Save(player.ActiveGame.DataPaths.Players);
}
}

View file

@ -0,0 +1,68 @@
/// <summary>
/// The Say command provides the player with the ability to chat with other players within the game world.
/// Players using the Say command can only talk to players that are currently within the same Room.
/// </summary>
public class CommandSay : 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 CommandSay()
{
Help = new List<String>();
Help.Add("Allows you to Chat with with players around you.");
Help.Add("Note that you can only chat with players that reside within the same Room as yourself.");
Help.Add("Usage: Say Hello everyone!");
}
/// <summary>
/// Constructor for the class.
/// </summary>
public void Execute(String command, BaseCharacter player)
{
//Check if the user only said 'Say ' or 'Say' with no message content.
if (command.Length <= 4)
{
//If no message content, print the help for the command to the player.
CommandHelp help = new CommandHelp();
help.Execute("Help Say", player);
return; //nothing to say, don't say anything at all.
}
//Get the message out of the command string.
String message = command.Substring("Say ".Length);
//Query the game world and find what players are within the same location as the chatting player.
var playerQuery =
from p in player.ActiveGame.GetPlayerCollection()
where p.CurrentWorldLocation == player.CurrentWorldLocation
select p;
//Send the message to each player found within our player query.
foreach (var p in playerQuery)
p.Send(player.Name + " says: " + message);
//Print the same message but in a alternate format to the player that sent the message originally.
player.Send("You say: " + message);
}
}

View file

@ -0,0 +1,120 @@
/// <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 show every
//available travel direction contained within the engine, regardless if we add or remove directions internally or not.
//It's a dynamic way of displaying 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);
//BAD - Don't invoke commands directly by the player as it causes issues for them client-side.
//Always invoke the command internally, passing a reference to the player instead.
//player.CommandSystem.ExecuteCommand("Look", player);
//Use the Look command to print the contents of the new Room to the Player.
//Good - Correct way of invoking commands automatically for the player.
//The command will be executed for which ever player is passed as a reference.
CommandLook look = new CommandLook();
look.Execute("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.");
}
}