Ejemplo n.º 1
0
        public ZhengBaSyncData LoadZhengBaSyncData(DateTime now, int selectRoleIfNewCreate, long dayBeginTicks)
        {
            ZhengBaSyncData syncData = new ZhengBaSyncData();

            syncData.Month = ZhengBaUtils.MakeMonth(now);
            syncData.IsThisMonthInActivity = CheckThisMonthInActivity(now, dayBeginTicks);

            bool bMonthFirst = false;

            if (syncData.IsThisMonthInActivity)
            {
                bMonthFirst          = CheckBuildZhengBaRank(selectRoleIfNewCreate, syncData.Month);
                syncData.RoleList    = LoadZhengBaRankData(syncData.Month);
                syncData.SupportList = LoadZhengBaSupportData(syncData.Month);
            }
            else
            {
                bMonthFirst          = false;
                syncData.RoleList    = new List <ZhengBaRoleInfoData>();
                syncData.SupportList = new List <ZhengBaSupportAnalysisData>();
            }

            syncData.RoleModTime    = now;
            syncData.SupportModTime = now;

            // 本月的参赛人数第一次创建到db中,那么广播公告和邮件通知
            if (bMonthFirst && MonthRankFirstCreate != null)
            {
                MonthRankFirstCreate(selectRoleIfNewCreate);
            }

            return(syncData);
        }
