Exemple #1
0
    /// <summary>
    /// 向该用户广播该房间的人物模型准备数据
    /// </summary>
    public void GetRoommateNetData(int uniqueID, AsyncUserToken userToken)
    {
        byte[] message = null;
        foreach (var item in ActorList)
        {
            MessageXieYi xieyi = null;
            if (item.Value == null)
            {
                Log4Debug("检查,房间不该为空");
                continue;
            }
            //准备数据发送完毕,打开UI
            message = SerializeHelper.Serialize <GameModelData>(new GameModelData()
            {
                userIndex = item.Value.UniqueID,
                pos       = (NetVector3)GameTypeManager.BackStandPos(RoomInfo.RoomType, item.Value.UniqueID),
                rotate    = new NetVector3(0, GameTypeManager.BackLookAt(RoomInfo.RoomType, item.Value.UniqueID), 0),
                animation = 0
            });//此处是初始数据
            xieyi = new MessageXieYi((byte)MessageConvention.updateModelInfo, 0, message);
            AsyncIOCPServer.instance.SendSave(userToken, xieyi.ToBytes());
        }
        //准备数据发送完毕,打开UI
        message = new byte[] { 1 };//此处的数组应该是初始数据
        MessageXieYi xieyiFinish = new MessageXieYi((byte)MessageConvention.getPreGameData, 0, message);

        AsyncIOCPServer.instance.SendSave(userToken, xieyiFinish.ToBytes());
    }
Exemple #2
0
    public void SetOriginal()
    {
        Debug.Log("播放死亡动画,设置到初始位置.");
        GameModelData info = new GameModelData()
        {
            userIndex = myIndex,
            pos       = (NetVector3)GameTypeManager.BackStandPos(DataController.instance.MyRoomInfo.RoomType, myIndex),
            rotate    = new NetVector3(0, GameTypeManager.BackLookAt(DataController.instance.MyRoomInfo.RoomType, myIndex), 0),
            animation = 0
        };

        SetPosition(SerializeHelper.BackVector(info.pos));
        SetRotate(SerializeHelper.BackVector(info.rotate));
        SetAnimation(info.animation);
    }
Exemple #3
0
    // 會員加入房間
    public bool Join(AsyncUserToken userToken, out int UniqueID)
    {
        UniqueID = -1;
        lock (ActorList)
        {
            foreach (KeyValuePair <int, RoomActor> item in ActorList)
            {
                if (item.Value.Register == null)
                {
                    UniqueID            = item.Key;
                    item.Value.Register = userToken.userInfo.Register;//先占位,放开lock,允许其他人加入。
                    break;
                }
            }
        }
        if (UniqueID != -1)
        {
            Log4Debug("账号->" + userToken.userInfo.Register.userID + " 用户名->" + userToken.userInfo.Register.name + " 加入房间->" + RoomInfo.RoomID + " 站位为->" + UniqueID);
            //
            TeamType myTeam = TeamType.Both;
            switch (RoomInfo.RoomType)
            {
            case GameModel.组队模式:
                if (UniqueID % 2 == 0)    //红蓝两队
                {
                    myTeam = TeamType.Blue;
                }
                else
                {
                    myTeam = TeamType.Red;
                }
                break;

            case GameModel.Boss模式:
                myTeam = TeamType.Blue;
                break;
            }
            //

            RoomActor actor = new RoomActor(RoomInfo.RoomID, UniqueID, userToken.userInfo.Register, myTeam);
            actor.MyModelInfo.pos       = (NetVector3)GameTypeManager.BackStandPos(RoomInfo.RoomType, UniqueID);
            actor.MyModelInfo.rotate    = new NetVector3(0, GameTypeManager.BackLookAt(RoomInfo.RoomType, UniqueID), 0);
            actor.MyModelInfo.animation = 0;

            userToken.userInfo = actor;
            lock (UserTokenInfo)
            {
                UserTokenInfo[UniqueID] = userToken;
            }
            lock (ActorList)
            {
                ActorList[UniqueID] = actor;
            }
            BoardcastActorInfo(UniqueID);
            //广播房间信息
            byte[]       message = SerializeHelper.Serialize <RoomInfo>(RoomInfo);
            MessageXieYi xieyi   = new MessageXieYi((byte)MessageConvention.getRoomInfo, 0, message);
            AsyncIOCPServer.instance.SendSave(userToken, xieyi.ToBytes());
            return(true);
        }
        else
        {
            return(false);
        }
    }
