From 00ce7b00253cec753513fc57e5a2155b10dc4427 Mon Sep 17 00:00:00 2001 From: Scionwest_cp Date: Sat, 4 Sep 2010 09:16:00 -0700 Subject: [PATCH] MudEngine: - Moved List command out of the engine and into the MudGame as a script. MudGame: - Migrated List command from engine to game script. - List command now supports 'List Commands'. It will now print all commands for admins, and only non-admin commands for non-admin players. - Added CreateRoom scripted command for instantly creating Rooms without needing to fully qualify a path. The Room will be created in the Admin's current Realm>Zone. In order to create a Room outside of their current Zone they will need to use the standard 'Create' command and supply a fully qualified name such as 'MyRealm>MyZone>MyRoom' --- MudEngine/Commands/CommandLogin.cs | 1 - MudEngine/Commands/CommandRestart.cs | 1 + MudEngine/Commands/CommandSaveWorld.cs | 1 + MudEngine/MudEngine.csproj | 1 - MudGame/MudGame.csproj | 8 +- MudGame/Scripts/CommandCreateRoom.cs | 58 ++++++++ MudGame/Scripts/CommandList.cs | 177 +++++++++++++++++++++++++ 7 files changed, 244 insertions(+), 3 deletions(-) create mode 100644 MudGame/Scripts/CommandCreateRoom.cs create mode 100644 MudGame/Scripts/CommandList.cs diff --git a/MudEngine/Commands/CommandLogin.cs b/MudEngine/Commands/CommandLogin.cs index aac1716..74b198a 100644 --- a/MudEngine/Commands/CommandLogin.cs +++ b/MudEngine/Commands/CommandLogin.cs @@ -27,7 +27,6 @@ namespace MudEngine.Commands /// public Boolean Override { get; set; } - /// /// The name of the command. /// If Override is set to true, this command will override any other command that contains the same name. /// diff --git a/MudEngine/Commands/CommandRestart.cs b/MudEngine/Commands/CommandRestart.cs index 32a40e2..e5ad8e2 100644 --- a/MudEngine/Commands/CommandRestart.cs +++ b/MudEngine/Commands/CommandRestart.cs @@ -20,6 +20,7 @@ namespace MudEngine.Commands { public String Name { get; set; } public Boolean Override { get; set; } + public List Help { get; set; } public CommandRestart() diff --git a/MudEngine/Commands/CommandSaveWorld.cs b/MudEngine/Commands/CommandSaveWorld.cs index 932d0fa..d4745b4 100644 --- a/MudEngine/Commands/CommandSaveWorld.cs +++ b/MudEngine/Commands/CommandSaveWorld.cs @@ -15,6 +15,7 @@ namespace MudEngine.Commands public class CommandSaveWorld : IGameCommand { public Boolean Override { get; set; } + public String Name { get; set; } public List Help { get; set; } diff --git a/MudEngine/MudEngine.csproj b/MudEngine/MudEngine.csproj index be5c922..fb2ef8d 100644 --- a/MudEngine/MudEngine.csproj +++ b/MudEngine/MudEngine.csproj @@ -53,7 +53,6 @@ - diff --git a/MudGame/MudGame.csproj b/MudGame/MudGame.csproj index 9b61f6b..9781045 100644 --- a/MudGame/MudGame.csproj +++ b/MudGame/MudGame.csproj @@ -45,6 +45,12 @@ + + PreserveNewest + + + PreserveNewest + PreserveNewest @@ -67,7 +73,7 @@ PreserveNewest - Always + PreserveNewest PreserveNewest diff --git a/MudGame/Scripts/CommandCreateRoom.cs b/MudGame/Scripts/CommandCreateRoom.cs new file mode 100644 index 0000000..0feb6fa --- /dev/null +++ b/MudGame/Scripts/CommandCreateRoom.cs @@ -0,0 +1,58 @@ +/// +/// 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. +/// +class CommandCreateRoom : IGameCommand +{ + /// + /// 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. + /// + public Boolean Override { get; set; } + + /// + /// The name of the command. + /// If Override is set to true, this command will override any other command that contains the same name. + /// + public String Name { get; set; } + + /// + /// 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. + /// + public List Help { get; set; } + + /// + /// Constructor for the class. + /// + public CommandCreateRoom() + { + Help = new List(); + 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; + } + + 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); + } + } +} \ No newline at end of file diff --git a/MudGame/Scripts/CommandList.cs b/MudGame/Scripts/CommandList.cs new file mode 100644 index 0000000..8091cad --- /dev/null +++ b/MudGame/Scripts/CommandList.cs @@ -0,0 +1,177 @@ +/// +/// The List command is used to list filenames of a specified object type. +/// +public class CommandList : IGameCommand +{ + /// + /// 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. + /// + public Boolean Override { get; set; } + + /// + /// The name of the command. + /// If Override is set to true, this command will override any other command that contains the same name. + /// + public String Name { get; set; } + + /// + /// 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. + /// + public List Help { get; set; } + + public CommandList() + { + Help = new List(); + 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); + } + } + } + } + } +} \ No newline at end of file