Esempio n. 1
0
        public override void Initialize()
        {
            base.Initialize();

            if (CurrentEvent != null)
            {
                CurrentEvent.EventEnd(this, (TwitchChat)mod);
                CurrentEvent = null;
            }

            TickUpdate?.Invoke(false);
            //Build new Scheduler based on main thread with clock based on world ticks (kind'a'like we root to game time instead real time schedule)
            WorldScheduler = new Scheduler(Thread.CurrentThread, new GameTickClock(this));

            RealtimeScheduler = new Scheduler(Thread.CurrentThread);

            lastDayState = Main.dayTime;

            if (ModLoader.version < new Version(0, 11, 5))
            {
                if (Main.netMode == NetmodeID.MultiplayerClient && mod.IsNetSynced)
                {
                    ModPacket p = mod.GetPacket();
                    p.Write((byte)TwitchChat.NetPacketType.Custom);
                    p.Write("NetSend");
                    p.Write(true);
                    p.Send(256);
                }
            }
        }
Esempio n. 2
0
        public void StartWorldEvent(WorldEvent ev)
        {
            try
            {
                if (Main.invasionType > 0 || Main.bloodMoon || Main.eclipse || Main.slimeRain)
                {
                    return;
                }
                CurrentEvent?.EventEnd(this, (TwitchChat)mod);
                CurrentEvent = ev;
                ev.Cd        = ev.Cooldown;
                if (!ev.UseWarning || ev.StartDelay == 0)
                {
                    CurrentEvent?.EventStart(this, (TwitchChat)mod);
                }
                else
                {
                    if (Main.netMode == NetmodeID.Server) // Server
                    {
                        NetMessage.BroadcastChatMessage(NetworkText.FromKey(LanguageManager.Instance.GetTextValue(ev.Warning)), ev.WarnColor);
                    }
                    else if (Main.netMode == NetmodeID.SinglePlayer) // Single Player
                    {
                        Main.NewText(Language.GetTextValue(LanguageManager.Instance.GetTextValue(ev.Warning)), ev.WarnColor);
                    }

                    WorldScheduler.AddDelayed(() =>
                    {
                        CurrentEvent?.EventStart(this, (TwitchChat)mod);  //We need to check because we can get null for now
                    }, ev.StartDelay);
                }
            }
            catch (Exception e)
            {
                mod.Logger.Error($"Warning! Exception caught in {nameof(StartWorldEvent)} ! Report mod author with stacktrace:\n" +
                                 $"{e.Message}\n" +
                                 $"{e.StackTrace}\n");
                //If we executing it as command, rethrow if
                //if (e.StackTrace.Contains(typeof(StartEventCommand).Name))
                //{
                //    throw e;
                //}
            }
        }