Пример #1
0
        /// <summary>
        /// 替换上场
        /// </summary>
        /// <param name="managerId"></param>
        /// <param name="teammemberId"></param>
        /// <param name="byTeammemberId"></param>
        /// <returns></returns>
        public NBSolutionInfoResponse ReplacePlayer(Guid managerId, Guid teammemberId, Guid byTeammemberId)
        {
            bool isChanagePlayer = false;

            try
            {
                ItemPackageFrame package  = null;
                MessageCode      messCode = MessageCode.Success;
                var soluti = MatchDataHelper.GetSolution(managerId);
                if (soluti == null)
                {
                    return(ResponseHelper.InvalidParameter <NBSolutionInfoResponse>());
                }
                var byteammember = GetTeammember(managerId, byTeammemberId);
                if (byteammember == null || !soluti.PlayerDic.ContainsKey(byteammember.PlayerId))
                {
                    return(ResponseHelper.Create <NBSolutionInfoResponse>((int)MessageCode.TeammemberNotMain));
                }
                var teammember   = GetTeammember(managerId, teammemberId);
                var playerString = "";
                var playerIdList = FrameUtil.CastIntList(soluti.PlayerString, ',');


                if (teammember != null)
                {
                    ExchangePlayer(playerIdList, teammember.PlayerId, byteammember.PlayerId, false, ref playerString);
                    soluti.PlayerString = playerString;
                    if (!NbSolutionMgr.Update(soluti))
                    {
                        return(ResponseHelper.Create <NBSolutionInfoResponse>((int)MessageCode.NbUpdateFail));
                    }
                    MemcachedFactory.SolutionClient.Delete(managerId);
                    KpiHandler.Instance.RebuildKpi(managerId, true);
                    var manager = MatchDataHelper.GetManager(managerId, true, true);
                    if (manager == null)
                    {
                        return(ResponseHelper.Create <NBSolutionInfoResponse>((int)MessageCode.NbParameterError));
                    }

                    var response1 = SolutionAndTeammemberResponse(managerId);
                    return(response1);
                    //换位置
                }
                else //换替补
                {
                    isChanagePlayer = true;
                    package         = ItemCore.Instance.GetPackage(managerId, EnumTransactionType.TeammemberTrans);
                    if (package == null)
                    {
                        return(ResponseHelper.Create <NBSolutionInfoResponse>(MessageCode.NbNoPackage));
                    }
                    var player = package.GetPlayer(teammemberId);
                    if (player.ItemType != (int)EnumItemType.PlayerCard)
                    {
                        return(ResponseHelper.Exception <NBSolutionInfoResponse>());
                    }
                    player.IsDeal = false;
                    var itemInfo = CacheFactory.ItemsdicCache.GetItem(player.ItemCode);
                    //限制金卡
                    if (itemInfo != null && itemInfo.ItemType == (int)EnumItemType.PlayerCard &&
                        itemInfo.PlayerCardLevel == (int)EnumPlayerCardLevel.Gold)
                    {
                        var solution = MatchDataHelper.GetSolutionInfo(managerId);
                        if (solution == null)
                        {
                            return(ResponseHelper.InvalidParameter <NBSolutionInfoResponse>());
                        }
                        if (solution.MaxVeteranCount <= solution.VeteranCount)
                        {
                            return
                                (ResponseHelper.Create <NBSolutionInfoResponse>(
                                     (int)MessageCode.TeammemberVeteranCountOver));
                        }
                    }
                    var pid = player.ItemCode % 100000;

                    //检查是否已有相同pid的球员
                    var linkList = CacheFactory.PlayersdicCache.GetLinkPlayerList(pid);
                    if (linkList != null)
                    {
                        foreach (var link in linkList)
                        {
                            if (playerIdList.Exists(d => d == link))
                            {
                                return(ResponseHelper.Create <NBSolutionInfoResponse>(MessageCode.TeammemberSolutionPlayerRepeat));
                            }
                        }
                    }
                    int teammemberCount = 0;
                    int returnCode      = 0;
                    TeammemberMgr.GetForTransCheck(managerId, pid, ShareUtil.GetTableMod(managerId),
                                                   (int)MessageCode.TeammemberRepeat, ref teammemberCount, ref returnCode);
                    if (returnCode != (int)MessageCode.Success)
                    {
                        return(ResponseHelper.Create <NBSolutionInfoResponse>(returnCode));
                    }
                    messCode = package.ReplacePlayerCard(100000 + byteammember.PlayerId, false,
                                                         byteammember.Strength,
                                                         byteammember.Idx, byteammember.Equipment, player.ItemId, byteammember.Level);
                    ExchangePlayer(playerIdList, pid, byteammember.PlayerId, true, ref playerString);
                    soluti.PlayerString = playerString;
                    if (messCode != MessageCode.Success)
                    {
                        return(ResponseHelper.Create <NBSolutionInfoResponse>(messCode));
                    }
                }
                using (var transactionManager = new TransactionManager(Dal.ConnectionFactory.Instance.GetDefault()))
                {
                    transactionManager.BeginTransaction();
                    messCode = MessageCode.NbUpdateFail;
                    do
                    {
                        if (package != null)
                        {
                            if (!package.SavePlayer(transactionManager.TransactionObject))
                            {
                                break;
                            }
                        }
                        if (!NbSolutionMgr.Update(soluti, transactionManager.TransactionObject))
                        {
                            break;
                        }
                        messCode = MessageCode.Success;
                    } while (false);
                    if (messCode == MessageCode.Success)
                    {
                        transactionManager.Commit();
                        MemcachedFactory.TeammembersClient.Delete(managerId);
                        MemcachedFactory.SolutionClient.Delete(managerId);
                        package.Shadow.Save();
                        int      orangeCount = 0;
                        string[] pIds        = playerString.Split(',');
                        foreach (var pId in pIds)
                        {
                            int id     = ConvertHelper.ConvertToInt(pId);
                            var player = CacheFactory.PlayersdicCache.GetPlayer(id);
                            if (player.CardLevel == (int)EnumPlayerCardLevel.Orange)
                            {
                                orangeCount++;
                            }
                        }
                        ActivityExThread.Instance.TememberColect(managerId, 3, orangeCount);
                    }
                    else
                    {
                        transactionManager.Rollback();
                        return(ResponseHelper.Create <NBSolutionInfoResponse>(messCode));
                    }
                }
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("替换球员上场", ex);
            }
            KpiHandler.Instance.RebuildKpi(managerId, true);

            var response = SolutionAndTeammemberResponse(managerId);

            if (isChanagePlayer)
            {
                var pop = TaskHandler.Instance.SolutionChangePlayer(managerId);
                if (response.Data != null)
                {
                    response.Data.PopMsg = pop;
                }
            }

            return(response);
        }