Exemple #4
0
    public void ChangeRoomState(RoomActorState state)
    {
        byte[]          message         = new byte[] { };
        RoomActorUpdate roomActorUpdate = new RoomActorUpdate();

        Log4Debug("房间更改状态为:" + CurState + "->" + state);
        CurState = state;
        switch (CurState)
        {
        case RoomActorState.NoReady:
            foreach (var item in ActorList)
            {
                if (item.Value == null)
                {
                    continue;
                }
                //初始化房间玩家部分信息
                item.Value.InitActor();
                //广播房间用户准备状态为未准备
                roomActorUpdate = new RoomActorUpdate()
                {
                    userIndex = item.Key,
                    update    = (int)item.Value.CurState + ""
                };
                UpdateState(roomActorUpdate);
            }
            break;

        case RoomActorState.Ready:
            Log4Debug("玩家都准备了。");
            //设置所有玩家默认值
            foreach (var item in ActorList)
            {
                if (item.Value == null)
                {
                    continue;
                }
                item.Value.MyModelInfo.pos    = (NetVector3)GameTypeManager.BackStandPos(RoomInfo.RoomType, item.Key);
                item.Value.MyModelInfo.rotate = new NetVector3(0, GameTypeManager.BackLookAt(RoomInfo.RoomType, item.Key), 0);
                roomActorUpdate = new RoomActorUpdate()
                {
                    userIndex = item.Key,
                    update    = (int)RoomActorState.PrepareModel + ""
                };
                UpdateState(roomActorUpdate);    //广播,修改玩家状态用来准备本机数据
            }
            //方块初始化
            BoxList = new ConcurrentDictionary <int, BoxInfo>();

            //倒计时进入游戏
            ChangeRoomState(RoomActorState.WaitForStart);
            break;

        case RoomActorState.WaitForStart:
            //
            Log4Debug("开始倒计时");
            //时间初始化
            PassedCountDownTime = 0;
            CountDownTimer      = new Timer(new TimerCallback(GameCountDowning), null, 0, 1 * 1000);

            break;

        case RoomActorState.Gaming:
            Log4Debug("开始游戏:" + FrameIndex);

            foreach (var item in ActorList)
            {
                if (item.Value == null)
                {
                    continue;
                }
                if (item.Value.CurState == RoomActorState.WaitForStart)
                {
                    roomActorUpdate = new RoomActorUpdate()
                    {
                        userIndex = item.Key,
                        update    = (int)RoomActorState.Gaming + ""
                    };
                    UpdateState(roomActorUpdate);    //广播,修改玩家状态用来准备本机数据
                }
                else
                {
                    Log4Debug("用户:" + item.Value.Register.name + "在倒计时期间内未准备好模型。");
                }
            }

            //保存帧同步
            FrameIndex = 0;
            FrameCount = (int)(RoomInfo.GameTime / RoomInfo.frameTime);
            FrameGroup = new ConcurrentDictionary <int, FrameInfo>();
            //FrameGroup = new Dictionary<int, FrameInfo>();
            //for (int i = 0; i < FrameCount; i++)
            //{
            //    FrameGroup.Add(i, new FrameInfo() { frameIndex = i, frameData = new List<byte[]>() });
            //}
            //线程池调用时间间隔逻辑
            ThFrameCount = new Thread(GameFrameReconding);
            ThFrameCount.IsBackground = true;
            ThFrameCount.Start();
            //ThreadPool.QueueUserWorkItem(new WaitCallback(GameFrameReconding), null);
            //
            string starttime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
            byte[] start     = SerializeHelper.ConvertToByte(starttime);
            BoardcastMessage(MessageConvention.startGaming, start);
            //发送游戏时间
            PassedGameTime = 0;
            break;

        case RoomActorState.GameEnd:
            Log4Debug("退出计数");
            TeamType winTeam = GetWinnerTeam();
            Log4Debug("游戏结束" + winTeam + "胜利");
            message = SerializeHelper.ConvertToByte((int)winTeam + "");
            BoardcastMessage(MessageConvention.endGaming, message);
            //
            InitRoom();
            break;
        }
    }