Пример #1
0
        public static GuildManager Add(Player player, Guild guildStruct)
        {
            if (guildStruct == null)
            {
                return(null);
            }
            GuildManager ret = null;

            if (CurrentManagers.ContainsKey(guildStruct.Name))
            {
                ret = CurrentManagers[guildStruct.Name];
                if (ret._guildStructs.ContainsKey(player.AccountId))
                {
                    ret._guildStructs[player.AccountId] = guildStruct;
                }
                else
                {
                    ret._guildStructs.Add(player.AccountId, guildStruct);
                }

                ret.Add(player);
            }
            else
            {
                ret = new GuildManager(guildStruct, player.Manager);
                ret._guildStructs.Add(player.AccountId, guildStruct);
                ret.Add(player);
                _currentManagers.Add(guildStruct.Name, ret);
            }
            return(ret);
        }
Пример #2
0
        public void TickLoop()
        {
            log.Info("Logic loop started.");
            Stopwatch watch = new Stopwatch();
            long      dt    = 0;
            long      count = 0;

            watch.Start();
            RealmTime t = new RealmTime();

            do
            {
                if (Manager.Terminating)
                {
                    break;
                }

                long times = dt / MsPT;
                dt -= times * MsPT;
                times++;

                long b = watch.ElapsedMilliseconds;

                count += times;
                if (times > 3)
                {
                    log.Warn("LAGGED!| time:" + times + " dt:" + dt + " count:" + count + " time:" + b + " tps:" +
                             count / (b / 1000.0));
                }

                t.tickTimes      = b;
                t.tickCount      = count;
                t.thisTickCounts = (int)times;
                t.thisTickTimes  = (int)(times * MsPT);

                foreach (ConcurrentQueue <Action <RealmTime> > i in pendings)
                {
                    Action <RealmTime> callback;
                    while (i.TryDequeue(out callback))
                    {
                        try
                        {
                            callback(t);
                        }
                        catch (Exception ex)
                        {
                            log.Error(ex);
                        }
                    }
                }
                TickWorlds1(t);

                Player[] tradingPlayers = TradeManager.TradingPlayers.Where(_ => _.Owner == null).ToArray();
                foreach (var player in tradingPlayers)
                {
                    TradeManager.TradingPlayers.Remove(player);
                }

                KeyValuePair <Player, Player>[] requestPlayers = TradeManager.CurrentRequests.Where(_ => _.Key.Owner == null || _.Value.Owner == null).ToArray();
                foreach (var players in requestPlayers)
                {
                    TradeManager.CurrentRequests.Remove(players);
                }

                //string[] accIds = Manager.Clients.Select(_ => _.Value.Account.AccountId).ToArray();

                //List<string> curGStructAccIds = new List<string>();

                //foreach(var i in GuildManager.CurrentManagers.Values)
                //    curGStructAccIds.AddRange(i.GuildStructs.Select(_ => _.Key));

                //foreach (var i in curGStructAccIds)
                //    if (!accIds.Contains(i))
                //        GuildManager.RemovePlayerWithId(i);

                //var m = GuildManager.CurrentManagers;
                //try
                //{
                //    foreach (var g in m)
                //        if (g.Value.Count == 0)
                //            GuildManager.CurrentManagers.Remove(g.Key);
                //}
                //catch (Exception ex)
                //{
                //    log.Error(ex);
                //}

                try
                {
                    GuildManager.Tick(CurrentTime);
                }
                catch (Exception ex)
                {
                    log.Error(ex);
                }

                Thread.Sleep(MsPT);
                dt += Math.Max(0, watch.ElapsedMilliseconds - b - MsPT);
            } while (true);
            log.Info("Logic loop stopped.");
        }
