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,247 @@
/// <summary>
/// The Create command is used to dynamically create content within the game world.
/// Content is created at run-time while the server/game is running and players are connected.
/// Newly created content will be available for players to use/traverse immediately after creation is completed.
/// Rooms that are created may be linked together using the LinkRoom command.
/// </summary>
public class CommandCreate : 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; }
//Private fields that are used during the creation of the environments.
private Realm realm;
private Zone zone;
private Room room;
/// <summary>
/// Constructor for the class.
/// </summary>
public CommandCreate()
{
Help = new List<string>();
Help.Add("Provides Admins the ability to create content dynamically within the game world.");
Help.Add("Content is created at run-time while the server/game is running and players are connected.");
Help.Add("Newly created content will be available for players to use/traverse immediately after creation is completed.");
Help.Add("Rooms that are created may be linked together using the LinkRoom command.");
Help.Add("You may create Realms by simply supplying a Realm name. If you wish to create a Zone, you must specify the Realm name followed by a '>' then the Zone name.");
Help.Add("Example: 'Create MyRealm>MyZone'");
Help.Add("The same concept is applied for creating Rooms.");
Help.Add("Example: 'Create MyRealm>MyZone>MyRoom'");
Help.Add("Creating just a single Realm is used by supplying only the Realm name.");
Help.Add("Example: 'Create MyRealm'");
}
/// <summary>
/// This will execute the command allowing Admins to generate environment objects dynamically on-the-fly.
/// </summary>
/// <param name="command"></param>
/// <param name="player"></param>
public void Execute(String command, BaseCharacter player)
{
//Check if the player has the proper security role in order to create content for the game world.
if ((player.Role != SecurityRoles.Admin) && (player.Role != SecurityRoles.GM))
{
Log.Write("Player " + player.Name + " attempted to invoke the Create command without having the correct security role assigned!");
return;
}
//Split the supplied string up. It wil give us an array of strings with the supplied
//object names if the admin has specified environment objects for creation.
String[] env = command.ToLower().Substring("Create ".Length).Split('>');
//No objects specified, so the admin didn't use the command correctly.
if (env.Length == 0)
{
player.Send("Invalid use of the 'Create' command. Please try 'Help Create' for help using the command.");
return;
}
//Only 1 object name supplied, so we assume the admin wants a Realm created with the supplied name.
else if (env.Length == 1)
{
//Check if the supplied name is a valid Realm name, and if the Realm can be created.
//If it's valid, the Realm is instanced and stored in our private Field 'realm'
Boolean validRealm = ValidateRealm(env[0], player);
if (validRealm)
{
player.ActiveGame.World.AddRealm(realm);
Log.Write(player.Name + " created a Realm called " + realm.Filename);
player.Send(env[0] + " created.");
}
//Add the 'realm' Field that was instanced via ValidateRealm
else
{
Log.Write("Failed to validate realm during dynamic Creation.");
player.Send("Failed to create Realm! Please ensure a duplicate file name does not exist!");
return;
}
}
//Recieved two names, so we assume the admin wants a Zone created.
//If the Realm that is supplied for this Zone does not create, we will create it.
else if (env.Length == 2)
{
//Check if the Realm name supplied already exists. If it does, this will return false (Invalid name due to already existing)
//If it returns true, then the Realm is valid, meaning non already exists, so we will create it.
Boolean validRealm = ValidateRealm(env[0], player);
//Add the Realm to the game world since this Zone is being created in a non-existant Realm.
if (validRealm)
{
player.ActiveGame.World.AddRealm(realm);
player.Send(env[0] + " created.");
Log.Write(player.Name + " created a Realm called " + realm.Filename);
}
//Check if this Zone is a valid Zone. if it returns true, then the 'zone' field will reference the new Zone
Boolean validZone = ValidateZone(env[0], env[1], player);
if (validZone)
{
realm.AddZone(zone);
player.Send(env[1] + " created.");
Log.Write(player.Name + " created a Zone called " + zone.Filename);
}
else
{
Log.Write("Failed to validate Zone during dynamic creation.");
player.Send("Failed to create Zone! Please ensure a duplicate filename does not exist!");
return;
}
}
else if (env.Length == 3)
{
//Check if the Realm name supplied already exists. If it does, this will return false (Invalid name due to already existing)
//If it returns true, then the Realm is valid, meaning non already exists, so we will create it.
Boolean validRealm = ValidateRealm(env[0], player);
//Add the Realm to the game world since this Zone is being created in a non-existant Realm.
if (validRealm)
{
player.ActiveGame.World.AddRealm(realm);
player.Send(env[0] + " created.");
Log.Write(player.Name + " created a Realm called " + realm.Filename);
}
Boolean validZone = ValidateZone(env[0], env[1], player);
if (validZone)
{
realm.AddZone(zone);
player.Send(env[1] + " created.");
Log.Write(player.Name + " created a Zone called " + zone.Filename);
}
Boolean validRoom = ValidateRoom(env[0], env[1], env[2], player);
if (validRoom)
{
zone.AddRoom(room);
player.Send(env[2] + " created.");
Log.Write(player.Name + " created a Room called " + room.Filename);
}
else
{
Log.Write("Failed to validate Room during dynamic creation.");
player.Send("Failed to create Room! Please ensure a duplicate filename does not exist!");
return;
}
}
}
/// <summary>
/// Validates if the supplied Realm filename exists in the game world or not.
/// Returns True if it does not exist; False if it does exist (As if it exists it's not a valid name to use during creation).
/// </summary>
/// <param name="name"></param>
/// <param name="player"></param>
/// <returns></returns>
private Boolean ValidateRealm(String name, BaseCharacter player)
{
if (player.ActiveGame.World.GetRealm(name + ".Realm") != null)
{
realm = player.ActiveGame.World.GetRealm(name + ".Realm");
return false;
}
realm = new Realm(player.ActiveGame);
realm.Name = name;
return true;
}
/// <summary>
/// Validates if the supplied Zone filename exists in the game world or not.
/// Returns True if it does not exist; False if it does exist (As if it exists it's not a valid name to use during creation).
/// If the Zones owning Realm does not exist, it returns false and fails.
/// </summary>
/// <param name="realmName"></param>
/// <param name="zoneName"></param>
/// <param name="player"></param>
/// <returns></returns>
private Boolean ValidateZone(String realmName, String zoneName, BaseCharacter player)
{
if (realm == null)
{
player.Send("Unable to validate Zone due to invalid Realm.");
return false;
}
if (realm.GetZone(zoneName + ".Zone").Count != 0)
{
zone = realm.GetZone(zoneName + ".Zone")[0];
return false;
}
zone = new Zone(player.ActiveGame);
zone.Name = zoneName;
return true;
}
/// <summary>
/// Validates if the supplied Room filename exists in the game world or not.
/// Returns True if it does not exist; False if it does exist (As if it exists it's not a valid name to use during creation).
/// If the Rooms owning Zone or Realm does not exist, it returns false and fails.
/// </summary>
/// <param name="realmName"></param>
/// <param name="zoneName"></param>
/// <param name="roomName"></param>
/// <param name="player"></param>
/// <returns></returns>
private Boolean ValidateRoom(String realmName, String zoneName, String roomName, BaseCharacter player)
{
if ((realm == null) || (zone == null))
{
player.Send("Unable to validate Room due to invalid Realm or Zone.");
return false;
}
if (zone.GetRoom(roomName + ".Room").Count != 0)
{
room = zone.GetRoom(roomName + ".Room")[0];
return false;
}
room = new Room(player.ActiveGame);
room.Name = roomName;
return true;
}
}

