diff --git a/MudEngine/Commands/CommandEditRealm.cs b/MudEngine/Commands/CommandEditRealm.cs index 79d4d55..034b5d4 100644 --- a/MudEngine/Commands/CommandEditRealm.cs +++ b/MudEngine/Commands/CommandEditRealm.cs @@ -21,7 +21,8 @@ namespace MudEngine.Commands public List Help { get; set; } private Realm realm; - BaseCharacter player; + private BaseCharacter player; + private Boolean isEditing; public CommandEditRealm() { @@ -52,7 +53,7 @@ namespace MudEngine.Commands //We have a filename, retrieve the Realm the admin wants to edit. realm = player.ActiveGame.World.GetRealm(filename); - + //If no Realm was retrieved (due to it not existing), let the admin know //that the Realm filename was not valid. if (realm == null) @@ -60,29 +61,35 @@ namespace MudEngine.Commands player.Send("Realm Editing canceled. The supplied Realm name is not valid."); return; } - //Otherwise, the Realm does exist and was retrieved. - //Lets build our Editing menu's and allow for Realm Editing. + //Otherwise, the Realm does exist and was retrieved. + //Lets build our Editing menu's and allow for Realm Editing. else { - //Construct the main editing menu. - BuildMenuMain(); - - //Find out what menu option the admin wants to use. - Int32 value = 0; - //Attempt to convert the String entered by the admin into a numeric value - try + //Always re-build the menu so the user doesn't need to re-enter the edit command. + //When the user selects the exit option, the loop will end. + isEditing = true; + while (isEditing) { - value = Convert.ToInt32(player.ReadInput()); - } + //Construct the main editing menu. + BuildMenuMain(); + + //Find out what menu option the admin wants to use. + Int32 value = 0; + //Attempt to convert the String entered by the admin into a numeric value + try + { + value = Convert.ToInt32(player.ReadInput()); + } //If a non-numeric value is supplied, the conversion failed. This is us catching that failure. - catch - { - player.Send("Realm Editing canceled. The supplied value was not numeric!"); - return; - } + catch + { + player.Send("Realm Editing canceled. The supplied value was not numeric!"); + return; + } - //Parse the menu option that the admin supplied. - ParseMenuSelection(value); + //Parse the menu option that the admin supplied. + ParseMenuSelection(value); + } //let the admin know that we have now exited the editor. player.Send("Editing completed."); } @@ -135,7 +142,7 @@ namespace MudEngine.Commands player.Send("Example: A Realm with a Visible name of \"My Test Realm\" can have a filename of \"Test.Realm\". You would access this object as a Admin by specifying a object name of \"Test\""); player.Send("Select from the available options below:"); player.Send(""); - + player.Send("1: Realm Visibile Name"); player.Send("2: Realm Filename"); player.Send("9: Exit"); @@ -238,6 +245,7 @@ namespace MudEngine.Commands ParseInitialSelection(entry); break; case 9: + isEditing = false; break; default: break; @@ -254,7 +262,7 @@ namespace MudEngine.Commands String input = ""; switch (value) { - //Simple Description + //Simple Description case 1: player.FlushConsole(); player.Send("Enter a simple description for this Realm."); @@ -277,7 +285,7 @@ namespace MudEngine.Commands player.ActiveGame.Save(); player.Send("New Simple Description saved."); break; - //Detailed Description + //Detailed Description case 2: Boolean isEditing = true; Int32 line = 1; @@ -322,7 +330,7 @@ namespace MudEngine.Commands else if (input.ToLower().StartsWith("edit")) { //Retrieve the line number from the users input. - String editLine= input.Substring("edit".Length).Trim(); + String editLine = input.Substring("edit".Length).Trim(); //If no line number was provided, cancel. if (String.IsNullOrEmpty(editLine)) @@ -543,33 +551,33 @@ namespace MudEngine.Commands player.Send("Current Value: ", false); player.Send(realm.Feel); } - + player.Send("Enter Value: ", false); realm.Feel = player.ReadInput(); break; case 2: //Listen player.Send("Enter the new default LISTEN description for this Realm."); player.Send("If you wish to clear the current description, just press ENTER to save a blank description."); - + if (!String.IsNullOrEmpty(realm.Listen)) { player.Send("Current Value: ", false); player.Send(realm.Listen); } - + player.Send("Enter value: ", false); realm.Listen = player.ReadInput(); break; case 3: //Smell player.Send("Enter the new default SMELL description for this Realm."); player.Send("If you wish to clear the current description, just press ENTER to save a blank description."); - + if (!String.IsNullOrEmpty(realm.Smell)) { player.Send("Current Value: ", false); player.Send(realm.Smell); } - + player.Send("Enter value: ", false); realm.Smell = player.ReadInput(); break; diff --git a/MudEngine/Commands/CommandEditRoom.cs b/MudEngine/Commands/CommandEditRoom.cs index 92f97b4..6e3be5c 100644 --- a/MudEngine/Commands/CommandEditRoom.cs +++ b/MudEngine/Commands/CommandEditRoom.cs @@ -21,7 +21,8 @@ namespace MudEngine.Commands public List Help { get; set; } private Room room; - BaseCharacter player; + private BaseCharacter player; + private Boolean isEditing; public CommandEditRoom() { @@ -82,25 +83,30 @@ namespace MudEngine.Commands //Lets build our Editing menu's and allow for Room Editing. else { - //Construct the main editing menu. - BuildMenuMain(); + isEditing = true; - //Find out what menu option the admin wants to use. - Int32 value = 0; - //Attempt to convert the String entered by the admin into a numeric value - try + while (isEditing) { - value = Convert.ToInt32(player.ReadInput()); - } - //If a non-numeric value is supplied, the conversion failed. This is us catching that failure. - catch - { - player.Send("Room Editing canceled. The supplied value was not numeric!"); - return; - } + //Construct the main editing menu. + BuildMenuMain(); - //Parse the menu option that the admin supplied. - ParseMenuSelection(value); + //Find out what menu option the admin wants to use. + Int32 value = 0; + //Attempt to convert the String entered by the admin into a numeric value + try + { + value = Convert.ToInt32(player.ReadInput()); + } + //If a non-numeric value is supplied, the conversion failed. This is us catching that failure. + catch + { + player.Send("Room Editing canceled. The supplied value was not numeric!"); + return; + } + + //Parse the menu option that the admin supplied. + ParseMenuSelection(value); + } //let the admin know that we have now exited the editor. player.Send("Editing completed."); } @@ -120,7 +126,7 @@ namespace MudEngine.Commands player.Send("3: Senses"); player.Send("4: Initial Room"); player.Send("5: Settings"); - player.Send("6: Doorways"); + //player.Send("6: Doorways"); player.Send("9: Exit"); player.Send("Enter numeric selection: ", false); } @@ -262,6 +268,7 @@ namespace MudEngine.Commands case 6: //Doorways break; case 9: + isEditing = false; break; default: break; @@ -694,7 +701,7 @@ namespace MudEngine.Commands //Next, we need to loop through every Room within this Room //and update their Rooms names to match the new one - foreach(Realm r in player.ActiveGame.World.RealmCollection) + foreach (Realm r in player.ActiveGame.World.RealmCollection) { foreach (Zone z in r.ZoneCollection) { diff --git a/MudEngine/Commands/CommandEditZone.cs b/MudEngine/Commands/CommandEditZone.cs index 45af473..71518e7 100644 --- a/MudEngine/Commands/CommandEditZone.cs +++ b/MudEngine/Commands/CommandEditZone.cs @@ -21,7 +21,8 @@ namespace MudEngine.Commands public List Help { get; set; } private Zone zone; - BaseCharacter player; + private BaseCharacter player; + private Boolean isEditing; public CommandEditZone() { @@ -76,25 +77,31 @@ namespace MudEngine.Commands //Lets build our Editing menu's and allow for Zone Editing. else { - //Construct the main editing menu. - BuildMenuMain(); - - //Find out what menu option the admin wants to use. - Int32 value = 0; - //Attempt to convert the String entered by the admin into a numeric value - try + //Always re-build the menu so the user doesn't need to re-enter the edit command. + //When the user selects the exit option, the loop will end. + isEditing = true; + while (isEditing) { - value = Convert.ToInt32(player.ReadInput()); - } - //If a non-numeric value is supplied, the conversion failed. This is us catching that failure. - catch - { - player.Send("Zone Editing canceled. The supplied value was not numeric!"); - return; - } + //Construct the main editing menu. + BuildMenuMain(); - //Parse the menu option that the admin supplied. - ParseMenuSelection(value); + //Find out what menu option the admin wants to use. + Int32 value = 0; + //Attempt to convert the String entered by the admin into a numeric value + try + { + value = Convert.ToInt32(player.ReadInput()); + } + //If a non-numeric value is supplied, the conversion failed. This is us catching that failure. + catch + { + player.Send("Zone Editing canceled. The supplied value was not numeric!"); + return; + } + + //Parse the menu option that the admin supplied. + ParseMenuSelection(value); + } //let the admin know that we have now exited the editor. player.Send("Editing completed."); } @@ -113,7 +120,7 @@ namespace MudEngine.Commands player.Send("2: Names"); player.Send("3: Senses"); player.Send("4: Initial Zone"); - player.Send("5: Settings"); + // player.Send("5: Settings"); player.Send("9: Exit"); player.Send("Enter numeric selection: ", false); } @@ -253,6 +260,7 @@ namespace MudEngine.Commands case 5: //Settings break; case 9: + isEditing = false; break; default: break; diff --git a/MudEngine/GameManagement/Game.cs b/MudEngine/GameManagement/Game.cs index 8ccd23e..576bf20 100644 --- a/MudEngine/GameManagement/Game.cs +++ b/MudEngine/GameManagement/Game.cs @@ -195,6 +195,7 @@ namespace MudEngine.GameManagement scriptEngine = new Scripting.ScriptEngine(this); World = new GameWorld(this); WorldTime = new GameTime(this); + InitialRealm = new Realm(this); //Prepare the Save Paths for all of our Game objects. DataPaths = new SaveDataPaths("World", "Player"); @@ -279,6 +280,17 @@ namespace MudEngine.GameManagement //Load the game and world if it was previously saved. Load(); + String[] env = InitialRealm.InitialZone.InitialRoom.RoomLocation.Split('>'); + if (env.Length == 3) + { + if ((String.IsNullOrEmpty(env[0])) || (String.IsNullOrEmpty(env[1])) || (String.IsNullOrEmpty(env[2]))) + { + Log.Write("Error: No starting location defined!"); + } + } + else + Log.Write("Error: No starting location defined!"); + Log.Write("Game startup complete."); return true; } @@ -429,6 +441,16 @@ namespace MudEngine.GameManagement //Restore the world. World.Load(); + //Check if any the initial room exists or not. + if ((this.InitialRealm == null) || (this.InitialRealm.InitialZone == null) || (this.InitialRealm.InitialZone.InitialRoom == null)) + { + Log.Write("ERROR: No initial location defined. Game startup failed!"); + Log.Write("Players will start in the Abyss. Each player will contain their own instance of this room."); + //return false; + } + else + Log.Write("Initial Location loaded: " + this.InitialRealm.InitialZone.InitialRoom.RoomLocationWithoutExtension); + Log.Write("Game Restore complete."); } diff --git a/MudEngine/GameManagement/GameWorld.cs b/MudEngine/GameManagement/GameWorld.cs index 63f1fe0..f23585a 100644 --- a/MudEngine/GameManagement/GameWorld.cs +++ b/MudEngine/GameManagement/GameWorld.cs @@ -74,17 +74,6 @@ namespace MudEngine.GameManagement break; } } - - //Check if any the initial room exists or not. - if ((_Game.InitialRealm == null) || (_Game.InitialRealm.InitialZone == null) || (_Game.InitialRealm.InitialZone.InitialRoom == null)) - { - Log.Write("ERROR: No initial location defined. Game startup failed!"); - Log.Write("Players will start in the Abyss. Each player will contain their own instance of this room."); - //return false; - } - else - Log.Write("Initial Location loaded: " + _Game.InitialRealm.InitialZone.InitialRoom.RoomLocationWithoutExtension); - } public void Save() diff --git a/MudEngine/GameObjects/Environment/Room.cs b/MudEngine/GameObjects/Environment/Room.cs index 3d04673..291fb78 100644 --- a/MudEngine/GameObjects/Environment/Room.cs +++ b/MudEngine/GameObjects/Environment/Room.cs @@ -70,7 +70,7 @@ namespace MudEngine.GameObjects.Environment { get { - return this.Realm + ">" + Zone + ">" + Filename; + return this.Realm + ">" + this.Zone + ">" + this.Filename; } } diff --git a/MudGame/Scripts/AdminCommands/CommandList.cs b/MudGame/Scripts/AdminCommands/CommandList.cs index 8091cad..10c62ee 100644 --- a/MudGame/Scripts/AdminCommands/CommandList.cs +++ b/MudGame/Scripts/AdminCommands/CommandList.cs @@ -57,26 +57,56 @@ public class CommandList : IGameCommand switch (data[0]) { case "realms": - player.Send("Currently loaded Realm files:"); - foreach (Realm r in player.ActiveGame.World.RealmCollection) - player.Send(r.Filename + " | ", false); + if (player.ActiveGame.World.RealmCollection.Count == 0) + player.Send("There are currently no loaded Realm files."); + else + { + 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")) + if (System.IO.Directory.GetFiles(player.ActiveGame.DataPaths.Players, "*.character").Length == 0) + player.Send("There are currently no characters created on this server."); + else { - p.Load(file); - player.Send(p.Name + " | ", false); + 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) + if (player.ActiveGame.World.RealmCollection.Count == 0) { - foreach (Zone z in r.ZoneCollection) + player.Send("There are currently no Zones created on this server."); + } + else + { + List names = new List(); + foreach (Realm r in player.ActiveGame.World.RealmCollection) { - player.Send(System.IO.Path.GetFileNameWithoutExtension(r.Filename) + ">" + System.IO.Path.GetFileNameWithoutExtension(z.Filename)); + foreach (Zone z in r.ZoneCollection) + { + names.Add(System.IO.Path.GetFileNameWithoutExtension(r.Filename) + ">" + System.IO.Path.GetFileNameWithoutExtension(z.Filename)); + } + } + + if (names.Count == 0) + { + player.Send("There are currently no Zones created on this server."); + } + else + { + player.Send("Currently loaded Zones. This spans across every Realm in the world."); + foreach (String name in names) + { + player.Send(name); + } } } break;