- FileManager.GetDataPath now returns the actual Root directory when Root is requested rather than Root/Projects. That was considered Root for the older Designer. - CommandEngine.GetCommands is now a method rather than a property. - CommandEngine.LoadAllCommands replaced with CommandEngine.LoadBaseCommands for loading Engine specific Game commands. This is called from within Game.Start. A possible property for disabling default commands could be looked at in the future. - CommandEngine.LoadCommandLibrary method added for loading custom user commands. This is fully implemented. - CommandEngine.ClearCommands method added for clearing all currently loaded commands. - Game.IsDebug static property added. - Added additional logging for testing purposes throughout the project. Changing Game.IsDebug to false will remove the majority of the logged messages. - Game.IsMultiplayer property added for enabling or disabling the server for Online/Offline support. Fully implemented. - Game no longer loads user script libraries as this was being handled already by ScriptEngine.Initialize() - Log now caches messages so consoles can print only content that was logged since the last loop. Using Log.FlushMessages() will clear the cached messages allowing each loop to show only the new logged messages. - BaseCharacter IsAdmin argument in the constructor has been removed. No longer needed for testing. - ScriptEngine can now compile more than 1 script without error. - ScriptEngine.Assembly property added for accessing the currently loaded script library. This should be a List<Assembly> in the future for multiple libraries. - Removed the last of my BlitScript engine code from ScriptEngine.cs as it was XNA specific. Need to look at StartupObject.cs as I believe that is XNA specific as well and not needed. MudGame: - Renamed MudGame to MudOfflineExample as it will be used for testing the game with Game.IsMultiplayer disabled. Makes testing easier then needing to stop/restart the server and connect via telnet constantly. MudServer: - Added MudServer project. This is a dedicated server that runs with Game.IsMultiplayer enabled. Developers can connect to it via telnet clients. All engine game commands are implemented. - MudServer includes bin/Debug/Scripts.dll, which is a compiled library of scripts generated via MudCompiler. MudEngine.Game handles loading the library and there is no additional code required by the developers to implement their libraries into their games provided the name is 'Scripts.dll'
163 lines
5.5 KiB
C#
163 lines
5.5 KiB
C#
//Microsoft .NET Framework
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
|
|
//MUD Engine
|
|
using MudEngine.GameObjects;
|
|
using MudEngine.GameObjects.Characters;
|
|
using MudEngine.GameObjects.Environment;
|
|
using MudEngine.GameManagement;
|
|
|
|
namespace MudEngine.GameManagement
|
|
{
|
|
public static class CommandEngine
|
|
{
|
|
/// <summary>
|
|
/// Gets or Sets a Dictionary list of available commands to use.
|
|
/// </summary>
|
|
static internal Dictionary<string, IGameCommand> Commands { get { return _Commands; } set { _Commands = value; } }
|
|
static Dictionary<string, IGameCommand> _Commands = new Dictionary<string, IGameCommand>();
|
|
|
|
public static List<string> GetCommands()
|
|
{
|
|
List<string> temp = new List<string>();
|
|
|
|
foreach (string name in Commands.Keys)
|
|
{
|
|
temp.Add(name);
|
|
}
|
|
|
|
return temp;
|
|
}
|
|
|
|
public static bool GetCommand(string Name)
|
|
{
|
|
if (Commands.ContainsKey(Name.ToLower()))
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
/// <summary>
|
|
/// Executes the specified command name if it exists in the Commands Dictionary.
|
|
/// </summary>
|
|
/// <param name="Name"></param>
|
|
/// <param name="Parameter"></param>
|
|
/// <returns></returns>
|
|
public static 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)
|
|
{
|
|
if (commandKey.ToLower().Contains(key.ToLower()))
|
|
{
|
|
return Commands[key.ToLower()].Execute(command, player);
|
|
}
|
|
}
|
|
|
|
return new CommandResults();
|
|
}
|
|
|
|
public static void LoadBaseCommands()
|
|
{
|
|
LoadCommandLibrary(Assembly.GetExecutingAssembly());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Dynamically loads the specified library into memory and stores all of the
|
|
/// classess inheriting from MudCreator.InputCommands.ICommand into the CommandEngines
|
|
/// commands dictionary for use with the project
|
|
/// </summary>
|
|
/// <param name="CommandLibrary"></param>
|
|
public static void LoadCommandLibrary()
|
|
{
|
|
LoadCommandLibrary(Assembly.GetExecutingAssembly());
|
|
}
|
|
|
|
public static void LoadCommandLibrary(string libraryFilename)
|
|
{
|
|
if (System.IO.File.Exists(libraryFilename))
|
|
{
|
|
Assembly assem = Assembly.LoadFile(libraryFilename);
|
|
LoadCommandLibrary(assem);
|
|
}
|
|
}
|
|
|
|
public static void LoadCommandLibrary(List<Assembly> commandLibraries)
|
|
{
|
|
foreach (Assembly lib in commandLibraries)
|
|
LoadCommandLibrary(lib);
|
|
}
|
|
|
|
public static void LoadCommandLibrary(Assembly commandLibrary)
|
|
{
|
|
LoadCommandLibrary(commandLibrary, false);
|
|
}
|
|
|
|
public static void LoadCommandLibrary(Assembly commandLibrary, bool purgeOldCommands)
|
|
{
|
|
//no assembly passed for whatever reason, don't attempt to enumerate through it.
|
|
if (commandLibrary == null)
|
|
return;
|
|
|
|
Log.Write("Loading commands within " + Path.GetFileName(commandLibrary.Location));
|
|
|
|
if (purgeOldCommands)
|
|
ClearCommands();
|
|
|
|
foreach (Type t in commandLibrary.GetTypes())
|
|
{
|
|
if (t.GetInterface(typeof(IGameCommand).FullName) != null)
|
|
{
|
|
//Use activator to create an instance
|
|
IGameCommand command = (IGameCommand)Activator.CreateInstance(t);
|
|
|
|
if (command != null)
|
|
{
|
|
if (command.Name == null)
|
|
command.Name = t.Name.ToLower();
|
|
else //Make sure the command is always in lower case.
|
|
command.Name = command.Name.ToLower();
|
|
|
|
//Add the command to the commands list if it does not already exist
|
|
if (Commands.ContainsKey(command.Name))
|
|
{
|
|
//Command exists, check if the command is set to override existing commands or not
|
|
if (command.Override)
|
|
{
|
|
Commands[command.Name] = command;
|
|
}
|
|
}
|
|
//Command does not exist, add it to the commands list
|
|
else
|
|
Commands.Add(command.Name, command);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void ClearCommands()
|
|
{
|
|
_Commands = new Dictionary<string, IGameCommand>();
|
|
}
|
|
|
|
public static string GetCommand(object Parameter)
|
|
{
|
|
List<object> objectList = (List<object>)Parameter;
|
|
|
|
foreach (object obj in objectList)
|
|
{
|
|
if (obj is string)
|
|
return (string)obj;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
}
|