View file

@ -0,0 +1,66 @@
/// <summary>
/// This command creates a Room within the players current Realm>Zone.
/// Admins using this command will not need to supply a fully qualified path like the 'Create' command requires.
/// However, they are restricted to creating Rooms only within their current Realm>Zone.
/// </summary>
class CommandCreateRoom : 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 CommandCreateRoom()
{
Help = new List<string>();
Help.Add("Creates a Room within the Admin's current Realm>Zone");
}
public void Execute(String command, BaseCharacter player)
{
if ((player.Role == SecurityRoles.Admin) || (player.Role == SecurityRoles.GM))
{
String roomname = command.Substring("Createroom".Length).Trim();
if (String.IsNullOrEmpty(roomname))
{
player.Send("You must supply a Room name! Refer to 'Help CreateRoom' for usage examples.");
return;
}
if ((String.IsNullOrEmpty(player.CurrentRoom.Realm)) || (String.IsNullOrEmpty(player.CurrentRoom.Zone)))
{
player.Send("You are not currently within a pre-existing Zone.");
player.Send("Use the Teleport command to teleport yourself into a valid Zone before using the CreateRoom command.");
return;
}
Room r = new Room(player.ActiveGame);
r.Realm = player.CurrentRoom.Realm;
r.Zone = player.CurrentRoom.Zone;
r.Name = roomname;
player.ActiveGame.World.GetRealm(r.Realm).GetZone(r.Zone)[0].AddRoom(r);
player.Send(r.Name + " created within " + r.Realm + ">" + r.Zone + ".");
Log.Write(player.Name + " created a new Room in " + r.RoomLocation);
}
}
}

