- Removed from solution Mud Engine: - Moved the CommandEngine, CommandResults and ICommand Interface out from the Commands namespace and into GameManagement since they manage the game commands. - Added CommandExit class to provide the ability to exit a game once running. This is fully implemented. - Realms, Zones and Rooms now have an IsInitial property for determining if this is an initial location for the Game. - Renamed GameSetup to Game. - Corrected GameObject being in the incorrect namespace. - Corrected the ScriptEngine not - CommandEngine no longer needs a Name argument. Arguments changed from 5 to 4 due to this change. Mud Game: - Added Example Game used for testing various MUDEngine features and testing constructability of games using the engine. - Currently only contains 1 Realm, 1 Zone and Two Rooms. Only working command is Exit.
86 lines
2.4 KiB
C#
86 lines
2.4 KiB
C#
using System;
|
|
using System.Reflection;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
using MudEngine.Scripting;
|
|
|
|
namespace MudEngine.Scripting
|
|
{
|
|
public class GameObject
|
|
{
|
|
/// <summary>
|
|
/// The script instance for this game object
|
|
/// </summary>
|
|
public object Instance { get; set; }
|
|
|
|
/// <summary>
|
|
/// The Type name for this object
|
|
/// </summary>
|
|
public string Name { get; set; }
|
|
|
|
/// <summary>
|
|
/// Determins if this object will recieve Update/Draw calls from the ScriptEngine
|
|
/// </summary>
|
|
public bool IsActive { get; set; }
|
|
|
|
public object CreateObject()
|
|
{
|
|
return Instance;
|
|
}
|
|
|
|
public bool DeleteObject()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
public void SetProperty(string propertyName, object propertyValue)
|
|
{
|
|
PropertyInfo propertyInfo = Instance.GetType().GetProperty(propertyName);
|
|
|
|
if (propertyValue is string)
|
|
{
|
|
if (propertyInfo.PropertyType.Name is string)
|
|
{
|
|
propertyInfo.SetValue(Instance, propertyValue, null);
|
|
}
|
|
}
|
|
}
|
|
/* Dynamic Type Instancing isn't supported in .NET 3.5
|
|
public dynamic SetProperty()
|
|
{
|
|
return Instance;
|
|
}
|
|
*/
|
|
public object GetProperty(string propertyName)
|
|
{
|
|
string[] tokens = propertyName.Split('.');
|
|
PropertyInfo previousProperty = Instance.GetType().GetProperty(tokens[0]);
|
|
|
|
return previousProperty.GetValue(Instance, null);
|
|
}
|
|
/* Dynamic Type Instancing isn't supported in .NET 3.5; Requires 4.0
|
|
public dynamic GetProperty()
|
|
{
|
|
return Instance;
|
|
}
|
|
*/
|
|
public object InvokeMethod(string methodName, params object[] parameters)
|
|
{
|
|
MethodInfo method = Instance.GetType().GetMethod(methodName);
|
|
|
|
try
|
|
{
|
|
if (parameters == null || parameters.Length == 0)
|
|
return method.Invoke(Instance, null);
|
|
else
|
|
return method.Invoke(Instance, parameters);
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|