Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 玩家移动
        /// </summary>
        /// <param name="client"></param>
        /// <param name="v1"></param>
        /// <param name="v2"></param>
        /// <param name="v3"></param>
        private void OnWalk(MOBAClient client, float x, float y, float z)
        {
            int        playerID   = playerCache.GetID(client);
            BattleRoom battleRoom = battleCache.GetRoom(playerID);

            if (battleRoom == null)
            {
                return;
            }
            //给每一个客户端发送谁移动到哪的信息
            battleRoom.Broadcast(OperationCode.BattleCode, OpBattle.Walk, 0, "有玩家移动", null, playerID, x, y, z);
        }
Exemplo n.º 3
0
        public void OnDisConnect(MOBAClient client)
        {
            //下线的时候,通知在线好友,显示离线状态
            //***这里要通过客户端获取到玩家账号ID,再用账号ID获取到玩家ID,否则会报空
            int accountID = accountCache.GetID(client);
            int playerID  = playerCache.GetID(accountID);

            PlayerModel playerModel = playerCache.GetPlayerModel(playerID);

            if (playerModel != null)
            {
                foreach (int friendID in playerModel.FriendIdList)
                {
                    if (!playerCache.IsOnLine(friendID))    //因为GetPlayerModel,GetClient是获取在线玩家的数据
                    {
                        continue;
                    }
                    MOBAClient friendClient = playerCache.GetClient(friendID);
                    Send(friendClient, OperationCode.PlayerCode, OpPlayer.FriendOnlineState, 1, "好友玩家下线", playerModel.Id);
                }
            }
            matchCache.OffLine(client, playerID);
            playerCache.OffLine(client);
        }