View file

@ -0,0 +1,419 @@
/// <summary>
/// The LinkRoom command is used to Link two previously created Rooms together.
/// Rooms linked together can be traversed by players.
/// This command is used to link Rooms dynamically during run-time by Admins, allowing environments to be created
/// and traversed on-the-fly without the need to modify scripts and re-start the server.
/// </summary>
public class CommandLinkRoom : 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 CommandLinkRoom()
{
//Instance the help collection and add our help information to it.
Help = new List<string>();
Help.Add("Use this to link two previously created Rooms together.");
//Incase Admins try to use the command, they will know that it's broken.
//Don't convert this class into a Script until it is fully completed.
Help.Add("NOTE: This command is not fully implemented. You may link two Rooms together provided they exist within the same Zone.");
Help.Add("You may experience some Rooms not being traversable even after linking.");
Help.Add("This command is a work-in-progress and will contain bugs.");
}
/// <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 Player has the correct privileges to Link Rooms together.
//If they are not a Admin or GM then the command will bail.
//This creates the illusion that this command possibly doesn't exist.
if ((player.Role != SecurityRoles.Admin) && (player.Role != SecurityRoles.GM))
{
player.Send("Invalid Command.");
return;
}
//Build the Menu system that will be displayed to Admins.
player.Send("Room linkage tool");
player.Send("Please select an option.");
player.Send("1: Link Room");
player.Send("2: Exit");
//Read the input from the Admin.
string input = player.ReadInput();
Int32 value = 0;
//Attempt to convert their input from a String into a numerical value.
//If they entered a non-numerical value, then the method will exit
try
{
value = Convert.ToInt32(input);
}
catch (Exception)
{
player.Send("Invalid selection. Please use numeric values.");
return;
}
//Ask what Room the Admin wants to use as the Departing Room.
//Departing Rooms will be where the travel direction originates from.
//meaning if the Admin selects West as the traveling direction, then traveling West will exit the
//Departing Room and enter the Arrival Room.
player.Send("");
player.Send("Please select which Realm your departing Room resides within:");
player.Send("");
//Instance a new Realm that we can use to reference an existing Realm so that we can find the
//Rooms within it that the Admin is looking for.
Boolean isValidRealm = false;
Realm realm = new Realm(player.ActiveGame);
//Create a Loop incase the Admin enters an invalid Realm, we can just loop
//back and re-ask the Admin the enter a valid Realm name.
while (!isValidRealm)
{
//Now that we are in the loop, set the isValidRealm to true, as we will assume that
//the user will enter a valid Realm name on the first shot. If we can't find a matching
//Realm, then this will get set to false once iterating through Realms is completed.
isValidRealm = true;
//Print each Realm out to the Admin so they may see a complete list to choose from.
//This is the Realm that their first Room will reside within.
//TODO: Currently only linking Rooms within the same Realm/Zone is supported. Need to fix that.
foreach (Realm r in player.ActiveGame.World.RealmCollection)
player.Send(r.Filename + " | ", false);
//As for the Admins selection, we will place the Admins input on the same line
//as the last message sent to the Admin by setting the newLine parameter to false.
player.Send("");
player.Send("Selection: ", false);
//Get the Admins input that should specify what Realm they are wanting.
input = player.ReadInput();
//Check if the Admin entered 'Cancel'. If so, then cancel the Link process.
if (input.ToLower() == "cancel")
{
player.Send("Room Linking aborted.");
return;
}
//Query the Active Games world collection, finding Realms that match the filename entered by the Admin
var realmQuery =
from r in player.ActiveGame.World.RealmCollection
where r.Filename.ToLower() == input.ToLower()
select r;
//Check if the query contains a Realm.
if (realmQuery.FirstOrDefault() != null)
{
//The query does in-fact contain a valid Realm. Assign it to our realm field for use later.
realm = realmQuery.FirstOrDefault();
//We can set this to true, allowing us to exit out of the loop.
isValidRealm = true;
}
//If the query does not contain a Realm, then we ensure that the loop will continue by forcing
//isValidRealm back to false.
else
{
isValidRealm = false;
//Let the Admin know that they entered an invalid Realm name and that they need to try again.
player.Send("That Realm does not exist! Please try again.");
}
}
//Let the Admin know that they need to now select which Zone the Room they are wanting to link resides within.
player.Send("");
player.Send("Please select which Zone your departing Room resides within:");
player.Send("");
//Instance a new Zone that we can use to reference an existing Zone so that we can find the
//Rooms within it that the Admin is looking for.
Boolean isValidZone = false;
Zone zone = new Zone(player.ActiveGame);
//Create a Loop incase the Admin enters an invalid Zone, we can just loop
//back and re-ask the Admin the enter a valid Zone name.
while (!isValidZone)
{
//Now that we are in the loop, set the isValidZone to true, as we will assume that
//the user will enter a valid Zone name on the first shot. If we can't find a matching
//Zone, then this will get set to false once iterating through Zone is completed.
isValidZone = true;
//Print each Zone out to the Admin so they may see a complete list to choose from.
//This is the Zone that their first Room will reside within.
//TODO: Currently only linking Rooms within the same Realm/Zone is supported. Need to fix that.
foreach (Zone z in realm.ZoneCollection)
{
player.Send(z.Filename + " | ", false);
}
//As for the Admins selection, we will place the Admins input on the same line
//as the last message sent to the Admin by setting the newLine parameter to false.
player.Send("");
player.Send("Selection: ", false);
//Get the Admins input that should specify what Zone they are wanting.
input = player.ReadInput();
//Check if the Admin entered 'Cancel'. If so, then cancel the Link process.
if (input.ToLower() == "cancel")
{
player.Send("Room Linking aborted.");
return;
}
//Query the stored Realm's Zone collection, finding Zones that match the filename entered by the Admin
var zoneQuery =
from z in realm.ZoneCollection
where z.Filename.ToLower() == input.ToLower()
select z;
//Check if the query contains a Zone.
if (zoneQuery.FirstOrDefault() != null)
{
//The query does in-fact contain a valid Zone. Assign it to our zone field for use later.
zone = zoneQuery.FirstOrDefault();
//We can set this to true, allowing us to exit out of the loop.
isValidZone = true;
}
//If the query does not contain a Zone, then we ensure that the loop will continue by forcing
//isValidZone back to false.
else
{
isValidZone = false;
//Let the Admin know that they entered an invalid Zone name and that they need to try again.
player.Send("That Zone does not exist! Please try again.");
}
}
//Let the Admin know that they need to now select Room they are wanting to link as the departure Room
player.Send("");
player.Send("Please select which Room that you wish to be the departing Room:");
player.Send("");
//Instance a new Room that we can store a reference to a existing Room.
//We will use this reference to link the departure and arrival Rooms together.
Boolean isValidRoom = false;
Room departingRoom = new Room(player.ActiveGame);
//Create a Loop incase the Admin enters an invalid Room, we can just loop
//back and re-ask the Admin the enter a valid Room name.
while (!isValidRoom)
{
//Now that we are in the loop, set the isValidRoom to true, as we will assume that
//the user will enter a valid Room name on the first shot. If we can't find a matching
//Room, then this will get set to false once iterating through Room is completed.
isValidRoom = true;
//Print each Room out to the Admin so they may see a complete list to choose from.
//This will be their departing Room.
//TODO: Currently only linking Rooms within the same Realm/Zone is supported. Need to fix that.
foreach (Room r in zone.RoomCollection)
{
player.Send(r.Filename + " | ", false);
}
//As for the Admins selection, we will place the Admins input on the same line
//as the last message sent to the Admin by setting the newLine parameter to false.
player.Send("");
player.Send("Selection: ", false);
//Get the Admins input that should specify what Room they are wanting.
input = player.ReadInput();
//Check if the Admin entered 'Cancel'. If so, then cancel the Link process.
if (input.ToLower() == "cancel")
{
player.Send("Room Linking aborted.");
return;
}
//Query the referenced zone's Room collection, finding Rooms that match the filename entered by the Admin
var roomQuery =
from r in zone.RoomCollection
where r.Filename.ToLower() == input.ToLower()
select r;
//Check if the query contains a Room.
if (roomQuery.FirstOrDefault() != null)
{
//The query does in-fact contain a valid Room. Assign it to our departingRoom field for use later.
departingRoom = roomQuery.FirstOrDefault();
//We can set this to true, allowing us to exit out of the loop.
isValidRoom = true;
}
//If the query does not contain a Room, then we ensure that the loop will continue by forcing
//isValidRoom back to false.
else
{
isValidRoom = false;
//Let the Admin know that they entered an invalid Room name and that they need to try again.
player.Send("That Room does not exist! Please try again.");
}
}
//Let the Admin know that they need to now select Room they are wanting to link as the Arrival Room
player.Send("");
player.Send("Please select which Room that you wish to be the Arrival Room:");
player.Send("");
//Instance a new Room that we can store a reference to a existing Room.
//We will use this reference to link the departure and arrival Rooms together.
isValidRoom = false;
Room arrivalRoom = new Room(player.ActiveGame);
//Create a Loop incase the Admin enters an invalid Room, we can just loop
//back and re-ask the Admin the enter a valid Room name.
while (!isValidRoom)
{
//Now that we are in the loop, set the isValidRoom to true, as we will assume that
//the user will enter a valid Room name on the first shot. If we can't find a matching
//Room, then this will get set to false once iterating through Room is completed.
isValidRoom = true;
//Print each Room out to the Admin so they may see a complete list to choose from.
//This will be their departing Room.
//TODO: Currently only linking Rooms within the same Realm/Zone is supported. Need to fix that.
foreach (Room r in zone.RoomCollection)
{
player.Send(r.Filename + " | ", false);
}
//As for the Admins selection, we will place the Admins input on the same line
//as the last message sent to the Admin by setting the newLine parameter to false.
player.Send("");
player.Send("Selection: ", false);
//Get the Admins input that should specify what Room they are wanting.
input = player.ReadInput();
//Check if the Admin entered 'Cancel'. If so, then cancel the Link process.
if (input.ToLower() == "cancel")
{
player.Send("Room Linking aborted.");
return;
}
//Query the referenced zone's Room collection, finding Rooms that match the filename entered by the Admin
var roomQuery =
from r in zone.RoomCollection
where r.Filename.ToLower() == input.ToLower()
select r;
//Check if the query contains a Room.
if (roomQuery.FirstOrDefault() != null)
{
//The query does in-fact contain a valid Room. Assign it to our departingRoom field for use later.
departingRoom = roomQuery.FirstOrDefault();
//We can set this to true, allowing us to exit out of the loop.
isValidRoom = true;
}
//If the query does not contain a Room, then we ensure that the loop will continue by forcing
//isValidRoom back to false.
else
{
isValidRoom = false;
//Let the Admin know that they entered an invalid Room name and that they need to try again.
player.Send("That Room does not exist! Please try again.");
}
}
//Let the Admin select the direction of travel required for a player to traverse from the
//departing Room into the arriving Room.
player.Send("Please select which direction you would like to travel while departing the departure Room.");
//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));
//Create a reference to the AvailableTravelDirections enum that we can use to assign a travel
//when we pass the Room linking off to the Rooms owning Zone.
AvailableTravelDirections direction = new AvailableTravelDirections();
Boolean isValidDirection = false;
//Perform the direction corrections within a while loop, incase the Admin enteres
//a invalid traveling direction and we need to re-acquire input from the Admin.
while (!isValidDirection)
{
//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);
//Print this current iterations value to the screen for the player.
player.Send(displayName + " | ");
}
//As for the Admins selection, we will place the Admins input on the same line
//as the last message sent to the Admin by setting the newLine parameter to false.
player.Send("Enter Selection: ", false);
input = player.ReadInput();
//Loop through each value found in our original array or values acquired from the AvailableTravelDirections enum.
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);
//Check if the Admins selected travel direction matches that of the current travel direction value found
//within our array of values harvested from the AvailableTravelDirections enum
if (displayName.ToLower() == input.ToLower())
{
//The two match up. Now you have to convert the String version of the travel direction, back into
//an enum equivilant for use by the Rooms owning Zone during linking.
direction = (AvailableTravelDirections)Enum.Parse(typeof(AvailableTravelDirections), displayName);
//We found a legal Travel Direction. Setting this to true will exit the while loop.
isValidDirection = true;
break;
}
else
isValidDirection = false;
}
//Check if we haven't found a valid direction yet. This will print to the Admin that the entered
//direction was invalid, and then loop back to the top of the current loop.
if (!isValidDirection)
{
player.Send("Invalid direction supplied!");
}
//The direction supplied by the Admin matched up and was concidered legal, so we shoud
//have a converted AvailableTravelDirection now with the value matching that of the Admins.
//Link the two rooms together, with the travel direction of the Admins choice.
else
{
zone.LinkRooms(direction, arrivalRoom, departingRoom);
}
}
}
}

