Beispiel #1
0
        private List <ZhengBaRoleInfoData> LoadZhengBaRankData(int nowMonth)
        {
            List <ZhengBaRoleInfoData> roleList = new List <ZhengBaRoleInfoData>();

            try
            {
                string strSql = string.Format("SELECT rid,rname,zoneid,duanweiid,duanweijifen,duanweirank,zhanli,grade,`group`,state,data1,data2 FROM t_zhengba_roles where `month`={0} ORDER BY duanweirank ASC;",
                                              nowMonth);
                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"]);
                    if (!sdr.IsDBNull(sdr.GetOrdinal("data1")))
                    {
                        roleData.TianTiPaiHangRoleData = (byte[])(sdr["data1"]);
                    }
                    if (!sdr.IsDBNull(sdr.GetOrdinal("data2")))
                    {
                        roleData.PlayerJingJiMirrorData = (byte[])(sdr["data2"]);
                    }

                    roleData.Grade    = (int)Convert.ToInt32(sdr["grade"]);
                    roleData.Group    = (int)Convert.ToInt32(sdr["group"]);
                    roleData.State    = (int)Convert.ToInt32(sdr["state"]);
                    roleData.RoleName = sdr["rname"].ToString();

                    roleList.Add(roleData);
                }

                if (sdr != null)
                {
                    sdr.Close();
                }
            }
            catch (Exception ex)
            {
                LogManager.WriteExceptionUseCache(ex.ToString());
            }

            return(roleList);
        }
 private ZhengBaRoleInfoData LoadZhengBaKingData(ref int month)
 {
     try
     {
         ZhengBaRoleInfoData kingRoleData = null;
         string          strSql           = string.Format("SELECT * FROM t_zhengba_roles WHERE grade={0} ORDER BY `month` DESC LIMIT 1;", 1);
         MySqlDataReader sdr = DbHelperMySQL.ExecuteReader(strSql, false);
         if (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"]);
             if (!sdr.IsDBNull(sdr.GetOrdinal("data1")))
             {
                 roleData.TianTiPaiHangRoleData = (byte[])sdr["data1"];
             }
             if (!sdr.IsDBNull(sdr.GetOrdinal("data2")))
             {
                 roleData.PlayerJingJiMirrorData = (byte[])sdr["data2"];
             }
             roleData.Grade    = Convert.ToInt32(sdr["grade"]);
             roleData.Group    = Convert.ToInt32(sdr["group"]);
             roleData.State    = Convert.ToInt32(sdr["state"]);
             roleData.RoleName = sdr["rname"].ToString();
             month             = Convert.ToInt32(sdr["month"]);
             kingRoleData      = roleData;
         }
         if (sdr != null)
         {
             sdr.Close();
         }
         return(kingRoleData);
     }
     catch (Exception ex)
     {
         LogManager.WriteExceptionUseCache(ex.ToString());
     }
     return(null);
 }
Beispiel #3
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);
        }
Beispiel #4
0
        public List <ZhengBaNtfPkResultData> ZhengBaPkResult(int gameId, int winner1, int FirstLeaveRoleId)
        {
            lock (Mutex)
            {
                ZhengBaPkLogData log = null;
                if (!ThisLoopPkLogs.TryGetValue(gameId, out log))
                {
                    return(null);
                }

                // 一个人走,另一个人赢
                if (FirstLeaveRoleId == log.RoleID1)
                {
                    winner1 = log.RoleID2;
                }
                else if (FirstLeaveRoleId == log.RoleID2)
                {
                    winner1 = log.RoleID1;
                }

                if (winner1 != log.RoleID1 && winner1 != log.RoleID2)
                {
                    // what's the f**k.
                    return(null);
                }

                JoinRolePkData joinRole1 = TodayJoinRoleDatas.Find(_r => _r.RoleID == log.RoleID1 && _r.CurrGameID == gameId);
                JoinRolePkData joinRole2 = TodayJoinRoleDatas.Find(_r => _r.RoleID == log.RoleID2 && _r.CurrGameID == gameId);
                if (joinRole1 == null || joinRole2 == null)
                {
                    // what's the f**k
                    return(null);
                }

                ZhengBaMatchConfig     matchConfig = _Config.MatchConfigList.Find(_m => _m.Day == SyncData.RealActDay);
                ZhengBaNtfPkResultData ntf1        = new ZhengBaNtfPkResultData()
                {
                    RoleID = joinRole1.RoleID
                };
                ZhengBaNtfPkResultData ntf2 = new ZhengBaNtfPkResultData()
                {
                    RoleID = joinRole2.RoleID
                };
                JoinRolePkData         winJoinRole = null;
                ZhengBaNtfPkResultData winNtf      = null;

                if (winner1 > 0 && winner1 == joinRole1.RoleID)
                {
                    winJoinRole = joinRole1;
                    winNtf      = ntf1;
                }
                else if (winner1 > 0 && winner1 == joinRole2.RoleID)
                {
                    winJoinRole = joinRole2;
                    winNtf      = ntf2;
                }

                if (winJoinRole != null && winNtf != null)
                {
                    winNtf.IsWin = true;
                    winJoinRole.WinTimes++;
                    if (winJoinRole.WinTimes >= matchConfig.NeedWinTimes && HadUpGradeRoleNum < matchConfig.MaxUpGradeNum)
                    {
                        int  calcGroup               = RandomGroup.Count > 0 ? RandomGroup.Last() : ZhengBaConsts.NoneGroup;
                        bool bSaveUpdate             = false;
                        ZhengBaRoleInfoData roleData = SyncData.RoleList.Find(_r => _r.RoleId == winJoinRole.RoleID);
                        if (roleData != null)
                        {
                            int newGrade = (int)matchConfig.WillUpGrade;
                            int newState = (int)EZhengBaState.UpGrade;
                            int newGroup = calcGroup != ZhengBaConsts.NoneGroup ? calcGroup : roleData.Group;

                            if (Persistence.UpdateRole(SyncData.Month, roleData.RoleId, newGrade, newState, newGroup))
                            {
                                // 必须保证把晋级情况落地到db之后,才能更新缓存
                                roleData.Grade       = newGrade;
                                roleData.State       = newState;
                                roleData.Group       = newGroup;
                                SyncData.RoleModTime = TimeUtil.NowDateTime();
                                bSaveUpdate          = true;

                                if (newGrade != (int)EZhengBaGrade.Grade1)
                                {
                                    AsyncEvQ.Enqueue(new AsyncDataItem(KuaFuEventTypes.ZhengBaButtetinJoin, new ZhengBaBulletinJoinData()
                                    {
                                        NtfType = ZhengBaBulletinJoinData.ENtfType.MailUpgradeRole,
                                        Args1   = roleData.RoleId,
                                    }));
                                }
                            }
                        }

                        if (bSaveUpdate)
                        {
                            // 晋级已落地到db,修改缓存
                            winNtf.RandGroup = calcGroup;
                            winNtf.IsUpGrade = true;
                            log.UpGrade      = true;
                            HadUpGradeRoleNum++;

                            RandomGroup.Remove(calcGroup);
                            TodayJoinRoleDatas.RemoveAll(_r => _r.RoleID == winJoinRole.RoleID);
                        }
                    }
                }

                log.EndTime = TimeUtil.NowDateTime();
                if (winner1 > 0 && winner1 == log.RoleID1)
                {
                    log.PkResult = (int)EZhengBaPKResult.Win;
                }
                else if (winner1 > 0 && winner1 == log.RoleID2)
                {
                    log.PkResult = (int)EZhengBaPKResult.Fail;
                }
                else
                {
                    log.PkResult = (int)EZhengBaPKResult.Invalid;
                }

                ntf1.StillNeedWin   = Math.Max(0, matchConfig.NeedWinTimes - joinRole1.WinTimes);
                ntf1.LeftUpGradeNum = matchConfig.MaxUpGradeNum - HadUpGradeRoleNum;
                ntf2.StillNeedWin   = Math.Max(0, matchConfig.NeedWinTimes - joinRole2.WinTimes);
                ntf2.LeftUpGradeNum = matchConfig.MaxUpGradeNum - HadUpGradeRoleNum;

                Persistence.SavePkLog(log);
                ThisLoopPkLogs.Remove(gameId);
                AsyncEvQ.Enqueue(new AsyncDataItem(KuaFuEventTypes.ZhengBaPkLog, log));

                return(new List <ZhengBaNtfPkResultData>()
                {
                    ntf1, ntf2
                });
            }
        }
Beispiel #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);
        }
        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);
        }
