Ejemplo n.º 1
0
        /// <summary>
        /// 获取阵型,计算阵型等级,和球员位置,技能
        /// </summary>
        /// <param name="managerId"></param>
        /// <returns></returns>
        public static NbSolutionEntity GetSolution(Guid managerId, string siteId = "")
        {
            bool             memFlag = string.IsNullOrEmpty(siteId);
            NbSolutionEntity entity  = null;

            if (memFlag)
            {
                entity = MemcachedFactory.SolutionClient.Get <NbSolutionEntity>(managerId);
            }
            if (entity == null)
            {
                entity = NbSolutionMgr.GetById(managerId, siteId);
                if (entity == null)
                {
                    return(null);
                }
                var formationData = new FormationDataListEntity(entity.FormationData);
                entity.FormationLevel = formationData.GetLevel(entity.FormationId);
                var formationDetails = CacheFactory.FormationCache.GetFormationDetail(entity.FormationId);
                var playerIdList     = FrameUtil.CastIntList(entity.PlayerString, ',');

                ////获取租借球员str,如果与实际阵容的str不同,就用虚拟的替换当前的,不改变实际阵容的str
                //var virtualPlayerIdList = FrameUtil.CastIntList(entity.HirePlayerString, ',');
                //for (int i = 0; i < playerIdList.Count; i++)
                //{
                //    for (int j = 0; j < virtualPlayerIdList.Count; j++)
                //    {
                //        if (playerIdList[i] != virtualPlayerIdList[j] && virtualPlayerIdList[j] != 0)
                //        {
                //            playerIdList[i] = virtualPlayerIdList[j];
                //        }
                //    }
                //}
                var skillList = new string[11];
                if (!string.IsNullOrEmpty(entity.SkillString))
                {
                    skillList = entity.SkillString.Split(',');
                }
                entity.PlayerDic = new Dictionary <int, SolutionPlayerEntity>(playerIdList.Count);
                for (int i = 0; i < playerIdList.Count; i++)
                {
                    entity.PlayerDic.Add(playerIdList[i], MatchDataUtil.BuildSolutionPlayer(playerIdList, formationDetails, playerIdList[i], skillList[i]));
                }
                if (memFlag)
                {
                    MemcachedFactory.SolutionClient.Set(managerId, entity);
                }
            }
            return(entity);
        }
Ejemplo n.º 2
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);
        }