public ObjectiveControl() { EventHandlers["ocw:regObjSpace"] += new Action <int>(objSpace => { m_objectiveSpace = VariableSpaceDispatcher.GetVariableSpace(objSpace); m_objectiveSpace.RegisterSetHandler("objective:", async(key, value) => { if (value.GetType() != typeof(bool)) { Debug.WriteLine("created objective {0}", value.typeId); TriggerEvent("ocw:newObjective", int.Parse(key.Split(':')[1]), value.typeId, value); } else { Objective instance; if (m_instances.TryGetValue(int.Parse(key.Split(':')[1]), out instance)) { await instance.TryDefuse(); } } }); }); EventHandlers["ocw:newObjective"] += new Action <int, string, dynamic>(async(objectiveId, objectiveType, data) => { var typeId = Assembly.GetExecutingAssembly().GetTypes().Where(a => { Debug.WriteLine("testing {0} {1}", a.Name, objectiveType); return(a.Name.Equals(objectiveType, StringComparison.InvariantCultureIgnoreCase)); }).Where(a => a.IsSubclassOf(typeof(Objective))).FirstOrDefault(); if (typeId != null) { Debug.WriteLine("Objective {0} resolved to {1}.", objectiveType, typeId.FullName); var instance = Activator.CreateInstance(typeId, data) as Objective; instance.ObjectiveId = objectiveId; if (instance != null) { instance.SetVariableSpace(VariableSpaceDispatcher.GetVariableSpace(data.spaceId)); await instance.Initialize(); BaseScript.RegisterScript(instance); m_instances[objectiveId] = instance; } } else { Debug.WriteLine("couldn't resolve {0}", typeId); } }); }
public ObjectiveControl() { EventHandlers["ocw:regObjSpace"] += new Action<int>(objSpace => { m_objectiveSpace = VariableSpaceDispatcher.GetVariableSpace(objSpace); m_objectiveSpace.RegisterSetHandler("objective:", async (key, value) => { if (value.GetType() != typeof(bool)) { Debug.WriteLine("created objective {0}", value.typeId); TriggerEvent("ocw:newObjective", int.Parse(key.Split(':')[1]), value.typeId, value); } else { Objective instance; if (m_instances.TryGetValue(int.Parse(key.Split(':')[1]), out instance)) { await instance.TryDefuse(); } } }); }); EventHandlers["ocw:newObjective"] += new Action<int, string, dynamic>(async (objectiveId, objectiveType, data) => { var typeId = Assembly.GetExecutingAssembly().GetTypes().Where(a => { Debug.WriteLine("testing {0} {1}", a.Name, objectiveType); return a.Name.Equals(objectiveType, StringComparison.InvariantCultureIgnoreCase); }).Where(a => a.IsSubclassOf(typeof(Objective))).FirstOrDefault(); if (typeId != null) { Debug.WriteLine("Objective {0} resolved to {1}.", objectiveType, typeId.FullName); var instance = Activator.CreateInstance(typeId, data) as Objective; instance.ObjectiveId = objectiveId; if (instance != null) { instance.SetVariableSpace(VariableSpaceDispatcher.GetVariableSpace(data.spaceId)); await instance.Initialize(); BaseScript.RegisterScript(instance); m_instances[objectiveId] = instance; } } else { Debug.WriteLine("couldn't resolve {0}", typeId); } }); }