View file

@ -0,0 +1,177 @@
/// <summary>
/// The List command is used to list filenames of a specified object type.
/// </summary>
public class CommandList : 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; }
public CommandList()
{
Help = new List<string>();
Help.Add("Using the List command, you can view a generated list of filenames that pertain to a supplied object type.");
Help.Add("Usage: List 'ItemType'");
Help.Add("Usage: List 'ItemName>ItemType'");
Help.Add("");
Help.Add("Supported Listable ItemTypes are as follows:");
Help.Add("Players");
Help.Add("Realms");
Help.Add("Zones");
Help.Add("RealmName>Rooms");
Help.Add("RealmName>Zones");
Help.Add("RealmName>ZoneName>Rooms");
}
public void Execute(String command, BaseCharacter player)
{
command = command.Substring("List".Length).Trim();
String[] data = command.ToLower().Split('>');
//Admin || GM only item listings.
if ((player.Role == SecurityRoles.Admin) || (player.Role == SecurityRoles.GM))
{
//Player must be a admin or GM to view all the objects on the server like this.
if ((data.Length == 0) || (String.IsNullOrEmpty(data[0])))
{
player.Send("Invalid command usage. Enter 'help List' for usage examples.");
return;
}
else if (data.Length == 1)
{
switch (data[0])
{
case "realms":
player.Send("Currently loaded Realm files:");
foreach (Realm r in player.ActiveGame.World.RealmCollection)
player.Send(r.Filename + " | ", false);
break;
case "players":
player.Send("Players with created characters:");
BaseCharacter p = new BaseCharacter(player.ActiveGame);
foreach (String file in System.IO.Directory.GetFiles(player.ActiveGame.DataPaths.Players, "*.character"))
{
p.Load(file);
player.Send(p.Name + " | ", false);
}
break;
case "zones":
player.Send("Currently loaded Zones. This spans across every Realm in the world.");
foreach (Realm r in player.ActiveGame.World.RealmCollection)
{
foreach (Zone z in r.ZoneCollection)
{
player.Send(System.IO.Path.GetFileNameWithoutExtension(r.Filename) + ">" + System.IO.Path.GetFileNameWithoutExtension(z.Filename));
}
}
break;
case "commands":
player.Send("The following commands are available for use:");
foreach (String cmd in CommandEngine.GetCommands())
{
IGameCommand gc = CommandEngine.GetCommand(cmd);
player.Send(gc.Name);
}
break;
default:
player.Send("Invalid token supplied. Enter 'Help List' for usage examples.");
break;
}
}
else if (data.Length == 2)
{
if (data[1] == "zones")
{
if (player.ActiveGame.World.GetRealm(data[0] + ".realm") == null)
{
player.Send("Invalid Realm, unable to list Zones.");
return;
}
player.Send("Displaying Currently loaded Zones within Realm " + data[0]);
foreach (Zone z in player.ActiveGame.World.GetRealm(data[0] + ".realm").ZoneCollection)
player.Send(z.Filename + " | ", false);
}
else if (data[1] == "rooms")
{
if (player.ActiveGame.World.GetRealm(data[0] + ".realm") == null)
{
player.Send("Invalid Realm, unable to list Rooms.");
return;
}
player.Send("Displaying currently loaded Rooms within Realm " + data[0] + ". These Rooms span multiple Zones.");
foreach (Zone z in player.ActiveGame.World.GetRealm(data[0] + ".realm").ZoneCollection)
{
foreach (Room r in z.RoomCollection)
{
player.Send(System.IO.Path.GetFileNameWithoutExtension(z.Filename) + ">" + System.IO.Path.GetFileNameWithoutExtension(r.Filename));
}
}
}
}
else if (data.Length == 3)
{
if (data[2] == "rooms")
{
if (player.ActiveGame.World.GetRealm(data[0] + ".realm") == null)
{
player.Send("Invalid Realm, unable to list Rooms.");
return;
}
if (player.ActiveGame.World.GetRealm(data[0] + ".realm").GetZone(data[1] + ".zone")[0] == null)
{
player.Send("Invalid Zone, unable to list Rooms.");
return;
}
player.Send("Displaying Currently loaded Rooms within " + data[0] + ">" + data[1]);
foreach (Room r in player.ActiveGame.World.GetRealm(data[0] + ".realm").GetZone(data[1] + ".zone")[0].RoomCollection)
player.Send(r.Filename + " | ", false);
}
}
} //End Admin || GM only item listings.
//Begin normal player item listings
else
{
//Player must be a admin or GM to view all the objects on the server like this.
if ((data.Length == 0) || (String.IsNullOrEmpty(data[0])))
{
player.Send("Invalid command usage. Enter 'help List' for usage examples.");
return;
}
else if (data.Length == 1)
{
if (data[0] == "commands")
{
player.Send("The following commands are available for use:");
foreach (String cmd in CommandEngine.GetCommands())
{
IGameCommand gc = CommandEngine.GetCommand(cmd);
if ((gc.Name == "CommandCreate") || (gc.Name == "CommandCreateRoom") || (gc.Name == "CommandLinkRoom") || (gc.Name == "CommandRestart") || (gc.Name == "CommandSaveWorld"))
continue;
player.Send(gc.Name);
}
}
}
}
}
}

