Example #1
0
 private MessageCode SaveRankPrize(NbManagerEntity manager, LeagueRecordEntity leagueRecord, LeagueManagerrecordEntity mLeagueRecord, LaegueManagerinfoEntity leagueManagerinfo, ItemPackageFrame package, int point, DbTransaction trans)
 {
     if (!ManagerUtil.SaveManagerData(manager, null, trans))
     {
         return(MessageCode.NbUpdateFail);
     }
     if (!LeagueRecordMgr.Update(leagueRecord, trans))
     {
         return(MessageCode.NbUpdateFail);
     }
     if (!LeagueManagerrecordMgr.Update(mLeagueRecord, trans))
     {
         return(MessageCode.NbUpdateFail);
     }
     if (!LaegueManagerinfoMgr.Update(leagueManagerinfo, trans))
     {
         return(MessageCode.NbUpdateFail);
     }
     if (package != null)
     {
         if (!package.Save(trans))
         {
             return(MessageCode.NbUpdateFail);
         }
         package.Shadow.Save();
     }
     if (point > 0)
     {
         var code = PayCore.Instance.AddBonus(manager.Idx, point, EnumChargeSourceType.LeaguePrize,
                                              ShareUtil.GenerateComb().ToString(), trans);
         return(code);
     }
     return(MessageCode.Success);
 }
Example #2
0
 private MessageCode SaveMatchConfirm(NbManagerEntity manager, ItemPackageFrame package, LeagueRecordEntity leagueRecordInfo,
                                      LeagueManagerrecordEntity nextManagerRecord, LeagueManagerrecordEntity leagueManagerRecord, int point,
                                      bool isUpdatenextManagerRecord, LaegueManagerinfoEntity leagueManagerInfo, LeagueFightMapFrame fightMap, NbManagerextraEntity managerExtra, LeagueWincountrecordEntity leagueWinCount, DbTransaction trans)
 {
     if (!ManagerUtil.SaveManagerData(manager, managerExtra, trans))
     {
         return(MessageCode.NbUpdateFail);
     }
     if (!NbManagerextraMgr.Update(managerExtra, trans))
     {
         return(MessageCode.NbUpdateFail);
     }
     if (package != null)
     {
         if (!package.Save(trans))
         {
             return(MessageCode.NbUpdateFail);
         }
         package.Shadow.Save();
     }
     if (!LeagueRecordMgr.Update(leagueRecordInfo, trans))
     {
         return(MessageCode.NbUpdateFail);
     }
     if (isUpdatenextManagerRecord)
     {
         if (nextManagerRecord != null)
         {
             if (!LeagueManagerrecordMgr.Update(nextManagerRecord, trans))
             {
                 return(MessageCode.NbUpdateFail);
             }
         }
     }
     if (!LaegueManagerinfoMgr.Update(leagueManagerInfo, trans))
     {
         return(MessageCode.NbUpdateFail);
     }
     if (!LeagueManagerrecordMgr.Update(leagueManagerRecord, trans))
     {
         return(MessageCode.NbUpdateFail);
     }
     if (point > 0)
     {
         var code = PayCore.Instance.AddBonus(manager.Idx, point, EnumChargeSourceType.LeaguePrize,
                                              ShareUtil.GenerateComb().ToString(), trans);
         return(code);
     }
     if (!fightMap.SaveFIghtMap(trans))
     {
         return(MessageCode.NbUpdateFail);
     }
     if (!LeagueWincountrecordMgr.Update(leagueWinCount, trans))
     {
         return(MessageCode.NbUpdateFail);
     }
     return(MessageCode.Success);
 }
