MudEngine:
- Converted CommandEngine fully to non-static.
This commit is contained in:
parent
7c6ca6a2b9
commit
368cdb00ee
3 changed files with 37 additions and 35 deletions
|
@ -19,23 +19,23 @@ namespace MudEngine.GameManagement
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or Sets a Dictionary list of available commands to use.
|
/// Gets or Sets a Dictionary list of available commands to use.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static Dictionary<string, IGameCommand> CommandCollection { get; set; }
|
public Dictionary<string, IGameCommand> CommandCollection { get; set; }
|
||||||
|
|
||||||
internal Dictionary<string, IGameCommand> _Commands { get; set; }
|
internal Dictionary<string, IGameCommand> _Commands { get; set; }
|
||||||
|
|
||||||
public CommandEngine()
|
public CommandEngine()
|
||||||
{
|
{
|
||||||
if ((CommandCollection == null) || (CommandCollection.Count == 0))
|
if ((CommandCollection == null) || (CommandCollection.Count == 0))
|
||||||
CommandEngine.LoadBaseCommands();
|
LoadBaseCommands();
|
||||||
|
|
||||||
_Commands = CommandCollection;
|
_Commands = CommandCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<string> GetCommands()
|
public List<string> GetCommands()
|
||||||
{
|
{
|
||||||
List<string> temp = new List<string>();
|
List<string> temp = new List<string>();
|
||||||
|
|
||||||
foreach (string name in CommandEngine.CommandCollection.Keys)
|
foreach (string name in CommandCollection.Keys)
|
||||||
{
|
{
|
||||||
temp.Add(name);
|
temp.Add(name);
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ namespace MudEngine.GameManagement
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetCommand(object Parameter)
|
public string GetCommand(object Parameter)
|
||||||
{
|
{
|
||||||
List<object> objectList = (List<object>)Parameter;
|
List<object> objectList = (List<object>)Parameter;
|
||||||
|
|
||||||
|
@ -56,9 +56,9 @@ namespace MudEngine.GameManagement
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsValidCommand(string Name)
|
public bool IsValidCommand(string Name)
|
||||||
{
|
{
|
||||||
if (CommandEngine.CommandCollection.ContainsKey(Name.ToLower()))
|
if (CommandCollection.ContainsKey(Name.ToLower()))
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
@ -75,11 +75,11 @@ namespace MudEngine.GameManagement
|
||||||
if (Game.IsDebug)
|
if (Game.IsDebug)
|
||||||
Log.Write("Executing command: " + command);
|
Log.Write("Executing command: " + command);
|
||||||
|
|
||||||
foreach (string key in player.CommandSystem._Commands.Keys)
|
foreach (string key in CommandCollection.Keys)
|
||||||
{
|
{
|
||||||
if (commandKey.ToLower().Contains(key.ToLower()))
|
if (commandKey.ToLower().Contains(key.ToLower()))
|
||||||
{
|
{
|
||||||
return player.CommandSystem._Commands[key.ToLower()].Execute(command, player);
|
return player.CommandSystem._Commands[key].Execute(command, player);
|
||||||
//return player.Commands.ExecuteCommand[key.ToLower()]Execute(command, player);
|
//return player.Commands.ExecuteCommand[key.ToLower()]Execute(command, player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ namespace MudEngine.GameManagement
|
||||||
return new CommandResults();
|
return new CommandResults();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadBaseCommands()
|
public void LoadBaseCommands()
|
||||||
{
|
{
|
||||||
LoadCommandLibrary(Assembly.GetExecutingAssembly(), true);
|
LoadCommandLibrary(Assembly.GetExecutingAssembly(), true);
|
||||||
}
|
}
|
||||||
|
@ -98,12 +98,12 @@ namespace MudEngine.GameManagement
|
||||||
/// commands dictionary for use with the project
|
/// commands dictionary for use with the project
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="CommandLibrary"></param>
|
/// <param name="CommandLibrary"></param>
|
||||||
public static void LoadCommandLibrary()
|
public void LoadCommandLibrary()
|
||||||
{
|
{
|
||||||
LoadCommandLibrary(Assembly.GetExecutingAssembly());
|
LoadCommandLibrary(Assembly.GetExecutingAssembly());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadCommandLibrary(string libraryFilename)
|
public void LoadCommandLibrary(string libraryFilename)
|
||||||
{
|
{
|
||||||
if (System.IO.File.Exists(libraryFilename))
|
if (System.IO.File.Exists(libraryFilename))
|
||||||
{
|
{
|
||||||
|
@ -112,18 +112,18 @@ namespace MudEngine.GameManagement
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadCommandLibrary(List<Assembly> commandLibraries)
|
public void LoadCommandLibrary(List<Assembly> commandLibraries)
|
||||||
{
|
{
|
||||||
foreach (Assembly lib in commandLibraries)
|
foreach (Assembly lib in commandLibraries)
|
||||||
LoadCommandLibrary(lib);
|
LoadCommandLibrary(lib);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadCommandLibrary(Assembly commandLibrary)
|
public void LoadCommandLibrary(Assembly commandLibrary)
|
||||||
{
|
{
|
||||||
LoadCommandLibrary(commandLibrary, false);
|
LoadCommandLibrary(commandLibrary, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadCommandLibrary(Assembly commandLibrary, bool purgeOldCommands)
|
public void LoadCommandLibrary(Assembly commandLibrary, bool purgeOldCommands)
|
||||||
{
|
{
|
||||||
//no assembly passed for whatever reason, don't attempt to enumerate through it.
|
//no assembly passed for whatever reason, don't attempt to enumerate through it.
|
||||||
if (commandLibrary == null)
|
if (commandLibrary == null)
|
||||||
|
@ -132,7 +132,7 @@ namespace MudEngine.GameManagement
|
||||||
Log.Write("Loading commands within " + Path.GetFileName(commandLibrary.Location));
|
Log.Write("Loading commands within " + Path.GetFileName(commandLibrary.Location));
|
||||||
|
|
||||||
if (purgeOldCommands)
|
if (purgeOldCommands)
|
||||||
CommandEngine.ClearCommands();
|
ClearCommands();
|
||||||
|
|
||||||
foreach (Type t in commandLibrary.GetTypes())
|
foreach (Type t in commandLibrary.GetTypes())
|
||||||
{
|
{
|
||||||
|
@ -149,25 +149,25 @@ namespace MudEngine.GameManagement
|
||||||
command.Name = command.Name.ToLower();
|
command.Name = command.Name.ToLower();
|
||||||
|
|
||||||
//Add the command to the commands list if it does not already exist
|
//Add the command to the commands list if it does not already exist
|
||||||
if (CommandEngine.CommandCollection.ContainsKey(command.Name))
|
if (CommandCollection.ContainsKey(command.Name))
|
||||||
{
|
{
|
||||||
//Command exists, check if the command is set to override existing commands or not
|
//Command exists, check if the command is set to override existing commands or not
|
||||||
if (command.Override)
|
if (command.Override)
|
||||||
{
|
{
|
||||||
CommandEngine.CommandCollection[command.Name] = command;
|
CommandCollection[command.Name] = command;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Command does not exist, add it to the commands list
|
//Command does not exist, add it to the commands list
|
||||||
else
|
else
|
||||||
CommandEngine.CommandCollection.Add(command.Name, command);
|
CommandCollection.Add(command.Name, command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ClearCommands()
|
public void ClearCommands()
|
||||||
{
|
{
|
||||||
CommandEngine.CommandCollection = new Dictionary<string, IGameCommand>();
|
CommandCollection = new Dictionary<string, IGameCommand>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -242,19 +242,6 @@ namespace MudEngine.GameManagement
|
||||||
//Setup the scripting engine and load our script library
|
//Setup the scripting engine and load our script library
|
||||||
scriptEngine.Initialize();
|
scriptEngine.Initialize();
|
||||||
|
|
||||||
Log.Write("Loading internal game commands...");
|
|
||||||
//Loads the MudEngine Game Commands
|
|
||||||
CommandEngine.LoadBaseCommands();
|
|
||||||
|
|
||||||
//Ensure custom commands are loaded until everything is fleshed out.
|
|
||||||
if (Game.IsDebug)
|
|
||||||
{
|
|
||||||
foreach (string command in CommandEngine.GetCommands())
|
|
||||||
{
|
|
||||||
Log.Write("Command loaded: " + command);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.Write("Initializing location...");
|
Log.Write("Initializing location...");
|
||||||
//See if we have an Initial Realm set
|
//See if we have an Initial Realm set
|
||||||
foreach (Realm r in RealmCollection)
|
foreach (Realm r in RealmCollection)
|
||||||
|
|
|
@ -147,7 +147,22 @@ namespace MudEngine.GameObjects.Characters
|
||||||
internal void Initialize()
|
internal void Initialize()
|
||||||
{
|
{
|
||||||
client.Receive(new byte[255]);
|
client.Receive(new byte[255]);
|
||||||
Log.Write("New Player Connected.");
|
|
||||||
|
if (Game.IsDebug)
|
||||||
|
Log.Write("New Player Connected.");
|
||||||
|
|
||||||
|
Log.Write("Loading internal game commands...");
|
||||||
|
//Loads the MudEngine Game Commands
|
||||||
|
CommandSystem.LoadBaseCommands();
|
||||||
|
|
||||||
|
//Ensure custom commands are loaded until everything is fleshed out.
|
||||||
|
if (Game.IsDebug)
|
||||||
|
{
|
||||||
|
foreach (string command in CommandSystem.GetCommands())
|
||||||
|
{
|
||||||
|
Log.Write("Command loaded: " + command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
string result = ExecuteCommand("Login");
|
string result = ExecuteCommand("Login");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue