コード例 #1
0
        /// <summary>
        /// 修复日期
        /// </summary>
        /// <param name="now"></param>
        /// <returns></returns>
        private bool FixSyncData_State(DateTime now)
        {
            bool bForceModify = false;
            int  nowDay       = now.Day - ZhengBaConsts.StartMonthDay + 1;

            lock (Mutex)
            {
                // 检测已有的排行数据应该是活动的第几天的战斗结果
                int rankOfDay = ZhengBaConsts.ContinueDays;
                for (; rankOfDay >= 1; rankOfDay--)
                {
                    EZhengBaGrade              willUpGrade = ZhengBaUtils.GetDayUpGrade(rankOfDay);
                    ZhengBaMatchConfig         matchConfig = _Config.MatchConfigList.Find(_m => _m.Day == rankOfDay);
                    List <ZhengBaRoleInfoData> roleList    = SyncData.RoleList.FindAll(_r => _r.Grade == (int)willUpGrade);
                    if (roleList.Count <= 0)
                    {
                        continue;
                    }

                    int needUpNum = matchConfig.MaxUpGradeNum - roleList.Count;
                    if (needUpNum > 0)
                    {
                        List <ZhengBaRoleInfoData> upGradeList = new List <ZhengBaRoleInfoData>();
                        if (rankOfDay <= 3)
                        {
                            //补位选手 --- 被淘汰的角色按照晋级、段位进行排序
                            List <ZhengBaRoleInfoData> luckList = SyncData.RoleList.FindAll(_r => _r.Grade > (int)willUpGrade);
                            luckList.Sort((_l, _r) =>
                            {
                                if (_l.Grade < _r.Grade)
                                {
                                    return(-1);
                                }
                                else if (_l.Grade > _r.Grade)
                                {
                                    return(1);
                                }
                                else
                                {
                                    return(_l.DuanWeiRank - _r.DuanWeiRank);
                                }
                            });

                            foreach (var luckRole in luckList.GetRange(0, Math.Min(needUpNum, luckList.Count)))
                            {
                                upGradeList.Add(luckRole);
                                LogManager.WriteLog(LogTypes.Error, string.Format("晋级补位 [s{0}.{1}] {2}->{3}", luckRole.ZoneId, luckRole.RoleId, luckRole.Grade, (int)willUpGrade));
                                luckRole.Grade = (int)willUpGrade;
                                bForceModify   = true;
                            }
                        }
                        else
                        {
                            // 第4天开始就是固定分组pk了,要防止同一个组的两个人都补位晋级的情况
                            foreach (var range in ZhengBaUtils.GetDayPkGroupRange(rankOfDay))
                            {
                                // 找出这个group中,在rankOfDay-1天晋级的玩家列表,尝试选取一个晋级到rankOfDay中
                                var groupRoleList = SyncData.RoleList.FindAll(_r => _r.Group >= range.Left && _r.Group <= range.Right);
                                if (groupRoleList.Exists(_r => _r.Grade <= (int)ZhengBaUtils.GetDayUpGrade(rankOfDay)))
                                {
                                    continue; // 本分组已有人在本天已晋级
                                }
                                // 只从rankOfDay-1天晋级的玩家中挑选
                                groupRoleList.RemoveAll(_r => _r.Grade != (int)ZhengBaUtils.GetDayUpGrade(rankOfDay - 1));
                                if (groupRoleList.Count <= 0)
                                {
                                    continue;
                                }

                                // 段位高者晋级
                                groupRoleList.Sort((_l, _r) => { return(_l.DuanWeiRank - _r.DuanWeiRank); });
                                ZhengBaRoleInfoData selectRole = groupRoleList[0];
                                LogManager.WriteLog(LogTypes.Error, string.Format("晋级补位 [s{0}.{1}] {2}->{3}", selectRole.ZoneId, selectRole.RoleId, selectRole.Grade, (int)willUpGrade));
                                selectRole.Grade = (int)ZhengBaUtils.GetDayUpGrade(rankOfDay);
                                bForceModify     = true;
                                upGradeList.Add(selectRole);
                            }
                        }

                        foreach (var luckRole in upGradeList)
                        {
                            AsyncEvQ.Enqueue(new AsyncDataItem(KuaFuEventTypes.ZhengBaButtetinJoin, new ZhengBaBulletinJoinData()
                            {
                                NtfType = ZhengBaBulletinJoinData.ENtfType.MailUpgradeRole,
                                Args1   = luckRole.RoleId,
                            }));
                        }
                    }

                    break;
                }

                // rankOfDay 表示当前是第几天结束时的结果
                SyncData.RankResultOfDay = rankOfDay;
                SyncData.RealActDay      = rankOfDay;
                foreach (var role in SyncData.RoleList)
                {
                    if (rankOfDay <= 0)
                    {
                        if (role.Grade != (int)EZhengBaGrade.Grade100 ||
                            role.State != (int)EZhengBaState.None ||
                            role.Group != (int)ZhengBaConsts.NoneGroup)
                        {
                            role.Grade   = (int)EZhengBaGrade.Grade100;
                            role.State   = (int)EZhengBaState.None;
                            role.Group   = (int)ZhengBaConsts.NoneGroup;
                            bForceModify = true;
                        }
                    }
                    else
                    {
                        EZhengBaGrade upGrade = _Config.MatchConfigList.Find(_m => _m.Day == rankOfDay).WillUpGrade;
                        if (role.Grade <= (int)upGrade && role.State != (int)EZhengBaState.UpGrade)
                        {
                            role.State   = (int)EZhengBaState.UpGrade;
                            bForceModify = true;
                        }

                        if (role.Grade > (int)upGrade && role.State != (int)EZhengBaState.Failed)
                        {
                            role.State   = (int)EZhengBaState.Failed;
                            bForceModify = true;
                        }
                    }
                }

                // 检测是否推进到后一天,进入活动开始日期 , 并且当前的实际活动天数 小于 现实天数
                if (nowDay > 0 && SyncData.RealActDay < nowDay)
                {
                    // 不是活动的最后一天, 才能够尝试推进到下一天
                    if (SyncData.RealActDay < ZhengBaConsts.ContinueDays)
                    {
                        ZhengBaMatchConfig matchConfig = _Config.MatchConfigList.Find(_m => _m.Day == SyncData.RealActDay + 1);
                        if (now.TimeOfDay.Ticks < matchConfig.DayBeginTick)
                        {
                            // 当前时间小于下一天活动的开始时间,ok,推进到下一天, 这里的时间按照相对于凌晨的Ticks而言
                            SyncData.RealActDay++;
                        }
                    }
                    else
                    {
                        // 当前是第7天的数据,可以直接推进到下一天了
                        SyncData.RealActDay = ZhengBaConsts.ContinueDays + 1;
                    }
                }
            }

            return(bForceModify);
        }
