Пример #1
0
        public void DropUnconscious(long duration = -1, bool toFront = true)
        {
            var          cat = AniCatalog.Unconscious;
            ScriptAniJob job = toFront ? cat.DropFront : cat.DropBack;

            if (job != null)
            {
                ModelInst.StartAniJob(job);
            }

            _Uncon = toFront ? Unconsciousness.Front : Unconsciousness.Back;

            var strm = BaseInst.GetScriptVobStream();

            strm.Write((byte)ScriptVobMessageIDs.Uncon);
            strm.Write((byte)_Uncon);
            BaseInst.SendScriptVobStream(strm);

            if (duration >= 0)
            {
                if (unconTimer == null)
                {
                    unconTimer = new GUCTimer(LiftUnconsciousness);
                }

                unconTimer.SetInterval(duration);
                unconTimer.Start();
            }

            OnUnconChange?.Invoke(this);
        }
Пример #2
0
        public ChatMenu(Chat chat)
        {
            _Chat = chat ?? throw new ArgumentNullException(nameof(chat));
            _Chat.ChatMessageReceived += (sender, args) => ReceiveServerMessage(args.Mode, args.Message);


            screenSize = GUCView.GetScreenSize();
            chatHeigth = screenSize.Y / 5;
            chatWidth  = screenSize.X - 350;

            chatBackground = new GUCVisual(0, 0, chatWidth, chatHeigth + 5);
            chatBackground.SetBackTexture("Dlg_Conversation.tga");

            const int space = 20;
            int       lines = chatHeigth / space;

            for (int i = 0; i < lines; i++)
            {
                chatBackground.CreateText("" + i, 20, 5 + i * space);
                chatBackground.Texts[i].Text = "";
            }

            textBox = new GUCTextBox(70, chatHeigth + 5, chatWidth - 90, false);
            prefix  = new GUCVisual(15, chatHeigth + 5, chatWidth, 20);
            prefix.CreateText("", 0, 0);

            chatInactivityTimer = new GUCTimer();
            chatInactivityTimer.SetCallback(() => { if (!textBox.Enabled)
                                                    {
                                                        chatBackground.Hide();
                                                    }
                                                    chatInactivityTimer.Stop(); });
            chatInactivityTimer.SetInterval(6 * TimeSpan.TicksPerSecond);
        }
Пример #3
0
        public ChatMenu()
        {
            screenSize = GUCView.GetScreenSize();
            chatHeigth = screenSize.Y / 5;
            chatWidth  = screenSize.X - 350;

            chatBackground = new GUCVisual(0, 0, chatWidth, chatHeigth + 5);
            chatBackground.SetBackTexture("Dlg_Conversation.tga");

            const int space = 20;
            int       lines = chatHeigth / space;

            for (int i = 0; i < lines; i++)
            {
                chatBackground.CreateText("" + i, 20, 5 + i * space);
                chatBackground.Texts[i].Text = "";
            }

            textBox = new GUCTextBox(70, chatHeigth + 5, chatWidth - 90, false);
            prefix  = new GUCVisual(15, chatHeigth + 5, chatWidth, 20);
            prefix.CreateText("", 0, 0);

            chatInactivityTimer = new GUCTimer();
            chatInactivityTimer.SetCallback(() => { if (!textBox.Enabled)
                                                    {
                                                        chatBackground.Hide();
                                                    }
                                                    chatInactivityTimer.Stop(); });
            chatInactivityTimer.SetInterval(6 * TimeSpan.TicksPerSecond);
        }
Пример #4
0
        static void RunOutgame(RegisterMemory rmem)
        {
            try
            {
                GameTime.Update();
                GUCTimer.Update(GameTime.Ticks);

                GameTime.Update();
                GameClient.Update();

                GameTime.Update();
                InputHandler.Update();

                if (!ShowConnectionAttempts())
                {
                    if (!outgameStarted)
                    {
                        outgameStarted = true;
                        VobRenderArgs.Init();
                        ScriptManager.Interface.StartOutgame();
                    }

                    GameTime.Update();
                    ScriptManager.Interface.Update(GameTime.Ticks);
                }

                #region Gothic

                WinApi.Process.CDECLCALL <WinApi.NullReturnCall>(0x5053E0); // void __cdecl sysEvent(void)

                using (zColor color = zColor.Create(0, 0, 0, 0))
                    zCRenderer.Vid_Clear(color, 3);

                zCRenderer.BeginFrame();
                zCView.GetScreen().Render();
                zCRenderer.EndFrame();
                zCRenderer.Vid_Blit(1, 0, 0);
                zCSndSys_MSS.DoSoundUpdate();

                #endregion

                if (fpsWatch.IsRunning)
                {
                    long diff = 8 * TimeSpan.TicksPerMillisecond - fpsWatch.Elapsed.Ticks;
                    if (diff > 0)
                    {
                        Thread.Sleep((int)(diff / TimeSpan.TicksPerMillisecond));
                    }
                }
                fpsWatch.Restart();
            }
            catch (Exception e)
            {
                Logger.LogError(e);
            }
        }
