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 KFZhengBaNtfEnterEvent(ZhengBaNtfEnterData data) : base((int)GlobalEventTypes.KFZhengBaNtfEnter) { this.Data = data; }
/// <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); }
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); } }