Exemplo n.º 1
0
        /// <summary>
        /// 带事务的Update
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="trans">The trans.</param>
        /// <returns></returns>
        /// <remarks>2016/1/4 17:07:40</remarks>
        public bool Update(LeagueRecordEntity entity, DbTransaction trans = null)
        {
            var       database       = new SqlDatabase(this.ConnectionString);
            DbCommand commandWrapper = database.GetStoredProcCommand("dbo.P_LeagueRecord_Update");

            database.AddInParameter(commandWrapper, "@Idx", DbType.Guid, entity.Idx);
            database.AddInParameter(commandWrapper, "@ManagerId", DbType.Guid, entity.ManagerId);
            database.AddInParameter(commandWrapper, "@LaegueId", DbType.Int32, entity.LaegueId);
            database.AddInParameter(commandWrapper, "@Schedule", DbType.Int32, entity.Schedule);
            database.AddInParameter(commandWrapper, "@Score", DbType.Int32, entity.Score);
            database.AddInParameter(commandWrapper, "@Rank", DbType.Int32, entity.Rank);
            database.AddInParameter(commandWrapper, "@IsSend", DbType.Boolean, entity.IsSend);
            database.AddInParameter(commandWrapper, "@UpdateTime", DbType.DateTime, entity.UpdateTime);
            database.AddInParameter(commandWrapper, "@RowTime", DbType.DateTime, entity.RowTime);
            database.AddInParameter(commandWrapper, "@PrizeTime", DbType.DateTime, entity.PrizeTime);


            int results = 0;

            if (trans != null)
            {
                results = database.ExecuteNonQuery(commandWrapper, trans);
            }
            else
            {
                results = database.ExecuteNonQuery(commandWrapper);
            }

            entity.Idx = (System.Guid)database.GetParameterValue(commandWrapper, "@Idx");

            return(Convert.ToBoolean(results));
        }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
0
        /// <summary>
        /// 将IDataReader的当前记录读取到LeagueRecordEntity 对象
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public LeagueRecordEntity LoadSingleRow(IDataReader reader)
        {
            var obj = new LeagueRecordEntity();

            obj.Idx        = (System.Guid)reader["Idx"];
            obj.ManagerId  = (System.Guid)reader["ManagerId"];
            obj.LaegueId   = (System.Int32)reader["LaegueId"];
            obj.Schedule   = (System.Int32)reader["Schedule"];
            obj.Score      = (System.Int32)reader["Score"];
            obj.Rank       = (System.Int32)reader["Rank"];
            obj.IsSend     = (System.Boolean)reader["IsSend"];
            obj.UpdateTime = (System.DateTime)reader["UpdateTime"];
            obj.RowTime    = (System.DateTime)reader["RowTime"];
            obj.PrizeTime  = (System.DateTime)reader["PrizeTime"];

            return(obj);
        }
Exemplo n.º 4
0
        /// <summary>
        /// GetById
        /// </summary>
        /// <param name="idx">idx</param>
        /// <returns>LeagueRecordEntity</returns>
        /// <remarks>2016/1/4 17:07:40</remarks>
        public LeagueRecordEntity GetById(System.Guid idx)
        {
            var database = new SqlDatabase(this.ConnectionString);

            DbCommand commandWrapper = database.GetStoredProcCommand("P_LeagueRecord_GetById");

            database.AddInParameter(commandWrapper, "@Idx", DbType.Guid, idx);


            LeagueRecordEntity obj = null;

            using (IDataReader reader = database.ExecuteReader(commandWrapper))
            {
                if (reader.Read())
                {
                    obj = LoadSingleRow(reader);
                }
            }
            return(obj);
        }
Exemplo n.º 5
0
        public static bool Update(LeagueRecordEntity leagueRecordEntity, DbTransaction trans = null, string zoneId = "")
        {
            var provider = new LeagueRecordProvider(zoneId);

            return(provider.Update(leagueRecordEntity, trans));
        }
Exemplo n.º 6
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);
 }