Ejemplo n.º 2
0
        public bool SaveSupportLog(ZhengBaSupportLogData data)
        {
            if (data == null)
            {
                return(false);
            }

            try
            {
                string sql = string.Format("INSERT INTO t_zhengba_support_log(month,from_rid,from_zoneid,from_rolename,support_type,to_union_group,to_group,`time`,rank_of_day,from_serverid) "
                                           + "VALUES({0},{1},{2},'{3}',{4},{5},{6},'{7}',{8},{9});",
                                           ZhengBaUtils.MakeMonth(data.Time), data.FromRoleId, data.FromZoneId, data.FromRolename,
                                           (int)data.SupportType, data.ToUnionGroup, data.ToGroup, data.Time.ToString("yyyy-MM-dd HH:mm:ss"),
                                           data.RankOfDay, data.FromServerId);

                if (DbHelperMySQL.ExecuteSql(sql) <= 0)
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                LogManager.WriteLog(LogTypes.Error, "SaveSupportLog failed!", ex);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        public ZhengBaSyncData LoadZhengBaSyncData(DateTime now, int selectRoleIfNewCreate, long dayBeginTicks)
        {
            ZhengBaSyncData syncData = new ZhengBaSyncData();

            syncData.Month = ZhengBaUtils.MakeMonth(now);
            syncData.IsThisMonthInActivity = this.CheckThisMonthInActivity(now, dayBeginTicks);
            bool bMonthFirst;

            if (syncData.IsThisMonthInActivity)
            {
                bMonthFirst          = this.CheckBuildZhengBaRank(selectRoleIfNewCreate, syncData.Month);
                syncData.RoleList    = this.LoadZhengBaRankData(syncData.Month);
                syncData.SupportList = this.LoadZhengBaSupportData(syncData.Month);
            }
            else
            {
                bMonthFirst          = false;
                syncData.RoleList    = new List <ZhengBaRoleInfoData>();
                syncData.SupportList = new List <ZhengBaSupportAnalysisData>();
            }
            syncData.LastKingData   = this.LoadZhengBaKingData(ref syncData.LastKingModTime);
            syncData.RoleModTime    = now;
            syncData.SupportModTime = now;
            if (bMonthFirst && this.MonthRankFirstCreate != null)
            {
                this.MonthRankFirstCreate(selectRoleIfNewCreate);
            }
            return(syncData);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 检测生成众生争霸排行榜
        /// </summary>
        /// <param name="now"></param>
        private bool CheckBuildZhengBaRank(int selectRoleIfNewCreate, int nowMonth)
        {
            bool bMonthFirst = false;

            try
            {
                DbHelperMySQL.ExecuteSql(
                    string.Format("INSERT IGNORE INTO t_async(`id`,`value`) VALUES({0},{1});",
                                  AsyncTypes.ZhengBaCurrMonth, ZhengBaConsts.DefaultAsyncMonth)
                    );

                // 防止人为的重新reload月排行榜导致众神争霸战斗信息丢失

                /* 这里有一些细节要注意:
                 * 1:每月1号凌晨3点更新月排行榜,然后触发更新争霸角色
                 * 2: 服务器启动的时候,尝试生成争霸角色
                 * 3:要防止当月的争霸角色重复生成
                 * 4:必须保证天梯排行角色已经生成,才能生成争霸角色 -->例如,1号凌晨两点启动,必须保证等到3点的时候,天梯月排行榜生成之后,能够生成本月的争霸角色
                 */
                int    oldMonth           = (int)DbHelperMySQL.GetSingle("select value from t_async where id = " + AsyncTypes.ZhengBaCurrMonth);
                object ageObj_tiantiMonth = DbHelperMySQL.GetSingle("select value from t_async where id = " + AsyncTypes.TianTiPaiHangModifyOffsetDay);
                if (oldMonth != nowMonth &&
                    ageObj_tiantiMonth != null &&
                    ZhengBaUtils.MakeMonth(DataHelper2.GetRealDate((int)ageObj_tiantiMonth)) == nowMonth)
                {
                    string strSql = string.Format("SELECT rid,rname,zoneid,duanweiid,duanweijifen,duanweirank,zhanli,data1,data2 FROM t_tianti_month_paihang ORDER BY duanweirank ASC LIMIT {0};", selectRoleIfNewCreate);
                    var    sdr    = DbHelperMySQL.ExecuteReader(strSql);
                    while (sdr != null && sdr.Read())
                    {
                        ZhengBaRoleInfoData roleData = new ZhengBaRoleInfoData();
                        roleData.RoleId       = (int)Convert.ToInt32(sdr["rid"]);
                        roleData.ZoneId       = (int)Convert.ToInt32(sdr["zoneid"]);
                        roleData.DuanWeiId    = (int)Convert.ToInt32(sdr["duanweiid"]);
                        roleData.DuanWeiJiFen = (int)Convert.ToInt32(sdr["duanweijifen"]);
                        roleData.DuanWeiRank  = (int)Convert.ToInt32(sdr["duanweirank"]);
                        roleData.ZhanLi       = (int)Convert.ToInt32(sdr["zhanli"]);
                        roleData.RoleName     = sdr["rname"].ToString();
                        if (!sdr.IsDBNull(sdr.GetOrdinal("data1")))
                        {
                            roleData.TianTiPaiHangRoleData = (byte[])(sdr["data1"]);
                        }
                        if (!sdr.IsDBNull(sdr.GetOrdinal("data2")))
                        {
                            roleData.PlayerJingJiMirrorData = (byte[])(sdr["data2"]);
                        }
                        if (string.IsNullOrEmpty(roleData.RoleName) && roleData.TianTiPaiHangRoleData != null)
                        {
                            var onlyName = DataHelper2.BytesToObject <TianTiPaiHangRoleData_OnlyName>(
                                roleData.TianTiPaiHangRoleData, 0, roleData.TianTiPaiHangRoleData.Length);
                            if (onlyName != null)
                            {
                                roleData.RoleName = onlyName.RoleName;
                            }
                        }

                        string repSql = string.Format(
                            "REPLACE INTO t_zhengba_roles(`month`,rid,zoneid,duanweiid,duanweijifen,duanweirank,zhanli,`grade`,`group`,state,rname,data1,data2) "
                            + "VALUES({0},{1},{2},{3},{4},{5},{6},{7},{8},{9},'{10}',@content,@mirror)",
                            nowMonth, roleData.RoleId, roleData.ZoneId, roleData.DuanWeiId,
                            roleData.DuanWeiJiFen, roleData.DuanWeiRank, roleData.ZhanLi,
                            (int)EZhengBaGrade.Grade100, (int)ZhengBaConsts.NoneGroup, (int)EZhengBaState.None, roleData.RoleName);

                        DbHelperMySQL.ExecuteSqlInsertImg(repSql,
                                                          new List <Tuple <string, byte[]> > {
                            new Tuple <string, byte[]>("content", roleData.TianTiPaiHangRoleData),
                            new Tuple <string, byte[]>("mirror", roleData.PlayerJingJiMirrorData)
                        });
                    }
                    if (sdr != null)
                    {
                        sdr.Close();
                    }

                    DbHelperMySQL.ExecuteSql(
                        string.Format("REPLACE INTO t_async(`id`,`value`) VALUES({0},{1});",
                                      AsyncTypes.ZhengBaCurrMonth, nowMonth)
                        );

                    bMonthFirst = true;
                }
            }
            catch (Exception ex)
            {
                LogManager.WriteExceptionUseCache(ex.ToString());
            }

            return(bMonthFirst);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        private bool CheckBuildZhengBaRank(int selectRoleIfNewCreate, int nowMonth)
        {
            bool bMonthFirst = false;

            try
            {
                DbHelperMySQL.ExecuteSql(string.Format("INSERT IGNORE INTO t_async(`id`,`value`) VALUES({0},{1});", 30, 201111));
                int    oldMonth           = (int)DbHelperMySQL.GetSingle("select value from t_async where id = " + 30);
                object ageObj_tiantiMonth = DbHelperMySQL.GetSingle("select value from t_async where id = " + 4);
                if (oldMonth != nowMonth && ageObj_tiantiMonth != null && ZhengBaUtils.MakeMonth(DataHelper2.GetRealDate((int)ageObj_tiantiMonth)) == nowMonth)
                {
                    string          strSql = string.Format("SELECT rid,rname,zoneid,duanweiid,duanweijifen,duanweirank,zhanli,data1,data2 FROM t_tianti_month_paihang ORDER BY duanweirank ASC LIMIT {0};", selectRoleIfNewCreate);
                    MySqlDataReader sdr    = DbHelperMySQL.ExecuteReader(strSql, false);
                    while (sdr != null && sdr.Read())
                    {
                        ZhengBaRoleInfoData roleData = new ZhengBaRoleInfoData();
                        roleData.RoleId       = Convert.ToInt32(sdr["rid"]);
                        roleData.ZoneId       = Convert.ToInt32(sdr["zoneid"]);
                        roleData.DuanWeiId    = Convert.ToInt32(sdr["duanweiid"]);
                        roleData.DuanWeiJiFen = Convert.ToInt32(sdr["duanweijifen"]);
                        roleData.DuanWeiRank  = Convert.ToInt32(sdr["duanweirank"]);
                        roleData.ZhanLi       = Convert.ToInt32(sdr["zhanli"]);
                        roleData.RoleName     = sdr["rname"].ToString();
                        if (!sdr.IsDBNull(sdr.GetOrdinal("data1")))
                        {
                            roleData.TianTiPaiHangRoleData = (byte[])sdr["data1"];
                        }
                        if (!sdr.IsDBNull(sdr.GetOrdinal("data2")))
                        {
                            roleData.PlayerJingJiMirrorData = (byte[])sdr["data2"];
                        }
                        if (string.IsNullOrEmpty(roleData.RoleName) && roleData.TianTiPaiHangRoleData != null)
                        {
                            TianTiPaiHangRoleData_OnlyName onlyName = DataHelper2.BytesToObject <TianTiPaiHangRoleData_OnlyName>(roleData.TianTiPaiHangRoleData, 0, roleData.TianTiPaiHangRoleData.Length);
                            if (onlyName != null)
                            {
                                roleData.RoleName = onlyName.RoleName;
                            }
                        }
                        string repSql = string.Format("REPLACE INTO t_zhengba_roles(`month`,rid,zoneid,duanweiid,duanweijifen,duanweirank,zhanli,`grade`,`group`,state,rname,data1,data2) VALUES({0},{1},{2},{3},{4},{5},{6},{7},{8},{9},'{10}',@content,@mirror)", new object[]
                        {
                            nowMonth,
                            roleData.RoleId,
                            roleData.ZoneId,
                            roleData.DuanWeiId,
                            roleData.DuanWeiJiFen,
                            roleData.DuanWeiRank,
                            roleData.ZhanLi,
                            100,
                            0,
                            0,
                            roleData.RoleName
                        });
                        DbHelperMySQL.ExecuteSqlInsertImg(repSql, new List <Tuple <string, byte[]> >
                        {
                            new Tuple <string, byte[]>("content", roleData.TianTiPaiHangRoleData),
                            new Tuple <string, byte[]>("mirror", roleData.PlayerJingJiMirrorData)
                        });
                    }
                    if (sdr != null)
                    {
                        sdr.Close();
                    }
                    DbHelperMySQL.ExecuteSql(string.Format("REPLACE INTO t_async(`id`,`value`) VALUES({0},{1});", 30, nowMonth));
                    bMonthFirst = true;
                }
            }
            catch (Exception ex)
            {
                LogManager.WriteExceptionUseCache(ex.ToString());
            }
            return(bMonthFirst);
        }
Ejemplo n.º 8
0
        private static bool FixSyncData_State(DateTime now)
        {
            bool bForceModify = false;
            int  endID        = 0;

            lock (ZhanDuiZhengBa_K.Mutex)
            {
                if (now.Day > ZhanDuiZhengBaConsts.StartMonthDay)
                {
                    endID = ZhanDuiZhengBa_K._Config.MatchConfigList[ZhanDuiZhengBa_K._Config.MatchConfigList.Count - 1].ID;
                }
                else if (now.Day == ZhanDuiZhengBaConsts.StartMonthDay)
                {
                    for (int i = 0; i < ZhanDuiZhengBa_K._Config.MatchConfigList.Count; i++)
                    {
                        ZhanDuiZhengBaMatchConfig c0 = ZhanDuiZhengBa_K._Config.MatchConfigList[i];
                        if (now.TimeOfDay.Ticks < c0.DayBeginTick)
                        {
                            break;
                        }
                        if (now.TimeOfDay.Ticks >= c0.ResultTick)
                        {
                            endID = c0.ID;
                        }
                    }
                }
                if (endID == ZhanDuiZhengBaUtils.WhichDayResultByGrade(EZhengBaGrade.Grade1))
                {
                    ZhanDuiZhengBa_K.SyncData.HasSeasonEnd = true;
                    ZhanDuiZhengBa_K.SyncData.TopZhanDui   = ZhanDuiZhengBa_K.Persistence.GetLastTopZhanDui(ZhanDuiZhengBa_K.SyncData.Month);
                }
                else
                {
                    ZhanDuiZhengBa_K.SyncData.HasSeasonEnd = false;
                    ZhanDuiZhengBa_K.SyncData.TopZhanDui   = ZhanDuiZhengBa_K.Persistence.GetLastTopZhanDui(ZhengBaUtils.MakeMonth(now.AddMonths(-1)));
                }
                int id;
                for (id = 1; id <= endID; id++)
                {
                    ZhanDuiZhengBaMatchConfig        config      = ZhanDuiZhengBa_K._Config.MatchConfigList.Find((ZhanDuiZhengBaMatchConfig _m) => _m.ID == id);
                    EZhengBaGrade                    preGrade    = config.JoinGrade;
                    EZhengBaGrade                    willUpGrade = config.WillUpGrade;
                    List <ZhanDuiZhengBaZhanDuiData> roleList    = ZhanDuiZhengBa_K.SyncData.ZhanDuiList.FindAll((ZhanDuiZhengBaZhanDuiData _r) => _r.Grade > (int)willUpGrade);
                    if (roleList.Count > 0)
                    {
                        List <ZhanDuiZhengBaZhanDuiData> upGradeList = new List <ZhanDuiZhengBaZhanDuiData>();
                        using (List <RangeKey> .Enumerator enumerator = ZhanDuiZhengBaUtils.GetDayPkGroupRange(id).GetEnumerator())
                        {
                            while (enumerator.MoveNext())
                            {
                                RangeKey range = enumerator.Current;
                                List <ZhanDuiZhengBaZhanDuiData> groupRoleList = ZhanDuiZhengBa_K.SyncData.ZhanDuiList.FindAll((ZhanDuiZhengBaZhanDuiData _r) => _r.Group >= range.Left && _r.Group <= range.Right && _r.Grade <= (int)preGrade);
                                if (groupRoleList.Count != 0)
                                {
                                    if (!groupRoleList.Exists((ZhanDuiZhengBaZhanDuiData _r) => _r.Grade <= (int)willUpGrade))
                                    {
                                        groupRoleList.Sort(delegate(ZhanDuiZhengBaZhanDuiData _l, ZhanDuiZhengBaZhanDuiData _r)
                                        {
                                            int result;
                                            if (_l.Grade != _r.Grade)
                                            {
                                                result = _l.Grade - _r.Grade;
                                            }
                                            else
                                            {
                                                result = _l.DuanWeiRank - _r.DuanWeiRank;
                                            }
                                            return(result);
                                        });
                                        ZhanDuiZhengBaZhanDuiData selectRole = groupRoleList[0];
                                        LogManager.WriteLog(LogTypes.Error, string.Format("战队争霸::晋级补位 [s{0}.{1}] {2}->{3}", new object[]
                                        {
                                            selectRole.ZoneId,
                                            selectRole.ZhanDuiID,
                                            selectRole.Grade,
                                            (int)willUpGrade
                                        }), null, true);
                                        selectRole.Grade = (int)willUpGrade;
                                        bForceModify     = true;
                                        upGradeList.Add(selectRole);
                                        if (groupRoleList.Count >= 2)
                                        {
                                            ZhanDuiZhengBaZhanDuiData faildRole = groupRoleList[1];
                                            faildRole.Grade = (int)preGrade;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                ZhanDuiZhengBa_K.SyncData.RealActID = endID;
                foreach (ZhanDuiZhengBaZhanDuiData role in ZhanDuiZhengBa_K.SyncData.ZhanDuiList)
                {
                    if (endID <= 0)
                    {
                        if (role.Grade != 64 || role.State != 0)
                        {
                            role.Grade   = 64;
                            role.State   = 0;
                            bForceModify = true;
                        }
                    }
                    else
                    {
                        EZhengBaGrade upGrade = ZhanDuiZhengBa_K._Config.MatchConfigList.Find((ZhanDuiZhengBaMatchConfig _m) => _m.ID == endID).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)
                        {
                            ZhanDuiZhengBa_K.SyncData.TopZhanDui = role.ZhanDuiID;
                        }
                    }
                }
            }
            return(bForceModify);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
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);
            }
        }
Ejemplo n.º 11
0
        public ZhanDuiZhengBaSyncData LoadZhengBaSyncData(DateTime now, int selectRoleIfNewCreate)
        {
            ZhanDuiZhengBaSyncData syncData = new ZhanDuiZhengBaSyncData();

            syncData.Month = ZhengBaUtils.MakeMonth(now);
            syncData.IsThisMonthInActivity = false;
            List <ZhanDuiZhengBaZhanDuiData> rankList    = new List <ZhanDuiZhengBaZhanDuiData>();
            List <ZhanDuiZhengBaZhanDuiData> zhanDuiList = new List <ZhanDuiZhengBaZhanDuiData>();
            List <ZhanDuiZhengBaPkLogData>   pkLogList   = new List <ZhanDuiZhengBaPkLogData>();

            if (KuaFuServerManager.IsGongNengOpened(113))
            {
                TianTi5v5RankData rankData = TianTi5v5Service.ZhanDuiGetRankingData(DateTime.MinValue);
                bool bMonthFirst           = this.CheckZhengBaRank(selectRoleIfNewCreate, syncData.Month);
                if (bMonthFirst)
                {
                    syncData.IsThisMonthInActivity = true;
                }
                else if (syncData.Month == ZhengBaUtils.MakeMonth(rankData.ModifyTime) && rankData.MonthPaiHangList.Count > ZhanDuiZhengBaConsts.MinZhanDuiNum)
                {
                    syncData.IsThisMonthInActivity = true;
                    int[] groupArray = MathEx.MatchGroupBinary(64);
                    int   i          = 0;
                    while (i < 64 && i < rankData.MonthPaiHangList.Count)
                    {
                        int group = Array.IndexOf <int>(groupArray, i + 1) + 1;
                        TianTi5v5ZhanDuiData      data    = rankData.MonthPaiHangList[i];
                        ZhanDuiZhengBaZhanDuiData zhandui = new ZhanDuiZhengBaZhanDuiData
                        {
                            ZhanDuiName = data.ZhanDuiName,
                            ZhanDuiID   = data.ZhanDuiID,
                            ZhanLi      = (long)((int)data.ZhanDouLi),
                            DuanWeiId   = data.DuanWeiId,
                            DuanWeiRank = data.DuanWeiRank,
                            ZoneId      = data.ZoneID,
                            MemberList  = new List <RoleOccuNameZhanLi>(),
                            Group       = group
                        };
                        foreach (TianTi5v5ZhanDuiRoleData a in data.teamerList)
                        {
                            if (a.RoleID == data.LeaderRoleID)
                            {
                                zhandui.MemberList.Insert(0, new RoleOccuNameZhanLi
                                {
                                    RoleName   = a.RoleName,
                                    Occupation = a.RoleOcc,
                                    ZhanLi     = a.ZhanLi
                                });
                            }
                            else
                            {
                                zhandui.MemberList.Add(new RoleOccuNameZhanLi
                                {
                                    RoleName   = a.RoleName,
                                    Occupation = a.RoleOcc,
                                    ZhanLi     = a.ZhanLi
                                });
                            }
                        }
                        rankList.Add(zhandui);
                        i++;
                    }
                    if (!this.BuildZhengBaRank(syncData.Month, rankList))
                    {
                        LogManager.WriteLog(LogTypes.Fatal, "生成并写入战队争霸64强数据失败!", null, true);
                        syncData.IsThisMonthInActivity = false;
                    }
                }
                if (syncData.IsThisMonthInActivity)
                {
                    zhanDuiList = this.LoadZhengBaRankData(syncData.Month);
                    pkLogList   = this.LoadPkLogList(syncData.Month);
                }
            }
            syncData.ZhanDuiList = zhanDuiList;
            syncData.PKLogList   = pkLogList;
            syncData.RoleModTime = now;
            return(syncData);
        }