muddesigner/MudEngine/Scripting/GameObject.cs
Scionwest_cp 9b023a2092 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.
2010-07-29 17:39:38 -07:00

87 lines
2.3 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 GameObject(object instance, string name)
{
Instance = instance;
Name = name;
}
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);
}
}
}
public object GetProperty(string propertyName)
{
string[] tokens = propertyName.Split('.');
PropertyInfo previousProperty = Instance.GetType().GetProperty(tokens[0]);
return previousProperty.GetValue(Instance, null);
}
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;
}
}
}
}