コード例 #1
0
ファイル: CoupleArenaService.cs プロジェクト: chenchungit/ky
        /// <summary>
        /// 夫妻匹配
        /// </summary>
        /// <param name="now"></param>
        private void CheckRoleMatch(DateTime now)
        {
            lock (Mutex)
            {
                var joinDatas = JoinDataUtil.GetJoinList();
                if (joinDatas == null || joinDatas.Count <= 0)
                {
                    return;
                }

                CoupleArenaJoinMatcher joinMatcher = new CoupleArenaJoinMatcher();
                foreach (var joinData in joinDatas)
                {
                    if ((now - joinData.StartTime).TotalSeconds >= 60 || joinData.ToKfServerId > 0)
                    {
                        JoinDataUtil.DelJoinData(joinData);
                    }
                    else if ((now - joinData.StartTime).TotalSeconds >= 30)
                    {
                        joinMatcher.AddGlobalJoinData(joinData);
                    }
                    else
                    {
                        joinMatcher.AddJoinData(joinData.DuanWeiType, joinData.DuanWeiLevel, joinData);
                    }
                }

                foreach (var list in joinMatcher.GetAllMatch())
                {
                    for (int i = 0; i < list.Count - 1;)
                    {
                        var one = list[i];
                        var two = list[i + 1];
                        if (MatchTimeLimiter.GetMatchTimes(one.RoleId1, one.RoleId2, two.RoleId1, two.RoleId2)
                            >= TianTiPersistence.Instance.MaxRolePairFightCount)
                        {
                            // 次数先知 第i个元素,让第i+1个元素和第i+2个元素进行匹配
                            i += 1;
                            continue;
                        }

                        CoupleArenaFuBenData fubenData = new CoupleArenaFuBenData();
                        fubenData.GameId    = Persistence.GetNextGameId();
                        fubenData.StartTime = now;
                        fubenData.RoleList  = new List <KuaFuFuBenRoleData>();
                        fubenData.RoleList.Add(new KuaFuFuBenRoleData()
                        {
                            ServerId = one.ServerId, RoleId = one.RoleId1, Side = 1
                        });
                        fubenData.RoleList.Add(new KuaFuFuBenRoleData()
                        {
                            ServerId = one.ServerId, RoleId = one.RoleId2, Side = 1
                        });
                        fubenData.RoleList.Add(new KuaFuFuBenRoleData()
                        {
                            ServerId = two.ServerId, RoleId = two.RoleId1, Side = 2
                        });
                        fubenData.RoleList.Add(new KuaFuFuBenRoleData()
                        {
                            ServerId = two.ServerId, RoleId = two.RoleId2, Side = 2
                        });
                        if (ClientAgentManager.Instance().AssginKfFuben(GameType, fubenData.GameId, 4, out fubenData.KfServerId))
                        {
                            MatchTimeLimiter.AddMatchTimes(one.RoleId1, one.RoleId2, two.RoleId1, two.RoleId2);
                            GameFuBenDict[fubenData.GameId] = fubenData;
                            i += 2;

                            one.ToKfServerId = fubenData.KfServerId;
                            two.ToKfServerId = fubenData.KfServerId;

                            CoupleArenaCanEnterData enterData1 = new CoupleArenaCanEnterData()
                            {
                                GameId     = fubenData.GameId,
                                KfServerId = fubenData.KfServerId,
                                RoleId1    = one.RoleId1,
                                RoleId2    = one.RoleId2
                            };
                            ClientAgentManager.Instance().PostAsyncEvent(one.ServerId, EvItemGameType,
                                                                         new AsyncDataItem(KuaFuEventTypes.CoupleArenaCanEnter, enterData1));

                            CoupleArenaCanEnterData enterData2 = new CoupleArenaCanEnterData()
                            {
                                GameId     = fubenData.GameId,
                                KfServerId = fubenData.KfServerId,
                                RoleId1    = two.RoleId1,
                                RoleId2    = two.RoleId2
                            };
                            AsyncDataItem evItem2 = new AsyncDataItem(KuaFuEventTypes.CoupleArenaCanEnter, fubenData.GameId, fubenData.KfServerId, two.RoleId1, two.RoleId2);
                            ClientAgentManager.Instance().PostAsyncEvent(two.ServerId, EvItemGameType,
                                                                         new AsyncDataItem(KuaFuEventTypes.CoupleArenaCanEnter, enterData2));
                        }
                        else
                        {
                            LogManager.WriteLog(LogTypes.Error, "CoupleArena 没有跨服可以分配");
                            return;
                        }
                    }
                }
            }
        }
