From a52ccf8da918cd2ab5efa7b79c7dcab739b3291b Mon Sep 17 00:00:00 2001 From: Scionwest_cp Date: Sat, 14 Aug 2010 00:20:43 -0700 Subject: [PATCH] MudEngine: - Converted all Types from C# types to .NET Types (such as bool changed to Boolean, and int changed to Int32). - Zone no longer gets saved from within GameWorld.Save, but rather in Realm.Save() - Room no longer gets saved from within GameWorld.Save(), but rather in Zone.Save(); - Added new SaveWorld command that admins only can execute to force save the world. It's not fully implemented at this time. MudGame: - began work on command execution from within the server while it's running. --- MUDCompiler/Program.cs | 4 +- MudEngine/Commands/CommandClear.cs | 6 +- MudEngine/Commands/CommandExit.cs | 14 ++--- MudEngine/Commands/CommandGetTime.cs | 6 +- MudEngine/Commands/CommandLoad.cs | 10 ++-- MudEngine/Commands/CommandLogin.cs | 22 +++---- MudEngine/Commands/CommandLook.cs | 8 +-- MudEngine/Commands/CommandRestart.cs | 12 ++-- MudEngine/Commands/CommandSave.cs | 6 +- MudEngine/Commands/CommandSaveWorld.cs | 30 ++++++++++ MudEngine/Commands/CommandWalk.cs | 10 ++-- MudEngine/FileSystem/FileManager.cs | 32 +++++----- MudEngine/FileSystem/SaveDataPaths.cs | 10 ++-- MudEngine/FileSystem/XmlSerialization.cs | 4 +- MudEngine/GameManagement/CommandEngine.cs | 26 ++++---- MudEngine/GameManagement/CommandResults.cs | 2 +- MudEngine/GameManagement/Game.cs | 45 +++++++------- MudEngine/GameManagement/GameTime.cs | 40 ++++++------- MudEngine/GameManagement/GameWorld.cs | 35 ++--------- MudEngine/GameManagement/ICommand.cs | 6 +- MudEngine/GameManagement/Log.cs | 13 ++-- MudEngine/GameObjects/Bag.cs | 4 +- MudEngine/GameObjects/BaseObject.cs | 44 +++++++------- .../GameObjects/Characters/BaseCharacter.cs | 46 +++++++------- MudEngine/GameObjects/Currency.cs | 2 +- MudEngine/GameObjects/Environment/Door.cs | 4 +- MudEngine/GameObjects/Environment/Realm.cs | 18 ++++-- MudEngine/GameObjects/Environment/Room.cs | 25 +++++--- .../Environment/StartingLocation.cs | 14 +++-- .../Environment/TravelDirections.cs | 6 +- MudEngine/GameObjects/Environment/Zone.cs | 34 +++++++++-- MudEngine/MudEngine.csproj | 1 + MudEngine/Networking/Server.cs | 16 ++--- MudEngine/Scripting/GameObject.cs | 20 +++---- MudEngine/Scripting/ScriptEngine.cs | 60 +++++++++---------- MudGame/Program.cs | 27 ++++++++- 36 files changed, 365 insertions(+), 297 deletions(-) create mode 100644 MudEngine/Commands/CommandSaveWorld.cs diff --git a/MUDCompiler/Program.cs b/MUDCompiler/Program.cs index db8f395..883be17 100644 --- a/MUDCompiler/Program.cs +++ b/MUDCompiler/Program.cs @@ -9,7 +9,7 @@ namespace MUDCompiler { class Program { - static void Main(string[] args) + static void Main(String[] args) { Console.WriteLine("==========================="); Console.WriteLine("MUD Engine Content Compiler"); @@ -20,7 +20,7 @@ namespace MUDCompiler Console.WriteLine("2): Exit Compiler"); Console.Write("Enter Selection: "); - string command = Console.ReadLine(); + String command = Console.ReadLine(); //command error checking. if (String.IsNullOrEmpty(command)) diff --git a/MudEngine/Commands/CommandClear.cs b/MudEngine/Commands/CommandClear.cs index 92f74a8..991044f 100644 --- a/MudEngine/Commands/CommandClear.cs +++ b/MudEngine/Commands/CommandClear.cs @@ -14,10 +14,10 @@ namespace MudEngine.Commands { public class CommandClear : IGameCommand { - public bool Override { get; set; } - public string Name { get; set; } + public Boolean Override { get; set; } + public String Name { get; set; } - public CommandResults Execute(string command, BaseCharacter player) + public CommandResults Execute(String command, BaseCharacter player) { player.FlushConsole(); diff --git a/MudEngine/Commands/CommandExit.cs b/MudEngine/Commands/CommandExit.cs index 585d299..ee5f62c 100644 --- a/MudEngine/Commands/CommandExit.cs +++ b/MudEngine/Commands/CommandExit.cs @@ -14,22 +14,22 @@ namespace MudEngine.Commands { public class CommandExit : IGameCommand { - public bool Override { get; set; } - public string Name { get; set; } + public Boolean Override { get; set; } + public String Name { get; set; } - public CommandResults Execute(string command, BaseCharacter player) + public CommandResults Execute(String command, BaseCharacter player) { if (player.ActiveGame.IsMultiplayer) { //Let other players know that the user walked in. - for (int i = 0; i != player.ActiveGame.PlayerCollection.Length; i++) + for (Int32 i = 0; i != player.ActiveGame.PlayerCollection.Length; i++) { if (player.ActiveGame.PlayerCollection[i].Name == player.Name) continue; - string room = player.ActiveGame.PlayerCollection[i].CurrentRoom.Name; - string realm = player.ActiveGame.PlayerCollection[i].CurrentRoom.Realm; - string zone = player.ActiveGame.PlayerCollection[i].CurrentRoom.Zone; + String room = player.ActiveGame.PlayerCollection[i].CurrentRoom.Name; + String realm = player.ActiveGame.PlayerCollection[i].CurrentRoom.Realm; + String zone = player.ActiveGame.PlayerCollection[i].CurrentRoom.Zone; if ((room == player.CurrentRoom.Name) && (realm == player.CurrentRoom.Realm) && (zone == player.CurrentRoom.Zone)) { diff --git a/MudEngine/Commands/CommandGetTime.cs b/MudEngine/Commands/CommandGetTime.cs index c9c73c4..c2f4cf0 100644 --- a/MudEngine/Commands/CommandGetTime.cs +++ b/MudEngine/Commands/CommandGetTime.cs @@ -9,11 +9,11 @@ namespace MudEngine.Commands { public class CommandGetTime : MudEngine.GameManagement.IGameCommand { - public string Name { get; set; } + public String Name { get; set; } - public bool Override { get; set; } + public Boolean Override { get; set; } - public MudEngine.GameManagement.CommandResults Execute(string command, BaseCharacter player) + public MudEngine.GameManagement.CommandResults Execute(String command, BaseCharacter player) { player.Send(player.ActiveGame.WorldTime.GetCurrentWorldTime()); diff --git a/MudEngine/Commands/CommandLoad.cs b/MudEngine/Commands/CommandLoad.cs index f461c5b..37489fb 100644 --- a/MudEngine/Commands/CommandLoad.cs +++ b/MudEngine/Commands/CommandLoad.cs @@ -13,13 +13,13 @@ namespace MudEngine.Commands { public class CommandLoad : IGameCommand { - public bool Override { get; set; } - public string Name { get; set; } + public Boolean Override { get; set; } + public String Name { get; set; } - public CommandResults Execute(string command, BaseCharacter player) + public CommandResults Execute(String command, BaseCharacter player) { - string path = player.ActiveGame.DataPaths.Players; - string filename = Path.Combine(path, player.Filename); + String path = player.ActiveGame.DataPaths.Players; + String filename = Path.Combine(path, player.Filename); player.Load(filename); diff --git a/MudEngine/Commands/CommandLogin.cs b/MudEngine/Commands/CommandLogin.cs index 7080b10..4af9d7b 100644 --- a/MudEngine/Commands/CommandLogin.cs +++ b/MudEngine/Commands/CommandLogin.cs @@ -14,10 +14,10 @@ namespace MudEngine.Commands { public class CommandLogin : IGameCommand { - public bool Override { get; set; } - public string Name { get; set; } + public Boolean Override { get; set; } + public String Name { get; set; } - public CommandResults Execute(string command, BaseCharacter player) + public CommandResults Execute(String command, BaseCharacter player) { player.Send(player.ActiveGame.GameTitle); player.Send(player.ActiveGame.Version); @@ -26,15 +26,15 @@ namespace MudEngine.Commands player.Send("Enter Character Name: ", false); - string input = player.ReadInput(); + String input = player.ReadInput(); Boolean playerFound = false; - string savedFile = ""; + String savedFile = ""; //See if this character already exists. if (!Directory.Exists(player.ActiveGame.DataPaths.Players)) Directory.CreateDirectory(player.ActiveGame.DataPaths.Players); - foreach (string filename in Directory.GetFiles(player.ActiveGame.DataPaths.Players)) + foreach (String filename in Directory.GetFiles(player.ActiveGame.DataPaths.Players)) { if (Path.GetFileNameWithoutExtension(filename).ToLower() == input.ToLower()) { @@ -48,7 +48,7 @@ namespace MudEngine.Commands //Next search if there is an existing player already logged in with this name, if so disconnect them. if (player.ActiveGame.IsMultiplayer) { - for (int i = 0; i <= player.ActiveGame.PlayerCollection.Length - 1; i++) + for (Int32 i = 0; i <= player.ActiveGame.PlayerCollection.Length - 1; i++) { if (player.ActiveGame.PlayerCollection[i].Name.ToLower() == input.ToLower()) { @@ -76,14 +76,14 @@ namespace MudEngine.Commands //Let other players know that the user walked in. if (player.ActiveGame.IsMultiplayer) { - for (int i = 0; i != player.ActiveGame.PlayerCollection.Length; i++) + for (Int32 i = 0; i != player.ActiveGame.PlayerCollection.Length; i++) { if (player.ActiveGame.PlayerCollection[i].Name == player.Name) continue; - string room = player.ActiveGame.PlayerCollection[i].CurrentRoom.Name; - string realm = player.ActiveGame.PlayerCollection[i].CurrentRoom.Realm; - string zone = player.ActiveGame.PlayerCollection[i].CurrentRoom.Zone; + String room = player.ActiveGame.PlayerCollection[i].CurrentRoom.Name; + String realm = player.ActiveGame.PlayerCollection[i].CurrentRoom.Realm; + String zone = player.ActiveGame.PlayerCollection[i].CurrentRoom.Zone; if ((room == player.CurrentRoom.Name) && (realm == player.CurrentRoom.Realm) && (zone == player.CurrentRoom.Zone)) { diff --git a/MudEngine/Commands/CommandLook.cs b/MudEngine/Commands/CommandLook.cs index 6960eee..62a9a97 100644 --- a/MudEngine/Commands/CommandLook.cs +++ b/MudEngine/Commands/CommandLook.cs @@ -14,10 +14,10 @@ namespace MudEngine.Commands { public class CommandLook : IGameCommand { - public string Name { get; set; } - public bool Override { get; set; } + public String Name { get; set; } + public Boolean Override { get; set; } - public CommandResults Execute(string command, BaseCharacter player) + public CommandResults Execute(String command, BaseCharacter player) { if (player.CurrentRoom == null) { @@ -28,7 +28,7 @@ namespace MudEngine.Commands player.Send(player.CurrentRoom.Description); else { - foreach(string entry in player.CurrentRoom.DetailedDescription) + foreach(String entry in player.CurrentRoom.DetailedDescription) { player.Send(entry); } diff --git a/MudEngine/Commands/CommandRestart.cs b/MudEngine/Commands/CommandRestart.cs index 58bb048..8b515f3 100644 --- a/MudEngine/Commands/CommandRestart.cs +++ b/MudEngine/Commands/CommandRestart.cs @@ -18,18 +18,18 @@ namespace MudEngine.Commands { class CommandRestart : IGameCommand { - public string Name { get; set; } - public bool Override { get; set; } + public String Name { get; set; } + public Boolean Override { get; set; } - public CommandResults Execute(string command, BaseCharacter player) + public CommandResults Execute(String command, BaseCharacter player) { if (player.Role == SecurityRoles.Admin) { - string path = player.ActiveGame.DataPaths.Players; + String path = player.ActiveGame.DataPaths.Players; - for (int i = 0; i < player.ActiveGame.PlayerCollection.Length; i++) + for (Int32 i = 0; i < player.ActiveGame.PlayerCollection.Length; i++) { - string filename = Path.Combine(path, player.ActiveGame.PlayerCollection[i].Filename); + String filename = Path.Combine(path, player.ActiveGame.PlayerCollection[i].Filename); player.ActiveGame.PlayerCollection[i].Save(filename); } diff --git a/MudEngine/Commands/CommandSave.cs b/MudEngine/Commands/CommandSave.cs index 0760ab3..39d60bf 100644 --- a/MudEngine/Commands/CommandSave.cs +++ b/MudEngine/Commands/CommandSave.cs @@ -13,10 +13,10 @@ namespace MudEngine.Commands { public class CommandSave : IGameCommand { - public bool Override { get; set; } - public string Name { get; set; } + public Boolean Override { get; set; } + public String Name { get; set; } - public CommandResults Execute(string command, BaseCharacter player) + public CommandResults Execute(String command, BaseCharacter player) { /* if (player.ActiveGame.PlayerCollection.Length != 0) diff --git a/MudEngine/Commands/CommandSaveWorld.cs b/MudEngine/Commands/CommandSaveWorld.cs new file mode 100644 index 0000000..c463843 --- /dev/null +++ b/MudEngine/Commands/CommandSaveWorld.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.IO; +using System.Text; + +using MudEngine.FileSystem; +using MudEngine.GameObjects.Characters; +using MudEngine.GameManagement; +using MudEngine.Commands; +using MudEngine.GameObjects.Environment; + +namespace MudEngine.Commands +{ + public class CommandSaveWorld : IGameCommand + { + public Boolean Override { get; set; } + public String Name { get; set; } + + public CommandResults Execute(String command, BaseCharacter player) + { + if ((player.Role == SecurityRoles.Admin) || (player.Role == SecurityRoles.GM)) + { + player.ActiveGame.Save(); + } + + return new CommandResults(); + } + } +} diff --git a/MudEngine/Commands/CommandWalk.cs b/MudEngine/Commands/CommandWalk.cs index b387b2e..160ab80 100644 --- a/MudEngine/Commands/CommandWalk.cs +++ b/MudEngine/Commands/CommandWalk.cs @@ -14,13 +14,13 @@ namespace MudEngine.Commands { public class CommandWalk : IGameCommand { - public string Name { get; set; } - public bool Override { get; set; } + public String Name { get; set; } + public Boolean Override { get; set; } - public CommandResults Execute(string command, BaseCharacter player) + public CommandResults Execute(String command, BaseCharacter player) { - string[] words = command.Split(' '); - List directions = new List(); + String[] words = command.Split(' '); + List directions = new List(); if (words.Length == 1) return new CommandResults("No direction supplied"); diff --git a/MudEngine/FileSystem/FileManager.cs b/MudEngine/FileSystem/FileManager.cs index 97dcf4b..95fce8d 100644 --- a/MudEngine/FileSystem/FileManager.cs +++ b/MudEngine/FileSystem/FileManager.cs @@ -33,7 +33,7 @@ namespace MudEngine.FileSystem /// /// /// - public static void WriteLine(string filename, string value, string name) + public static void WriteLine(String filename, String value, String name) { if (!File.Exists(filename)) { @@ -52,9 +52,9 @@ namespace MudEngine.FileSystem } } - public static string GetData(string filename, string name) + public static String GetData(String filename, String name) { - foreach (string line in File.ReadAllLines(filename)) + foreach (String line in File.ReadAllLines(filename)) { //Ignore comments if (line.StartsWith(";")) @@ -72,11 +72,11 @@ namespace MudEngine.FileSystem /// /// /// - public static string GetDataPath(SaveDataTypes DataType) + public static String GetDataPath(SaveDataTypes DataType) { - string assemblyPath = System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName; - string assemblyName = System.IO.Path.GetFileName(assemblyPath); - string installBase = assemblyPath.Substring(0, assemblyPath.Length - assemblyName.Length); + String assemblyPath = System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName; + String assemblyName = System.IO.Path.GetFileName(assemblyPath); + String installBase = assemblyPath.Substring(0, assemblyPath.Length - assemblyName.Length); if (DataType == SaveDataTypes.Root) return installBase; @@ -84,20 +84,20 @@ namespace MudEngine.FileSystem return System.IO.Path.Combine(installBase, DataType.ToString()); } - public static string GetDataPath(string Realm, string Zone) + public static String GetDataPath(String Realm, String Zone) { - string assemblyPath = System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName; - string assemblyName = System.IO.Path.GetFileName(assemblyPath); - string installBase = assemblyPath.Substring(0, assemblyPath.Length - assemblyName.Length); - string realmsPath = System.IO.Path.Combine(installBase, "Realms"); - string requestRealm = Path.Combine(installBase, Realm); - string requestedRealmZones = Path.Combine(installBase, "Zones"); - string requestedZone = Path.Combine(installBase, Zone); + String assemblyPath = System.Reflection.Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName; + String assemblyName = System.IO.Path.GetFileName(assemblyPath); + String installBase = assemblyPath.Substring(0, assemblyPath.Length - assemblyName.Length); + String realmsPath = System.IO.Path.Combine(installBase, "Realms"); + String requestRealm = Path.Combine(installBase, Realm); + String requestedRealmZones = Path.Combine(installBase, "Zones"); + String requestedZone = Path.Combine(installBase, Zone); return requestedZone; } - public static string GetDataPath(string Realm, string Zone, string Room) + public static String GetDataPath(String Realm, String Zone, String Room) { return System.IO.Path.Combine(GetDataPath(Realm, Zone), Room); } diff --git a/MudEngine/FileSystem/SaveDataPaths.cs b/MudEngine/FileSystem/SaveDataPaths.cs index 21679f9..4159267 100644 --- a/MudEngine/FileSystem/SaveDataPaths.cs +++ b/MudEngine/FileSystem/SaveDataPaths.cs @@ -7,7 +7,7 @@ namespace MudEngine.FileSystem { public struct SaveDataPaths { - public string Players + public String Players { get { @@ -19,7 +19,7 @@ namespace MudEngine.FileSystem } } - public string Environment + public String Environment { get { @@ -30,10 +30,10 @@ namespace MudEngine.FileSystem _Environment = value; } } - private string _Players; - private string _Environment; + private String _Players; + private String _Environment; - public SaveDataPaths(string environment, string players) + public SaveDataPaths(String environment, String players) { _Players = players; _Environment = environment; diff --git a/MudEngine/FileSystem/XmlSerialization.cs b/MudEngine/FileSystem/XmlSerialization.cs index 728a9c6..e61a460 100644 --- a/MudEngine/FileSystem/XmlSerialization.cs +++ b/MudEngine/FileSystem/XmlSerialization.cs @@ -10,7 +10,7 @@ namespace MudEngine.FileSystem { internal class XmlSerialization { - internal static void Save(string Filename, object o) + internal static void Save(String Filename, object o) { Stream stream = File.Create(Filename); @@ -25,7 +25,7 @@ namespace MudEngine.FileSystem /// /// The Xml document to deserialize. /// - internal static object Load(string Filename, object o) + internal static object Load(String Filename, object o) { Stream stream = File.OpenRead(Filename); diff --git a/MudEngine/GameManagement/CommandEngine.cs b/MudEngine/GameManagement/CommandEngine.cs index 92c3864..f723fc3 100644 --- a/MudEngine/GameManagement/CommandEngine.cs +++ b/MudEngine/GameManagement/CommandEngine.cs @@ -19,9 +19,9 @@ namespace MudEngine.GameManagement /// /// Gets or Sets a Dictionary list of available commands to use. /// - public static Dictionary CommandCollection { get; set; } + public static Dictionary CommandCollection { get; set; } - internal Dictionary __Commands { get; set; } + internal Dictionary __Commands { get; set; } public CommandEngine() { @@ -31,11 +31,11 @@ namespace MudEngine.GameManagement //_Commands = CommandEngine.CommandCollection; } - public static List GetCommands() + public static List GetCommands() { - List temp = new List(); + List temp = new List(); - foreach (string name in CommandEngine.CommandCollection.Keys) + foreach (String name in CommandEngine.CommandCollection.Keys) { temp.Add(name); } @@ -43,7 +43,7 @@ namespace MudEngine.GameManagement return temp; } - public static IGameCommand GetCommand(string command) + public static IGameCommand GetCommand(String command) { if (IsValidCommand(command)) { @@ -57,7 +57,7 @@ namespace MudEngine.GameManagement return null; } - public static bool IsValidCommand(string Name) + public static Boolean IsValidCommand(String Name) { if (CommandCollection.ContainsKey(Name.ToLower())) return true; @@ -70,13 +70,13 @@ namespace MudEngine.GameManagement /// /// /// - public CommandResults ExecuteCommand(string command, BaseCharacter player) + public CommandResults ExecuteCommand(String command, BaseCharacter player) { - string commandKey = command.Insert(0, "Command"); + String commandKey = command.Insert(0, "Command"); if (Game.IsDebug) Log.Write("Executing command: " + command); - foreach (string key in CommandEngine.CommandCollection.Keys) + foreach (String key in CommandEngine.CommandCollection.Keys) { if (commandKey.ToLower().Contains(key.ToLower())) { @@ -106,7 +106,7 @@ namespace MudEngine.GameManagement LoadCommandLibrary(Assembly.GetExecutingAssembly()); } - public static void LoadCommandLibrary(string libraryFilename) + public static void LoadCommandLibrary(String libraryFilename) { if (System.IO.File.Exists(libraryFilename)) { @@ -126,7 +126,7 @@ namespace MudEngine.GameManagement LoadCommandLibrary(commandLibrary, false); } - public static void LoadCommandLibrary(Assembly commandLibrary, bool purgeOldCommands) + public static void LoadCommandLibrary(Assembly commandLibrary, Boolean purgeOldCommands) { //no assembly passed for whatever reason, don't attempt to enumerate through it. if (commandLibrary == null) @@ -170,7 +170,7 @@ namespace MudEngine.GameManagement public static void ClearCommands() { - CommandCollection = new Dictionary(); + CommandCollection = new Dictionary(); } } } diff --git a/MudEngine/GameManagement/CommandResults.cs b/MudEngine/GameManagement/CommandResults.cs index 27548bf..2a14764 100644 --- a/MudEngine/GameManagement/CommandResults.cs +++ b/MudEngine/GameManagement/CommandResults.cs @@ -22,7 +22,7 @@ namespace MudEngine.GameManagement this.Result = Result; } - public CommandResults(string message) + public CommandResults(String message) { this.Result = new object[] { message }; } diff --git a/MudEngine/GameManagement/Game.cs b/MudEngine/GameManagement/Game.cs index 16b47e9..3efff3f 100644 --- a/MudEngine/GameManagement/Game.cs +++ b/MudEngine/GameManagement/Game.cs @@ -17,6 +17,7 @@ using MudEngine.GameObjects; using MudEngine.GameObjects.Characters; using MudEngine.GameObjects.Environment; using MudEngine.Scripting; +using MudEngine.Networking; namespace MudEngine.GameManagement { @@ -33,18 +34,18 @@ namespace MudEngine.GameManagement /// /// Gets or Sets if this game is running in debug mode. Additional information is sent to the log if enabled. /// - public static bool IsDebug { get; set; } + public static Boolean IsDebug { get; set; } /// /// Gets or Sets if the game will run with a server or not. /// - public bool IsMultiplayer { get; set; } + public Boolean IsMultiplayer { get; set; } /// /// Gets or Sets if this game is currently running. /// [Browsable(false)] - public bool IsRunning { get; internal set; } + public Boolean IsRunning { get; internal set; } /// /// Gets or Sets the paths to various project related objects. @@ -60,14 +61,14 @@ namespace MudEngine.GameManagement /// Gets or Sets the path to the current project /// [Browsable(false)] - public string ProjectPath { get; set; } + public String ProjectPath { get; set; } /// /// Gets or Sets if all objects will be laoded during server startup. Enabling this results in a slower server start time, but faster object access. /// [Category("Project Settings")] [Description("If enabled, all objects will be loaded during server startup resulting in a slower server start time, but faster load time during gameplay")] - public bool PreCacheObjects { get; set; } + public Boolean PreCacheObjects { get; set; } /// /// Gets a copy of all identifiers being used in the game. @@ -81,25 +82,25 @@ namespace MudEngine.GameManagement /// /// Gets or Sets the name of the company /// - public string CompanyName { get; set; } + public String CompanyName { get; set; } [Category("Company Settings")] [Description("The website URL that a player can visit to view additional information related to the game")] /// /// Gets or Sets the companies website for this project /// - public string Website { get; set; } + public String Website { get; set; } [Category("Project Settings")] [Description("The name of the game displayed to the users, and title bar of the runtime.")] - public string GameTitle { get; set; } + public String GameTitle { get; set; } /// /// Gets or Sets the current working version of the game. /// [Category("Project Settings")] [Description("The current working version of the game.")] - public string Version { get; set; } + public String Version { get; set; } [Browsable(false)] public List CurrencyList { get; set; } @@ -115,7 +116,7 @@ namespace MudEngine.GameManagement /// /// The Story that is displayed on initial player entry into the game /// - public string Story { get; set; } + public String Story { get; set; } [Category("Project Settings")] [Description("Enable or Disable Auto-saving of players when the player travels")] @@ -123,7 +124,7 @@ namespace MudEngine.GameManagement /// Gets or Sets if the Game world is automatically saved at a specified interval. /// Players will be saved every-time they change location. /// - public bool AutoSave { get; set; } + public Boolean AutoSave { get; set; } /// /// Gets or Sets the interval in which the Game will automatically save every game object. @@ -135,17 +136,17 @@ namespace MudEngine.GameManagement /// /// Gets or Sets if room names are hidden during console output. /// - public bool HideRoomNames { get; set; } + public Boolean HideRoomNames { get; set; } [Category("Game Currency")] [DefaultValue(1)] [Description("Sets the amount that the base currency is valued at.")] - public uint BaseCurrencyAmount { get; set; } + public Int32 BaseCurrencyAmount { get; set; } [Category("Game Currency")] [DefaultValue("Copper")] - public string BaseCurrencyName { get; set; } + public String BaseCurrencyName { get; set; } public GameTime WorldTime { get; set; } @@ -162,7 +163,7 @@ namespace MudEngine.GameManagement /// /// Gets the current running Server object. /// - public MudEngine.Networking.Server Server { get; internal set; } + public Server Server { get; internal set; } /// /// Gets or Sets the protocol used by the server. @@ -172,12 +173,12 @@ namespace MudEngine.GameManagement /// /// Gets or Sets the port that the server will run on /// - public int ServerPort { get; set; } + public Int32 ServerPort { get; set; } /// /// Gets or Sets the maximum number of Players permitted to run on this Games server. /// - public int MaximumPlayers { get; set; } + public Int32 MaximumPlayers { get; set; } #endregion #endregion @@ -212,7 +213,7 @@ namespace MudEngine.GameManagement //Setup the player arrays //used to be in Start PlayerCollection = new BaseCharacter[MaximumPlayers]; - for (int i = 0; i < MaximumPlayers; i++) + for (Int32 i = 0; i < MaximumPlayers; i++) PlayerCollection[i] = new BaseCharacter(this); GameTime.Time t = new GameTime.Time(); @@ -240,7 +241,7 @@ namespace MudEngine.GameManagement /// /// Starts the game and runs the server if IsMultiplayer is true /// - public virtual bool Start() + public virtual Boolean Start() { Log.Write("Game Initializing..."); if (!Directory.Exists(DataPaths.Players)) @@ -263,7 +264,7 @@ namespace MudEngine.GameManagement if (IsDebug) { - foreach (string command in CommandEngine.CommandCollection.Keys) + foreach (String command in CommandEngine.CommandCollection.Keys) Log.Write("Command Loaded: " + command); } @@ -314,7 +315,7 @@ namespace MudEngine.GameManagement DateTime serverTime = new DateTime(); DateTime systemTime = DateTime.Now; - int lastSaveGap = 0; + Int32 lastSaveGap = 0; WorldTime.Update(); @@ -349,7 +350,7 @@ namespace MudEngine.GameManagement Log.Write("Saving Game world...."); Log.Write("Saving Game Players..."); - for (int i = 0; i <= PlayerCollection.Length - 1; i++) + for (Int32 i = 0; i <= PlayerCollection.Length - 1; i++) { if (PlayerCollection[i].Name == "New BaseCharacter") continue; diff --git a/MudEngine/GameManagement/GameTime.cs b/MudEngine/GameManagement/GameTime.cs index 59e80e0..1831ed6 100644 --- a/MudEngine/GameManagement/GameTime.cs +++ b/MudEngine/GameManagement/GameTime.cs @@ -9,12 +9,12 @@ namespace MudEngine.GameManagement { public struct Time { - public int Year { get; set; } - public int Month { get; set; } - public int Day { get; set; } - public int Hour { get; set; } - public int Minute { get; set; } - public int Second { get; set; } + public Int32 Year { get; set; } + public Int32 Month { get; set; } + public Int32 Day { get; set; } + public Int32 Hour { get; set; } + public Int32 Minute { get; set; } + public Int32 Second { get; set; } private GameTime gameTime; } @@ -45,37 +45,37 @@ namespace MudEngine.GameManagement /// /// Gets or Sets how many Hours it takes to make a full day in the World /// - public int HoursPerDay { get; set; } + public Int32 HoursPerDay { get; set; } /// /// Gets or Sets how many minutes it takes to make a full Hour /// - public int MinutesPerHour { get; set; } + public Int32 MinutesPerHour { get; set; } /// /// Gets or Sets how many seconds it takes to make a full minute /// - public int SecondsPerMinute { get; set; } + public Int32 SecondsPerMinute { get; set; } /// /// Gets or Sets how many Days it takes to make a full month in the world /// - public int DaysPerMonth { get; set; } + public Int32 DaysPerMonth { get; set; } /// /// Gets or Sets how many Months it takes to make a full Year in the world /// - public int MonthsPerYear { get; set; } + public Int32 MonthsPerYear { get; set; } /// /// Gets or Sets the name of each Day in a Week. /// - public List DayNames { get; set; } + public List DayNames { get; set; } /// /// Gets or Sets the name of each Month in a Year. /// - public List MonthNames { get; set; } + public List MonthNames { get; set; } /// /// Gets or Sets what time of day the world is currently in. @@ -85,12 +85,12 @@ namespace MudEngine.GameManagement /// /// Gets or Sets what time of day that it begins to transition to night. /// - public int DawnTime { get; set; } + public Int32 DawnTime { get; set; } /// /// /Gets or Sets what time of day that it begins to transition into day time. /// - public int SunriseTime { get; set; } + public Int32 SunriseTime { get; set; } /// /// Gets or Sets the initial Time that the world starts in. @@ -103,8 +103,8 @@ namespace MudEngine.GameManagement ServerStartTime = DateTime.Now; - DayNames = new List(); - MonthNames = new List(); + DayNames = new List(); + MonthNames = new List(); DayNames.Add("Monday"); DayNames.Add("Tuesday"); @@ -240,7 +240,7 @@ namespace MudEngine.GameManagement CurrentWorldTime = t; } - public string GetCurrentWorldTime() + public String GetCurrentWorldTime() { if (DayNames.Count < CurrentWorldTime.Day) { @@ -251,8 +251,8 @@ namespace MudEngine.GameManagement return "Not enough Month names specified to match up with MonthsPerYear property."; } - string day = DayNames[CurrentWorldTime.Day - 1]; - string month = MonthNames[CurrentWorldTime.Month - 1]; + String day = DayNames[CurrentWorldTime.Day - 1]; + String month = MonthNames[CurrentWorldTime.Month - 1]; return day + ", " + month + " " + CurrentWorldTime.Day + ", " + CurrentWorldTime.Year + ": " + CurrentWorldTime.Hour + ":" + CurrentWorldTime.Minute + ":" + CurrentWorldTime.Second; } diff --git a/MudEngine/GameManagement/GameWorld.cs b/MudEngine/GameManagement/GameWorld.cs index 03b5141..862d48a 100644 --- a/MudEngine/GameManagement/GameWorld.cs +++ b/MudEngine/GameManagement/GameWorld.cs @@ -90,35 +90,10 @@ namespace MudEngine.GameManagement public void Save() { //Save all of the Environments - for (int x = 0; x <= Realms.Count - 1; x++) + for (Int32 x = 0; x <= Realms.Count - 1; x++) { - string realmFile = Path.Combine(_Game.DataPaths.Environment, Realms[x].Filename); - - //Save the Realm - Realms[x].Save(realmFile); - - //Loop through each Zone in the Realm and save it. - for (int y = 0; y <= Realms[x].ZoneCollection.Count - 1; y++) - { - string zonePath = Path.Combine(_Game.DataPaths.Environment, Path.GetFileNameWithoutExtension(Realms[x].Filename), Path.GetFileNameWithoutExtension(Realms[x].ZoneCollection[y].Filename)); - - if (!Directory.Exists(zonePath)) - Directory.CreateDirectory(zonePath); - - //Save the Zone. - Realms[x].ZoneCollection[y].Save(Path.Combine(zonePath, Realms[x].ZoneCollection[y].Filename)); - - for (int z = 0; z <= Realms[x].ZoneCollection[y].RoomCollection.Count - 1; z++) - { - if (!Directory.Exists(Path.Combine(zonePath, "Rooms"))) - Directory.CreateDirectory(Path.Combine(zonePath, "Rooms")); - - string roomPath = Path.Combine(zonePath, "Rooms"); - - Realms[x].ZoneCollection[y].RoomCollection[z].Save(Path.Combine(roomPath, Realms[x].ZoneCollection[y].RoomCollection[z].Filename)); - } - } - } //Complete Environment saving. + Realms[x].Save(_Game.DataPaths.Environment); + } } /// @@ -156,7 +131,7 @@ namespace MudEngine.GameManagement /// Determins the Type of object to perform the search for. Using Standard will search for objects that inherit from BaseObject, but none of BaseObjects child Types. /// /// - public BaseObject GetObject(ObjectTypes objectType, string filename) + public BaseObject GetObject(ObjectTypes objectType, String filename) { BaseObject obj = new BaseObject(_Game); @@ -190,7 +165,7 @@ namespace MudEngine.GameManagement /// /// /// - private Realm GetRealm(string filename) + private Realm GetRealm(String filename) { foreach (Realm r in Realms) { diff --git a/MudEngine/GameManagement/ICommand.cs b/MudEngine/GameManagement/ICommand.cs index 76a94ef..b2b6ac4 100644 --- a/MudEngine/GameManagement/ICommand.cs +++ b/MudEngine/GameManagement/ICommand.cs @@ -15,10 +15,10 @@ namespace MudEngine.GameManagement public interface IGameCommand { //Name of the command - string Name { get; set; } + String Name { get; set; } //Used to override commands with the same name - bool Override { get; set; } + Boolean Override { get; set; } //Executes the command. - CommandResults Execute(string command, BaseCharacter player); + CommandResults Execute(String command, BaseCharacter player); } } diff --git a/MudEngine/GameManagement/Log.cs b/MudEngine/GameManagement/Log.cs index b1f9bea..058293e 100644 --- a/MudEngine/GameManagement/Log.cs +++ b/MudEngine/GameManagement/Log.cs @@ -10,12 +10,12 @@ namespace MudEngine.GameManagement { public static class Log { - static List cachedMessages = new List(); + static List cachedMessages = new List(); public static Boolean IsVerbose; - public static void Write(string message) + public static void Write(String message) { - string filename = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Root), "Log.txt"); + String filename = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Root), "Log.txt"); StreamWriter sw; if (File.Exists(filename)) @@ -30,12 +30,11 @@ namespace MudEngine.GameManagement cachedMessages.Add(message); } - public static string GetMessages() + public static String GetMessages() { - string messages = ""; StringBuilder sb = new StringBuilder(); - foreach (string message in cachedMessages) + foreach (String message in cachedMessages) { sb.AppendLine(message); } @@ -48,7 +47,7 @@ namespace MudEngine.GameManagement public static void FlushMessages() { - cachedMessages = new List(); + cachedMessages = new List(); } } } diff --git a/MudEngine/GameObjects/Bag.cs b/MudEngine/GameObjects/Bag.cs index f9c0a6b..908d55c 100644 --- a/MudEngine/GameObjects/Bag.cs +++ b/MudEngine/GameObjects/Bag.cs @@ -14,7 +14,7 @@ namespace MudEngine.GameObjects /// /// Gets or Sets the size of the bag. /// - public int Size + public Int32 Size { get; set; @@ -32,7 +32,7 @@ namespace MudEngine.GameObjects Items.Add(item); } - public int GetSlotsRemaining() + public Int32 GetSlotsRemaining() { return Size - Items.Count; } diff --git a/MudEngine/GameObjects/BaseObject.cs b/MudEngine/GameObjects/BaseObject.cs index a370117..1801eba 100644 --- a/MudEngine/GameObjects/BaseObject.cs +++ b/MudEngine/GameObjects/BaseObject.cs @@ -19,7 +19,7 @@ namespace MudEngine.GameObjects [Description("The Display Name assigned to this object.")] //Required to refresh Filename property in the editors propertygrid [RefreshProperties(RefreshProperties.All)] - public string Name + public String Name { get { @@ -34,21 +34,21 @@ namespace MudEngine.GameObjects Filename = value + "." + this.GetType().Name; } } - private string _Name; + private String _Name; [Category("Object Setup")] [Description("A brief description of this object. The description is displayed to users when they use a command for investigating an object")] - public string Description { get; set; } + public String Description { get; set; } /// /// A detailed description that treats each entry as a seperete line when outputted to the player /// - public List DetailedDescription { get; set; } + public List DetailedDescription { get; set; } [Category("Object Setup")] [ReadOnly(true)] [Description("The filename of the current object. This is assigned by the engine and not editable.")] - public string Filename + public String Filename { //Returns the name of the object + the objects Type as it's extension. //Filenames are generated by the class itself, users can not assign it. @@ -59,17 +59,17 @@ namespace MudEngine.GameObjects [Category("Environment Information")] [Description("If a user asks to use his/her senses to investigate an area, this is one of the results that will be displayed. Senses can be used to assist blind characters.")] [DefaultValue("You don't smell anything unsual.")] - public string Smell { get; set; } + public String Smell { get; set; } [Category("Environment Information")] [Description("If a user asks to use his/her senses to investigate an area, this is one of the results that will be displayed. Senses can be used to assist blind characters.")] [DefaultValue("You hear nothing of interest.")] - public string Listen { get; set; } + public String Listen { get; set; } [Category("Environment Information")] [Description("If a user asks to use his/her senses to investigate an area, this is one of the results that will be displayed. Senses can be used to assist blind characters.")] [DefaultValue("You feel nothing.")] - public string Feel { get; set; } + public String Feel { get; set; } public Game ActiveGame { get; set; } @@ -80,7 +80,7 @@ namespace MudEngine.GameObjects { Name = "New " + this.GetType().Name; ActiveGame = game; - DetailedDescription = new List(); + DetailedDescription = new List(); this.Feel = "You feel nothing."; this.Listen = "You hear nothing of interest."; @@ -95,7 +95,7 @@ namespace MudEngine.GameObjects { } - private bool ShouldSerializeName() + private Boolean ShouldSerializeName() { return this.Name != DefaultName(); } @@ -105,13 +105,13 @@ namespace MudEngine.GameObjects this.Name = DefaultName(); } - private string DefaultName() + private String DefaultName() { return "New " + this.GetType().Name; } #region Public Methods - public override string ToString() + public override String ToString() { return this.Name; } @@ -148,7 +148,7 @@ namespace MudEngine.GameObjects { } - public virtual void Save(string path) + public virtual void Save(String path) { if (String.IsNullOrEmpty(path)) return; @@ -156,19 +156,19 @@ namespace MudEngine.GameObjects if (!Directory.Exists(path)) Directory.CreateDirectory(path); - path = Path.Combine(path, Filename); + String filename = Path.Combine(path, Filename); - if (File.Exists(path)) - File.Delete(path); + if (File.Exists(filename)) + File.Delete(filename); - FileManager.WriteLine(path, this.Name, "Name"); - FileManager.WriteLine(path, this.Description, "Description"); - FileManager.WriteLine(path, this.Feel, "Feel"); - FileManager.WriteLine(path, this.Listen, "Listen"); - FileManager.WriteLine(path, this.Smell, "Smell"); + FileManager.WriteLine(filename, this.Name, "Name"); + FileManager.WriteLine(filename, this.Description, "Description"); + FileManager.WriteLine(filename, this.Feel, "Feel"); + FileManager.WriteLine(filename, this.Listen, "Listen"); + FileManager.WriteLine(filename, this.Smell, "Smell"); } - public virtual void Load(string filename) + public virtual void Load(String filename) { this.Name = FileManager.GetData(filename, "Name"); this.Description = FileManager.GetData(filename, "Description"); diff --git a/MudEngine/GameObjects/Characters/BaseCharacter.cs b/MudEngine/GameObjects/Characters/BaseCharacter.cs index e8740bb..abf1374 100644 --- a/MudEngine/GameObjects/Characters/BaseCharacter.cs +++ b/MudEngine/GameObjects/Characters/BaseCharacter.cs @@ -67,7 +67,7 @@ namespace MudEngine.GameObjects.Characters CommandSystem = new CommandEngine(); } - public override void Load(string filename) + public override void Load(String filename) { base.Load(filename); @@ -75,12 +75,12 @@ namespace MudEngine.GameObjects.Characters //Need to re-assign the enumerator value that was previously assigned to the Role property Array values = Enum.GetValues(typeof(SecurityRoles)); - foreach (int value in values) + foreach (Int32 value in values) { - //Since enum values are not strings, we can't simply just assign the string to the enum - string displayName = Enum.GetName(typeof(SecurityRoles), value); + //Since enum values are not strings, we can't simply just assign the String to the enum + String displayName = Enum.GetName(typeof(SecurityRoles), value); - //If the value = the string saved, then perform the needed conversion to get our data back + //If the value = the String saved, then perform the needed conversion to get our data back if (displayName.ToLower() == FileManager.GetData(filename, "Role").ToLower()) { Role = (SecurityRoles)Enum.Parse(typeof(SecurityRoles), displayName); @@ -138,7 +138,7 @@ namespace MudEngine.GameObjects.Characters } } - public override void Save(string path) + public override void Save(String path) { base.Save(path); @@ -157,7 +157,7 @@ namespace MudEngine.GameObjects.Characters /// /// /// - public bool Move(AvailableTravelDirections travelDirection) + public Boolean Move(AvailableTravelDirections travelDirection) { //Check if the current room has a doorway in the supplied direction of travel. if (!CurrentRoom.DoorwayExist(travelDirection)) @@ -166,14 +166,14 @@ namespace MudEngine.GameObjects.Characters } //Let other players know that the user walked out. - for (int i = 0; i != ActiveGame.PlayerCollection.Length; i++) + for (Int32 i = 0; i != ActiveGame.PlayerCollection.Length; i++) { if (ActiveGame.PlayerCollection[i].Name == Name) continue; - string room = ActiveGame.PlayerCollection[i].CurrentRoom.Filename; - string realm = ActiveGame.PlayerCollection[i].CurrentRoom.Realm; - string zone = ActiveGame.PlayerCollection[i].CurrentRoom.Zone; + String room = ActiveGame.PlayerCollection[i].CurrentRoom.Filename; + String realm = ActiveGame.PlayerCollection[i].CurrentRoom.Realm; + String zone = ActiveGame.PlayerCollection[i].CurrentRoom.Zone; if ((room == CurrentRoom.Filename) && (realm == CurrentRoom.Realm) && (zone == CurrentRoom.Zone)) { @@ -193,14 +193,14 @@ namespace MudEngine.GameObjects.Characters { //TODO: Check the Room/Zone/Realm to see if anything needs to occure during travel. //Let other players know that the user walked in. - for (int i = 0; i != ActiveGame.PlayerCollection.Length; i++) + for (Int32 i = 0; i != ActiveGame.PlayerCollection.Length; i++) { if (ActiveGame.PlayerCollection[i].Name == Name) continue; - string room = ActiveGame.PlayerCollection[i].CurrentRoom.Name; - string realm = ActiveGame.PlayerCollection[i].CurrentRoom.Realm; - string zone = ActiveGame.PlayerCollection[i].CurrentRoom.Zone; + String room = ActiveGame.PlayerCollection[i].CurrentRoom.Name; + String realm = ActiveGame.PlayerCollection[i].CurrentRoom.Realm; + String zone = ActiveGame.PlayerCollection[i].CurrentRoom.Zone; if ((room == CurrentRoom.Name) && (realm == CurrentRoom.Realm) && (zone == CurrentRoom.Zone)) { @@ -209,7 +209,7 @@ namespace MudEngine.GameObjects.Characters } } - public void ExecuteCommand(string command) + public void ExecuteCommand(String command) { //TODO: Character class can handle a lot of the command management here, checking various things prior to sending //the command off to the command engine for execution. @@ -226,7 +226,7 @@ namespace MudEngine.GameObjects.Characters StringBuilder sb = new StringBuilder(); foreach (object item in result.Result) { - if (item is string) + if (item is String) sb.AppendLine(item.ToString()); } return sb.ToString(); @@ -249,7 +249,7 @@ namespace MudEngine.GameObjects.Characters //Ensure custom commands are loaded until everything is fleshed out. if (Game.IsDebug) { - foreach (string command in CommandEngine.GetCommands()) + foreach (String command in CommandEngine.GetCommands()) { Log.Write("Command loaded: " + command); } @@ -268,7 +268,7 @@ namespace MudEngine.GameObjects.Characters ExecuteCommand("Login"); ExecuteCommand("Look"); //MUST happen after Room setup is completed, otherwise the player default Abyss Room is printed. } - internal void Receive(string data) + internal void Receive(String data) { //data = ExecuteCommand(data); ExecuteCommand(data); @@ -282,7 +282,7 @@ namespace MudEngine.GameObjects.Characters /// /// /// - internal void Send(string data, bool newLine) + internal void Send(String data, Boolean newLine) { try { @@ -305,7 +305,7 @@ namespace MudEngine.GameObjects.Characters /// Sends data to the player. /// /// - internal void Send(string data) + internal void Send(String data) { Send(data, true); } @@ -346,7 +346,7 @@ namespace MudEngine.GameObjects.Characters Log.Write("Player " + this.Name + " disconnected."); } } - internal string ReadInput() + internal String ReadInput() { if (ActiveGame.IsMultiplayer) { @@ -356,7 +356,7 @@ namespace MudEngine.GameObjects.Characters try { byte[] buf = new byte[1]; - int recved = client.Receive(buf); + Int32 recved = client.Receive(buf); if (recved > 0) { diff --git a/MudEngine/GameObjects/Currency.cs b/MudEngine/GameObjects/Currency.cs index 86a49d8..6e5e1ca 100644 --- a/MudEngine/GameObjects/Currency.cs +++ b/MudEngine/GameObjects/Currency.cs @@ -15,7 +15,7 @@ namespace MudEngine.GameObjects /// /// The value of this currency. It should be how many 'base currency' it takes to equal 1 of this currency /// - public int Value + public Int32 Value { get; set; diff --git a/MudEngine/GameObjects/Environment/Door.cs b/MudEngine/GameObjects/Environment/Door.cs index f4daad4..6ae80dc 100644 --- a/MudEngine/GameObjects/Environment/Door.cs +++ b/MudEngine/GameObjects/Environment/Door.cs @@ -17,7 +17,7 @@ namespace MudEngine.GameObjects.Environment { [Category("Door Settings")] [DefaultValue(false)] - public bool IsLocked + public Boolean IsLocked { get; set; @@ -33,7 +33,7 @@ namespace MudEngine.GameObjects.Environment [Category("Door Settings")] [DefaultValue(0)] - public int LevelRequirement + public Int32 LevelRequirement { get; set; diff --git a/MudEngine/GameObjects/Environment/Realm.cs b/MudEngine/GameObjects/Environment/Realm.cs index d07626d..f86775a 100644 --- a/MudEngine/GameObjects/Environment/Realm.cs +++ b/MudEngine/GameObjects/Environment/Realm.cs @@ -23,7 +23,7 @@ namespace MudEngine.GameObjects.Environment /// /// Gets or Sets if this Realm is the starting realm for the game. /// - public bool IsInitialRealm { get; set; } + public Boolean IsInitialRealm { get; set; } /// /// The Initial Starting Zone for this Realm. @@ -35,14 +35,24 @@ namespace MudEngine.GameObjects.Environment ZoneCollection = new List(); } - public override void Save(string path) + public override void Save(String path) { + path = Path.Combine(path, Path.GetFileNameWithoutExtension(Filename)); base.Save(path); - //TODO: Save Realm collections and Zone to file. + String filename = Path.Combine(path, Filename); + + FileManager.WriteLine(filename, this.IsInitialRealm.ToString(), "IsInitialRealm"); + FileManager.WriteLine(filename, this.InitialZone.Filename, "InitialZone"); + + foreach (Zone z in ZoneCollection) + { + FileManager.WriteLine(filename, z.Filename, "ZoneCollection"); + z.Save(path); + } } - public List GetZoneByFilename(string filename) + public List GetZoneByFilename(String filename) { List zones = new List(); diff --git a/MudEngine/GameObjects/Environment/Room.cs b/MudEngine/GameObjects/Environment/Room.cs index 6a1caf9..44a40c4 100644 --- a/MudEngine/GameObjects/Environment/Room.cs +++ b/MudEngine/GameObjects/Environment/Room.cs @@ -27,7 +27,7 @@ namespace MudEngine.GameObjects.Environment [ReadOnly(true)] [Description("This is the Zone that the Room is currently assigned to.")] [Category("Environment Information")] - public string Zone + public String Zone { get; set; @@ -36,7 +36,7 @@ namespace MudEngine.GameObjects.Environment [ReadOnly(true)] [Description("This is the Realm that the Room belongs to.")] [Category("Environment Information")] - public string Realm + public String Realm { get; set; @@ -45,18 +45,18 @@ namespace MudEngine.GameObjects.Environment [Category("Environment Information")] [DefaultValue(false)] [Description("Determins if the Player can be attacked within this Room or not.")] - public bool IsSafe + public Boolean IsSafe { get; set; } [Browsable(false)] - public string InstallPath + public String InstallPath { get { - string zonePath = ""; + String zonePath = ""; if (this.Realm == null || this.Realm == "No Realm Associated.") { zonePath = FileManager.GetDataPath(SaveDataTypes.Zones); @@ -65,8 +65,8 @@ namespace MudEngine.GameObjects.Environment else zonePath = FileManager.GetDataPath(this.Realm, this.Zone); - string roomPath = Path.Combine(zonePath, "Rooms"); - string filename = Path.Combine(roomPath, this.Filename); + String roomPath = Path.Combine(zonePath, "Rooms"); + String filename = Path.Combine(roomPath, this.Filename); return filename; } } @@ -76,7 +76,7 @@ namespace MudEngine.GameObjects.Environment /// [Browsable(true)] [Description("Sets if this is the starting room for the Zone that contains it.")] - public bool IsInitialRoom + public Boolean IsInitialRoom { get; set; @@ -89,12 +89,19 @@ namespace MudEngine.GameObjects.Environment IsSafe = false; } + public override void Save(String path) + { + base.Save(path); + + String filename = Path.Combine(path, Filename); + } + /// /// Checks to see if a doorway in the travelDirection exists. /// /// /// - public bool DoorwayExist(AvailableTravelDirections travelDirection) + public Boolean DoorwayExist(AvailableTravelDirections travelDirection) { foreach (Door door in Doorways) { diff --git a/MudEngine/GameObjects/Environment/StartingLocation.cs b/MudEngine/GameObjects/Environment/StartingLocation.cs index 0c75c4b..767ddd2 100644 --- a/MudEngine/GameObjects/Environment/StartingLocation.cs +++ b/MudEngine/GameObjects/Environment/StartingLocation.cs @@ -1,4 +1,6 @@ -//MUD Engine +using System; + +//MUD Engine using MudEngine.FileSystem; using MudEngine.GameObjects; using MudEngine.GameObjects.Environment; @@ -7,13 +9,13 @@ namespace MudEngine.GameObjects.Environment { public struct StartingLocation { - public string Room; - public string Zone; - public string Realm; + public String Room; + public String Zone; + public String Realm; - public override string ToString() + public override String ToString() { - if (string.IsNullOrEmpty(Room)) + if (String.IsNullOrEmpty(Room)) return "No initial location defined."; else { diff --git a/MudEngine/GameObjects/Environment/TravelDirections.cs b/MudEngine/GameObjects/Environment/TravelDirections.cs index d88e5ae..138c64b 100644 --- a/MudEngine/GameObjects/Environment/TravelDirections.cs +++ b/MudEngine/GameObjects/Environment/TravelDirections.cs @@ -39,13 +39,13 @@ namespace MudEngine.GameObjects } } - public static AvailableTravelDirections GetTravelDirectionValue(string Direction) + public static AvailableTravelDirections GetTravelDirectionValue(String Direction) { Array values = Enum.GetValues(typeof(AvailableTravelDirections)); - foreach (int value in values) + foreach (Int32 value in values) { - string displayName = Enum.GetName(typeof(AvailableTravelDirections), value); + String displayName = Enum.GetName(typeof(AvailableTravelDirections), value); if (displayName.ToLower() == Direction.ToLower()) return (AvailableTravelDirections)Enum.Parse(typeof(AvailableTravelDirections), displayName); diff --git a/MudEngine/GameObjects/Environment/Zone.cs b/MudEngine/GameObjects/Environment/Zone.cs index 3241732..ef07abd 100644 --- a/MudEngine/GameObjects/Environment/Zone.cs +++ b/MudEngine/GameObjects/Environment/Zone.cs @@ -20,7 +20,7 @@ namespace MudEngine.GameObjects.Environment [Category("Environment Information")] [DefaultValue(0)] [Description("The amount to drain each stat by if StatDrain is enabled.")] - public int StatDrainAmount + public Int32 StatDrainAmount { get; set; @@ -29,7 +29,7 @@ namespace MudEngine.GameObjects.Environment [Category("Environment Information")] [Description("Enable or Disable the ability for draining stats while traversing.")] [DefaultValue(false)] - public bool StatDrain + public Boolean StatDrain { get; set; @@ -38,7 +38,7 @@ namespace MudEngine.GameObjects.Environment [ReadOnly(true)] [Category("Environment Information")] [Description("The Realm that this Zone is assigned to. It is not required to be contained within a Realm.")] - public string Realm + public String Realm { get; set; @@ -47,7 +47,7 @@ namespace MudEngine.GameObjects.Environment [Category("Environment Information")] [Description("Determins if the Player can be attacked within this Room or not.")] [DefaultValue(false)] - public bool IsSafe + public Boolean IsSafe { get; set; @@ -59,7 +59,7 @@ namespace MudEngine.GameObjects.Environment [Category("Environment Information")] [Description("Sets that this Zone is a starting Zone for the game.")] [DefaultValue(false)] - public bool IsInitialZone + public Boolean IsInitialZone { get; set; @@ -83,6 +83,28 @@ namespace MudEngine.GameObjects.Environment Realm = "No Realm Associated."; } + public override void Save(String path) + { + path = Path.Combine(path, Path.GetFileNameWithoutExtension(Filename)); + + base.Save(path); + + String filename = Path.Combine(path, Filename); + + FileManager.WriteLine(filename, this.IsInitialZone.ToString(), "IsInitialZone"); + FileManager.WriteLine(filename, this.IsSafe.ToString(), "IsSafe"); + FileManager.WriteLine(filename, this.Realm, "Realm"); + FileManager.WriteLine(filename, this.StatDrain.ToString(), "StatDrain"); + FileManager.WriteLine(filename, this.StatDrainAmount.ToString(), "StatDrainAmount"); + FileManager.WriteLine(filename, this.InitialRoom.Filename, "InitialRoom"); + + foreach (Room r in RoomCollection) + { + FileManager.WriteLine(filename, r.Filename, "Room"); + r.Save(path); + } + } + /// /// Adds the supplied room into the Zones Room collection. /// @@ -111,7 +133,7 @@ namespace MudEngine.GameObjects.Environment room.Realm = Realm; } - public List GetRoomByFilename(string filename) + public List GetRoomByFilename(String filename) { List rooms = new List(); diff --git a/MudEngine/MudEngine.csproj b/MudEngine/MudEngine.csproj index c7090c8..a5a574b 100644 --- a/MudEngine/MudEngine.csproj +++ b/MudEngine/MudEngine.csproj @@ -59,6 +59,7 @@ + diff --git a/MudEngine/Networking/Server.cs b/MudEngine/Networking/Server.cs index bf35c10..64660cb 100644 --- a/MudEngine/Networking/Server.cs +++ b/MudEngine/Networking/Server.cs @@ -24,7 +24,7 @@ namespace MudEngine.Networking stage = 0; port = 0; } - public bool Initialize(int p, ref BaseCharacter[] pbs) + public Boolean Initialize(Int32 p, ref BaseCharacter[] pbs) { if (stage != 0) return false; @@ -36,7 +36,7 @@ namespace MudEngine.Networking stage++; return true; } - public bool Start() + public Boolean Start() { try { @@ -65,10 +65,10 @@ namespace MudEngine.Networking { while (stage == 2) { - int sub = -1; + Int32 sub = -1; do { - for (int i = 0; i < players.Length; i++) + for (Int32 i = 0; i < players.Length; i++) { if (!players[i].IsActive) { @@ -86,14 +86,14 @@ namespace MudEngine.Networking } private void ReceiveThread(object obj) { - int sub = (int)obj; + Int32 sub = (Int32)obj; players[sub].Initialize(); while (stage == 2 && players[sub].IsActive) { players[sub].Receive(players[sub].ReadInput()); } } - public void Disconnect(int sub) + public void Disconnect(Int32 sub) { if (sub > 0 && sub < players.Length) { @@ -105,8 +105,8 @@ namespace MudEngine.Networking private Thread serverThread; private Socket server; - private int stage; - private int port; + private Int32 stage; + private Int32 port; BaseCharacter[] players; diff --git a/MudEngine/Scripting/GameObject.cs b/MudEngine/Scripting/GameObject.cs index aa93c21..f6ec286 100644 --- a/MudEngine/Scripting/GameObject.cs +++ b/MudEngine/Scripting/GameObject.cs @@ -18,14 +18,14 @@ namespace MudEngine.Scripting /// /// The Type name for this object /// - public string Name { get; set; } + public String Name { get; set; } /// /// Determins if this object will recieve Update/Draw calls from the ScriptEngine /// - public bool IsActive { get; set; } + public Boolean IsActive { get; set; } - public GameObject(object instance, string name) + public GameObject(object instance, String name) { Instance = instance; Name = name; @@ -36,27 +36,27 @@ namespace MudEngine.Scripting return Instance; } - public bool DeleteObject() + public Boolean DeleteObject() { return true; } - public void SetProperty(string propertyName, object propertyValue) + public void SetProperty(String propertyName, object propertyValue) { PropertyInfo propertyInfo = Instance.GetType().GetProperty(propertyName); - if (propertyValue is string) + if (propertyValue is String) { - if (propertyInfo.PropertyType.Name is string) + if (propertyInfo.PropertyType.Name is String) { propertyInfo.SetValue(Instance, propertyValue, null); } } } - public object GetProperty(string propertyName) + public object GetProperty(String propertyName) { - string[] tokens = propertyName.Split('.'); + String[] tokens = propertyName.Split('.'); PropertyInfo previousProperty = Instance.GetType().GetProperty(tokens[0]); return previousProperty.GetValue(Instance, null); @@ -67,7 +67,7 @@ namespace MudEngine.Scripting return Instance; } - public object InvokeMethod(string methodName, params object[] parameters) + public object InvokeMethod(String methodName, params object[] parameters) { MethodInfo method = Instance.GetType().GetMethod(methodName); diff --git a/MudEngine/Scripting/ScriptEngine.cs b/MudEngine/Scripting/ScriptEngine.cs index b4f15e6..61985d9 100644 --- a/MudEngine/Scripting/ScriptEngine.cs +++ b/MudEngine/Scripting/ScriptEngine.cs @@ -30,7 +30,7 @@ namespace MudEngine.Scripting /// /// Path to the the script files directory /// - public string ScriptPath + public String ScriptPath { get { @@ -41,9 +41,9 @@ namespace MudEngine.Scripting _ScriptPath = Path.Combine(FileManager.GetDataPath(SaveDataTypes.Root), value); } } - string _ScriptPath; + String _ScriptPath; - public string InstallPath { get; private set; } + public String InstallPath { get; private set; } public GameObjectCollection ObjectCollection { get; private set; } /// @@ -58,33 +58,33 @@ namespace MudEngine.Scripting /// /// File Extension for the scripts /// - public string ScriptExtension { get; set; } + public String ScriptExtension { get; set; } /// /// Error Messages logged during script compilation /// - public string ErrorMessage + public String ErrorMessage { get { - string errorMessages = "Script Compilation Failed!\n"; + String errorMessages = "Script Compilation Failed!\n"; //Construct our error message. - foreach (string error in _ErrorMessages) + foreach (String error in _ErrorMessages) errorMessages += error + "\n"; return errorMessages; } private set { - _ErrorMessages = new string[] { value }; + _ErrorMessages = new String[] { value }; } } internal ScriptTypes ScriptType { get; set; } private Assembly _ScriptAssembly; private List _AssemblyCollection; - private string[] _ErrorMessages; - private string _SettingsFile; + private String[] _ErrorMessages; + private String _SettingsFile; Game _Game; public ScriptEngine(Game game) : this(game, ScriptTypes.Assembly) @@ -123,7 +123,7 @@ namespace MudEngine.Scripting /// Compiles a collection of scripts stored in ScriptEngine.ScriptPath. Not supported on XBox360. /// /// - public bool CompileScripts() + public Boolean CompileScripts() { #if !MOBILE //Ensure the script path exists. @@ -133,7 +133,7 @@ namespace MudEngine.Scripting return false; } //Build an array of scripts - string[] scripts = System.IO.Directory.GetFiles(ScriptPath, "*" + ScriptExtension, System.IO.SearchOption.AllDirectories); + String[] scripts = System.IO.Directory.GetFiles(ScriptPath, "*" + ScriptExtension, System.IO.SearchOption.AllDirectories); //Prepare the scripts. MUD Scripts are wrote without defining a namespace if (Directory.Exists("temp")) @@ -142,20 +142,20 @@ namespace MudEngine.Scripting Directory.CreateDirectory("temp"); //Setup the additional sourcecode that's needed in the script. - string[] usingStatements = new string[] { "using System;", "using MudEngine.GameObjects;", "using MudEngine.GameObjects.Characters;", "using MudEngine.GameObjects.Environment;", "using MudEngine.GameObjects.Items;", "using MudEngine.GameManagement;", "using MudEngine.FileSystem;", "using MudEngine.Scripting;" }; + String[] usingStatements = new String[] { "using System;", "using MudEngine.GameObjects;", "using MudEngine.GameObjects.Characters;", "using MudEngine.GameObjects.Environment;", "using MudEngine.GameObjects.Items;", "using MudEngine.GameManagement;", "using MudEngine.FileSystem;", "using MudEngine.Scripting;" }; - foreach (string script in scripts) + foreach (String script in scripts) { - string tempPath = "temp"; - string source = "\nnamespace MudScripts{\n}"; + String tempPath = "temp"; + String source = "\nnamespace MudScripts{\n}"; FileStream fr = new FileStream(script, FileMode.Open, FileAccess.Read, FileShare.None); FileStream fw = new FileStream(Path.Combine(tempPath, Path.GetFileName(script)), FileMode.Create, FileAccess.Write); StreamWriter sw = new StreamWriter(fw, System.Text.Encoding.Default); StreamReader sr = new StreamReader(fr, System.Text.Encoding.Default); - string content = sr.ReadToEnd(); - foreach (string statement in usingStatements) + String content = sr.ReadToEnd(); + foreach (String statement in usingStatements) source = source.Insert(0, statement); source = source.Insert(source.Length - 1, content); @@ -164,14 +164,14 @@ namespace MudEngine.Scripting sw.Flush(); sw.Close(); } - string oldPath = ScriptPath; + String oldPath = ScriptPath; ScriptPath = "temp"; //Prepare the compiler. - Dictionary providerOptions = new Dictionary(); + Dictionary providerOptions = new Dictionary(); providerOptions.Add("CompilerVersion", "v3.5"); - CompilerParameters param = new CompilerParameters(new string[] {"mscorlib.dll", "System.dll", "MudEngine.dll"}); + CompilerParameters param = new CompilerParameters(new String[] {"mscorlib.dll", "System.dll", "MudEngine.dll"}); param.GenerateExecutable = false; param.GenerateInMemory = true; if (!param.GenerateInMemory) @@ -193,10 +193,10 @@ namespace MudEngine.Scripting //if we encountered errors we need to log them to our ErrorMessages property if (results.Errors.Count >= 1) { - List errorCollection = new List(); + List errorCollection = new List(); foreach (CompilerError error in results.Errors) { - string prefix = "Error: "; + String prefix = "Error: "; if (error.IsWarning) prefix = "Warning: "; @@ -270,7 +270,7 @@ namespace MudEngine.Scripting Log.Write("Supplied script path does not exist! No scripts loaded."); return; } - string[] libraries = Directory.GetFiles(ScriptPath, "*.dll", SearchOption.AllDirectories); + String[] libraries = Directory.GetFiles(ScriptPath, "*.dll", SearchOption.AllDirectories); if (libraries.Length == 0) { @@ -278,9 +278,9 @@ namespace MudEngine.Scripting return; } - foreach (string library in libraries) + foreach (String library in libraries) { - bool isOK = true; + Boolean isOK = true; foreach (Assembly assembly in _AssemblyCollection) { @@ -304,7 +304,7 @@ namespace MudEngine.Scripting if (!Directory.Exists(ScriptPath)) Directory.CreateDirectory(ScriptPath); - string[] scripts = Directory.GetFiles(ScriptPath, "*.cs", SearchOption.AllDirectories); + String[] scripts = Directory.GetFiles(ScriptPath, "*.cs", SearchOption.AllDirectories); if (scripts.Length == 0) { @@ -315,7 +315,7 @@ namespace MudEngine.Scripting if (!CompileScripts()) { Log.Write("Error Compiling Scripts:"); - foreach (string error in _ErrorMessages) + foreach (String error in _ErrorMessages) { Log.Write("Error: " + error); } @@ -324,7 +324,7 @@ namespace MudEngine.Scripting _AssemblyCollection.Add(_ScriptAssembly); } - public GameObject GetObject(string objectName) + public GameObject GetObject(String objectName) { IEnumerable objectQuery = from gameObject in ObjectCollection._GameObjects @@ -340,7 +340,7 @@ namespace MudEngine.Scripting return null; } - public GameObject GetObjectOf(string baseTypeName) + public GameObject GetObjectOf(String baseTypeName) { foreach (GameObject obj in GameObjects) { diff --git a/MudGame/Program.cs b/MudGame/Program.cs index 8a0319b..1314d83 100644 --- a/MudGame/Program.cs +++ b/MudGame/Program.cs @@ -14,10 +14,10 @@ namespace MudGame { static class Program { - const string SettingsFile = "Settings.ini"; + const String SettingsFile = "Settings.ini"; static Game game; - static void Main(string[] args) + static void Main(String[] args) { Log.Write("Launching..."); @@ -61,7 +61,7 @@ namespace MudGame } else { - Log.Write("Setting up " + obj.GetProperty().GameTitle + " Manager..."); + Log.Write("Setting up " + obj.GetProperty("GameTitle") + " Manager..."); game = (Game)obj.Instance; scriptEngine = new ScriptEngine(game, ScriptEngine.ScriptTypes.Both); } @@ -109,10 +109,31 @@ namespace MudGame } } + Console.Title = game.GameTitle; + + if (game.IsMultiplayer) + Console.Title += " server running."; + + List buf = new List(); + while (game.IsRunning) { game.Update(); System.Threading.Thread.Sleep(1); + + StringBuilder sb = new StringBuilder(); + + ConsoleKeyInfo info = Console.ReadKey(); + + if (info.KeyChar == '\r') + { + foreach (char c in buf) + sb.Append(c); + + game.PlayerCollection[0].ExecuteCommand(sb.ToString()); + } + else + buf.Add(info.KeyChar); } } }