Example #1
0
        public static void CheckSameCorpTeamId(GameOrder order)
        {
            var corpTeamList = GameHelper.GetSameCorpTeamList(order.GameId);

            if (corpTeamList.IsNotNullOrEmpty())
            {
                int count = order.PositionList.Count / 2;
                for (int i = 0; i < count; i++)
                {
                    var team1 = corpTeamList.FirstOrDefault(p => p.Id == order.PositionList[i * 2].UserId.GetId());
                    var team2 = corpTeamList.FirstOrDefault(p => p.Id == order.PositionList[i * 2 + 1].UserId.GetId());
                    if (team1 == null || team2 == null)
                    {
                        continue;
                    }
                    //相同单位队伍第一轮淘汰赛相遇,调整位置
                    if (team2.CompanyId == team1.CompanyId)
                    {
                        var pos1 = order.PositionList[i * 2];
                        var pos2 = order.PositionList[i * 2 + 1];
                        //交换低排名的相同单位队伍
                        var switchPos = pos1.Rank > pos2.Rank ? pos1 : pos2;
                        //查找相同本middle区域排名相同的非轮空队伍
                        var other = order.PositionList.FirstOrDefault(p => p.Index / order.Middle() == switchPos.Index / order.Middle() && p.Rank == switchPos.Rank && p.Index != switchPos.Index && !p.IsBye);
                        if (other != null)
                        {
                            //交换位置
                            var tempUserId = switchPos.UserId;
                            switchPos.UserId = other.UserId;
                            other.UserId     = tempUserId;
                        }
                    }
                }
            }
        }
        private static List <GameTeam> CheckByeOrKnock(GameOrder order, List <int> posListAll, List <GameTeam> memberList)
        {
            var emptyCount = Math.Abs(order.KnockoutTotal - memberList.Count);

            if (emptyCount > 0)
            {
                if (order.KnockoutTotal > memberList.Count)
                {
                    //设置轮空
                    for (int i = 0; i < emptyCount; i++)
                    {
                        var pos = posListAll[i] % 2 == 0 ? posListAll[i] + 1 : posListAll[i] - 1;
                        //查找本middle区域非轮空的空位
                        var targetPos = order.PositionList.FirstOrDefault(p =>
                                                                          p.Index / order.Middle() == pos / order.Middle() && p.UserId.IsNullOrEmpty() && !p.IsBye);
                        if (targetPos != null)
                        {
                            targetPos.UserId  = order.PositionList[pos].UserId;
                            targetPos.GroupId = order.PositionList[pos].GroupId;
                            order.PositionList[pos].UserId  = null;
                            order.PositionList[pos].GroupId = null;
                            order.PositionList[pos].IsBye   = true;
                        }
                    }
                }
                else
                {
                    //抢号人员
                    var knockList = memberList.Where(p => p.IsEnterPos == false).ToList();
                    //设置抢号,取小值循环
                    int count = Math.Min(Math.Min(emptyCount, knockList.Count), posListAll.Count);
                    for (int i = 0; i < count; i++)
                    {
                        var pos = posListAll[i] % 2 == 0 ? posListAll[i] + 1 : posListAll[i] - 1;
                        order.PositionList[pos].KnockUserId = knockList[i].Id.Link(knockList[i].TeamName);
                    }
                }
            }
            return(memberList);
        }
Example #3
0
        private static void CheckByeOrKnock(GameOrder order, List <int> posList1, List <GameGroupMember> memberList)
        {
            var count = Math.Abs(order.KnockoutTotalAB - order.ActualCount());

            if (count > 0)
            {
                if (order.KnockoutTotalAB > order.ActualCount())
                {
                    //设置轮空
                    for (int i = 0; i < count; i++)
                    {
                        var pos = posList1[i] % 2 == 0 ? posList1[i] + 1 : posList1[i] - 1;
                        //查找本middle区域非轮空的空位
                        var targetPos = order.PositionList.FirstOrDefault(p => p.Index / order.Middle() == pos / order.Middle() && p.UserId.IsNullOrEmpty() && !p.IsBye);
                        if (targetPos != null)
                        {
                            targetPos.UserId  = order.PositionList[pos].UserId;
                            targetPos.GroupId = order.PositionList[pos].GroupId;
                            order.PositionList[pos].UserId  = null;
                            order.PositionList[pos].GroupId = null;
                            order.PositionList[pos].IsBye   = true;
                        }
                    }
                }
                else
                {
                    //抢号人员
                    var knockList = memberList.Where(p => p.IsEnterPos == false).ToList();
                    //设置抢号
                    for (int i = 0; i < count; i++)
                    {
                        var pos = posList1[i] % 2 == 0 ? posList1[i] + 1 : posList1[i] - 1;
                        order.PositionList[pos].KnockUserId = knockList[i].TeamId;
                    }
                }
            }
        }