コード例 #2
0
 private void CheckRoleMatch(DateTime now)
 {
     lock (this.Mutex)
     {
         List <CoupleArenaJoinData> joinDatas = this.JoinDataUtil.GetJoinList();
         if (joinDatas != null && joinDatas.Count > 0)
         {
             CoupleArenaJoinMatcher joinMatcher = new CoupleArenaJoinMatcher();
             foreach (CoupleArenaJoinData joinData in joinDatas)
             {
                 if ((now - joinData.StartTime).TotalSeconds >= 60.0 || joinData.ToKfServerId > 0)
                 {
                     this.JoinDataUtil.DelJoinData(joinData);
                 }
                 else if ((now - joinData.StartTime).TotalSeconds >= 30.0)
                 {
                     joinMatcher.AddGlobalJoinData(joinData);
                 }
                 else
                 {
                     joinMatcher.AddJoinData(joinData.DuanWeiType, joinData.DuanWeiLevel, joinData);
                 }
             }
             foreach (List <CoupleArenaJoinData> list in joinMatcher.GetAllMatch())
             {
                 int i = 0;
                 while (i < list.Count - 1)
                 {
                     CoupleArenaJoinData one = list[i];
                     CoupleArenaJoinData two = list[i + 1];
                     if (this.MatchTimeLimiter.GetMatchTimes(one.RoleId1, one.RoleId2, two.RoleId1, two.RoleId2) >= TianTiPersistence.Instance.MaxRolePairFightCount)
                     {
                         i++;
                     }
                     else
                     {
                         CoupleArenaFuBenData fubenData = new CoupleArenaFuBenData();
                         fubenData.GameId    = this.Persistence.GetNextGameId();
                         fubenData.StartTime = now;
                         fubenData.RoleList  = new List <KuaFuFuBenRoleData>();
                         fubenData.RoleList.Add(new KuaFuFuBenRoleData
                         {
                             ServerId = one.ServerId,
                             RoleId   = one.RoleId1,
                             Side     = 1
                         });
                         fubenData.RoleList.Add(new KuaFuFuBenRoleData
                         {
                             ServerId = one.ServerId,
                             RoleId   = one.RoleId2,
                             Side     = 1
                         });
                         fubenData.RoleList.Add(new KuaFuFuBenRoleData
                         {
                             ServerId = two.ServerId,
                             RoleId   = two.RoleId1,
                             Side     = 2
                         });
                         fubenData.RoleList.Add(new KuaFuFuBenRoleData
                         {
                             ServerId = two.ServerId,
                             RoleId   = two.RoleId2,
                             Side     = 2
                         });
                         if (!ClientAgentManager.Instance().AssginKfFuben(this.GameType, fubenData.GameId, 4, out fubenData.KfServerId))
                         {
                             LogManager.WriteLog(LogTypes.Error, "CoupleArena 没有跨服可以分配", null, true);
                             return;
                         }
                         this.MatchTimeLimiter.AddMatchTimes(one.RoleId1, one.RoleId2, two.RoleId1, two.RoleId2, 1);
                         this.GameFuBenDict[fubenData.GameId] = fubenData;
                         i += 2;
                         one.ToKfServerId = fubenData.KfServerId;
                         two.ToKfServerId = fubenData.KfServerId;
                         CoupleArenaCanEnterData enterData = new CoupleArenaCanEnterData
                         {
                             GameId     = fubenData.GameId,
                             KfServerId = fubenData.KfServerId,
                             RoleId1    = one.RoleId1,
                             RoleId2    = one.RoleId2
                         };
                         ClientAgentManager.Instance().PostAsyncEvent(one.ServerId, this.EvItemGameType, new AsyncDataItem(KuaFuEventTypes.CoupleArenaCanEnter, new object[]
                         {
                             enterData
                         }));
                         CoupleArenaCanEnterData enterData2 = new CoupleArenaCanEnterData
                         {
                             GameId     = fubenData.GameId,
                             KfServerId = fubenData.KfServerId,
                             RoleId1    = two.RoleId1,
                             RoleId2    = two.RoleId2
                         };
                         AsyncDataItem evItem2 = new AsyncDataItem(KuaFuEventTypes.CoupleArenaCanEnter, new object[]
                         {
                             fubenData.GameId,
                             fubenData.KfServerId,
                             two.RoleId1,
                             two.RoleId2
                         });
                         ClientAgentManager.Instance().PostAsyncEvent(two.ServerId, this.EvItemGameType, new AsyncDataItem(KuaFuEventTypes.CoupleArenaCanEnter, new object[]
                         {
                             enterData2
                         }));
                     }
                 }
             }
         }
     }
 }