예제 #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;
                        }
                    }
                }
            }
        }