Ejemplo n.º 1
0
 /// <summary>
 /// Determines whether [is manager busy] [the specified manager id].
 /// </summary>
 /// <param name="managerId">The manager id.</param>
 /// <returns>
 ///     <c>true</c> if [is manager busy] [the specified manager id]; otherwise, <c>false</c>.
 /// </returns>
 private bool IsManagerBusy(Guid managerId)
 {
     if (ManagerFightDic != null && ManagerFightDic.ContainsKey(managerId))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 报名天梯赛.
 /// </summary>
 /// <returns></returns>
 public MessageCodeResponse AttendLadder(Guid managerId, bool hasTask, bool isGuide = false)
 {
     if (_ManagerMatchCD.ContainsKey(managerId))
     {
         if (_ManagerMatchCD[managerId] > DateTime.Now)
         {
             return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.LadderMatchCding));
         }
     }
     if (ManagerFightDic != null && ManagerFightDic.ContainsKey(managerId))
     {
         ManagerFightDic.Remove(managerId);
     }
     if (isGuide) //引导
     {
         var response = GuideMatch(managerId);
         if (response.Code == (int)MessageCode.Success)
         {
             return(response);
         }
     }
     if (!CompetitorDic.ContainsKey(managerId))
     {
         var manager = ManagerCore.Instance.GetManager(managerId);
         if (manager == null)
         {
             return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.LoginNoManager));
         }
         var arenaManager = InnerGetLadderManager(managerId);
         if (arenaManager == null)
         {
             return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.NbParameterError));
         }
         arenaManager.IsBot      = false;
         arenaManager.Name       = manager.Name;
         arenaManager.UpdateTime = DateTime.Now;
         arenaManager.HasTask    = true;
         //锁住
         lock (_competitorLock)
         {
             if (_playerNum == 0)
             {
                 StartTime = DateTime.Now;
             }
             CompetitorDic.Add(managerId, arenaManager);
             _playerNum++;
         }
     }
     return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.Success));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 状态轮询.
 /// </summary>
 /// <param name="managerId">The manager id.</param>
 /// <returns></returns>
 public CrowdHeartResponse Heart(Guid managerId)
 {
     if (CompetitorDic.ContainsKey(managerId))
     {
         ////锁住
         //lock (_competitorLock)
         //{
         //    if (CompetitorDic.ContainsKey(managerId))
         //    {
         //        CompetitorDic[managerId].UpdateTime = DateTime.Now;
         //    }
         //}
         return(ResponseHelper.CreateSuccess <CrowdHeartResponse>());
     }
     else if (ManagerFightDic != null && ManagerFightDic.ContainsKey(managerId))
     {
         var heartEntity = ManagerFightDic[managerId];
         if (heartEntity == null)
         {
             if (_status == EnumLadderStatus.Grouping)
             {
                 return(ResponseHelper.Create <CrowdHeartResponse>(MessageCode.Success));
             }
             else
             {
                 return(ResponseHelper.Create <CrowdHeartResponse>(MessageCode.Success));
             }
         }
         else
         {
             var response = ResponseHelper.Create <CrowdHeartResponse>(MessageCode.Success);
             response.Data = heartEntity;
             return(response);
         }
     }
     else
     {
         var heartEntity = MemcachedFactory.CrowdHeartClient.Get <CrowdHeartEntity>(managerId);
         if (heartEntity == null)
         {
             return(ResponseHelper.Create <CrowdHeartResponse>(MessageCode.Success));
         }
         else
         {
             var response = ResponseHelper.Create <CrowdHeartResponse>(MessageCode.Success);
             response.Data = heartEntity;
             return(response);
         }
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 将已进入比赛池的经理重新丢回排序池.
 /// </summary>
 /// <param name="arenaCompetitor">The arena competitor.</param>
 public void PushFightToCompetitor(LadderManagerEntity arenaCompetitor)
 {
     lock (_competitorLock)
     {
         if (ManagerFightDic != null && ManagerFightDic.ContainsKey(arenaCompetitor.ManagerId))
         {
             ManagerFightDic.Remove(arenaCompetitor.ManagerId);
             if (!CompetitorDic.ContainsKey(arenaCompetitor.ManagerId))
             {
                 if (_playerNum == 0)
                 {
                     StartTime = DateTime.Now;
                 }
                 CompetitorDic.Add(arenaCompetitor.ManagerId, arenaCompetitor);
                 _playerNum++;
             }
         }
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 天梯赛状态轮询.
        /// </summary>
        /// <param name="managerId">The manager id.</param>
        /// <returns></returns>
        public Ladder_HeartResponse LadderHeart(Guid managerId)
        {
            Ladder_HeartResponse response;

            if (CompetitorDic.ContainsKey(managerId))
            {
                //锁住
                //lock (_competitorLock)
                //{
                //    if (CompetitorDic.ContainsKey(managerId))
                //    {
                //        CompetitorDic[managerId].UpdateTime = DateTime.Now;
                //    }
                //}
                response = ResponseHelper.CreateSuccess <Ladder_HeartResponse>();
            }
            else if (ManagerFightDic != null && ManagerFightDic.ContainsKey(managerId))
            {
                var matchId = ManagerFightDic[managerId];

                if (matchId == Guid.Empty)
                {
                    if (Status == EnumLadderStatus.Grouping)
                    {
                        response = ResponseHelper.Create <Ladder_HeartResponse>(MessageCode.Success);
                    }
                    else
                    {
                        response = ResponseHelper.Create <Ladder_HeartResponse>(MessageCode.NbParameterError);
                    }
                }
                else
                {
                    response              = ResponseHelper.Create <Ladder_HeartResponse>(MessageCode.Success);
                    response.Data         = new Ladder_Heart();
                    response.Data.MatchId = matchId;
                }
            }
            else if (ManagerGuideFightDic != null && ManagerGuideFightDic.ContainsKey(managerId))//引导比赛
            {
                var matchId = ManagerGuideFightDic[managerId];
                response              = ResponseHelper.Create <Ladder_HeartResponse>(MessageCode.Success);
                response.Data         = new Ladder_Heart();
                response.Data.MatchId = matchId;
                if (ManagerGuideFightDic.ContainsKey(managerId))
                {
                    ManagerGuideFightDic.Remove(managerId);
                }
            }
            else
            {
                response = ResponseHelper.Create <Ladder_HeartResponse>(MessageCode.NbParameterError);
            }
            if (response.Data == null)
            {
                response.Data = new Ladder_Heart();
            }
            if (RecentlyAvgWaitSecond > 60)
            {
                response.Data.AvgWaitTime = 60;
            }
            else
            {
                response.Data.AvgWaitTime = RecentlyAvgWaitSecond;
            }

            return(response);
        }