Beispiel #7
0
        public List <ZhengBaNtfPkResultData> ZhengBaPkResult(int gameId, int winner1, int FirstLeaveRoleId)
        {
            List <ZhengBaNtfPkResultData> result;

            lock (this.Mutex)
            {
                ZhengBaPkLogData log = null;
                if (!this.ThisLoopPkLogs.TryGetValue(gameId, out log))
                {
                    result = null;
                }
                else
                {
                    if (FirstLeaveRoleId == log.RoleID1)
                    {
                        winner1 = log.RoleID2;
                    }
                    else if (FirstLeaveRoleId == log.RoleID2)
                    {
                        winner1 = log.RoleID1;
                    }
                    if (winner1 != log.RoleID1 && winner1 != log.RoleID2)
                    {
                        result = null;
                    }
                    else
                    {
                        ZhengBaManagerK.JoinRolePkData joinRole  = this.TodayJoinRoleDatas.Find((ZhengBaManagerK.JoinRolePkData _r) => _r.RoleID == log.RoleID1 && _r.CurrGameID == gameId);
                        ZhengBaManagerK.JoinRolePkData joinRole2 = this.TodayJoinRoleDatas.Find((ZhengBaManagerK.JoinRolePkData _r) => _r.RoleID == log.RoleID2 && _r.CurrGameID == gameId);
                        if (joinRole == null || joinRole2 == null)
                        {
                            result = null;
                        }
                        else
                        {
                            ZhengBaMatchConfig     matchConfig = this._Config.MatchConfigList.Find((ZhengBaMatchConfig _m) => _m.Day == this.SyncData.RealActDay);
                            ZhengBaNtfPkResultData ntf         = new ZhengBaNtfPkResultData
                            {
                                RoleID = joinRole.RoleID
                            };
                            ZhengBaNtfPkResultData ntf2 = new ZhengBaNtfPkResultData
                            {
                                RoleID = joinRole2.RoleID
                            };
                            ZhengBaManagerK.JoinRolePkData winJoinRole = null;
                            ZhengBaNtfPkResultData         winNtf      = null;
                            if (winner1 > 0 && winner1 == joinRole.RoleID)
                            {
                                winJoinRole = joinRole;
                                winNtf      = ntf;
                            }
                            else if (winner1 > 0 && winner1 == joinRole2.RoleID)
                            {
                                winJoinRole = joinRole2;
                                winNtf      = ntf2;
                            }
                            if (winJoinRole != null && winNtf != null)
                            {
                                winNtf.IsWin = true;
                                winJoinRole.WinTimes++;
                                if (winJoinRole.WinTimes >= matchConfig.NeedWinTimes && this.HadUpGradeRoleNum < matchConfig.MaxUpGradeNum)
                                {
                                    int  calcGroup               = (this.RandomGroup.Count > 0) ? this.RandomGroup.Last <int>() : 0;
                                    bool bSaveUpdate             = false;
                                    ZhengBaRoleInfoData roleData = this.SyncData.RoleList.Find((ZhengBaRoleInfoData _r) => _r.RoleId == winJoinRole.RoleID);
                                    if (roleData != null)
                                    {
                                        int newGrade = (int)matchConfig.WillUpGrade;
                                        int newState = 1;
                                        int newGroup = (calcGroup != 0) ? calcGroup : roleData.Group;
                                        if (this.Persistence.UpdateRole(this.SyncData.Month, roleData.RoleId, newGrade, newState, newGroup))
                                        {
                                            roleData.Grade            = newGrade;
                                            roleData.State            = newState;
                                            roleData.Group            = newGroup;
                                            this.SyncData.RoleModTime = TimeUtil.NowDateTime();
                                            bSaveUpdate = true;
                                            if (newGrade != 1)
                                            {
                                                this.AsyncEvQ.Enqueue(new AsyncDataItem(KuaFuEventTypes.ZhengBaButtetinJoin, new object[]
                                                {
                                                    new ZhengBaBulletinJoinData
                                                    {
                                                        NtfType = ZhengBaBulletinJoinData.ENtfType.MailUpgradeRole,
                                                        Args1   = roleData.RoleId
                                                    }
                                                }));
                                            }
                                        }
                                    }
                                    if (bSaveUpdate)
                                    {
                                        winNtf.RandGroup = calcGroup;
                                        winNtf.IsUpGrade = true;
                                        winNtf.NewGrade  = roleData.Grade;
                                        log.UpGrade      = true;
                                        this.HadUpGradeRoleNum++;
                                        this.RandomGroup.Remove(calcGroup);
                                        this.TodayJoinRoleDatas.RemoveAll((ZhengBaManagerK.JoinRolePkData _r) => _r.RoleID == winJoinRole.RoleID);
                                    }
                                }
                            }
                            log.EndTime = TimeUtil.NowDateTime();
                            if (winner1 > 0 && winner1 == log.RoleID1)
                            {
                                log.PkResult = 1;
                            }
                            else if (winner1 > 0 && winner1 == log.RoleID2)
                            {
                                log.PkResult = 2;
                            }
                            else
                            {
                                log.PkResult = 0;
                            }
                            ntf.StillNeedWin    = Math.Max(0, matchConfig.NeedWinTimes - joinRole.WinTimes);
                            ntf.LeftUpGradeNum  = matchConfig.MaxUpGradeNum - this.HadUpGradeRoleNum;
                            ntf2.StillNeedWin   = Math.Max(0, matchConfig.NeedWinTimes - joinRole2.WinTimes);
                            ntf2.LeftUpGradeNum = matchConfig.MaxUpGradeNum - this.HadUpGradeRoleNum;
                            this.Persistence.SavePkLog(log);
                            this.ThisLoopPkLogs.Remove(gameId);
                            this.AsyncEvQ.Enqueue(new AsyncDataItem(KuaFuEventTypes.ZhengBaPkLog, new object[]
                            {
                                log
                            }));
                            result = new List <ZhengBaNtfPkResultData>
                            {
                                ntf,
                                ntf2
                            };
                        }
                    }
                }
            }
            return(result);
        }
Beispiel #8
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);
        }