コード例 #1
0
        /// <summary>
        /// 玩家确认选择(准备)
        /// </summary>
        /// <param name="client"></param>
        private void OnReady(MOBAClient client)
        {
            int        playerID   = playerCache.GetID(client);
            SelectRoom selectRoom = selectCache.Ready(playerID);

            if (selectRoom == null)
            {
                //返回准备失败给客户端
                Send(client, OperationCode.SelectCode, OpSelect.Ready, -1, "准备失败");
                return;
            }
            //通知房间所有人此玩家准备
            selectRoom.Broadcast(OperationCode.SelectCode, OpSelect.Ready, 0, "有人准备了", null, playerID);

            //检测 是否全部人都准备,都准备就进入战斗
            if (selectRoom.IsAllReady)
            {
                StartBattleAction(selectRoom.RedTeamSelectModels.Values.ToList(),
                                  selectRoom.BlueTeamSelectModels.Values.ToList());
                //给客户端发送消息:准备战斗 切换场景
                selectRoom.Broadcast(OperationCode.SelectCode, OpSelect.StartBattle, 0, "准备进入战斗场景", null);

                //销毁当前房间
                selectCache.DestorySelectRoom(selectRoom.ID);
            }
        }
コード例 #2
0
        /// <summary>
        /// 进入选人
        /// </summary>
        /// <param name="client"></param>
        private void OnEnter(MOBAClient client)
        {
            int        playerID   = playerCache.GetID(client);
            SelectRoom selectRoom = selectCache.Enter(playerID, client);

            if (selectRoom == null)
            {
                return;
            }
            //进入成功
            //先给客户端发一个房间模型,再给房间内的客户端发一条消息:有人进入房间
            Send(client, OperationCode.SelectCode, OpSelect.GetInfo, 0, "获取房间信息",
                 JsonMapper.ToJson(selectRoom.RedTeamSelectModels.Values.ToArray()),
                 JsonMapper.ToJson(selectRoom.BlueTeamSelectModels.Values.ToArray()));
            selectRoom.Broadcast(OperationCode.SelectCode, OpSelect.Enter, 0, "有玩家进入房间", client, playerID);
            //检测是否全部都进入房间
            if (selectRoom.IsAllEnter)
            {
                //如果全部都进入房间就开启一个定时任务,通知玩家在60秒内准备,不准备房间就解散
                selectRoom.StartSchedule(DateTime.UtcNow.AddSeconds(60), () =>
                {
                    //房间解散
                    if (!selectRoom.IsAllReady)
                    {
                        selectRoom.Broadcast(OperationCode.SelectCode, OpSelect.Cancel, 1, "有玩家60秒内未准备,解散当前房间", null);
                        selectCache.DestorySelectRoom(selectRoom.ID);
                    }
                });
                //给所有人发送全部玩家进入房间的消息
                selectRoom.Broadcast(OperationCode.SelectCode, OpSelect.Enter, 1, "全部玩家进入房间", null, playerID);
            }
        }
コード例 #3
0
        /// <summary>
        /// 玩家选人
        /// </summary>
        /// <param name="client"></param>
        private void OnSelect(MOBAClient client, int heroID)
        {
            int        playerID   = playerCache.GetID(client);
            SelectRoom selectRoom = selectCache.Select(playerID, heroID);

            if (selectRoom == null)
            {
                Send(client, OperationCode.SelectCode, OpSelect.Select, -1, "选择失败");
                return;
            }
            //给房间里面的所有人发一条消息:谁选了什么英雄(playerID,heroID)
            selectRoom.Broadcast(OperationCode.SelectCode, OpSelect.Select, 0, "有人选择了英雄", null, playerID, heroID);
        }
コード例 #4
0
        private void OnChat(MOBAClient client, string text)
        {
            //给当前客户端所在的房间内的所有人发一条消息
            PlayerModel playerModel = playerCache.GetPlayerModel(client);

            if (playerModel == null)
            {
                return;
            }
            SelectRoom selectRoom = selectCache.GetRoom(playerModel.Id);

            if (selectRoom != null)
            {
                string str = string.Format("{0}:{1}", playerModel.Name, text);
                selectRoom.Broadcast(OperationCode.SelectCode, OpSelect.Chat, 0, "有玩家发言了", null, str);
            }
        }