Beispiel #1
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>());
     }
 }
Beispiel #2
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));
        }
Beispiel #3
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);
        }