/// <summary> /// Use for deserialization from a saved game /// </summary> public static MyGlobalEventBase CreateEvent(MyObjectBuilder_GlobalEventBase ob) { MyGlobalEventBase globalEvent = null; // Backwards compatibility if (ob.DefinitionId.HasValue) { if (ob.DefinitionId.Value.TypeId == MyObjectBuilderType.Invalid) { return(CreateEventObsolete(ob)); } ob.SubtypeName = ob.DefinitionId.Value.SubtypeName; } var eventDefinition = MyDefinitionManager.Static.GetEventDefinition(ob.GetId()); if (eventDefinition == null) { return(null); } globalEvent = CreateEvent(ob.GetId()); globalEvent.Init(ob); return(globalEvent); }
private static MyGlobalEventBase CreateEventObsolete(MyObjectBuilder_GlobalEventBase ob) { MyGlobalEventBase globalEvent = CreateEvent(GetEventDefinitionObsolete(ob.EventType)); globalEvent.SetActivationTime(TimeSpan.FromMilliseconds(ob.ActivationTimeMs)); globalEvent.Enabled = ob.Enabled; return(globalEvent); }
private void StartGlobalEvent(MyGlobalEventBase globalEvent) { AddGlobalEventToEventLog(globalEvent); if (globalEvent.IsHandlerValid) { globalEvent.Action.Invoke(this, new object[] { globalEvent }); } }
private void StartGlobalEvent(MyGlobalEventBase globalEvent) { AddGlobalEventToEventLog(globalEvent); if (globalEvent.IsHandlerValid) { globalEvent.Action(globalEvent); } }
public override void UpdateBeforeSimulation() { // Events are executed on the server only if (!Sync.IsServer) { return; } m_elapsedTimeInMilliseconds += MySandboxGame.TotalGamePlayTimeInMilliseconds - m_previousTime; m_previousTime = MySandboxGame.TotalGamePlayTimeInMilliseconds; if (m_elapsedTimeInMilliseconds < GLOBAL_EVENT_UPDATE_RATIO_IN_MS) { return; } // Subtract elapsed time from the activation time of all events foreach (MyGlobalEventBase e in m_globalEvents) { e.SetActivationTime(TimeSpan.FromTicks(e.ActivationTime.Ticks - m_elapsedTimeInMilliseconds * TimeSpan.TicksPerMillisecond)); } // Execute elapsed events MyGlobalEventBase globalEvent = m_globalEvents.FirstOrDefault(); while (globalEvent != null && globalEvent.IsInPast) { m_globalEvents.Remove(globalEvent); if (globalEvent.Enabled) { ProfilerShort.Begin(globalEvent.Definition.Id.ToString()); StartGlobalEvent(globalEvent); ProfilerShort.End(); } // Reschedule periodic events. Test whether the handler did not reschedule the event if (globalEvent.IsPeriodic) { if (globalEvent.RemoveAfterHandlerExit) { m_globalEvents.Remove(globalEvent); } else if (!m_globalEvents.Contains(globalEvent)) { globalEvent.RecalculateActivationTime(); AddGlobalEvent(globalEvent); } } globalEvent = m_globalEvents.FirstOrDefault(); } m_elapsedTimeInMilliseconds = 0; }
public static MyGlobalEventBase CreateEvent(MyDefinitionId id) { var eventDefinition = MyDefinitionManager.Static.GetEventDefinition(id); MyGlobalEventBase globalEvent = m_globalEventFactory.CreateInstance(id.TypeId); if (globalEvent == null) { return(globalEvent); } globalEvent.InitFromDefinition(eventDefinition); return(globalEvent); }
private static void RetryEventWithMaxTry(MyGlobalEventBase evt) { if (++m_eventSpawnTry <= EVENT_SPAWN_TRY_MAX) { MySandboxGame.Log.WriteLine("Could not spawn event. Try " + m_eventSpawnTry + " of " + EVENT_SPAWN_TRY_MAX); MyGlobalEvents.RescheduleEvent(evt, NEUTRAL_SHIP_RESCHEDULE_TIME); return; } else { m_eventSpawnTry = 0; return; } }
public static void LoadEvents(MyObjectBuilder_GlobalEvents eventsBuilder) { if (eventsBuilder == null) { return; } foreach (var globalEventBuilder in eventsBuilder.Events) { MyGlobalEventBase globalEvent = MyGlobalEventFactory.CreateEvent(globalEventBuilder); Debug.Assert(globalEvent == null || globalEvent.IsHandlerValid, "Event handler could not be found on load. Call a programmer please! You can ignore this, if you don't mind the given event not happening."); if (globalEvent != null && globalEvent.IsHandlerValid) { m_globalEvents.Add(globalEvent); } } }
/// <summary> /// Use for deserialization from a saved game /// </summary> public static MyGlobalEventBase CreateEvent(MyObjectBuilder_GlobalEventBase ob) { if (ob.DefinitionId.TypeId == MyObjectBuilderType.Invalid) { return(CreateEventObsolete(ob)); } var eventDefinition = MyDefinitionManager.Static.GetEventDefinition(ob.DefinitionId); if (eventDefinition == null) { return(null); } var globalEvent = new MyGlobalEventBase(); globalEvent.Init(ob); return(globalEvent); }
public static void RescheduleEvent(MyGlobalEventBase globalEvent, TimeSpan time) { m_globalEvents.Remove(globalEvent); globalEvent.SetActivationTime(time); m_globalEvents.Add(globalEvent); }
public static void RemoveGlobalEvent(MyGlobalEventBase globalEvent) { m_globalEvents.Remove(globalEvent); }
private void StartGlobalEvent(MyGlobalEventBase globalEvent) { AddGlobalEventToEventLog(globalEvent); if (globalEvent.IsHandlerValid) { globalEvent.Action.Invoke(this, new object[] { globalEvent }); } }
private void StartGlobalEvent(MyGlobalEventBase globalEvent) { AddGlobalEventToEventLog(globalEvent); if (globalEvent.IsHandlerValid) globalEvent.Action(globalEvent); }
public static void RemoveGlobalEvent(MyGlobalEventBase globalEvent) { m_globalEvents.Remove(globalEvent); }
protected override void UnloadData() { m_getEntities.Clear(); m_lemmings.Clear(); m_timeToNextSpawn = -1; m_timeToNextChange = -1; m_spawnMedical = null; m_spawnCount = SPAWN_COUNT; MyLemmingCharacter.Positions.Clear(); m_started = false; m_globalEvent = null; m_timeToEnd = LIFE_TIME; if (m_notification != null) { MyHud.Notifications.Remove(m_notification); m_notification = null; } base.UnloadData(); }
private void AddGlobalEventToEventLog(MyGlobalEventBase globalEvent) { MySandboxGame.Log.WriteLine("MyGlobalEvents.StartGlobalEvent: " + globalEvent.Definition.Id.ToString()); }
public static void Surprise(object senderEvent) { if (!m_started) { m_globalEvent = ((MyGlobalEventBase)senderEvent); StartSurprise(senderEvent); } }
public static void AddGlobalEvent(MyGlobalEventBase globalEvent) { m_globalEvents.Add(globalEvent); }
private static bool RemovalPredicate(MyGlobalEventBase globalEvent) { return globalEvent.Definition.Id == m_defIdToRemove; }
public static void RescheduleEvent(MyGlobalEventBase globalEvent, TimeSpan time) { m_globalEvents.Remove(globalEvent); globalEvent.SetActivationTime(time); m_globalEvents.Add(globalEvent); }
private static bool RemovalPredicate(MyGlobalEventBase globalEvent) { return(globalEvent.Definition.Id == m_defIdToRemove); }
private void AddGlobalEventToEventLog(MyGlobalEventBase globalEvent) { MySandboxGame.Log.WriteLine("MyGlobalEvents.StartGlobalEvent: " + globalEvent.Definition.Id.ToString()); }
public static void AddGlobalEvent(MyGlobalEventBase globalEvent) { m_globalEvents.Add(globalEvent); }