Example #1
0
        /// <summary>
        /// 初始化赛季
        /// </summary>
        /// <returns></returns>
        public MessageCode InitSeason()
        {
            try
            {
                DateTime date = DateTime.Now;
                _season = ArenaSeasonMgr.GetSeason(date.Date);
                if (_season == null)
                {
                    return(MessageCode.NbParameterError);
                }
                _seasonInfo = ArenaSeasoninfoMgr.GetSeasonInfo(_season.SeasonId, _domainId);
                DateTime endTime = _season.EndTime.AddDays(1).AddSeconds(-1);
                this.ArenaType = _season.ArenaType;
                //新赛季
                if (_seasonInfo == null)
                {
                    if (_season.SeasonId == 1)
                    {
                        //第一个赛季
                        _seasonInfo = new ArenaSeasoninfoEntity(0, _season.PrepareTime, _season.StartTime,
                                                                endTime, _season.ArenaType, 0, false, date, new Guid(), "", "", new Guid(), "", "", 0,
                                                                date, date, _domainId, _season.SeasonId);
                    }
                    else
                    {
                        //上一赛季
                        var onSeasonInfo = ArenaSeasoninfoMgr.GetSeasonInfo(_season.SeasonId - 1, _domainId);

                        #region 初始化赛季

                        var messageCode = CalculateSeason(onSeasonInfo);
                        if (messageCode != MessageCode.Success)
                        {
                            return(messageCode);
                        }

                        #endregion

                        //上届冠军
                        var onChampionId       = new Guid();
                        var onChampionName     = "";
                        var onChampionZoneName = "";

                        //王者之师
                        var theKingName           = "";
                        var theKingZoneName       = "";
                        var theKingId             = new Guid();
                        var theKingChampionNumber = 0;
                        //获取上届冠军
                        var onChampion = ArenaManagerrecordMgr.GetChampion(_season.SeasonId - 1, _domainId);
                        if (onChampion != null)
                        {
                            onChampionId       = onChampion.ManagerId;
                            onChampionName     = onChampion.ManagerName;
                            onChampionZoneName = onChampion.ZoneName;
                            //冠军次数+1
                            ArenaManagerinfoMgr.SetChampion(onChampion.ManagerId);
                        }
                        //获取得到冠军次数最多的人
                        var maxChampion = ArenaManagerinfoMgr.GetChampionMax(_domainId);
                        if (maxChampion != null)
                        {
                            if (onSeasonInfo != null)
                            {
                                //上一届跟这一届是同一个人
                                if (onSeasonInfo.TheKingId == maxChampion.ManagerId)
                                {
                                    theKingId       = maxChampion.ManagerId;
                                    theKingName     = maxChampion.ZoneName + "." + maxChampion.ManagerName;
                                    theKingZoneName = maxChampion.ZoneName;
                                }
                                else //不是同一人
                                {
                                    //获取上一届王者之师用户信息
                                    var onTheKingInfo = ArenaManagerinfoMgr.GetById(onSeasonInfo.TheKingId);
                                    //先达到的为主
                                    if (onTheKingInfo != null &&
                                        onTheKingInfo.ChampionNumber >= maxChampion.ChampionNumber)
                                    {
                                        theKingId       = onTheKingInfo.ManagerId;
                                        theKingName     = onTheKingInfo.ZoneName + "." + onTheKingInfo.ManagerName;
                                        theKingZoneName = onTheKingInfo.ZoneName;
                                    }
                                    else
                                    {
                                        theKingId       = maxChampion.ManagerId;
                                        theKingName     = maxChampion.ZoneName + "." + maxChampion.ManagerName;
                                        theKingZoneName = maxChampion.ZoneName;
                                    }
                                }
                            }
                            else
                            {
                                theKingId       = maxChampion.ManagerId;
                                theKingName     = maxChampion.ZoneName + "." + maxChampion.ManagerName;
                                theKingZoneName = maxChampion.ZoneName;
                            }
                            theKingChampionNumber = maxChampion.ChampionNumber;
                        }
                        _seasonInfo = new ArenaSeasoninfoEntity(0, _season.PrepareTime, _season.StartTime,
                                                                endTime, _season.ArenaType, 0, false, date, onChampionId, onChampionName,
                                                                onChampionZoneName, theKingId, theKingName, theKingZoneName, theKingChampionNumber, date,
                                                                date, _domainId, _season.SeasonId);
                        //达到开始条件
                        if (_seasonInfo.StartTime.Date <= date.Date && _seasonInfo.Status == 0)
                        {
                            _seasonInfo.Status = 1;
                            ArenaManagerinfoMgr.ClearRecord(_seasonInfo.ArenaType, _domainId);
                        }
                    }

                    if (!ArenaSeasoninfoMgr.Insert(_seasonInfo))
                    {
                        return(MessageCode.NbUpdateFail);
                    }
                    Refresh();
                }
                else
                {
                    //达到开始条件
                    if (_seasonInfo.StartTime.Date <= date.Date && _seasonInfo.Status == 0)
                    {
                        _seasonInfo.Status = 1;
                        ArenaManagerinfoMgr.ClearRecord(_seasonInfo.ArenaType, _domainId);
                        if (!ArenaSeasoninfoMgr.Update(_seasonInfo))
                        {
                            return(MessageCode.NbUpdateFail);
                        }
                        Refresh();
                    }
                }
            }
            catch (Exception ex)
            {
                SystemlogMgr.Error("竞技场初始化赛季", ex);
                return(MessageCode.NbParameterError);
            }
            return(MessageCode.Success);
        }
Example #2
0
        /// <summary>
        /// 发奖
        /// </summary>
        /// <returns></returns>
        public MessageCode SendPrize()
        {
            //获取1000条未发奖的记录
            var prizeList = ArenaManagerrecordMgr.GetNotPrize();

            foreach (var item in prizeList)
            {
                if (item.IsPrize || item.PrizeId > 0)
                {
                    continue;
                }
                var prize = CacheFactory.ArenaCache.GetPrize(item.Rank);
                if (prize == null || prize.Count == 0)
                {
                    continue;
                }
                int arenaCoin = 0;
                var mail      = new MailBuilder(item.ManagerId, EnumMailType.Arena, item.ArenaType, item.Rank, prize,
                                                ref arenaCoin);

                item.IsPrize   = true;
                item.PrizeId   = item.Rank;
                item.PrizeTime = DateTime.Now;
                var messageCode = MessageCode.NbUpdateFail;
                using (
                    var transactionManager =
                        new TransactionManager(Dal.ConnectionFactory.Instance.GetConnectionString(EnumDbType.Support)))
                {
                    transactionManager.BeginTransaction();
                    do
                    {
                        if (!ArenaManagerinfoMgr.AddArenaCoin(item.ManagerId, arenaCoin,
                                                              transactionManager.TransactionObject))
                        {
                            break;
                        }
                        if (!ArenaManagerrecordMgr.Update(item, transactionManager.TransactionObject))
                        {
                            break;
                        }
                        messageCode = MessageCode.Success;
                    } while (false);
                    if (messageCode == MessageCode.Success)
                    {
                        transactionManager.Commit();
                    }
                    else
                    {
                        transactionManager.Rollback();
                        continue;
                    }
                }
                if (messageCode == MessageCode.Success)
                {
                    mail.Save(item.SiteId);
                }
            }

            //刷新对手和排名
            MessageCode messageResult = MessageCode.Success;

            foreach (var item in _threadDic)
            {
                var messageCode = item.Value.Refresh();
                if (messageCode != MessageCode.Success)
                {
                    messageResult = messageCode;
                }
            }
            return(messageResult);
        }