示例#1
0
        /// <summary>
        /// Builds the bot.
        /// </summary>
        private void BuildBot(LadderInfoEntity ladderInfo)
        {
            var managerFightList = ladderInfo.FightList;

            var competitorCount = managerFightList.Count;

            try
            {
                var botCount = 4 - competitorCount % 4;
                if (botCount > 0 && botCount < 4)
                {
                    managerFightList.Sort(new CompareArenaManager());

                    var minScore = managerFightList[0].Score;
                    var maxScore = managerFightList[competitorCount - 1].Score;

                    var botList = LadderManagerMgr.GetBot(botCount, minScore, maxScore);
                    if (botList != null)
                    {
                        foreach (var list in botList)
                        {
                            list.Name  = _botName;
                            list.IsBot = true;
                            managerFightList.Add(list);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("LadderThread-BuildBot", ex.Message, ex.StackTrace);
            }
        }
示例#2
0
        /// <summary>
        /// 引导比赛
        /// </summary>
        /// <param name="managerId"></param>
        /// <returns></returns>
        private MessageCodeResponse GuideMatch(Guid managerId)
        {
            var manager = ManagerCore.Instance.GetManager(managerId);

            if (manager == null)
            {
                return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.NbParameterError));
            }
            var arenaManager = InnerGetLadderManager(managerId);

            if (arenaManager == null)
            {
                return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.NbParameterError));
            }


            if (ManagerGuideFightDic == null)
            {
                ManagerGuideFightDic = new Dictionary <Guid, Guid>();
            }
            var laddermanager = GetLadderManager(managerId);

            if (laddermanager.MatchTime > 0)
            {
                return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.NbParameterError));
            }
            LadderManagerEntity bot = new LadderManagerEntity();
            var botList             = LadderManagerMgr.GetBot(1, 0, 1201);

            if (botList != null)
            {
                bot       = botList[0];
                bot.Name  = "送分小王子";
                bot.IsBot = true;
                bot.Score = laddermanager.Score;
            }

            laddermanager.IsBot      = false;
            laddermanager.Name       = manager.Name;
            laddermanager.UpdateTime = DateTime.Now;
            laddermanager.HasTask    = true;

            var ladderInfo = new LadderInfoEntity();

            ladderInfo.Idx       = ShareUtil.GenerateComb();
            ladderInfo.FightList = new List <LadderManagerEntity>()
            {
                laddermanager, bot
            };
            ladderInfo.StartTime     = DateTime.Now;
            ladderInfo.GroupingTime  = DateTime.Now;
            ladderInfo.CountdownTime = DateTime.Now;

            ladderInfo.CountdownTime = DateTime.Now.AddSeconds(1);

            ladderInfo.PlayerNumber = 2;
            ladderInfo.AvgWaitTime  = 2;

            var matchId     = ShareUtil.GenerateComb();
            var ladderMatch = new LadderMatchEntity(laddermanager, bot, matchId, ladderInfo.Idx, 1);
            ConcurrentDictionary <Guid, LadderMatchEntity> fightDic = new ConcurrentDictionary <Guid, LadderMatchEntity>();

            fightDic.TryAdd(ladderMatch.Idx, ladderMatch);

            MemcachedFactory.LadderMatchClient.Set(ladderMatch.Idx, ladderMatch);
            var process = new LadderProcess(fightDic, ladderInfo, LadderThread.Instance._ladderProctiveScore, true);

            process.StartProcess();
            if (!ManagerGuideFightDic.ContainsKey(managerId))
            {
                ManagerGuideFightDic.Add(managerId, matchId);
            }
            return(ResponseHelper.Create <MessageCodeResponse>(MessageCode.Success));
        }