diff --git a/MudEngine/Commands/CommandLogin.cs b/MudEngine/Commands/CommandLogin.cs index 3e23830..036b41c 100644 --- a/MudEngine/Commands/CommandLogin.cs +++ b/MudEngine/Commands/CommandLogin.cs @@ -53,9 +53,6 @@ namespace MudEngine.Commands } player.Send("Welcome " + player.Name + "!"); - - //string playerName = player.Receive(); - //TODO: Read user input... return new CommandResults(); } } diff --git a/MudEngine/Commands/CommandWalk.cs b/MudEngine/Commands/CommandWalk.cs index df4113e..cd91ff4 100644 --- a/MudEngine/Commands/CommandWalk.cs +++ b/MudEngine/Commands/CommandWalk.cs @@ -33,7 +33,7 @@ namespace MudEngine.Commands //Move the player into their new room player.Move(door.TravelDirection); - CommandResults cmd = CommandEngine.ExecuteCommand("Look", player); + CommandResults cmd = player.CommandSystem.ExecuteCommand("Look", player); string lookValue = ""; if (cmd.Result.Length != 0) diff --git a/MudEngine/GameManagement/CommandEngine.cs b/MudEngine/GameManagement/CommandEngine.cs index 529f293..4745622 100644 --- a/MudEngine/GameManagement/CommandEngine.cs +++ b/MudEngine/GameManagement/CommandEngine.cs @@ -14,19 +14,28 @@ using MudEngine.GameManagement; namespace MudEngine.GameManagement { - public static class CommandEngine + public class CommandEngine { /// /// Gets or Sets a Dictionary list of available commands to use. /// - static internal Dictionary Commands { get { return _Commands; } set { _Commands = value; } } - static Dictionary _Commands = new Dictionary(); + public static Dictionary CommandCollection { get; set; } + + internal Dictionary _Commands { get; set; } + + public CommandEngine() + { + if ((CommandCollection == null) || (CommandCollection.Count == 0)) + CommandEngine.LoadBaseCommands(); + + _Commands = CommandCollection; + } public static List GetCommands() { List temp = new List(); - foreach (string name in Commands.Keys) + foreach (string name in CommandEngine.CommandCollection.Keys) { temp.Add(name); } @@ -34,9 +43,22 @@ namespace MudEngine.GameManagement return temp; } - public static bool GetCommand(string Name) + public static string GetCommand(object Parameter) { - if (Commands.ContainsKey(Name.ToLower())) + List objectList = (List)Parameter; + + foreach (object obj in objectList) + { + if (obj is string) + return (string)obj; + } + + return null; + } + + public static bool IsValidCommand(string Name) + { + if (CommandEngine.CommandCollection.ContainsKey(Name.ToLower())) return true; else return false; @@ -47,17 +69,18 @@ namespace MudEngine.GameManagement /// /// /// - public static CommandResults ExecuteCommand(string command, BaseCharacter player) + public CommandResults ExecuteCommand(string command, BaseCharacter player) { string commandKey = command.Insert(0, "Command"); if (Game.IsDebug) Log.Write("Executing command: " + command); - foreach (string key in Commands.Keys) + foreach (string key in player.CommandSystem._Commands.Keys) { if (commandKey.ToLower().Contains(key.ToLower())) { - return Commands[key.ToLower()].Execute(command, player); + return player.CommandSystem._Commands[key.ToLower()].Execute(command, player); + //return player.Commands.ExecuteCommand[key.ToLower()]Execute(command, player); } } @@ -66,7 +89,7 @@ namespace MudEngine.GameManagement public static void LoadBaseCommands() { - LoadCommandLibrary(Assembly.GetExecutingAssembly()); + LoadCommandLibrary(Assembly.GetExecutingAssembly(), true); } /// @@ -109,7 +132,7 @@ namespace MudEngine.GameManagement Log.Write("Loading commands within " + Path.GetFileName(commandLibrary.Location)); if (purgeOldCommands) - ClearCommands(); + CommandEngine.ClearCommands(); foreach (Type t in commandLibrary.GetTypes()) { @@ -126,17 +149,17 @@ namespace MudEngine.GameManagement command.Name = command.Name.ToLower(); //Add the command to the commands list if it does not already exist - if (Commands.ContainsKey(command.Name)) + if (CommandEngine.CommandCollection.ContainsKey(command.Name)) { //Command exists, check if the command is set to override existing commands or not if (command.Override) { - Commands[command.Name] = command; + CommandEngine.CommandCollection[command.Name] = command; } } //Command does not exist, add it to the commands list else - Commands.Add(command.Name, command); + CommandEngine.CommandCollection.Add(command.Name, command); } } } @@ -144,20 +167,7 @@ namespace MudEngine.GameManagement public static void ClearCommands() { - _Commands = new Dictionary(); - } - - public static string GetCommand(object Parameter) - { - List objectList = (List)Parameter; - - foreach (object obj in objectList) - { - if (obj is string) - return (string)obj; - } - - return null; + CommandEngine.CommandCollection = new Dictionary(); } } } diff --git a/MudEngine/GameObjects/Characters/BaseCharacter.cs b/MudEngine/GameObjects/Characters/BaseCharacter.cs index ef33a0a..d3ee58e 100644 --- a/MudEngine/GameObjects/Characters/BaseCharacter.cs +++ b/MudEngine/GameObjects/Characters/BaseCharacter.cs @@ -45,12 +45,18 @@ namespace MudEngine.GameObjects.Characters /// public Bag Inventory { get; private set; } + /// + /// Gets a working copy of the CommandEngine used by the player. + /// + public CommandEngine CommandSystem { get; internal set; } + public BaseCharacter(Game game) : base(game) { ActiveGame = game; IsActive = false; CurrentRoom = game.InitialRealm.InitialZone.InitialRoom; Inventory = new Bag(game); + CommandSystem = new CommandEngine(); } @@ -123,7 +129,7 @@ namespace MudEngine.GameObjects.Characters { //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. - CommandResults result = CommandEngine.ExecuteCommand(command, this); + CommandResults result = CommandSystem.ExecuteCommand(command, this); if (result.Result != null) { @@ -191,7 +197,7 @@ namespace MudEngine.GameObjects.Characters { if (IsActive) { - string filePath = Path.Combine(ActiveGame.DataPaths.Players, Filename); + string filePath ="" /*= Path.Combine(ActiveGame.DataPaths.Players, Filename)*/; this.Save(filePath); IsActive = false; diff --git a/MudEngine/Networking/Server.cs b/MudEngine/Networking/Server.cs index 84c00f9..8596c97 100644 --- a/MudEngine/Networking/Server.cs +++ b/MudEngine/Networking/Server.cs @@ -78,7 +78,7 @@ namespace MudEngine.Networking } } while (sub < 0); players[sub].client = server.Accept(); - players[sub].Initialize(); + //players[sub].Initialize(); clientThreads[sub] = new Thread(ReceiveThread); clientThreads[sub].Start((object)sub); } @@ -86,7 +86,7 @@ namespace MudEngine.Networking private void ReceiveThread(object obj) { int sub = (int)obj; - //players[sub].Initialize(); + players[sub].Initialize(); while (stage == 2 && players[sub].IsActive) { players[sub].Receive(players[sub].ReadInput());