Пример #1
0
        /// <summary>
        /// 教练升级
        /// </summary>
        /// <param name="managerId"></param>
        /// <param name="coachId"></param>
        /// <returns></returns>
        public CoachGetInfoResponse CoachUpgrade(Guid managerId, int coachId)
        {
            var response = new CoachGetInfoResponse();

            response.Data = new CoachGetInfoEntity();
            try
            {
                var frame = GetFrame(managerId);
                var info  = frame.GetCoachInfo(coachId);
                if (info == null)
                {
                    return(ResponseHelper.Create <CoachGetInfoResponse>(MessageCode.CoachNotAlready));
                }
                var manager = ManagerCore.Instance.GetManager(managerId);
                if (manager == null)
                {
                    return(ResponseHelper.Create <CoachGetInfoResponse>(MessageCode.NbParameterError));
                }
                if (info.CoachLevel >= manager.Level)
                {
                    return(ResponseHelper.Create <CoachGetInfoResponse>(MessageCode.LackofManagerLevel));
                }
                if (frame.Entity == null)
                {
                    return(ResponseHelper.Create <CoachGetInfoResponse>(MessageCode.NbParameterError));
                }
                if (frame.Entity.HaveExp <= 0)
                {
                    return(ResponseHelper.Create <CoachGetInfoResponse>(MessageCode.CoachExpNot));
                }
                var costExp = frame.CoachUpgarde(coachId);
                if (!frame.Save())
                {
                    return(ResponseHelper.Create <CoachGetInfoResponse>(MessageCode.NbUpdateFail));
                }
                //插入扣除记录
                if (costExp > 0)
                {
                    CoachManagerMgr.CostExpRecord(managerId, costExp);
                }
                response.Data.CoachInfo     = frame.GetCoachInfo(coachId);
                response.Data.EnableCoachId = frame.Entity.EnableCoachId;
                response.Data.SumExp        = frame.Entity.HaveExp;

                MatchDataCacheHelper.DeleteTeammemberAndSolutionCache(managerId, true);
                response.Data.Kpi = ManagerCore.Instance.GetKpi(managerId);
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("教练升级", ex);
                response.Code = (int)MessageCode.NbParameterError;
            }
            return(response);
        }
Пример #2
0
        /// <summary>
        /// 设置阵型id
        /// </summary>
        /// <param name="managerId"></param>
        /// <param name="formationId"></param>
        /// <returns></returns>
        public SetFormationResponse SetFormation(Guid managerId, int formationId)
        {
            var response = new SetFormationResponse();

            response.Data = new Entity.SetFormation();
            var solution = GetSolution(managerId);

            solution.FormationId = formationId;
            if (NbSolutionMgr.Update(solution))
            {
                MatchDataCacheHelper.DeleteSolutionCache(managerId, true);
                response.Data.SolutionInfo = SolutionAndTeammemberResponse(managerId).Data;
                response.Data.Package      = ItemCore.Instance.GetPackageResponse(managerId).Data;
            }
            else
            {
                return(ResponseHelper.Create <SetFormationResponse>(MessageCode.NbUpdateFail));
            }
            return(response);
        }
Пример #3
0
 void DeleteSolutionCache(Guid managerId, bool isSync)
 {
     MatchDataCacheHelper.DeleteSolutionCache(managerId, isSync);
 }
Пример #4
0
 void DeleteTeamembersCache(Guid managerId, bool isSync)
 {
     MatchDataCacheHelper.DeleteTeamembersCache(managerId, isSync);
 }