Example #3
0
 /// <summary>
 /// 获取联赛情况
 /// </summary>
 /// <param name="managerId"></param>
 /// <param name="leagueId"></param>
 /// <param name="currectLeague"></param>
 /// <returns></returns>
 public GetLeagueInfoResponse GetLeagueInfo(Guid managerId, int leagueId, LeagueManagerrecordEntity currectLeague)
 {
     try
     {
         if (currectLeague == null)
         {
             currectLeague = LeagueManagerrecordMgr.GetManagerMarkInfo(managerId, leagueId);
         }
         if (currectLeague == null)
         {
             SystemlogMgr.Error("获取联赛信息", "经理联赛记录未找到ManagerId:" + managerId);
             return(ResponseHelper.InvalidParameter <GetLeagueInfoResponse>());
         }
         var leagueRecord = LeagueRecordMgr.GetById(currectLeague.LeagueRecordId);
         //获取胜场
         var leagueWincountRecord = LeagueWincountrecordMgr.GetRecord(managerId, currectLeague.LaegueId);
         var winConfig            = CacheFactory.LeagueCache.GetLeagueStar(leagueId);
         var winList     = new List <LeagueWinCountInfo>();
         var prizeStatus = leagueWincountRecord.PrizeStep.Split(',');
         foreach (var item in winConfig)
         {
             LeagueWinCountInfo entity = new LeagueWinCountInfo();
             entity.PrizeLevel = item.PrizeLevel;
             if (prizeStatus.Length >= item.PrizeLevel)
             {
                 entity.PrizeStatus = ConvertHelper.ConvertToInt(prizeStatus[item.PrizeLevel - 1]);
             }
             winList.Add(entity);
         }
         //获取排名
         var leagueFightMap = new LeagueFightMapFrame(managerId);
         int myRank         = 0;
         int myScore        = 0;
         var rankList       = leagueFightMap.GetRank(ref myRank, ref myScore);
         var response       = ResponseHelper.CreateSuccess <GetLeagueInfoResponse>();
         response.Data = new LeagueInfoEntity();
         if (leagueRecord.Schedule > currectLeague.MaxWheelNumber)
         {
             response.Data.IsHaveReturnMain = true;
             leagueRecord.Schedule          = currectLeague.MaxWheelNumber;
         }
         response.Data.LeagueInfo           = currectLeague;
         response.Data.MyWinCount           = leagueWincountRecord.MaxWinCount;
         response.Data.LeagueRecord         = leagueRecord;
         response.Data.LeagueWincountRecord = winList;
         response.Data.MyRank            = myRank;
         response.Data.RankList          = rankList;
         response.Data.IsHaveStartLeague = true;
         return(response);
     }
     catch (Exception ex)
     {
         SystemlogMgr.Error("联赛-获取联赛信息", ex);
         return(ResponseHelper.InvalidParameter <GetLeagueInfoResponse>());
     }
 }
Example #4
0
        /// <summary>
        /// 领取赛季奖励
        /// </summary>
        /// <param name="managerId"></param>
        /// <param name="leagueRecordId"></param>
        /// <returns></returns>
        public LeaguePrizeResponse GetRankPrize(Guid managerId, Guid leagueRecordId)
        {
            var leagueRecordInfo = LeagueRecordMgr.GetById(leagueRecordId);

            if (leagueRecordInfo == null)
            {
                return(ResponseHelper.Create <LeaguePrizeResponse>(MessageCode.NbParameterError));
            }
            var npcCount = CacheFactory.LeagueCache.GetTeamCount(leagueRecordInfo.LaegueId);
            int maxWheel = npcCount * 2;

            //最后一轮
            if (leagueRecordInfo.Schedule <= maxWheel)
            {
                return(ResponseHelper.Create <LeaguePrizeResponse>(MessageCode.LeagueNoEnd));
            }

            //玩家记录
            var leagueManagerRecord = LeagueManagerrecordMgr.GetManagerMarkInfo(managerId,
                                                                                leagueRecordInfo.LaegueId);

            if (leagueRecordInfo.PrizeTime == DateTime.Today)
            {
                return(ResponseHelper.Create <LeaguePrizeResponse>(MessageCode.LeaguePrizeReceivedToday));
            }

            if (leagueRecordInfo.Rank == 1)                 //冠军奖励
            {
                if (leagueManagerRecord.SendFirstPassPrize) //首次通关才有奖励
                {
                    return(ResponseHelper.Create <LeaguePrizeResponse>(MessageCode.LeaguePrizeReceivedToday));
                }
                leagueManagerRecord.SendFirstPassPrize = true;
                //排名奖励
                var rankPrizes           = LeagueCache.Instance.GetLeaguePrize(leagueRecordInfo.LaegueId, 5);
                int exp                  = 0;
                int coin                 = 0;
                int score                = 0;
                int vipExp               = 0;
                ItemPackageFrame package = null;
                int point                = 0;
                var manager              = ManagerCore.Instance.GetManager(managerId);
                SendPrize(rankPrizes, manager, leagueRecordInfo.LaegueId, ref exp, ref coin, ref score, ref package, ref point, ref vipExp);
                leagueRecordInfo.IsSend     = true;
                leagueRecordInfo.Schedule   = -1;
                leagueRecordInfo.PrizeTime  = DateTime.Today;
                leagueRecordInfo.UpdateTime = DateTime.Now;

                leagueManagerRecord.Score += score;


                var leagueManager = LaegueManagerinfoMgr.GetById(managerId);
                leagueManager.SumScore += score;

                ManagerUtil.AddManagerData(manager, exp, coin, 0, EnumCoinChargeSourceType.LeaguePrize, ShareUtil.CreateSequential().ToString());

                leagueManagerRecord.LastPrizeLeagueRecordId = new Guid();
                using (var transactionManager = new TransactionManager(Dal.ConnectionFactory.Instance.GetConnectionString(EnumDbType.Main)))
                {
                    transactionManager.BeginTransaction();
                    var messageCode = SaveRankPrize(manager, leagueRecordInfo, leagueManagerRecord, leagueManager, package, point, transactionManager.TransactionObject);
                    if (messageCode == MessageCode.Success)
                    {
                        transactionManager.Commit();
                    }
                    else
                    {
                        transactionManager.Rollback();
                        return(ResponseHelper.Create <LeaguePrizeResponse>(messageCode));
                    }
                }
                //leagueManagerRecord.LastPrizeLeagueRecordId = leagueManagerRecord.LeagueRecordId;

                //奖励结果
                var response = ResponseHelper.CreateSuccess <LeaguePrizeResponse>();
                response.Data = new LeaguePrizes
                {
                    PrizeList = new List <LeaguePrizeEntity>()
                };
                foreach (var prize in rankPrizes)
                {
                    var entity = new LeaguePrizeEntity();
                    entity.PrizeType = prize.PrizeType;
                    entity.ItemCode  = prize.PrizeType;
                    entity.Count     = prize.Count;
                    response.Data.PrizeList.Add(entity);
                }
                response.Data.VipExp = vipExp;
                return(response);
            }
            return(ResponseHelper.Create <LeaguePrizeResponse>(MessageCode.LeagueNotChampion));
        }
