public virtual void Init(MyObjectBuilder_GlobalEventBase ob)
 {
     Definition     = MyDefinitionManager.Static.GetEventDefinition(ob.DefinitionId);
     Action         = MyGlobalEventFactory.GetEventHandler(Definition.Id);
     ActivationTime = TimeSpan.FromMilliseconds(ob.ActivationTimeMs);
     Enabled        = ob.Enabled;
 }
        public override void BeforeStart()
        {
            base.BeforeStart();

            if (!Sync.IsServer)
            {
                return;
            }

            bool shouldHaveCargoShips = MyFakes.ENABLE_CARGO_SHIPS && MySession.Static.CargoShipsEnabled;

            var cargoShipEvent = MyGlobalEvents.GetEventById(new MyDefinitionId(typeof(MyObjectBuilder_GlobalEventBase), "SpawnCargoShip"));

            if (cargoShipEvent == null && shouldHaveCargoShips)
            {
                var globalEvent = MyGlobalEventFactory.CreateEvent(new MyDefinitionId(typeof(MyObjectBuilder_GlobalEventBase), "SpawnCargoShip"));
                MyGlobalEvents.AddGlobalEvent(globalEvent);
            }
            else if (cargoShipEvent != null)
            {
                if (shouldHaveCargoShips)
                {
                    cargoShipEvent.Enabled = true;
                }
                else
                {
                    cargoShipEvent.Enabled = false;
                }
            }
        }
Exemple #3
0
 public void Init(MyObjectBuilder_GlobalEvents objectBuilder)
 {
     foreach (var eventBuilder in objectBuilder.Events)
     {
         m_globalEvents.Add(MyGlobalEventFactory.CreateEvent(eventBuilder));
     }
 }
Exemple #4
0
 public virtual void Init(MyObjectBuilder_GlobalEventBase ob)
 {
     Definition             = MyDefinitionManager.Static.GetEventDefinition(ob.GetId());
     Action                 = MyGlobalEventFactory.GetEventHandler(ob.GetId());
     ActivationTime         = TimeSpan.FromMilliseconds(ob.ActivationTimeMs);
     Enabled                = ob.Enabled;
     RemoveAfterHandlerExit = false;
 }
 public virtual void InitFromDefinition(MyGlobalEventDefinition definition)
 {
     Definition = definition;
     Action     = MyGlobalEventFactory.GetEventHandler(Definition.Id);
     if (Definition.FirstActivationTime.HasValue)
     {
         ActivationTime = Definition.FirstActivationTime.Value;
     }
     else
     {
         RecalculateActivationTime();
     }
     Enabled = true;
 }
Exemple #6
0
        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);
                }
            }
        }