Exemplo n.º 7
0
        /// <summary>
        /// 确认比赛结果
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="leagueRecordInfo"></param>
        /// <returns></returns>
        public LeaguePrizeResponse MatchConfirm(NbManagerEntity manager, LeagueRecordEntity leagueRecordInfo, LeagueManagerrecordEntity leagueManagerRecord, LaegueManagerinfoEntity lagueManagerInfo, BaseMatchData matchData, LeagueFightMapFrame fightMap, NbManagerextraEntity managerExtra, LeagueWincountrecordEntity leagueWinCount)
        {
            //发放玩家单场比赛奖励---------------------------------------------------
            int winType = 0;

            if (matchData.Home.ManagerId == manager.Idx)         //玩家为主队
            {
                if (matchData.Home.Score > matchData.Away.Score) //主队胜
                {
                    winType = 1;
                }
                else if (matchData.Home.Score == matchData.Away.Score) //平
                {
                    winType = 2;
                }
                else //负
                {
                    winType = 3;
                }
            }
            else //玩家为客队
            {
                if (matchData.Home.Score < matchData.Away.Score)//客队胜
                {
                    winType = 1;
                }
                else if (matchData.Home.Score == matchData.Away.Score) //平
                {
                    winType = 2;
                }
                else//负
                {
                    winType = 3;
                }
            }
            var managerPrizes = LeagueCache.Instance.GetLeaguePrize(leagueRecordInfo.LaegueId, winType);

            int exp   = 0;
            int coin  = 0;
            int score = 0;
            ItemPackageFrame package = null;
            int point  = 0;
            int vipExp = 0;

            SendPrize(managerPrizes, manager, leagueRecordInfo.LaegueId, ref exp, ref coin, ref score, ref package,
                      ref point, ref vipExp);
            ManagerUtil.AddManagerData(manager, exp, coin, 0, EnumCoinChargeSourceType.LeaguePrize, ShareUtil.CreateSequential().ToString());

            if (lagueManagerInfo == null)
            {
                lagueManagerInfo = LaegueManagerinfoMgr.GetById(manager.Idx);
            }
            lagueManagerInfo.SumScore += score;

            leagueManagerRecord.MatchId    = new Guid();
            leagueManagerRecord.UpdateTime = DateTime.Now;
            bool isLastWheel = false;

            leagueManagerRecord.Score += score;
            //本联赛最后一轮
            if (leagueRecordInfo.Schedule >= leagueManagerRecord.MaxWheelNumber)
            {
                isLastWheel = true;
                leagueManagerRecord.IsPass      = true;
                leagueManagerRecord.PassNumber += 1;
            }
            int myRank  = 0;
            int myScore = 0;

            //更新排名
            fightMap.UpdateRankList();
            fightMap.GetRank(ref myRank, ref myScore);

            leagueRecordInfo.Score += score;
            leagueRecordInfo.Rank   = myRank;
            //----------------------------
            leagueRecordInfo.Schedule++;
            leagueRecordInfo.IsSend     = true;
            leagueRecordInfo.UpdateTime = DateTime.Now;
            //本联赛最后一轮,如果是冠军解锁下一轮
            bool isUpdatenextManagerRecord = false;
            LeagueManagerrecordEntity nextManagerRecord = null;

            if (isLastWheel)
            {
                if (leagueRecordInfo.Rank == 1)
                {
                    leagueManagerRecord.LastPrizeLeagueRecordId = leagueManagerRecord.LeagueRecordId;
                    if (leagueRecordInfo.LaegueId != 8)
                    {
                        nextManagerRecord = LeagueManagerrecordMgr.GetManagerMarkInfo(manager.Idx,
                                                                                      leagueRecordInfo.LaegueId + 1);
                        nextManagerRecord.IsLock  = false;
                        isUpdatenextManagerRecord = true;
                    }
                    //记录成就相关数据
                    AchievementTaskCore.Instance.UpdateLeagueScore(manager.Idx, leagueRecordInfo.LaegueId,
                                                                   myScore);
                    TaskHandler.Instance.LeagueChampionScore(manager.Idx);
                }
            }

            using (var transactionManager = new TransactionManager(Dal.ConnectionFactory.Instance.GetConnectionString(EnumDbType.Main)))
            {
                transactionManager.BeginTransaction();
                var messageCode = SaveMatchConfirm(manager, package, leagueRecordInfo,
                                                   nextManagerRecord, leagueManagerRecord, point, isUpdatenextManagerRecord, lagueManagerInfo, fightMap, managerExtra, leagueWinCount, transactionManager.TransactionObject);
                if (messageCode == MessageCode.Success)
                {
                    transactionManager.Commit();
                }
                else
                {
                    transactionManager.Rollback();
                    return(ResponseHelper.Create <LeaguePrizeResponse>(messageCode));
                }
            }
            //奖励结果
            var response = ResponseHelper.CreateSuccess <LeaguePrizeResponse>();

            response.Data = new LeaguePrizes
            {
                PrizeList = new List <LeaguePrizeEntity>()
            };
            foreach (var prize in managerPrizes)
            {
                var entity = new LeaguePrizeEntity();
                entity.PrizeType = prize.PrizeType;
                entity.ItemCode  = prize.ItemCode;
                entity.Count     = prize.Count;
                response.Data.PrizeList.Add(entity);
            }
            response.Data.VipExp = vipExp;
            return(response);
        }
Exemplo n.º 8
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);
        }