コード例 #2
0
        private bool FixSyncData_State(DateTime now)
        {
            bool bForceModify = false;
            int  nowDay       = now.Day - ZhengBaConsts.StartMonthDay + 1;

            lock (this.Mutex)
            {
                int rankOfDay;
                for (rankOfDay = 7; rankOfDay >= 1; rankOfDay--)
                {
                    EZhengBaGrade              willUpGrade = ZhengBaUtils.GetDayUpGrade(rankOfDay);
                    ZhengBaMatchConfig         matchConfig = this._Config.MatchConfigList.Find((ZhengBaMatchConfig _m) => _m.Day == rankOfDay);
                    List <ZhengBaRoleInfoData> roleList    = this.SyncData.RoleList.FindAll((ZhengBaRoleInfoData _r) => _r.Grade == (int)willUpGrade);
                    if (roleList.Count > 0)
                    {
                        int needUpNum = matchConfig.MaxUpGradeNum - roleList.Count;
                        if (needUpNum > 0)
                        {
                            List <ZhengBaRoleInfoData> upGradeList = new List <ZhengBaRoleInfoData>();
                            if (rankOfDay <= 3)
                            {
                                List <ZhengBaRoleInfoData> luckList = this.SyncData.RoleList.FindAll((ZhengBaRoleInfoData _r) => _r.Grade > (int)willUpGrade);
                                luckList.Sort(delegate(ZhengBaRoleInfoData _l, ZhengBaRoleInfoData _r)
                                {
                                    int result;
                                    if (_l.Grade < _r.Grade)
                                    {
                                        result = -1;
                                    }
                                    else if (_l.Grade > _r.Grade)
                                    {
                                        result = 1;
                                    }
                                    else
                                    {
                                        result = _l.DuanWeiRank - _r.DuanWeiRank;
                                    }
                                    return(result);
                                });
                                foreach (ZhengBaRoleInfoData luckRole in luckList.GetRange(0, Math.Min(needUpNum, luckList.Count)))
                                {
                                    upGradeList.Add(luckRole);
                                    LogManager.WriteLog(LogTypes.Error, string.Format("晋级补位 [s{0}.{1}] {2}->{3}", new object[]
                                    {
                                        luckRole.ZoneId,
                                        luckRole.RoleId,
                                        luckRole.Grade,
                                        (int)willUpGrade
                                    }), null, true);
                                    luckRole.Grade = (int)willUpGrade;
                                    bForceModify   = true;
                                }
                            }
                            else
                            {
                                using (List <RangeKey> .Enumerator enumerator2 = ZhengBaUtils.GetDayPkGroupRange(rankOfDay).GetEnumerator())
                                {
                                    while (enumerator2.MoveNext())
                                    {
                                        RangeKey range = enumerator2.Current;
                                        List <ZhengBaRoleInfoData> groupRoleList = this.SyncData.RoleList.FindAll((ZhengBaRoleInfoData _r) => _r.Group >= range.Left && _r.Group <= range.Right);
                                        if (!groupRoleList.Exists((ZhengBaRoleInfoData _r) => _r.Grade <= (int)ZhengBaUtils.GetDayUpGrade(rankOfDay)))
                                        {
                                            groupRoleList.RemoveAll((ZhengBaRoleInfoData _r) => _r.Grade != (int)ZhengBaUtils.GetDayUpGrade(rankOfDay - 1));
                                            if (groupRoleList.Count > 0)
                                            {
                                                groupRoleList.Sort((ZhengBaRoleInfoData _l, ZhengBaRoleInfoData _r) => _l.DuanWeiRank - _r.DuanWeiRank);
                                                ZhengBaRoleInfoData selectRole = groupRoleList[0];
                                                LogManager.WriteLog(LogTypes.Error, string.Format("晋级补位 [s{0}.{1}] {2}->{3}", new object[]
                                                {
                                                    selectRole.ZoneId,
                                                    selectRole.RoleId,
                                                    selectRole.Grade,
                                                    (int)willUpGrade
                                                }), null, true);
                                                selectRole.Grade = (int)ZhengBaUtils.GetDayUpGrade(rankOfDay);
                                                bForceModify     = true;
                                                upGradeList.Add(selectRole);
                                            }
                                        }
                                    }
                                }
                            }
                            foreach (ZhengBaRoleInfoData luckRole in upGradeList)
                            {
                                this.AsyncEvQ.Enqueue(new AsyncDataItem(KuaFuEventTypes.ZhengBaButtetinJoin, new object[]
                                {
                                    new ZhengBaBulletinJoinData
                                    {
                                        NtfType = ZhengBaBulletinJoinData.ENtfType.MailUpgradeRole,
                                        Args1   = luckRole.RoleId
                                    }
                                }));
                            }
                        }
                        break;
                    }
                }
                this.SyncData.RankResultOfDay = rankOfDay;
                this.SyncData.RealActDay      = rankOfDay;
                foreach (ZhengBaRoleInfoData role in this.SyncData.RoleList)
                {
                    if (rankOfDay <= 0)
                    {
                        if (role.Grade != 100 || role.State != 0 || role.Group != 0)
                        {
                            role.Grade   = 100;
                            role.State   = 0;
                            role.Group   = 0;
                            bForceModify = true;
                        }
                    }
                    else
                    {
                        EZhengBaGrade upGrade = this._Config.MatchConfigList.Find((ZhengBaMatchConfig _m) => _m.Day == rankOfDay).WillUpGrade;
                        if (role.Grade <= (int)upGrade && role.State != 1)
                        {
                            role.State   = 1;
                            bForceModify = true;
                        }
                        if (role.Grade > (int)upGrade && role.State != 2)
                        {
                            role.State   = 2;
                            bForceModify = true;
                        }
                    }
                    if (role.Grade == 1 && this.SyncData.LastKingModTime != this.SyncData.Month)
                    {
                        this.SyncData.LastKingData    = role;
                        this.SyncData.LastKingModTime = this.SyncData.Month;
                    }
                }
                if (nowDay > 0 && this.SyncData.RealActDay < nowDay)
                {
                    if (this.SyncData.RealActDay < 7)
                    {
                        ZhengBaMatchConfig matchConfig = this._Config.MatchConfigList.Find((ZhengBaMatchConfig _m) => _m.Day == this.SyncData.RealActDay + 1);
                        if (now.TimeOfDay.Ticks < matchConfig.DayBeginTick)
                        {
                            this.SyncData.RealActDay++;
                        }
                    }
                    else
                    {
                        this.SyncData.RealActDay = 8;
                    }
                }
            }
            return(bForceModify);
        }
