Exemplo n.º 1
0
        public void Update(AccurateDelta delta)
        {
            if (Disposed)
            {
                return;
            }

            try
            {
                if (!Players.Any())
                {
                    RoomManager.Remove(this);
                    return;
                }

                if (!(Master?.IsLoggedIn() ?? true) || Master?.Room != this)
                {
                    ChangeMasterIfNeeded(GetPlayerWithLowestPing(), true);
                    ChangeHostIfNeeded(GetPlayerWithLowestPing(), true);
                }

                if (!TeamManager.NoSpectatorPlayers.Any() && TeamManager.Players.Any())
                {
                    foreach (var spectator in TeamManager.Spectators)
                    {
                        TeamManager.ChangeMode(spectator, PlayerGameMode.Normal);
                    }
                }

                if (IsChangingRules)
                {
                    _changingRulesTimer += delta.delta;
                    if (_changingRulesTimer >= _changingRulesTime && !IsChangingRulesCooldown)
                    {
                        RoomManager.Channel.BroadcastCencored(new RoomChangeRoomInfoAck2Message(GetRoomInfo()));
                        Broadcast(new RoomChangeRuleAckMessage(Options.Map <RoomCreationOptions, ChangeRuleDto2>()));
                        Broadcast(new GameChangeStateAckMessage(GameState));
                        IsChangingRulesCooldown = true;
                    }

                    foreach (var player in _players.Values)
                    {
                        player.RoomInfo.LastMapID = (byte)Options.MapId;
                    }

                    if (_changingRulesTimer >= _changingRulesTime.Add(TimeSpan.FromSeconds(3)))
                    {
                        IsChangingRules         = false;
                        IsChangingRulesCooldown = false;
                    }
                }
                else
                {
                    foreach (var player in Players.Values.Where(x => !TeamManager.Players.Contains(x)))
                    {
                        TeamManager.Join(player);
                    }
                }

                if (VoteKickMgr.State == VoteKickManager.KickState.Execution)
                {
                    _voteKicktimer += delta.delta;
                    if (_voteKicktimer < _voteKickTime)
                    {
                        VoteKickMgr.Update();
                    }
                    else
                    {
                        _voteKicktimer = TimeSpan.Zero;
                        VoteKickMgr.Evaluate();
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error(e.ToString());
            }

            GameRuleManager?.Update(delta);
        }