View file

@ -0,0 +1,101 @@
/// <summary>
/// The List command is used to list filenames of a specified object type.
/// </summary>
public class CommandTeleport : 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; }
public CommandTeleport()
{
Help = new List<string>();
Help.Add("The Teleport command will teleport a player to a specified Room, regardless of where they are at.");
Help.Add("Usage: Teleport playername FullyQualifiedRoomPath");
Help.Add("Example: Teleport Billy MyRealm>MyZone>MyRoom");
}
public void Execute(String command, BaseCharacter player)
{
command = command.Substring("teleport".Length).Trim();
String[] data = command.ToLower().Split(' ');
//Admin || GM only item listings.
if ((player.Role == SecurityRoles.Admin) || (player.Role == SecurityRoles.GM))
{
if (data.Length == 0)
{
player.Send("Invalid operation. You must supply a username along with a fully qualified path name for the user to be teleported to.");
return;
}
else if (data.Length == 1)
{
player.Send("Invalid operation. You must supply a fully qualified path name for the user to be teleported.");
return;
}
else
{
foreach (BaseCharacter p in player.ActiveGame.GetPlayerCollection())
{
if (p.Name.ToLower() == data[0].ToLower())
{
String[] values = data[1].Split('>');
if (values.Length != 3)
{
player.Send("Invalid Operation. You must supply a fully qualified path name for the user to be teleported.");
return;
}
else
{
Realm r = player.ActiveGame.World.GetRealm(values[0]);
if (r == null)
{
player.Send("Invalid Operation. Supplied Realm does not exist.");
return;
}
Zone z = r.GetZone(values[1])[0];
if (z == null)
{
player.Send("Invalid operation. Supplied Zone does not exist.");
return;
}
Room rm = z.GetRoom(values[2])[0];
if (rm == null)
{
player.Send("Invalid operation. Supplied Room does not exist.");
return;
}
p.CurrentRoom = rm;
//Tell the teleported player that they have been moved.
p.Send("You have been teleported by some higher power.");
IGameCommand gc = CommandEngine.GetCommand("CommandLook");
gc.Execute("Look", p);
player.Send("Teleporting completed.");
}
}
}
}
}
}
}