Пример #5
0
        /// <summary>
        /// 激活教练
        /// </summary>
        /// <param name="managerId"></param>
        /// <param name="coachId"></param>
        /// <returns></returns>
        public CoachGetInfoResponse ActivationCoach(Guid managerId, int coachId)
        {
            var response = new CoachGetInfoResponse();

            response.Data = new CoachGetInfoEntity();
            try
            {
                //获取教练配置
                var coachConfig = CacheFactory.CoachCache.GetCoachInfo(coachId);
                if (coachConfig == null)
                {
                    return(ResponseHelper.Create <CoachGetInfoResponse>(MessageCode.NbParameterError));
                }
                var frame     = GetFrame(managerId);
                var coachInfo = frame.GetCoachInfo(coachId);
                if (coachInfo != null)
                {
                    return(ResponseHelper.Create <CoachGetInfoResponse>(MessageCode.AlreadyHaveCoach));
                }
                var package = ItemCore.Instance.GetPackage(managerId, EnumTransactionType.CoachActivation);
                //获取激活配置
                var starConfig = CacheFactory.CoachCache.GetCoachStarInfo(coachId, 0);
                if (starConfig == null)
                {
                    return(ResponseHelper.Create <CoachGetInfoResponse>(MessageCode.NbParameterError));
                }
                var itemCount = package.GetItemNumber(coachConfig.DebrisCode);
                //教练碎片不足
                if (itemCount < starConfig.ConsumeDebris)
                {
                    return(ResponseHelper.Create <CoachGetInfoResponse>(MessageCode.CoachDebrisNot));
                }
                //激活教练
                if (!frame.TheActivation(coachId))
                {
                    return(ResponseHelper.Create <CoachGetInfoResponse>(MessageCode.CoachAlreadyNotActivation));
                }
                var messageCode = package.Delete(coachConfig.DebrisCode, starConfig.ConsumeDebris);
                if (messageCode != MessageCode.Success)
                {
                    return(ResponseHelper.Create <CoachGetInfoResponse>(messageCode));
                }
                using (var transactionManager = new TransactionManager(Dal.ConnectionFactory.Instance.GetDefault()))
                {
                    transactionManager.BeginTransaction();
                    var messCode = MessageCode.NbUpdateFail;
                    do
                    {
                        if (!package.Save(transactionManager.TransactionObject))
                        {
                            break;
                        }
                        if (!frame.Save(transactionManager.TransactionObject))
                        {
                            break;
                        }
                        messCode = MessageCode.Success;
                    } while (false);
                    if (messCode == MessageCode.Success)
                    {
                        transactionManager.Commit();
                        package.Shadow.Save();
                    }
                    else
                    {
                        transactionManager.Rollback();
                        return(ResponseHelper.Create <CoachGetInfoResponse>((int)MessageCode.NbUpdateFail));
                    }
                }

                MatchDataCacheHelper.DeleteTeammemberAndSolutionCache(managerId, true);
                response.Data.Kpi           = ManagerCore.Instance.GetKpi(managerId);
                response.Data.CoachInfo     = frame.GetCoachInfo(coachId);
                response.Data.EnableCoachId = frame.Entity.EnableCoachId;
                response.Data.SumExp        = frame.Entity.HaveExp;
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("激活教练", ex);
                response.Code = (int)MessageCode.NbParameterError;
            }
            return(response);
        }
Пример #6
0
        /// <summary>
        /// 教练升星
        /// </summary>
        /// <param name="managerId"></param>
        /// <param name="coachId"></param>
        /// <returns></returns>
        public CoachGetInfoResponse CoachStarUpgrade(Guid managerId, int coachId)
        {
            var response = new CoachGetInfoResponse();

            response.Data = new CoachGetInfoEntity();
            try
            {
                var frame = GetFrame(managerId);
                var info  = frame.GetCoachInfo(coachId);
                if (info == null)
                {
                    return(ResponseHelper.Create <CoachGetInfoResponse>(MessageCode.CoachNotAlready));
                }
                if (info.IsMaxStar)
                {
                    return(ResponseHelper.Create <CoachGetInfoResponse>(MessageCode.MaxTheStar));
                }
                var package     = ItemCore.Instance.GetPackage(managerId, EnumTransactionType.CoachActivation);
                var coachConfig = CacheFactory.CoachCache.GetCoachInfo(coachId);
                var starConfig  = CacheFactory.CoachCache.GetCoachStarInfo(coachId, info.CoachStar + 1);
                if (coachConfig == null || starConfig == null)
                {
                    return(ResponseHelper.Create <CoachGetInfoResponse>(MessageCode.NbParameterError));
                }
                //升星需要的物品
                var itemCode  = coachConfig.DebrisCode;
                var itemCount = starConfig.ConsumeDebris;
                var haveCount = package.GetItemNumber(itemCode);
                if (haveCount < itemCount)
                {
                    return(ResponseHelper.Create <CoachGetInfoResponse>(MessageCode.ItemCountInvalid));
                }
                var messageCode = package.Delete(itemCode, itemCount);
                if (messageCode != MessageCode.Success)
                {
                    return(ResponseHelper.Create <CoachGetInfoResponse>(messageCode));
                }
                messageCode = frame.CoachStarUpgrade(coachId);
                if (messageCode != MessageCode.Success)
                {
                    return(ResponseHelper.Create <CoachGetInfoResponse>(messageCode));
                }
                using (var transactionManager = new TransactionManager(Dal.ConnectionFactory.Instance.GetDefault()))
                {
                    transactionManager.BeginTransaction();
                    var messCode = MessageCode.NbUpdateFail;
                    do
                    {
                        if (!package.Save(transactionManager.TransactionObject))
                        {
                            break;
                        }
                        if (!frame.Save(transactionManager.TransactionObject))
                        {
                            break;
                        }
                        messCode = MessageCode.Success;
                    } while (false);
                    if (messCode == MessageCode.Success)
                    {
                        transactionManager.Commit();
                        package.Shadow.Save();
                    }
                    else
                    {
                        transactionManager.Rollback();
                        return(ResponseHelper.Create <CoachGetInfoResponse>((int)MessageCode.NbUpdateFail));
                    }
                }

                MatchDataCacheHelper.DeleteTeammemberAndSolutionCache(managerId, true);
                response.Data.Kpi           = ManagerCore.Instance.GetKpi(managerId);
                response.Data.CoachInfo     = frame.GetCoachInfo(coachId);
                response.Data.EnableCoachId = frame.Entity.EnableCoachId;
                response.Data.SumExp        = frame.Entity.HaveExp;
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("教练升星", ex);
                response.Code = (int)MessageCode.NbParameterError;
            }
            return(response);
        }