Example #1
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);
        }
Example #2
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);
        }
Example #3
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
                });
            }
        }