コード例 #3
0
        /// <summary>
        /// InitPkLoop 状态机 --- enter,初始化本轮pk信息,分组,切入 NotifyEnter
        /// </summary>
        /// <param name="now"></param>
        private void MS_InitPkLoop_Enter(DateTime now)
        {
            ThisLoopPkLogs.Clear();
            CurrLoopIndex++;

            ZhengBaMatchConfig matchConfig = _Config.MatchConfigList.Find(_m => _m.Day == SyncData.RealActDay);

            if (this.HadUpGradeRoleNum >= (int)matchConfig.MaxUpGradeNum || TodayJoinRoleDatas.Count <= 1)
            {
                StateMachine.SetCurrState(ZhengBaStateMachine.StateType.TodayPkEnd, now);
                return;
            }

            if (matchConfig.Mathching == EZhengBaMatching.Random) // 随机分组
            {
                Random r = new Random((int)now.Ticks);
                for (int i = 0; TodayJoinRoleDatas.Count > 0 && i < TodayJoinRoleDatas.Count * 2; i++)
                {
                    int idx1 = r.Next(0, TodayJoinRoleDatas.Count), idx2 = r.Next(0, TodayJoinRoleDatas.Count);

                    var tmp = TodayJoinRoleDatas[idx1];
                    TodayJoinRoleDatas[idx1] = TodayJoinRoleDatas[idx2];
                    TodayJoinRoleDatas[idx2] = tmp;
                }
            }
            else if (matchConfig.Mathching == EZhengBaMatching.Group)
            {
                List <JoinRolePkData> tmpRoleDatas = new List <JoinRolePkData>();
                foreach (var range in ZhengBaUtils.GetDayPkGroupRange(SyncData.RealActDay))
                {
                    var groupRoles = TodayJoinRoleDatas.FindAll(_r => _r.Group >= range.Left && _r.Group <= range.Right);
                    if (groupRoles != null && groupRoles.Count == 2)
                    {
                        tmpRoleDatas.AddRange(groupRoles);
                    }
                }

                TodayJoinRoleDatas.Clear();
                TodayJoinRoleDatas.AddRange(tmpRoleDatas);
            }
            else
            {
                Debug.Assert(false, "unknown pk match type");
            }

            // 两两分组
            int currIdx = 0;

            for (int i = 0; i < TodayJoinRoleDatas.Count / 2; i++)
            {
                var joinRole1 = TodayJoinRoleDatas[currIdx++];
                var joinRole2 = TodayJoinRoleDatas[currIdx++];

                int toServerId = 0, gameId = 0;
                gameId = TianTiPersistence.Instance.GetNextGameId();
                if (ClientAgentManager.Instance().AssginKfFuben(TianTiService.Instance.GameType, gameId, 2, out toServerId))
                {
                    joinRole1.ToServerID     = joinRole2.ToServerID = toServerId;
                    joinRole1.CurrGameID     = joinRole2.CurrGameID = gameId;
                    joinRole1.WaitReqEnter   = joinRole2.WaitReqEnter = true;
                    joinRole1.WaitKuaFuLogin = joinRole2.WaitKuaFuLogin = false;

                    ZhengBaNtfEnterData data = new ZhengBaNtfEnterData();
                    data.RoleId1    = joinRole1.RoleID;
                    data.RoleId2    = joinRole2.RoleID;
                    data.ToServerId = toServerId;
                    data.GameId     = gameId;
                    data.Day        = SyncData.RealActDay;
                    data.Loop       = CurrLoopIndex;
                    AsyncEvQ.Enqueue(new AsyncDataItem(KuaFuEventTypes.ZhengBaNtfEnter, data));

                    ZhengBaPkLogData log = new ZhengBaPkLogData();
                    log.Month     = SyncData.Month;
                    log.Day       = SyncData.RealActDay;
                    log.RoleID1   = joinRole1.RoleID;
                    log.ZoneID1   = joinRole1.ZoneId;
                    log.RoleName1 = joinRole1.RoleName;
                    log.RoleID2   = joinRole2.RoleID;
                    log.ZoneID2   = joinRole2.ZoneId;
                    log.RoleName2 = joinRole2.RoleName;
                    log.StartTime = now;

                    ThisLoopPkLogs[gameId] = log;
                }
                else
                {
                    LogManager.WriteLog(LogTypes.Error, string.Format("众神争霸第{0}天第{1}轮分配游戏服务器失败,role1={2},role2={3}", SyncData.RealActDay, CurrLoopIndex, joinRole1.RoleID, joinRole2.RoleID));
                }
            }

            // 匹配不到对手!!!,人数为奇数了
            while (currIdx < TodayJoinRoleDatas.Count)
            {
                var joinRole = TodayJoinRoleDatas[currIdx++];
                joinRole.ToServerID     = 0;
                joinRole.CurrGameID     = 0;
                joinRole.WaitReqEnter   = false;
                joinRole.WaitKuaFuLogin = false;
            }
            StateMachine.SetCurrState(ZhengBaStateMachine.StateType.NotifyEnter, now);
        }
