Tick() 개인적인 메소드

private Tick ( ) : void
리턴 void
예제 #1
0
        public void Tick()
        {
            try {
                if (this.CurrentState != RoomState.Active && this.CurrentState != RoomState.Finish)
                {
                    return;
                }

                long curTime = TimeUtility.GetLocalMilliseconds();
                if (m_LastLogTime + 60000 < curTime)
                {
                    m_LastLogTime = curTime;

                    LogSys.Log(LOG_TYPE.INFO, "Room.Tick {0}", RoomId);
                }

                if (this.CurrentState == RoomState.Active)
                {
                    Scene scene = ActiveScene;
                    if (null != scene)
                    {
                        scene.Tick();
                        OnTick();
                    }
                    m_DisconnectedUsers.Clear();
                    m_RequestDeleteUsers.Clear();
                    foreach (User user in m_RoomUserMgr.RoomUsers)
                    {
                        if (user != null)
                        {
                            user.Tick();
                            if (user.IsTimeout())
                            {
                                if (user.UserControlState == (int)UserControlState.User)
                                {
                                    m_DisconnectedUsers.Add(user);
                                }
                                else if (user.UserControlState == (int)UserControlState.Remove)
                                {
                                    m_RequestDeleteUsers.Add(user);
                                }
                                else if (user.UserControlState == (int)UserControlState.UserDropped)
                                {
                                    if (user.LastNotifyUserDropTime + c_NotifyUserDropInterval < curTime)
                                    {
                                        Msg_RL_UserDrop uaqBuilder = new Msg_RL_UserDrop();
                                        uaqBuilder.RoomId      = m_RoomId;
                                        uaqBuilder.UserGuid    = user.Guid;
                                        uaqBuilder.IsBattleEnd = false;
                                        m_Connector.SendMsgToLobby(uaqBuilder);

                                        user.LastNotifyUserDropTime = curTime;
                                    }
                                    //临时处理,踢掉断线的玩家
                                    user.UserControlState = (int)UserControlState.Remove;
                                }
                            }
                        }
                    }
                    foreach (User user in m_DisconnectedUsers)
                    {
                        m_RoomUserMgr.DropUser(user);
                    }
                    foreach (User user in m_RequestDeleteUsers)
                    {
                        m_RoomUserMgr.RemoveUser(user);
                    }
                    //todo:观察者掉线处理
                    for (int i = 0; i < m_RoomUserMgr.RoomObservers.Length; ++i)
                    {
                        Observer observer = m_RoomUserMgr.RoomObservers[i];
                        if (!observer.IsIdle)
                        {
                            observer.Tick();
                        }
                    }
                    if (!IsFieldRoom)
                    {
                        int userCount = GetActiveRoomUserCount();
                        if (userCount <= 0 && CanFinish)
                        {
                            if (GetMinimizeElapsedDroppedTime() > c_FinishTimeForNoUsers)
                            {
                                //若房间内玩家数目为0,结束战斗,关闭房间
                                Finish((int)CampIdEnum.Unkown);
                            }
                        }
                    }
                    //每个Tick结束,将空间属性同步给Peer,用于Peer转发消息
                    foreach (User user in m_RoomUserMgr.RoomUsers)
                    {
                        if (null != user && null != user.Info && null != user.Info.GetMovementStateInfo())
                        {
                            GameFramework.RoomPeer peer = user.GetPeer();
                            if (null != peer)
                            {
                                MovementStateInfo info = user.Info.GetMovementStateInfo();
                                peer.Position = info.GetPosition3D();
                                peer.FaceDir  = info.GetFaceDir();
                            }
                        }
                    }
                }
                else if (m_FinishTime + c_DeactiveWaitTime < curTime)
                {
                    Deactive();
                }
            } catch (Exception ex) {
                LogSys.Log(LOG_TYPE.ERROR, "Exception {0}\n{1}", ex.Message, ex.StackTrace);
            }
        }