private void MainServerLoop()
        {
            _lastHeavyUpdate = DateTime.UtcNow;

            while (true)
            {
                var elapsedTime = DateTime.UtcNow - _lastHeavyUpdate;

                Lorule.Update(() =>
                {
                    UpdateClients(elapsedTime);
                    UpdateComponents(elapsedTime);
                    UpdateAreas(elapsedTime);
                    _lastHeavyUpdate = DateTime.UtcNow;
                    Thread.Sleep(_heavyUpdateSpan);
                });
            }
        }
Пример #2
0
        private async void UpdateServer()
        {
            _previousGameTime = DateTime.UtcNow;

            while (ServerContext.Running)
            {
                var gameTime = DateTime.UtcNow - _previousGameTime;

                Lorule.Update(() =>
                {
                    UpdateClients(gameTime);
                    UpdateComponents(gameTime);

                    foreach (var map in ServerContext.GlobalMapCache)
                    {
                        map.Value?.Update(gameTime);
                    }
                });

                _previousGameTime += gameTime;

                await Task.Delay(8);
            }
        }
        public GameClient LoadSpellBook()
        {
            lock (_syncObj)
            {
                Lorule.Update(() =>
                {
                    var spellsAvailable = Aisling.SpellBook.Spells.Values
                                          .Where(i => i != null && i.Template != null).ToArray();

                    for (var i = 0; i < spellsAvailable.Length; i++)
                    {
                        var spell = spellsAvailable[i];

                        if (spell.Template != null)
                        {
                            if (ServerContextBase.GlobalSpellTemplateCache.ContainsKey(spell.Template.Name))
                            {
                                var template = ServerContextBase.GlobalSpellTemplateCache[spell.Template.Name];
                                {
                                    spell.Template = template;
                                }
                            }
                        }

                        spell.Lines = spell.Template.BaseLines;

                        Spell.AttachScript(Aisling, spell);
                        {
                            Aisling.SpellBook.Set(spell, false);
                        }

                        Send(new ServerFormat17(spell));

                        if (spell.NextAvailableUse.Year > 1)
                        {
                            Task.Delay(1000).ContinueWith(ct =>
                            {
                                var delta  = (int)Math.Abs((DateTime.UtcNow - spell.NextAvailableUse).TotalSeconds);
                                var offset = Math.Abs(spell.Template.Cooldown - delta);

                                if (delta <= spell.Template.Cooldown)
                                {
                                    Send(new ServerFormat3F(0,
                                                            spell.Slot,
                                                            delta));
                                }
                            });
                        }
                        else
                        {
                            spell.NextAvailableUse = DateTime.UtcNow;
                        }
                    }

                    if (Aisling.GameMaster)
                    {
                        foreach (var spell in ServerContextBase.GlobalSpellTemplateCache.Select(i => i.Value))
                        {
                            if (spell.Name.StartsWith("[GM]"))
                            {
                                if (Spell.GiveTo(Aisling, spell.Name, 1))
                                {
                                    ServerContext.Logger(
                                        $"[GM] -> Spell {spell.Name} Given to GameMaster {Aisling.Username}.");
                                }
                            }
                        }
                    }
                });
            }

            return(this);
        }
 private static void Pulse(TimeSpan elapsedTime, IGameClient client)
 {
     Lorule.Update(() => { client.Update(elapsedTime); });
 }