Пример #5
0
        static void RunServer()
        {
            try
            {
                TimeStat  timeAll         = new TimeStat();
                LockTimer perfUpdateTimer = new LockTimer(60 * 1000);
                perfUpdateTimer.Trigger();

                while (true)
                {
                    timeAll.Start();

                    GameTime.Update();
                    OnTick?.Invoke();

                    GameTime.Update();
                    GUCTimer.Update(GameTime.Ticks); // move to new thread?

                    //Run the dispatcher
                    GUCDispatcher.Execute();


                    GameTime.Update();
                    GameServer.Update(); //process received packets

                    GameTime.Update();
                    WorldObjects.World.ForEach(w => w.OnTick(GameTime.Ticks));

                    long elapsed = timeAll.Stop();
                    if (perfUpdateTimer.IsReady)
                    {
                        Logger.Log("Performance: {0:0}ms avg, {1:0}ms max. RAM: {2:0.0}MB", timeAll.Average, timeAll.Maximum, Process.GetCurrentProcess().PrivateMemorySize64 / 1000000d);
                        timeAll.Reset();
                    }

                    long diff = (updateRate - elapsed) / TimeSpan.TicksPerMillisecond;
                    if (diff > 0)
                    {
                        Thread.Sleep((int)diff);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.LogError(e.Source + "<br>" + e.Message + "<br>" + e.StackTrace);
            }
        }
Пример #6
0
        public static void ReadRequest(ArenaClient requester, PacketReader stream)
        {
            if (requester.Character == null || requester.IsDueling || requester.Character.IsDead || requester.GMJoined)
            {
                return;
            }

            if (!requester.Character.World.TryGetVob(stream.ReadUShort(), out NPCInst target))
            {
                return;
            }

            if (target.Client == null || target.IsDead)
            {
                return;
            }

            var targetClient = (ArenaClient)target.Client;

            if (targetClient.IsDueling || targetClient.GMJoined)
            {
                return;
            }

            int index;

            if ((index = targetClient.DuelRequests.FindIndex(r => r.Item1 == requester)) >= 0) // other player has already sent a request
            {
                targetClient.DuelRequests[index].Item2.Stop();
                targetClient.DuelRequests.RemoveAt(index);
                DuelStart(requester, targetClient);
            }
            else if ((index = requester.DuelRequests.FindIndex(r => r.Item1 == targetClient)) >= 0) // already sent a request
            {
                requester.DuelRequests[index].Item2.Restart();
            }
            else // add new request
            {
                var timer = new GUCTimer(DuelRequestDuration, () => requester.DuelRequests.RemoveAll(r => r.Item1 == targetClient));
                timer.Start();
                requester.DuelRequests.Add(targetClient, timer);

                SendRequest(requester, targetClient);
            }
        }
Пример #7
0
        public void Toggle(ArenaClient client, bool open)
        {
            if (open)
            {
                if (!clients.ContainsKey(client))
                {
                    GUCTimer timer = new GUCTimer(UpdateInterval, () => SendUpdate(client));
                    clients.Add(client, timer);
                    timer.Start();

                    if (clients.Count == 1)
                    {
                        packetTimer.Start();
                        WriteUpdate();
                    }

                    SendUpdate(client);
                }
            }
            else
            {
                Remove(client);
            }
        }
Пример #8
0
        static void RunIngame(RegisterMemory rmem)
        {
            try
            {
                spikeWatch.Restart();
                // Update Timers
                GameTime.Update();
                GUCTimer.Update(GameTime.Ticks);

                // Do networking, read packets
                GameTime.Update();
                GameClient.Update();

                // handle peripherals' input
                GameTime.Update();
                InputHandler.Update();

                if (!ShowConnectionAttempts())
                {
                    if (!ingameStarted)
                    {
                        ingameStarted = true;
                        ScriptManager.Interface.StartIngame();
                    }

                    // ClientScripts update
                    GameTime.Update();
                    ScriptManager.Interface.Update(GameTime.Ticks);

                    if (GameClient.Client.IsIngame)
                    {
                        // Update worlds
                        GameTime.Update();
                        World.UpdateWorlds(GameTime.Ticks);
                    }

                    // Check spectator stuff
                    GameTime.Update();
                    GameClient.UpdateSpectator(GameTime.Ticks);

                    // check player hero
                    GameTime.Update();
                    NPC.UpdateHero(GameTime.Ticks);
                }

                // update guc sounds
                GameTime.Update();
                SoundHandler.Update3DSounds();

                spikeWatch.Stop();
                if (spikeTimer.IsReady)
                {
                    spikeLongest = 0;
                }
                if (spikeLongest < spikeWatch.Elapsed.Ticks)
                {
                    spikeLongest = spikeWatch.Elapsed.Ticks;
                }

                if (fpsWatch.IsRunning)
                {
                    long diff;
                    if ((diff = 8 * TimeSpan.TicksPerMillisecond - fpsWatch.Elapsed.Ticks) > 0)
                    {
                        Thread.Sleep((int)(diff / TimeSpan.TicksPerMillisecond));
                    }
                }
                lastElapsed = fpsWatch.Elapsed.Ticks;
                fpsWatch.Restart();
            }
            catch (Exception e)
            {
                Logger.LogError(e);
            }
        }
Пример #9
0
 partial void pConstruct()
 {
     rainTimer = new GUCTimer(2 * TimeSpan.TicksPerMinute, OnRainChange);
 }
Пример #10
0
 public ScoreBoard(ScriptMessages messageID)
 {
     msgID       = messageID;
     clients     = new Dictionary <ArenaClient, GUCTimer>(20);
     packetTimer = new GUCTimer(UpdateInterval, WriteUpdate);
 }
Пример #11
0
 public static void Init()
 {
     timer = new GUCTimer(RegenerationInterval, RegeneratePlayers);
     timer.Start();
 }
Пример #12
0
 public ScriptWeatherCtrl(WorldInst world)
 {
     World      = world ?? throw new ArgumentNullException(nameof(world));
     _RainTimer = new GUCTimer(2 * TimeSpan.TicksPerMinute, OnRainChange);
 }
Пример #13
0
 protected ScoreBoardScreen(ScriptMessages messageID)
 {
     this.msgID      = messageID;
     this.closeTimer = new GUCTimer(DoClose);
 }