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 VariableSpaceDispatcher() { EventHandlers["ocw:varSpace:create"] += new Action <int, dynamic>(async(space, dataMap) => { var varSpace = new VariableSpace(space); ms_variableSpaces[space] = varSpace; var dictionary = dataMap as IDictionary <string, object>; Debug.WriteLine("variable space {0} created (map is {1}, dict is {2})", space, dataMap.GetType().Name, dictionary); if (dictionary != null) { foreach (var kvp in dictionary) { Debug.WriteLine("setting {0} in space {1} to {2}", kvp.Key, space, kvp.Value); await varSpace.SetValueNoSync(kvp.Key, kvp.Value); } } }); EventHandlers["ocw:varSpace:set"] += new Action <int, string, dynamic>((space, key, value) => { // get the variable space requested VariableSpace varSpace; if (ms_variableSpaces.TryGetValue(space, out varSpace)) { Debug.WriteLine("setting {0} in space {1} to {2}", key, space, value); varSpace.SetValueNoSync(key, value); } }); EventHandlers["onClientGameTypeStart"] += new Action <string>(a => { TriggerServerEvent("ocw:varSpace:resync"); }); Tick += VariableSpaceDispatcher_Tick; }
public VariableSpaceDispatcher() { EventHandlers["ocw:varSpace:create"] += new Action<int, dynamic>(async (space, dataMap) => { var varSpace = new VariableSpace(space); ms_variableSpaces[space] = varSpace; var dictionary = dataMap as IDictionary<string, object>; Debug.WriteLine("variable space {0} created (map is {1}, dict is {2})", space, dataMap.GetType().Name, dictionary); if (dictionary != null) { foreach (var kvp in dictionary) { Debug.WriteLine("setting {0} in space {1} to {2}", kvp.Key, space,kvp.Value); await varSpace.SetValueNoSync(kvp.Key, kvp.Value); } } }); EventHandlers["ocw:varSpace:set"] += new Action<int, string, dynamic>((space, key, value) => { // get the variable space requested VariableSpace varSpace; if (ms_variableSpaces.TryGetValue(space, out varSpace)) { Debug.WriteLine("setting {0} in space {1} to {2}", key, space, value); varSpace.SetValueNoSync(key, value); } }); EventHandlers["onClientGameTypeStart"] += new Action<string>(a => { TriggerServerEvent("ocw:varSpace:resync"); }); Tick += VariableSpaceDispatcher_Tick; }
public EntityManager(VariableSpace variableSpace) { m_variableSpace = variableSpace; }
internal void SetVariableSpace(VariableSpace space) { m_variableSpace = space; m_entityManager = new EntityManager(space); }
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); } }); }