public bool SavePkLog(ZhengBaPkLogData log) { if (log == null) { return(false); } try { string sql = string.Format("INSERT INTO t_zhengba_pk_log(month,day,rid1,zoneid1,rname1,ismirror1,rid2,zoneid2,rname2,ismirror2,result,upgrade,starttime,endtime) " + "VALUES({0},{1},{2},{3},'{4}',{5},{6},{7},'{8}',{9},{10},{11},'{12}','{13}');", log.Month, log.Day, log.RoleID1, log.ZoneID1, log.RoleName1, log.IsMirror1 ? 1 : 0, log.RoleID2, log.ZoneID2, log.RoleName2, log.IsMirror2 ? 1 : 0, (int)log.PkResult, log.UpGrade ? 1 : 0, log.StartTime.ToString("yyyy-MM-dd HH:mm:ss"), log.EndTime.ToString("yyyy-MM-dd HH:mm:ss")); if (DbHelperMySQL.ExecuteSql(sql) <= 0) { return(false); } } catch (Exception ex) { LogManager.WriteLog(LogTypes.Error, "SavePkLog failed!", ex); return(false); } return(true); }
private void MS_NotifyEnter_Update(DateTime now) { ZhengBaMatchConfig matchConfig = this._Config.MatchConfigList.Find((ZhengBaMatchConfig _m) => _m.Day == this.SyncData.RealActDay); if (this.StateMachine.ContinueTicks(now) >= (long)matchConfig.WaitSeconds * 10000000L) { int i = 0; int currIdx = 0; while (i < this.TodayJoinRoleDatas.Count / 2) { ZhengBaManagerK.JoinRolePkData joinRole = this.TodayJoinRoleDatas[currIdx++]; if (joinRole.WaitReqEnter) { joinRole.WaitReqEnter = false; joinRole.WaitKuaFuLogin = false; ZhengBaPkLogData log = null; if (this.ThisLoopPkLogs.TryGetValue(joinRole.CurrGameID, out log)) { log.IsMirror1 = true; this.AsyncEvQ.Enqueue(new AsyncDataItem(KuaFuEventTypes.ZhengBaMirrorFight, new object[] { new ZhengBaMirrorFightData { GameId = joinRole.CurrGameID, RoleId = joinRole.RoleID, ToServerId = joinRole.ToServerID } })); } } ZhengBaManagerK.JoinRolePkData joinRole2 = this.TodayJoinRoleDatas[currIdx++]; if (joinRole2.WaitReqEnter) { joinRole2.WaitReqEnter = false; joinRole2.WaitKuaFuLogin = false; ZhengBaPkLogData log = null; if (this.ThisLoopPkLogs.TryGetValue(joinRole2.CurrGameID, out log)) { log.IsMirror2 = true; this.AsyncEvQ.Enqueue(new AsyncDataItem(KuaFuEventTypes.ZhengBaMirrorFight, new object[] { new ZhengBaMirrorFightData { GameId = joinRole2.CurrGameID, RoleId = joinRole2.RoleID, ToServerId = joinRole2.ToServerID } })); } } i++; } this.StateMachine.SetCurrState(ZhengBaStateMachine.StateType.PkLoopStart, now); } }
/// <summary> /// NotifyEnter状态机 --- update,超时检测未进入的玩家,中心发起镜像出战, 切入PkLoopStart /// </summary> /// <param name="now"></param> private void MS_NotifyEnter_Update(DateTime now) { ZhengBaMatchConfig matchConfig = _Config.MatchConfigList.Find(_m => _m.Day == SyncData.RealActDay); if (StateMachine.ContinueTicks(now) < matchConfig.WaitSeconds * TimeSpan.TicksPerSecond) { return; } // 等待进入超时后,对位未进入的玩家(例如不在线,或者未作出任何点击的在线玩家),中心发起镜像出战的通知 for (int i = 0, currIdx = 0; i < TodayJoinRoleDatas.Count / 2; i++) { var joinRole1 = TodayJoinRoleDatas[currIdx++]; if (joinRole1.WaitReqEnter) // 等待客户端点击进入或者镜像出战 { joinRole1.WaitReqEnter = false; joinRole1.WaitKuaFuLogin = false; ZhengBaPkLogData log = null; if (ThisLoopPkLogs.TryGetValue(joinRole1.CurrGameID, out log)) { log.IsMirror1 = true; AsyncEvQ.Enqueue(new AsyncDataItem(KuaFuEventTypes.ZhengBaMirrorFight, new ZhengBaMirrorFightData() { GameId = joinRole1.CurrGameID, RoleId = joinRole1.RoleID, ToServerId = joinRole1.ToServerID })); } } var joinRole2 = TodayJoinRoleDatas[currIdx++]; if (joinRole2.WaitReqEnter) // 等待客户端点击进入或者镜像出战 { joinRole2.WaitReqEnter = false; joinRole2.WaitKuaFuLogin = false; ZhengBaPkLogData log = null; if (ThisLoopPkLogs.TryGetValue(joinRole2.CurrGameID, out log)) { log.IsMirror2 = true; AsyncEvQ.Enqueue(new AsyncDataItem(KuaFuEventTypes.ZhengBaMirrorFight, new ZhengBaMirrorFightData() { GameId = joinRole2.CurrGameID, RoleId = joinRole2.RoleID, ToServerId = joinRole2.ToServerID })); } } } StateMachine.SetCurrState(ZhengBaStateMachine.StateType.PkLoopStart, now); }
public int ZhengBaKuaFuLogin(int roleid, int gameId) { lock (this.Mutex) { ZhengBaManagerK.JoinRolePkData roleData = this.TodayJoinRoleDatas.Find((ZhengBaManagerK.JoinRolePkData _r) => _r.RoleID == roleid && _r.CurrGameID == gameId); ZhengBaPkLogData logData = null; this.ThisLoopPkLogs.TryGetValue(gameId, out logData); if (roleData == null || logData == null) { return(-12); } if (!roleData.WaitKuaFuLogin) { return(-12); } } return(0); }
public int ZhengBaRequestEnter(int roleId, int gameId, EZhengBaEnterType enter) { lock (Mutex) { if (StateMachine.GetCurrState() != ZhengBaStateMachine.StateType.NotifyEnter) { return(StdErrorCode.Error_Not_In_valid_Time); } JoinRolePkData roleData = TodayJoinRoleDatas.Find(_r => _r.RoleID == roleId && _r.CurrGameID == gameId); ZhengBaPkLogData logData = null; ThisLoopPkLogs.TryGetValue(gameId, out logData); if (roleData == null || logData == null) { return(StdErrorCode.Error_Operation_Denied); } if (!roleData.WaitReqEnter) { return(StdErrorCode.Error_Operation_Denied); } roleData.WaitReqEnter = false; roleData.WaitKuaFuLogin = true; if (enter == EZhengBaEnterType.Mirror) { if (logData.RoleID1 == roleId) { logData.IsMirror1 = true; } else if (logData.RoleID2 == roleId) { logData.IsMirror2 = true; } AsyncEvQ.Enqueue(new AsyncDataItem(KuaFuEventTypes.ZhengBaMirrorFight, new ZhengBaMirrorFightData() { RoleId = roleId, GameId = gameId, ToServerId = roleData.ToServerID })); } } return(StdErrorCode.Error_Success_No_Info); }
public int ZhengBaRequestEnter(int roleId, int gameId, EZhengBaEnterType enter) { lock (this.Mutex) { if (this.StateMachine.GetCurrState() != ZhengBaStateMachine.StateType.NotifyEnter) { return(-2001); } ZhengBaManagerK.JoinRolePkData roleData = this.TodayJoinRoleDatas.Find((ZhengBaManagerK.JoinRolePkData _r) => _r.RoleID == roleId && _r.CurrGameID == gameId); ZhengBaPkLogData logData = null; this.ThisLoopPkLogs.TryGetValue(gameId, out logData); if (roleData == null || logData == null) { return(-12); } if (!roleData.WaitReqEnter) { return(-12); } roleData.WaitReqEnter = false; roleData.WaitKuaFuLogin = true; if (enter == EZhengBaEnterType.Mirror) { if (logData.RoleID1 == roleId) { logData.IsMirror1 = true; } else if (logData.RoleID2 == roleId) { logData.IsMirror2 = true; } this.AsyncEvQ.Enqueue(new AsyncDataItem(KuaFuEventTypes.ZhengBaMirrorFight, new object[] { new ZhengBaMirrorFightData { RoleId = roleId, GameId = gameId, ToServerId = roleData.ToServerID } })); } } return(0); }
public int ZhengBaKuaFuLogin(int roleid, int gameId) { lock (Mutex) { JoinRolePkData roleData = TodayJoinRoleDatas.Find(_r => _r.RoleID == roleid && _r.CurrGameID == gameId); ZhengBaPkLogData logData = null; ThisLoopPkLogs.TryGetValue(gameId, out logData); if (roleData == null || logData == null) { return(StdErrorCode.Error_Operation_Denied); } if (!roleData.WaitKuaFuLogin) { return(StdErrorCode.Error_Operation_Denied); } // 这句话会导致CMD_LOGIN_ON 无法通过第二次验证, (原服未下线,跨服已上线,前几次CMD_LOGIN_ON会失败) // roleData.WaitKuaFuLogin = false; } return(StdErrorCode.Error_Success_No_Info); }
private void HandleSavePkLog(GameServerClient client, int nID, byte[] cmdParams, int count) { try { ZhengBaPkLogData data = DataHelper.BytesToObject <ZhengBaPkLogData>(cmdParams, 0, count); string logSql = string.Format("INSERT INTO t_zhengba_pk_log(month,day,rid1,zoneid1,rname1,ismirror1,rid2,zoneid2,rname2,ismirror2,result,upgrade,starttime,endtime) VALUES({0},{1},{2},{3},'{4}',{5},{6},{7},'{8}',{9},{10},{11},'{12}','{13}')", new object[] { data.Month, data.Day, data.RoleID1, data.ZoneID1, data.RoleName1, data.IsMirror1 ? 1 : 0, data.RoleID2, data.ZoneID2, data.RoleName2, data.IsMirror2 ? 1 : 0, data.PkResult, data.UpGrade ? 1 : 0, data.StartTime.ToString("yyyy-MM-dd HH:mm:ss"), data.EndTime.ToString("yyyy-MM-dd HH:mm:ss") }); if (!this.ExecNonQuery(logSql)) { client.sendCmd <bool>(nID, false); } else { client.sendCmd <bool>(nID, true); } } catch (Exception ex) { LogManager.WriteException(ex.Message); client.sendCmd <bool>(nID, false); } }
public void EventCallBackHandler(int eventType, params object[] args) { try { switch (eventType) { case (int)KuaFuEventTypes.NotifyWaitingRoleCount: { if (args.Length == 2) { int rid = (int)args[0]; int count = (int)args[1]; CoreInterface.GetEventSourceInterface().fireEvent(new KuaFuFuBenRoleCountEvent(rid, count), SceneType); } } break; case (int)KuaFuEventTypes.RoleSignUp: case (int)KuaFuEventTypes.RoleStateChange: { if (args.Length == 1) { KuaFuRoleData kuaFuRoleData = args[0] as KuaFuRoleData; if (null != kuaFuRoleData) { UpdateRoleData(kuaFuRoleData, kuaFuRoleData.RoleId); } } } break; case (int)KuaFuEventTypes.UpdateAndNotifyEnterGame: { if (args.Length == 1) { KuaFuRoleData kuaFuRoleData = args[0] as KuaFuRoleData; if (null != kuaFuRoleData) { UpdateRoleData(kuaFuRoleData, kuaFuRoleData.RoleId); TianTiFuBenData TianTiFuBenData = GetKuaFuFuBenData(kuaFuRoleData.GameId); if (null != TianTiFuBenData && TianTiFuBenData.State == GameFuBenState.Start) { KuaFuServerLoginData kuaFuServerLoginData = new KuaFuServerLoginData() { RoleId = kuaFuRoleData.RoleId, GameType = kuaFuRoleData.GameType, GameId = kuaFuRoleData.GameId, EndTicks = kuaFuRoleData.StateEndTicks, }; kuaFuServerLoginData.ServerId = ClientInfo.ServerId; lock (Mutex) { KuaFuServerInfo kuaFuServerInfo; if (ServerIdServerInfoDict.TryGetValue(TianTiFuBenData.ServerId, out kuaFuServerInfo)) { kuaFuServerLoginData.ServerIp = kuaFuServerInfo.Ip; kuaFuServerLoginData.ServerPort = kuaFuServerInfo.Port; } } CoreInterface.GetEventSourceInterface().fireEvent(new KuaFuNotifyEnterGameEvent(kuaFuServerLoginData), SceneType); } } } } break; case (int)KuaFuEventTypes.ZhengBaSupport: { ZhengBaSupportLogData data = args[0] as ZhengBaSupportLogData; if (null != data && data.FromServerId != ClientInfo.ServerId) { CoreInterface.GetEventSourceInterface().fireEvent(new KFZhengBaSupportEvent(data), (int)SceneUIClasses.KFZhengBa); } } break; case (int)KuaFuEventTypes.ZhengBaPkLog: { if (args.Length == 1) { ZhengBaPkLogData log = args[0] as ZhengBaPkLogData; if (log != null) { CoreInterface.GetEventSourceInterface().fireEvent(new KFZhengBaPkLogEvent(log), (int)SceneUIClasses.KFZhengBa); } } } break; case (int)KuaFuEventTypes.ZhengBaNtfEnter: { ZhengBaNtfEnterData data = args[0] as ZhengBaNtfEnterData; lock (Mutex) { KuaFuServerInfo kuaFuServerInfo; if (ServerIdServerInfoDict.TryGetValue(data.ToServerId, out kuaFuServerInfo)) { data.ToServerIp = kuaFuServerInfo.Ip; data.ToServerPort = kuaFuServerInfo.Port; } else { LogManager.WriteLog(LogTypes.Error, string.Format("KuaFuEventTypes.ZhengBaNtfEnter not find kfserver={0}", data.ToServerId)); } } CoreInterface.GetEventSourceInterface().fireEvent(new KFZhengBaNtfEnterEvent(data), (int)SceneUIClasses.KFZhengBa); } break; case (int)KuaFuEventTypes.ZhengBaMirrorFight: { ZhengBaMirrorFightData data = args[0] as ZhengBaMirrorFightData; CoreInterface.GetEventSourceInterface().fireEvent(new KFZhengBaMirrorFightEvent(data), (int)SceneUIClasses.KFZhengBa); } break; case (int)KuaFuEventTypes.ZhengBaButtetinJoin: { ZhengBaBulletinJoinData data = args[0] as ZhengBaBulletinJoinData; CoreInterface.GetEventSourceInterface().fireEvent(new KFZhengBaBulletinJoinEvent(data), (int)SceneUIClasses.KFZhengBa); } break; case (int)KuaFuEventTypes.CoupleArenaCanEnter: { CoreInterface.GetEventSourceInterface().fireEvent( new CoupleArenaCanEnterEvent(args[0] as CoupleArenaCanEnterData), (int)SceneUIClasses.CoupleArena); } break; } } catch (Exception ex) { LogManager.WriteExceptionUseCache(ex.ToString()); } }
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 }); } }
/// <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); }
public KFZhengBaPkLogEvent(ZhengBaPkLogData log) : base((int)GlobalEventTypes.KFZhengBaPkLog) { this.Log = log; }
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); }
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); } }