Example #5
0
        /// <summary>
        /// 开启一个新的联赛
        /// </summary>
        /// <param name="managerId"></param>
        /// <param name="leagueId"></param>
        /// <param name="leagueManagerRecord"></param>
        /// <returns></returns>
        public MessageCode StartLeague(Guid managerId, int leagueId, ref LeagueManagerrecordEntity leagueManagerRecord)
        {
            var recordList = LeagueManagerrecordMgr.GetManagerAllMark(managerId);

            foreach (var record in recordList)
            {
                if (record.LaegueId == leagueId)
                {
                    leagueManagerRecord = record;
                }
                if (record.IsStart)
                {
                    return(MessageCode.LeagueHasStart);
                }
            }
            if (leagueManagerRecord == null)
            {
                return(MessageCode.NbParameterError);
            }
            if (leagueManagerRecord.IsLock)
            {
                return(MessageCode.LeagueIdMarkNotLock);
            }
            #region 去掉等级限制
            //var openLevel= LeagueCache.Instance.GetLeagueOpenLevel(leagueId);
            //if (openLevel == -1)
            //    return MessageCode.NbParameterError;
            //var manager = ManagerCore.Instance.GetManager(managerId);
            //if(manager==null)
            //    return MessageCode.NbParameterError;
            //if(manager.Level<openLevel)
            //    return MessageCode.LeagueIdMarkNotLock;
            #endregion
            DateTime date           = DateTime.Now;
            var      leagueRecordId = ShareUtil.GenerateComb();
            leagueManagerRecord.LeagueRecordId = leagueRecordId;
            //info.LastPrizeLeagueRecordId = new Guid();
            leagueManagerRecord.IsPass       = false;
            leagueManagerRecord.IsStart      = true;
            leagueManagerRecord.MatchNumber  = 0;
            leagueManagerRecord.Score        = 0;
            leagueManagerRecord.WinNumber    = 0;
            leagueManagerRecord.FlatNumber   = 0;
            leagueManagerRecord.LoseNumber   = 0;
            leagueManagerRecord.GoalsNumber  = 0;
            leagueManagerRecord.FumbleNumber = 0;
            leagueManagerRecord.UpdateTime   = date;

            var npcCount   = CacheFactory.LeagueCache.GetTeamCount(leagueId);
            var templateId = CacheFactory.LeagueCache.GetTemplateId(npcCount + 1);
            leagueManagerRecord.MaxWheelNumber = npcCount * 2;//总轮数
            leagueManagerRecord.FightDicId     = templateId;

            LeagueRecordEntity entity = new LeagueRecordEntity(leagueRecordId, managerId, leagueId, 1, 0, 0, false, date, date, ShareUtil.BaseTime);
            entity.Idx        = leagueRecordId;
            entity.ManagerId  = managerId;
            entity.LaegueId   = leagueId;
            entity.IsSend     = false;
            entity.Rank       = -1;
            entity.RowTime    = date;
            entity.Schedule   = 1;
            entity.UpdateTime = date;
            entity.Score      = 0;
            var leagueWinCount = LeagueWincountrecordMgr.GetRecord(managerId, leagueId);
            if (leagueWinCount != null)
            {
                if (leagueWinCount.PrizeDate.Date != DateTime.Now.Date)
                {
                    leagueWinCount.WinCount1Status = 0;
                    leagueWinCount.WinCount2Status = 0;
                    leagueWinCount.WinCount3Status = 0;
                    leagueWinCount.UpdateTime      = DateTime.Now;
                    leagueWinCount.PrizeDate       = DateTime.Now;
                    leagueWinCount.PrizeStep       = "0,0,0,0,0";
                }
                leagueWinCount.MaxWinCount = 0;
            }
            //更新当前联赛记录
            if (!LeagueManagerrecordMgr.Update(leagueManagerRecord))
            {
                return(MessageCode.FailUpdate);
            }
            if (!LeagueRecordMgr.Insert(entity))
            {
                return(MessageCode.FailUpdate);
            }
            var figMap = new LeagueFightMapFrame(managerId);
            figMap.ClearFightMapStartLeague(npcCount + 1);
            if (leagueWinCount != null)
            {
                if (!LeagueWincountrecordMgr.Update(leagueWinCount))
                {
                    return(MessageCode.FailUpdate);
                }
            }
            return(MessageCode.Success);
        }