Пример #3
0
        public void TickLoop()
        {
            if (CheckConfig.IsDebugOn())
            {
                Console.WriteLine("Logic loop started.");
            }
            Stopwatch watch = new Stopwatch();
            long      dt    = 0;
            long      count = 0;

            watch.Start();
            RealmTime t = new RealmTime();

            do
            {
                if (Manager.Terminating)
                {
                    break;
                }

                long times = dt / MsPT;
                dt -= times * MsPT;
                times++;

                long b = watch.ElapsedMilliseconds;

                count += times;
                if (times > 3)
                {
                    Console.WriteLine("LAGGED!| time:" + times + " dt:" + dt + " count:" + count + " time:" + b + " tps:" +
                                      count / (b / 1000.0));
                }

                t.tickTimes      = b;
                t.tickCount      = count;
                t.thisTickCounts = (int)times;
                t.thisTickTimes  = (int)(times * MsPT);

                foreach (ConcurrentQueue <Action <RealmTime> > i in pendings)
                {
                    Action <RealmTime> callback;
                    while (i.TryDequeue(out callback))
                    {
                        try
                        {
                            callback(t);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                        }
                    }
                }
                TickWorlds1(t);

                Player[] tradingPlayers = TradeManager.TradingPlayers.Where(_ => _.Owner == null).ToArray();
                foreach (var player in tradingPlayers)
                {
                    TradeManager.TradingPlayers.Remove(player);
                }

                KeyValuePair <Player, Player>[] requestPlayers = TradeManager.CurrentRequests.Where(_ => _.Key.Owner == null || _.Value.Owner == null).ToArray();
                foreach (var players in requestPlayers)
                {
                    TradeManager.CurrentRequests.Remove(players);
                }

                try
                {
                    GuildManager.Tick(CurrentTime);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }

                Thread.Sleep(MsPT);
                dt += Math.Max(0, watch.ElapsedMilliseconds - b - MsPT);
            } while (true);
            Console.WriteLine("Logic loop stopped.");
        }
Пример #4
0
        public void TickLoop()
        {
            if (CheckConfig.IsDebugOn())
            {
                Console.WriteLine("Logic loop started.");
            }
            Stopwatch watch = new Stopwatch();
            long      dt    = 0;
            long      count = 0;
            long      good  = 0;

            watch.Start();
            RealmTime t = new RealmTime();

            do
            {
                if (Manager.Terminating)
                {
                    break;
                }

                long times = dt / MsPT;
                dt -= times * MsPT;
                times++;

                long b = watch.ElapsedMilliseconds;

                count += times;
                if (times > 3)
                {
                    Program.writeNotable("LAGGED!| time:" + times + " dt:" + dt + " count:" + count + " time:" + b + " tps:" +
                                         count / (b / 1000.0));
                    if (dt > 2000)
                    {
                        foreach (Client i in Manager.Clients.Values)
                        {
                            i.Player.ApplyConditionEffect(new ConditionEffect
                            {
                                Effect     = ConditionEffectIndex.Invulnerable,
                                DurationMS = 5 * 1000
                            });
                            i.Player.SendInfo("Lag Detected, giving Invulnerability to prevent death");
                        }
                    }
                    foreach (Client i in Manager.Clients.Values)
                    {
                        if (i.Player != null)
                        {
                            i.Player.dexShotViolation = 0;
                        }
                    }
                    Program.isLagging = true;
                    good = 0;
                }
                if (good > 100)
                {
                    Program.isLagging = false;
                }
                good++;

                t.tickTimes      = b;
                t.tickCount      = count;
                t.thisTickCounts = (int)times;
                t.thisTickTimes  = (int)(times * MsPT);

                foreach (ConcurrentQueue <Action <RealmTime> > i in pendings)
                {
                    Action <RealmTime> callback;
                    while (i.TryDequeue(out callback))
                    {
                        try
                        {
                            callback(t);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                        }
                    }
                }
                TickWorlds1(t);

                Player[] tradingPlayers = TradeManager.TradingPlayers.Where(_ => _.Owner == null).ToArray();
                foreach (var player in tradingPlayers)
                {
                    TradeManager.TradingPlayers.Remove(player);
                }

                KeyValuePair <Player, Player>[] requestPlayers = TradeManager.CurrentRequests.Where(_ => _.Key.Owner == null || _.Value.Owner == null).ToArray();
                foreach (var players in requestPlayers)
                {
                    TradeManager.CurrentRequests.Remove(players);
                }

                try
                {
                    GuildManager.Tick(CurrentTime);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }

                Thread.Sleep(MsPT);
                dt += Math.Max(0, watch.ElapsedMilliseconds - b - MsPT);
            } while (true);
            Console.WriteLine("Logic loop stopped.");
        }