Exemplo n.º 1
0
        public KFCopyTeamJoinRsp JoinTeam(KFCopyTeamJoinReq req)
        {
            KFCopyTeamJoinRsp rsp = new KFCopyTeamJoinRsp();

            try
            {
                lock (this.Mutex)
                {
                    this.ForceLeaveRoom(req.Member.RoleID);
                    CopyTeamData td = null;
                    if (!this.CopyTeamDict.TryGetValue(req.TeamId, out td))
                    {
                        rsp.ErrorCode = CopyTeamErrorCodes.TeamIsDestoryed;
                        return(rsp);
                    }
                    if (td.StartTime > 0L)
                    {
                        rsp.ErrorCode = CopyTeamErrorCodes.TeamAlreadyStart;
                        return(rsp);
                    }
                    if (td.MemberCount >= ConstData.CopyRoleMax(req.CopyId))
                    {
                        rsp.ErrorCode = CopyTeamErrorCodes.TeamIsFull;
                        return(rsp);
                    }
                    req.Member.IsReady = false;
                    td.TeamRoles.Add(req.Member);
                    td.MemberCount = td.TeamRoles.Count;
                    if (!req.Member.IsReady)
                    {
                        req.Member.NoReadyTicks = TimeUtil.NOW();
                    }
                    this.RoleId2JoinedTeam[req.Member.RoleID] = td.TeamID;
                    CopyTeamJoinData data = new CopyTeamJoinData();
                    data.Member = req.Member;
                    data.TeamId = req.TeamId;
                    this.AddAsyncEvent(new AsyncDataItem
                    {
                        EventType = KuaFuEventTypes.KFCopyTeamJoin,
                        Args      = new object[]
                        {
                            req.Member.ServerId,
                            data
                        }
                    });
                    rsp.ErrorCode = CopyTeamErrorCodes.Success;
                    rsp.Data      = data;
                }
            }
            catch (Exception ex)
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("加入跨服副本队伍异常, serverid={0}, role={1}, teamid={2}", req.Member.ServerId, req.Member.RoleID, req.TeamId), ex, true);
                rsp.ErrorCode = CopyTeamErrorCodes.CenterServerFailed;
            }
            return(rsp);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 加入房间
        /// </summary>
        public KFCopyTeamJoinRsp JoinTeam(KFCopyTeamJoinReq req)
        {
            KFCopyTeamJoinRsp rsp = new KFCopyTeamJoinRsp();

            try
            {
                lock (Mutex)
                {
                    // 这里有个很微妙的情况,因为加入队伍时,首先GameServer要检查
                    // 但是如果GameServer重启了,那么必然能通过检查,但是其实在中心上已经为该角色加入了一个队伍,必须强制踢掉
                    ForceLeaveRoom(req.Member.RoleID);

                    CopyTeamData td = null;
                    if (!CopyTeamDict.TryGetValue(req.TeamId, out td))
                    {
                        // 房间不存在!!! GameServer要检查这个错误码,可能出现的情况是 跨服中心重启了,那么GameServer要把这个房间清掉
                        rsp.ErrorCode = CopyTeamErrorCodes.TeamIsDestoryed;
                        return(rsp);
                    }

                    if (td.StartTime > 0)
                    {
                        // 房间已经开始了
                        rsp.ErrorCode = CopyTeamErrorCodes.TeamAlreadyStart;
                        return(rsp);
                    }

                    // 擦,写死了5个人
                    if (td.MemberCount >= ConstData.CopyRoleMax(req.CopyId))
                    {
                        rsp.ErrorCode = CopyTeamErrorCodes.TeamIsFull;
                        return(rsp);
                    }

                    req.Member.IsReady = false;
                    td.TeamRoles.Add(req.Member);
                    td.MemberCount = td.TeamRoles.Count;

                    RoleId2JoinedTeam[req.Member.RoleID] = td.TeamID;

                    // 异步广播加入队伍的事件
                    CopyTeamJoinData data = new CopyTeamJoinData();
                    data.Member = req.Member;
                    data.TeamId = req.TeamId;
                    AsyncDataItem evItem = new AsyncDataItem();
                    evItem.EventType = KuaFuEventTypes.KFCopyTeamJoin;
                    evItem.Args      = new object[2] {
                        req.Member.ServerId, data
                    };
                    AddAsyncEvent(evItem);

                    rsp.ErrorCode = CopyTeamErrorCodes.Success;
                    rsp.Data      = data;
                }
            }
            catch (Exception ex)
            {
                LogManager.WriteLog(LogTypes.Error, string.Format("加入跨服副本队伍异常, serverid={0}, role={1}, teamid={2}", req.Member.ServerId, req.Member.RoleID, req.TeamId), ex);
                rsp.ErrorCode = CopyTeamErrorCodes.CenterServerFailed;
            }

            return(rsp);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 设置准备状态 回调
        /// </summary>
        /// <param name="data"></param>
        private void OnTeamSetReady(CopyTeamReadyData data)
        {
            if (data == null)
            {
                return;
            }

            lock (Mutex)
            {
                CopyTeamData td = null;
                if (!TeamDict.TryGetValue(data.TeamId, out td))
                {
                    return;
                }

                CopyTeamMemberData member = td.TeamRoles.Find(_role => _role.RoleID == data.RoleId);
                if (member == null)
                {
                    return;
                }

                member.IsReady = data.Ready > 0;
                if (member.ServerId == ThisServerId)
                {
                    GameClient client = GameManager.ClientMgr.FindClient(member.RoleID);
                    if (client != null)
                    {
                        NotifyTeamStateChanged(client, td.TeamID, member.RoleID, data.Ready);
                    }
                }

                NotifyTeamData(td);

                // 满员了,所有人都已经准备,那么就开吧
                if (member.IsReady && td.AutoStart && td.MemberCount >= ConstData.CopyRoleMax(td.FuBenId) && td.TeamRoles.All(_role => _role.IsReady))
                {
                    CopyTeamMemberData leader = td.TeamRoles.Find(_role => _role.RoleID == td.LeaderRoleID);
                    if (leader != null && leader.ServerId == ThisServerId)
                    {
                        GameClient client = GameManager.ClientMgr.FindClient(leader.RoleID);
                        if (client != null)
                        {
                            NotifyTeamCmd(client, CopyTeamErrorCodes.Success, (int)TeamCmds.Start, 0, "");
                        }
                    }
                }
            }

            /*
             * //int teamType = (int)TeamCmds.Ready;
             * int roleID = client.ClientData.RoleID;
             * long teamID = FindRoleID2TeamID(client.ClientData.RoleID);
             * if (teamID <= 0)
             * {
             *
             * }
             *
             * CopyTeamData td = FindData(teamID);
             * if (null != td)
             * {
             *  int readyCount = 0;
             *  bool someoneOffline = false;
             *  lock (td)
             *  {
             *      for (int i = 0; i < td.TeamRoles.Count; i++)
             *      {
             *          GameClient gc;
             *          if (td.TeamRoles[i].RoleID == roleID)
             *          {
             *              td.TeamRoles[i].IsReady = ready > 0; //更新状态
             *              gc = client;
             *          }
             *          else
             *          {
             *              gc = GameManager.ClientMgr.FindClient(td.TeamRoles[i].RoleID);
             *          }
             *
             *          if (null == gc)
             *          {
             *              td.TeamRoles[i].IsReady = false;
             *              someoneOffline = true;
             *              continue;
             *          }
             *
             *          //状态变化通知
             *          NotifyTeamStateChanged(gc, teamID, roleID, ready);
             *
             *          if (!someoneOffline && td.TeamRoles[i].IsReady && td.AutoStart)
             *          {
             *              readyCount++;
             *              if (readyCount == MaxTeamMemberCount)
             *              {
             *                  GameClient leader = GameManager.ClientMgr.FindClient(td.LeaderRoleID);
             *                  NotifyTeamCmd(leader, CopyTeamErrorCodes.Success, (int)TeamCmds.Start, 0, "");
             *              }
             *          }
             *      }
             *  }
             *
             *  if (someoneOffline)
             *  {
             *      NotifyTeamData(td);
             *  }
             * }*/
        }
Exemplo n.º 4
0
        /// <summary>
        /// 加入队伍回调
        /// </summary>
        /// <param name="data"></param>
        private void OnTeamJoin(CopyTeamJoinData data)
        {
            if (data == null)
            {
                return;
            }

            lock (Mutex)
            {
                CopyTeamData td;
                if (!TeamDict.TryGetValue(data.TeamId, out td))
                {
                    return;
                }

                if (td.TeamRoles.Count >= ConstData.CopyRoleMax(td.FuBenId))
                {
                    return;
                }

                td.TeamRoles.Add(data.Member);
                td.MemberCount = td.TeamRoles.Count();

                if (data.Member.ServerId == ThisServerId)
                {
                    RoleId2JoinedTeam[data.Member.RoleID] = td.TeamID;
                    GameClient client = GameManager.ClientMgr.FindClient(data.Member.RoleID);
                    if (client != null)
                    {
                        NotifyTeamCmd(client, CopyTeamErrorCodes.Success, (int)TeamCmds.Apply, td.TeamID, td.TeamName);
                    }
                }

                NotifyTeamData(td);
                NotifyTeamListChange(td);
            }

            /*
             * lock (td)
             * {
             *
             *  //是否能加入队伍
             *  //if (!CopyTeamManager.getInstance().CanAddToTeam(roleID, otherClient.ClientData.TeamID, 0))
             *
             *
             *  int index = td.TeamRoles.FindIndex((x) => x.RoleID == roleID);
             *  if (index >= 0)
             *  {
             *      td.TeamRoles[index] = ClientDataToTeamMemberData(client.ClientData);
             *  }
             *  else
             *  {
             *      td.TeamRoles.Add(ClientDataToTeamMemberData(client.ClientData));
             *  }
             *  td.MemberCount = td.TeamRoles.Count;
             * }
             *
             * AddRoleID2TeamID(roleID, teamID);
             *
             * //通知角色组队的指令信息
             * NotifyTeamCmd(client, CopyTeamErrorCodes.Success, (int)TeamCmds.Apply, teamID, td.TeamName);
             * NotifyTeamData(td);
             * NotifyTeamListChange(td);
             *
             *
             */
        }