Ejemplo n.º 1
0
        /// <summary>
        /// 初始化盟战数据库
        /// </summary>
        private void InitDataBase()
        {
            var data            = new DBUnionBattleData();
            var firstBattleTime = GetFirstBattleTime();

            if (DateTime.Now > firstBattleTime.AddDays(7))
            { // 如果当前周超过开启时间一周
                firstBattleTime = GetMonday(
                    new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day,
                                 firstBattleTime.Hour, firstBattleTime.Minute, firstBattleTime.Second));
                if (DateTime.Now > firstBattleTime.AddDays(UnionBattleManager.EnrollDurationDays / 2.0))
                { // 如果报名时间超过了报名时间的一半,则推迟到下周
                    firstBattleTime = firstBattleTime.AddDays(7);
                }
            }
            data.OpenTime = firstBattleTime.ToBinary();
            if (DateTime.Now > firstBattleTime)
            {
                data.Stage = (int)UnionBattleStage.Enroll;
            }
            else
            {
                data.Stage = (int)UnionBattleStage.Wait;
            }
            UnionBattleManager.mDBData = data;

            UnionBattleManager.Dirty = true;
        }
Ejemplo n.º 2
0
        // 按对应轮次的比赛积分进行排名,积分相同时则比较战力
        private IOrderedEnumerable <KeyValuePair <int, long> > GetSortScore(DBUnionBattleData dbData)
        {
            if (dbData == null)
            {
                return(null);
            }

            var fpDict = new Dictionary <int, long>();

            foreach (var allianceId in dbData.EnrollList)
            {
                long w = 0L;
                int  score;
                if (dbData.Scores.TryGetValue(allianceId, out score))
                {
                    w += (score * 1000000000L);
                }

                var alliance = ServerAllianceManager.GetAllianceById(allianceId);
                if (alliance != null)
                {
                    w += alliance.GetTotleFightPoint();
                }
                fpDict[allianceId] = w;
            }
            var sortList = fpDict.OrderBy(s => s.Value);

            return(sortList);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 读取服务器数据
        /// </summary>
        /// <param name="dbData"></param>
        private void LoadFromDataBase(DBUnionBattleData dbData)
        {
            UnionBattleManager.mDBData = dbData;

            var battleTime = DateTime.FromBinary(UnionBattleManager.mDBData.OpenTime);
            var dt         = new DateTime(battleTime.Year, battleTime.Month, battleTime.Day, 0, 0, 0);

            if (DateTime.Now >= dt.AddDays(7))
            { // 超过1周了
                battleTime = dt.AddDays(7 * UnionBattleManager.WeekInterval);
                if (DateTime.Now > battleTime)
                {
                    battleTime = GetMonday(battleTime.AddDays(7));
                }
                ChangeStage(UnionBattleStage.Enroll);
                ClearDataBase();
            }
            dbData.OpenTime = battleTime.ToBinary();
        }