Ejemplo n.º 1
0
        public static void MatchGame()
        {
            //List<BaseSceneGame> tempList = new List<BaseSceneGame>();
            //lock (_synclock)
            //{
            //    foreach (BaseSceneGame game in _pairUpList.Values)
            //    {
            //        tempList.Add(game);
            //    }
            //}

            BaseSceneGame[] tempList = GetPairUpList();

            foreach (BaseSceneGame game in tempList)
            {
                if (game.GameState != eGameState.PAIRUP || game.pairUpState != 0)
                {
                    continue;
                }

                game.pairUpState = 2;

                BaseSceneGame matchGame1 = null;
                BaseSceneGame matchGame2 = null;
                BaseSceneGame matchGame3 = null;
                BaseSceneGame matchGame4 = null;
                BaseSceneGame matchGame5 = null;


                foreach (BaseSceneGame g in tempList)
                {
                    if (game.GameState != eGameState.PAIRUP || g.pairUpState != 0)
                    {
                        continue;
                    }

                    if (game.GameClass == eGameClass.FREE_OR_CONSORTIA)
                    {
                        if (g.Count == game.Count && g.GameMode == game.GameMode)
                        {
                            if (g.GameClass == eGameClass.CONSORTIA)
                            {
                                if (2 == ConsortiaMgr.FindConsortiaAlly(game.ConsortiaID, g.ConsortiaID))
                                {
                                    matchGame1 = g;
                                    //matchGame1.GameClass = eGameClass.CONSORTIA;
                                    game.GameClass = eGameClass.CONSORTIA;
                                }
                                else if (0 == ConsortiaMgr.FindConsortiaAlly(game.ConsortiaID, g.ConsortiaID))
                                {
                                    matchGame2 = g;
                                    //matchGame2.GameClass = eGameClass.CONSORTIA;
                                    game.GameClass = eGameClass.CONSORTIA;
                                }
                            }
                            else if (g.GameClass == eGameClass.FREE_OR_CONSORTIA)
                            {
                                if (2 == ConsortiaMgr.FindConsortiaAlly(game.ConsortiaID, g.ConsortiaID))
                                {
                                    matchGame1 = g;
                                    //matchGame1.GameClass = eGameClass.CONSORTIA;
                                    game.GameClass = eGameClass.CONSORTIA;
                                }
                                else if (0 == ConsortiaMgr.FindConsortiaAlly(game.ConsortiaID, g.ConsortiaID))
                                {
                                    matchGame2 = g;
                                    //matchGame2.GameClass = eGameClass.CONSORTIA;
                                    game.GameClass = eGameClass.CONSORTIA;
                                }
                                else if (game.ConsortiaID != g.ConsortiaID)
                                {
                                    int level = Math.Abs(game.AverageLevel() - g.AverageLevel());
                                    //平均等级小于10级
                                    if (level < 5)
                                    {
                                        matchGame3     = g;
                                        game.GameClass = eGameClass.FREE;
                                    }
                                    else if (level < 10)
                                    {
                                        matchGame4     = g;
                                        game.GameClass = eGameClass.FREE;
                                    }
                                    else
                                    {
                                        matchGame5     = g;
                                        game.GameClass = eGameClass.FREE;
                                    }
                                }
                            }
                            else
                            {
                                if (game.ConsortiaID != g.ConsortiaID)
                                {
                                    int level = Math.Abs(game.AverageLevel() - g.AverageLevel());
                                    //平均等级小于10级
                                    if (level < 5)
                                    {
                                        matchGame3     = g;
                                        game.GameClass = eGameClass.FREE;
                                    }
                                    else if (level < 10)
                                    {
                                        matchGame4     = g;
                                        game.GameClass = eGameClass.FREE;
                                    }
                                    else
                                    {
                                        matchGame5     = g;
                                        game.GameClass = eGameClass.FREE;
                                    }
                                }
                            }
                        }
                    }
                    else if (game.GameClass == eGameClass.CONSORTIA)
                    {
                        if (g.GameClass == eGameClass.CONSORTIA || g.GameClass == eGameClass.FREE_OR_CONSORTIA)
                        {
                            if (g.Count == game.Count && g.GameMode == game.GameMode)
                            {
                                if (2 == ConsortiaMgr.FindConsortiaAlly(game.ConsortiaID, g.ConsortiaID))
                                {
                                    matchGame1 = g;
                                    //matchGame1.GameClass = eGameClass.CONSORTIA;
                                }
                                else if (0 == ConsortiaMgr.FindConsortiaAlly(game.ConsortiaID, g.ConsortiaID))
                                {
                                    matchGame2 = g;
                                    //matchGame2.GameClass = eGameClass.CONSORTIA;
                                }
                            }
                        }
                    }
                    else if (game.GameClass == eGameClass.FREE)
                    {
                        if (g.GameClass == eGameClass.FREE)
                        {
                            if (g.Count == game.Count && g.GameMode == game.GameMode)
                            {
                                if (game.ConsortiaID != 0 || g.ConsortiaID != 0)
                                {
                                    if (game.ConsortiaID != g.ConsortiaID)
                                    {
                                        int level = Math.Abs(game.AverageLevel() - g.AverageLevel());
                                        //平均等级小于10级
                                        if (level < 5)
                                        {
                                            matchGame1 = g;
                                        }
                                        else if (level < 10)
                                        {
                                            matchGame2 = g;
                                        }
                                        else
                                        {
                                            matchGame3 = g;
                                        }
                                    }
                                }
                                else
                                {
                                    int level = Math.Abs(game.AverageLevel() - g.AverageLevel());
                                    //平均等级小于10级
                                    if (level < 5)
                                    {
                                        matchGame1 = g;
                                    }
                                    else if (level < 10)
                                    {
                                        matchGame2 = g;
                                    }
                                    else
                                    {
                                        matchGame3 = g;
                                    }
                                }
                            }
                        }
                    }
                }

                if (matchGame1 != null)
                {
                    //matchGame.StopTimer();
                    //_pairUpList.Remove(matchGame.ID);
                    matchGame1.pairUpState = 1;
                    game.pairUpState       = 1;
                    if (matchGame1.GameClass == eGameClass.FREE_OR_CONSORTIA)
                    {
                        matchGame1.GameClass = game.GameClass;
                    }
                    game.MatchGame       = matchGame1;
                    matchGame1.MatchGame = game;

                    PairUpGameEntry(game);
                    game.BeginPairUpLoad();
                }
                else if (matchGame2 != null)
                {
                    matchGame2.pairUpState = 1;
                    game.pairUpState       = 1;
                    if (matchGame2.GameClass == eGameClass.FREE_OR_CONSORTIA)
                    {
                        matchGame2.GameClass = game.GameClass;
                    }
                    game.MatchGame       = matchGame2;
                    matchGame2.MatchGame = game;

                    PairUpGameEntry(game);
                    game.BeginPairUpLoad();
                }
                else if (matchGame3 != null)
                {
                    matchGame3.pairUpState = 1;
                    game.pairUpState       = 1;
                    if (matchGame3.GameClass == eGameClass.FREE_OR_CONSORTIA)
                    {
                        matchGame3.GameClass = game.GameClass;
                    }
                    game.MatchGame       = matchGame3;
                    matchGame3.MatchGame = game;

                    PairUpGameEntry(game);
                    game.BeginPairUpLoad();
                }
                else if (matchGame4 != null)
                {
                    matchGame4.pairUpState = 1;
                    game.pairUpState       = 1;
                    if (matchGame4.GameClass == eGameClass.FREE_OR_CONSORTIA)
                    {
                        matchGame4.GameClass = game.GameClass;
                    }
                    game.MatchGame       = matchGame4;
                    matchGame4.MatchGame = game;

                    PairUpGameEntry(game);
                    game.BeginPairUpLoad();
                }
                else if (matchGame5 != null)
                {
                    matchGame5.pairUpState = 1;
                    game.pairUpState       = 1;
                    if (matchGame5.GameClass == eGameClass.FREE_OR_CONSORTIA)
                    {
                        matchGame5.GameClass = game.GameClass;
                    }
                    game.MatchGame       = matchGame5;
                    matchGame5.MatchGame = game;

                    PairUpGameEntry(game);
                    game.BeginPairUpLoad();
                }
                else
                {
                    game.pairUpState = 0;
                }
            }

            //List<BaseSceneGame> list = _pairUpList.Values.ToList();
            BaseSceneGame[] list = GetPairUpList();
            lock (_synclock)
            {
                foreach (BaseSceneGame game in list)
                {
                    if (game.pairUpState != 0)
                    {
                        game.pairUpState = 0;
                        _pairUpList.Remove(game.ID);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void HandleFindConsortiaAlly(GSPacketIn pkg)
        {
            int state = ConsortiaMgr.FindConsortiaAlly(pkg.ReadInt(), pkg.ReadInt());

            this.SendFindConsortiaAlly(state, pkg.ReadInt());
        }