MudCompiler:
- Updated to work with ScriptingEngine changes. MudEngine: - Game.PlayerCollection changed to a List<>. Server obtains a array version of it within Server.initialize() via players = pbs.ToArray(). - All BaseObject classes now require a reference to the Game and contain a property called ActiveGame. - Player.Game removed and now uses it's parent objects ActiveGame property. - Player.Role property added. Uses the new SecurityRoles enum that specifies what level of access the player has. - ScriptEngine now loads all libraries found within the specified ScriptsPath directory, instances the scripts and places them into a collection. - Custom character script instancing is now supported, but not fully implemented throughout the engine. They can be loaded, but not used during runtime at this time.
This commit is contained in:
parent
631ce62e73
commit
9b023a2092
24 changed files with 127 additions and 74 deletions
|
@ -30,8 +30,15 @@ namespace MudEngine.Scripting
|
|||
public string InstallPath { get; private set; }
|
||||
public GameObjectCollection ObjectCollection { get; private set; }
|
||||
|
||||
public Assembly Assembly { get { return _ScriptAssembly; } private set { _ScriptAssembly = value; } }
|
||||
/// <summary>
|
||||
/// Collection of currently loaded objects created from compiled scripts
|
||||
/// </summary>
|
||||
public List<GameObject> GameObjects { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Collection of currently loaded game commecnts that can be used. These must be compiled scripts inheriting from IGameCommand
|
||||
/// </summary>
|
||||
public List<IGameCommand> GameCommands { get; private set; }
|
||||
/// <summary>
|
||||
/// File Extension for the scripts
|
||||
/// </summary>
|
||||
|
@ -59,11 +66,13 @@ namespace MudEngine.Scripting
|
|||
|
||||
private ScriptTypes _ScriptTypes;
|
||||
private Assembly _ScriptAssembly;
|
||||
private List<Assembly> _AssemblyCollection;
|
||||
private string[] _ErrorMessages;
|
||||
Game _Game;
|
||||
|
||||
public ScriptEngine() : this(ScriptTypes.Assembly)
|
||||
public ScriptEngine(Game game) : this(game, ScriptTypes.Assembly)
|
||||
{
|
||||
//Empty constructor. Only here for end-user ease of use. ScriptEngine(Game, ScriptTypes) is called from here.
|
||||
_Game = game;
|
||||
}
|
||||
|
||||
|
||||
|
@ -71,15 +80,19 @@ namespace MudEngine.Scripting
|
|||
/// Instances a new copy of the script engine
|
||||
/// </summary>
|
||||
/// <param name="scriptTypes">Tells the engine what kind of scripts will be loaded. Source File or assembly based.</param>
|
||||
public ScriptEngine(ScriptTypes scriptTypes)
|
||||
public ScriptEngine(Game game, ScriptTypes scriptTypes)
|
||||
{
|
||||
//Initialize our engine fields
|
||||
_ScriptTypes = scriptTypes;
|
||||
ScriptExtension = ".cs";
|
||||
|
||||
//Get our current install path
|
||||
ScriptPath = Environment.CurrentDirectory;
|
||||
ScriptPath = Path.Combine(Environment.CurrentDirectory, "Scripts");
|
||||
InstallPath = Environment.CurrentDirectory;
|
||||
GameObjects = new List<GameObject>();
|
||||
_AssemblyCollection = new List<Assembly>();
|
||||
|
||||
_Game = game;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -183,26 +196,48 @@ namespace MudEngine.Scripting
|
|||
{
|
||||
InitializeSourceFiles();
|
||||
}
|
||||
|
||||
foreach (Assembly assembly in _AssemblyCollection)
|
||||
{
|
||||
foreach (Type t in assembly.GetTypes())
|
||||
{
|
||||
if (t.BaseType == null)
|
||||
continue;
|
||||
if (t.BaseType.Name == "BaseObject")
|
||||
{
|
||||
GameObjects.Add(new GameObject(Activator.CreateInstance(t, new object[] {_Game}), t.Name));
|
||||
continue;
|
||||
}
|
||||
else if (t.BaseType.Name == "BaseCharacter")
|
||||
{
|
||||
GameObject obj = new GameObject(Activator.CreateInstance(t, new object[] {_Game}), t.Name);
|
||||
GameObjects.Add(obj);
|
||||
obj.GetProperty().CurrentRoom = _Game.InitialRealm.InitialZone.InitialRoom;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializeAssembly()
|
||||
{
|
||||
if (!System.IO.File.Exists("Scripts.dll"))
|
||||
if (!Directory.Exists(ScriptPath))
|
||||
{
|
||||
ErrorMessage = "Failed to load Script Assembly!";
|
||||
Log.Write(ErrorMessage);
|
||||
Log.Write("Supplied script path does not exist! No scripts loaded.");
|
||||
return;
|
||||
}
|
||||
string[] libraries = Directory.GetFiles(ScriptPath, "*.dll", SearchOption.AllDirectories);
|
||||
|
||||
if (libraries.Length == 0)
|
||||
{
|
||||
Log.Write("Failed to load Script Assembly!");
|
||||
return;
|
||||
}
|
||||
|
||||
_ScriptAssembly = Assembly.LoadFile(Path.Combine(InstallPath, "Scripts.dll"));
|
||||
foreach (string library in libraries)
|
||||
_AssemblyCollection.Add(Assembly.LoadFile(library));
|
||||
|
||||
foreach (Type type in _ScriptAssembly.GetTypes())
|
||||
{
|
||||
if (type.BaseType == typeof(BaseCharacter))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
_AssemblyCollection.Add(Assembly.GetExecutingAssembly());
|
||||
}
|
||||
|
||||
private void InitializeSourceFiles()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue