Ejemplo n.º 1
0
        /// <summary>
        /// 玩家确认选择
        /// </summary>
        /// <param name="client"></param>
        private void onReady(MobaClient client)
        {
            int        playerId = playerCache.GetId(client);
            SelectRoom room     = selectCache.Ready(playerId);

            if (room == null)
            {
                //告诉他自己确认失败
                this.Send(client, OpCode.SelectCode, OpSelect.Ready, -1, "确认失败");
                return;
            }
            //告诉房间所有人 此人确认选择了
            room.Brocast(OpCode.SelectCode, OpSelect.Ready, 0, "有人确认选择了", null, playerId);

            //判断 是否全部准备了 如果全部准备了 就开始战斗
            if (room.IsAllReady)
            {
                //TODO
                this.StartFightEvent(room.team1Dict.Values.ToList(), room.team2Dict.Values.ToList());

                //给客户端发送消息:准备战斗 切换场景
                room.Brocast(OpCode.SelectCode, OpSelect.StartFight, 0, "准备进入战斗场景", null);
                //销毁房间
                selectCache.Destroy(room.Id);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 玩家确认英雄
        /// </summary>
        /// <param name="client"></param>
        private void OnReady(MobaClient client)
        {
            int        playerId = playerCache.GetId(client);
            SelectRoom room     = selectCache.OnReady(playerId);

            if (room == null)
            {
                this.Send(client, OpCode.SelectCode, OpSelect.Ready, -1, "确认失败");
            }
            else
            {
                room.Brocast(OpCode.SelectCode, OpSelect.Ready, 0, "有人确认选择了", null, playerId);
                //判断是否全部准备了,如果全部准备了,就开始战斗
                if (room.IsAllReady)
                {
                    //通知开始战斗
                    this.StartFightEvent(room.team1Dict.Values.ToList(), room.team2Dict.Values.ToList());
                    //给客户端发送准备战斗,切换场景
                    room.Brocast(OpCode.SelectCode, OpSelect.StartFight, 0, "准备进入战斗");

                    //销毁房间
                    selectCache.Destroy(room.Id);
                }
            }
        }
Ejemplo n.º 3
0
        public override void OnOperationRequest(OperationRequest request, SendParameters sendParameters, MobaPeer peer)
        {
            MobaServer.LogInfo("处理准备完成的请求");

            int        playerId = UserManager.GetPlayer(peer.Username).Identification;
            SelectRoom room     = Caches.Select.Ready(playerId);

            if (room == null)
            {
                // 告诉自己确认失败
                SendResponse(peer, request.OperationCode, null, ReturnCode.Falied);
                return;
            }
            // 告诉房间内所有人:有人确定选择
            Dictionary <byte, object> data = new Dictionary <byte, object>();

            data.Add((byte)ParameterCode.PlayerId, playerId);
            room.Brocast(OperationCode.BeReadySelect, data);

            // 如果全部准备好了 则开始战斗
            if (room.IsAllReady)
            {
                // 创建战斗的房间
                Caches.Battle.CreateRoom(room.TeamOneDict.Values.ToList(), room.TeamTwoDict.Values.ToList());
                // 通知所有客户端准备战斗
                room.Brocast(OperationCode.ReadyBattle, null);
                // 销毁选择的房间
                Caches.Select.DestroyRoom(room.Id);
            }
        }
Ejemplo n.º 4
0
        public override void OnOperationRequest(OperationRequest request, SendParameters sendParameters, MobaPeer peer)
        {
            MobaServer.LogInfo("处理进入选择房间的请求");

            DataBase.Model.Player player = UserManager.GetPlayer(peer.Username);
            SelectRoom            room   = Caches.Select.EnterRoom(player.Identification, peer);

            if (room == null)
            {
                return;
            }

            OperationResponse response = new OperationResponse();

            // 先给客户端发送已经进入房间的玩家数据(房间模型)
            response.OperationCode = (byte)OperationCode.SelectGetInfo;
            response.Parameters    = new Dictionary <byte, object>();
            response[(byte)ParameterCode.TeamOneSelectData] = JsonMapper.ToJson(room.TeamOneDict.Values.ToArray());
            response[(byte)ParameterCode.TeamTwoSelectData] = JsonMapper.ToJson(room.TeamTwoDict.Values.ToArray());
            peer.SendOperationResponse(response, sendParameters);

            // 再给房间内的其他客户端发一条消息:有人进入了
            Dictionary <byte, object> data = new Dictionary <byte, object>();

            data.Add((byte)(ParameterCode.PlayerId), player.Identification);
            room.Brocast(OperationCode.EnterSelect, data);
        }
Ejemplo n.º 5
0
        public override void OnOperationRequest(OperationRequest request, SendParameters sendParameters, MobaPeer peer)
        {
            MobaServer.LogInfo("处理选择的请求");

            int playerId = UserManager.GetPlayer(peer.Username).Identification;
            int heroId   = (int)request.Parameters.ExTryGet((byte)ParameterCode.HeroId);

            SelectRoom room = Caches.Select.Select(playerId, heroId);

            if (room == null)
            {
                // 告诉自己选择失败
                OperationResponse response = new OperationResponse(request.OperationCode);
                response.ReturnCode = (short)ReturnCode.Falied;
                peer.SendOperationResponse(response, sendParameters);
                return;
            }

            // 给房间内的所有人发一条消息:谁选择了什么英雄
            Dictionary <byte, object> data = new Dictionary <byte, object>();

            data.Add((byte)ParameterCode.PlayerId, playerId);
            data.Add((byte)ParameterCode.HeroId, heroId);
            room.Brocast(OperationCode.Selected, data);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 进入选人
        /// </summary>
        /// <param name="client"></param>
        private void onEnter(MobaClient client)
        {
            SelectRoom room = selectCache.Enter(playerCache.GetId(client), client);

            if (room == null)
            {
                return;
            }
            //先给此客户端发一个房间模型
            this.Send(client, OpCode.SelectCode, OpSelect.GetInfo, 0, "获取房间模型", JsonMapper.ToJson(room.team1Dict.Values.ToArray()), JsonMapper.ToJson(room.team2Dict.Values.ToArray()));
            //再给房间内的客户端发一条消息:有人进入了
            room.Brocast(OpCode.SelectCode, OpSelect.Enter, 0, "有玩家进入", client, playerCache.GetId(client));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 玩家选择英雄
        /// </summary>
        private void OnSelect(MobaClient client, int heroId)
        {
            int        playerId = playerCache.GetId(client);
            SelectRoom room     = selectCache.Select(playerId, heroId);

            if (room == null)
            {
                this.Send(client, OpCode.SelectCode, OpSelect.Select, -1, "选择英雄失败");
                return;
            }
            //给房间的所有人发送一条谁选了谁(playerId,heroId)
            room.Brocast(OpCode.SelectCode, OpSelect.Select, 0, "有人选择英雄了", null, playerId, heroId);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 玩家选择英雄
        /// </summary>
        /// <param name="client"></param>
        /// <param name="heroId"></param>
        private void onSelect(MobaClient client, int heroId)
        {
            //给房间里面的所有人发一条消息:谁选了谁(playerID,heroId)
            int        playerId = playerCache.GetId(client);
            SelectRoom room     = selectCache.Select(playerId, heroId);

            if (room == null)
            {
                //告诉他自己选择失败
                Send(client, OpCode.SelectCode, OpSelect.Select, -1, "选择失败");
                return;
            }
            room.Brocast(OpCode.SelectCode, OpSelect.Select, 0, "有人选择英雄了", null, playerId, heroId);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 聊天
        /// </summary>
        /// <param name="client"></param>
        /// <param name="v"></param>
        private void onTalk(MobaClient client, string text)
        {
            //给当前客户端所在的房间内所有人发一条消息 :text
            PlayerModel player = playerCache.GetModel(client);

            if (player == null)
            {
                return;
            }
            SelectRoom room = selectCache.GetRoom(player.Id);
            //角色名:我要选这个
            string str = string.Format("{0}:{1}", player.Name, text);

            room.Brocast(OpCode.SelectCode, OpSelect.Talk, 0, "有玩家发言了", null, str);
        }
Ejemplo n.º 10
0
        public override void OnOperationRequest(OperationRequest request, SendParameters sendParameters, MobaPeer peer)
        {
            MobaServer.LogInfo("处理选人界面的聊天请求");

            int        playerId = UserManager.GetPlayer(peer.Username).Identification;
            SelectRoom room     = Caches.Select.GetRoomByPlayerId(playerId);

            if (room == null)
            {
                MobaServer.LogError(">>>>> 异常:玩家找不到房间 TalkInSelectHandler");
                return;
            }

            // 将聊天内容发给所有客户端 测试方便
            room.Brocast(OperationCode.TalkInSelect, request.Parameters);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 聊天,给房间所有人发聊天信息
        /// </summary>
        /// <param name="client"></param>
        /// <param name="text"></param>
        private void onTalk(MobaClient client, string text)
        {
            //服务器输出到日志文件的日志
            //MobaApplication.LogInfo(text);
            //给当前客户端所在的房间内所有人发一条消息
            PlayerModel player = playerCache.GetModel(client);

            if (player == null)
            {
                return;
            }

            SelectRoom room = selectCache.GetRoom(player.Id);
            //角色名:说了什么
            string str = string.Format("{0} : {1}", player.Name, text);

            room.Brocast(OpCode.SelectCode, OpSelect.Talk, 0, "有玩家发言了", null, str);
        }
Ejemplo n.º 12
0
        private void OnTalk(MobaClient client, string context)
        {
            //给房间内的当前客户端所有人发一条消息:context
            PlayerModel player = playerCache.GetModel(client);

            if (player == null)
            {
                return;
            }
            SelectRoom room = selectCache.GetRoom(player.Id);

            if (room == null)
            {
                return;
            }
            string str = string.Format("{0} : {1}", player.Name, context);

            room.Brocast(OpCode.SelectCode, OpSelect.Talk, 0, "有玩家发言了", null, str);
        }