コード例 #4
0
        private void MS_InitPkLoop_Enter(DateTime now)
        {
            this.ThisLoopPkLogs.Clear();
            this.CurrLoopIndex++;
            ZhengBaMatchConfig matchConfig = this._Config.MatchConfigList.Find((ZhengBaMatchConfig _m) => _m.Day == this.SyncData.RealActDay);

            if (this.HadUpGradeRoleNum >= matchConfig.MaxUpGradeNum || this.TodayJoinRoleDatas.Count <= 1)
            {
                this.StateMachine.SetCurrState(ZhengBaStateMachine.StateType.TodayPkEnd, now);
            }
            else
            {
                if (matchConfig.Mathching == EZhengBaMatching.Random)
                {
                    Random r = new Random((int)now.Ticks);
                    int    i = 0;
                    while (this.TodayJoinRoleDatas.Count > 0 && i < this.TodayJoinRoleDatas.Count * 2)
                    {
                        int idx  = r.Next(0, this.TodayJoinRoleDatas.Count);
                        int idx2 = r.Next(0, this.TodayJoinRoleDatas.Count);
                        ZhengBaManagerK.JoinRolePkData tmp = this.TodayJoinRoleDatas[idx];
                        this.TodayJoinRoleDatas[idx]  = this.TodayJoinRoleDatas[idx2];
                        this.TodayJoinRoleDatas[idx2] = tmp;
                        i++;
                    }
                }
                else if (matchConfig.Mathching == EZhengBaMatching.Group)
                {
                    List <ZhengBaManagerK.JoinRolePkData> tmpRoleDatas = new List <ZhengBaManagerK.JoinRolePkData>();
                    using (List <RangeKey> .Enumerator enumerator = ZhengBaUtils.GetDayPkGroupRange(this.SyncData.RealActDay).GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            RangeKey range = enumerator.Current;
                            List <ZhengBaManagerK.JoinRolePkData> groupRoles = this.TodayJoinRoleDatas.FindAll((ZhengBaManagerK.JoinRolePkData _r) => _r.Group >= range.Left && _r.Group <= range.Right);
                            if (groupRoles != null && groupRoles.Count == 2)
                            {
                                tmpRoleDatas.AddRange(groupRoles);
                            }
                        }
                    }
                    this.TodayJoinRoleDatas.Clear();
                    this.TodayJoinRoleDatas.AddRange(tmpRoleDatas);
                }
                else
                {
                    Debug.Assert(false, "unknown pk match type");
                }
                int currIdx = 0;
                for (int i = 0; i < this.TodayJoinRoleDatas.Count / 2; i++)
                {
                    ZhengBaManagerK.JoinRolePkData joinRole  = this.TodayJoinRoleDatas[currIdx++];
                    ZhengBaManagerK.JoinRolePkData joinRole2 = this.TodayJoinRoleDatas[currIdx++];
                    int toServerId = 0;
                    int gameId     = TianTiPersistence.Instance.GetNextGameId();
                    if (ClientAgentManager.Instance().AssginKfFuben(TianTiService.Instance.GameType, (long)gameId, 2, out toServerId))
                    {
                        joinRole.ToServerID     = (joinRole2.ToServerID = toServerId);
                        joinRole.CurrGameID     = (joinRole2.CurrGameID = gameId);
                        joinRole.WaitReqEnter   = (joinRole2.WaitReqEnter = true);
                        joinRole.WaitKuaFuLogin = (joinRole2.WaitKuaFuLogin = false);
                        ZhengBaNtfEnterData data = new ZhengBaNtfEnterData();
                        data.RoleId1    = joinRole.RoleID;
                        data.RoleId2    = joinRole2.RoleID;
                        data.ToServerId = toServerId;
                        data.GameId     = gameId;
                        data.Day        = this.SyncData.RealActDay;
                        data.Loop       = this.CurrLoopIndex;
                        this.AsyncEvQ.Enqueue(new AsyncDataItem(KuaFuEventTypes.ZhengBaNtfEnter, new object[]
                        {
                            data
                        }));
                        ZhengBaPkLogData log = new ZhengBaPkLogData();
                        log.Month     = this.SyncData.Month;
                        log.Day       = this.SyncData.RealActDay;
                        log.RoleID1   = joinRole.RoleID;
                        log.ZoneID1   = joinRole.ZoneId;
                        log.RoleName1 = joinRole.RoleName;
                        log.RoleID2   = joinRole2.RoleID;
                        log.ZoneID2   = joinRole2.ZoneId;
                        log.RoleName2 = joinRole2.RoleName;
                        log.StartTime = now;
                        this.ThisLoopPkLogs[gameId] = log;
                    }
                    else
                    {
                        LogManager.WriteLog(LogTypes.Error, string.Format("众神争霸第{0}天第{1}轮分配游戏服务器失败,role1={2},role2={3}", new object[]
                        {
                            this.SyncData.RealActDay,
                            this.CurrLoopIndex,
                            joinRole.RoleID,
                            joinRole2.RoleID
                        }), null, true);
                    }
                }
                while (currIdx < this.TodayJoinRoleDatas.Count)
                {
                    ZhengBaManagerK.JoinRolePkData joinRole3 = this.TodayJoinRoleDatas[currIdx++];
                    joinRole3.ToServerID     = 0;
                    joinRole3.CurrGameID     = 0;
                    joinRole3.WaitReqEnter   = false;
                    joinRole3.WaitKuaFuLogin = false;
                }
                this.StateMachine.SetCurrState(ZhengBaStateMachine.StateType.NotifyEnter, now);
            }
        }