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 }); } }
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); }