Example #6
0
        /// <summary>
        ///  联赛打比赛
        /// </summary>
        /// <param name="leagueId"></param>
        /// <param name="managerId"></param>
        /// <returns></returns>
        public LeagueFightResultResponse Fight(Guid managerId, int leagueId)
        {
            var manager = ManagerCore.Instance.GetManager(managerId);

            if (manager == null)
            {
                return(ResponseHelper.Create <LeagueFightResultResponse>(MessageCode.NbParameterError));
            }
            var managerExtra = ManagerCore.Instance.GetManagerExtra(managerId);

            if (managerExtra == null)
            {
                return(ResponseHelper.Create <LeagueFightResultResponse>(MessageCode.NbParameterError));
            }
            if (managerExtra.Stamina < 5)
            {
                return(ResponseHelper.Create <LeagueFightResultResponse>(MessageCode.LeagueStaminaNotEnough));
            }
            var currectLeague = LeagueManagerrecordMgr.GetManagerMarkInfo(managerId, leagueId);

            if (currectLeague == null)
            {
                return(ResponseHelper.Create <LeagueFightResultResponse>(MessageCode.NbParameterError));
            }
            var leagueRecordInfo = LeagueRecordMgr.GetById(currectLeague.LeagueRecordId);

            if (leagueRecordInfo == null)
            {
                return(ResponseHelper.Create <LeagueFightResultResponse>(MessageCode.NbParameterError));
            }
            if (leagueRecordInfo.Schedule > currectLeague.MaxWheelNumber)
            {
                return(ResponseHelper.Create <LeagueFightResultResponse>(MessageCode.LeagueHavePass));
            }
            //扣除行动力
            var code = ManagerCore.Instance.SubStamina(managerExtra, 5, manager.Level, manager.VipLevel);

            if (code != MessageCode.Success)
            {
                return(ResponseHelper.Create <LeagueFightResultResponse>(code));
            }
            //遍历对阵
            int botStatus = 0;//0=主队和客队都是NPC 1 我是主队 2 我是客队
            var npchome   = Guid.Empty;
            var npcaway   = Guid.Empty;
            var matchId   = ShareUtil.GenerateComb();
            //获取对阵记录
            var fightMap = new LeagueFightMapFrame(managerId);
            //获取对阵
            var           pairList     = CreateFightMap(currectLeague.FightDicId, leagueRecordInfo.Schedule);
            BaseMatchData managerMatch = null;

            foreach (var item in pairList)
            {
                botStatus = 0;
                if (item.HomeId == 0)
                {
                    botStatus = 1;
                    npchome   = managerId;
                    npcaway   = CacheFactory.LeagueCache.GetLeagueNpcGuid(leagueId, item.AwayId);
                }
                else if (item.AwayId == 0)
                {
                    botStatus = 2;
                    npchome   = CacheFactory.LeagueCache.GetLeagueNpcGuid(leagueId, item.HomeId);
                    npcaway   = managerId;
                }
                else
                {
                    npchome = CacheFactory.LeagueCache.GetLeagueNpcGuid(leagueId, item.HomeId);
                    npcaway = CacheFactory.LeagueCache.GetLeagueNpcGuid(leagueId, item.AwayId);
                }
                SingleMatch(leagueRecordInfo.Schedule, npchome, npcaway, item.HomeId, item.AwayId, leagueRecordInfo.LaegueId, matchId, botStatus, fightMap, ref managerMatch);
            }
            if (managerMatch == null)
            {
                return(ResponseHelper.Create <LeagueFightResultResponse>(MessageCode.MatchCreateFail));
            }
            LeagueWincountrecordEntity leagueWincountRecord = null;


            //记录比赛数据
            if (managerMatch.Away.IsBot)
            {
                MatchCore.SaveMatchStat(managerId, EnumMatchType.League, managerMatch.Home.Score, managerMatch.Away.Score, managerMatch.Home.Score);
            }
            else
            {
                MatchCore.SaveMatchStat(managerId, EnumMatchType.League, managerMatch.Away.Score, managerMatch.Home.Score, managerMatch.Away.Score);
            }
            var response = ResponseHelper.CreateSuccess <LeagueFightResultResponse>();

            response.Data = new LeagueFightResult
            {
                HomeGoals = managerMatch.Home.Score,
                AwayGoals = managerMatch.Away.Score,
                PrizeList = new List <LeaguePrizeEntity>()
            };
            int star = 0;

            if (managerMatch.Home.Score > managerMatch.Away.Score)
            {
                if (managerMatch.Home.ManagerId == managerId)
                {
                    star = managerMatch.Home.Score - managerMatch.Away.Score;
                    response.Data.Result = 0;
                }
                else
                {
                    response.Data.Result = 2;
                }
            }

            else if (managerMatch.Home.Score == managerMatch.Away.Score)
            {
                response.Data.Result = 1;
            }
            else
            {
                if (managerMatch.Away.ManagerId == managerId)
                {
                    star = managerMatch.Away.Score - managerMatch.Home.Score;
                    response.Data.Result = 0;
                }
                else
                {
                    response.Data.Result = 2;
                }
            }
            var winType = CalWinType(response.Data.Result);
            LaegueManagerinfoEntity leagueManagerInfo = null;

            if (winType == EnumWinType.Win)
            {
                leagueManagerInfo = LaegueManagerinfoMgr.GetById(managerId);
                if (leagueManagerInfo.DailyWinUpdateTime.Date != DateTime.Now.Date)
                {
                    leagueManagerInfo.DailyWinCount = 1;
                }
                else
                {
                    leagueManagerInfo.DailyWinCount++;
                }
                leagueManagerInfo.DailyWinUpdateTime = DateTime.Now;
            }

            //更新胜场奖励
            star = star > 3 ? 3 : star;
            star = star < 0 ? 0 : star;
            UpdateWincountRecord(managerId, leagueId, star, ref leagueWincountRecord);
            currectLeague.MatchId    = matchId;
            currectLeague.UpdateTime = DateTime.Now;
            var result = MatchConfirm(manager, leagueRecordInfo, currectLeague, leagueManagerInfo, managerMatch, fightMap, managerExtra, leagueWincountRecord);

            if (result.Code != (int)MessageCode.Success)
            {
                return(ResponseHelper.Create <LeagueFightResultResponse>(result.Code));
            }
            var pop = TaskHandler.Instance.LeagueFight(managerId, (int)winType);

            if (pop != null)
            {
                MemcachedFactory.MatchPopClient.Set(managerId, pop);
            }
            response.Data.StarNumber = star;
            response.Data.Stamina    = managerExtra.Stamina;
            response.Data.PrizeList  = result.Data.PrizeList;
            response.Data.VipExp     = result.Data.VipExp;
            response.Data.MatchId    = managerMatch.MatchId;
            return(response);
        }