Пример #1
0
        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);
            }
        }
Пример #2
0
 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);
 }
Пример #3
0
 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);
 }
Пример #4
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);
        }
Пример #5
0
        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);
            }
        }