任何人都可以提出一个干净的方法来做到这一点。我想要一个包含游戏中所有实例化对象的世界。但我不确定如何正确投射。
这些对象都应该在 1 个伞形对象和 1 个字典中,以便于保存/搜索。
//all connected players
private Dictionary<IOClient, string> IOClients = new Dictionary<IOClient, string>();
player = new MObject(new object[]{result.Remove(0,1)}, 1);
public class MObject
{
private Serial m_Serial;
public Serial Serial { get { return m_Serial; } }
public Player player = null;
public Item item = null;
public MObject(object[] obj, int type)
{
// m_Serial = Serial.NewMobile;
if (obj.GetType() == typeof(Player) || type == 1)
{
player = new Player((string)obj[0]);
}
if (obj.GetType() == typeof(Item) || type == 2)
{
// item = new Item();
}
}
}
//Also a World
public static class World
{
private static bool m_Loading;
private static bool m_Loaded;
private static Dictionary<Serial, MObject> m_MObjects;
public static Dictionary<Serial, MObject> MObjects
{ get { return m_MObjects; } }
}