Exemple #1
0
        private void Create_ThreadPool()
        {
            try
            {
                threadPool = new Dictionary <string, Thread>();
                eventPool  = new Dictionary <string, ManualResetEvent>();
                Thread thread;

                eventPool.Add("CB_Queue", new ManualResetEvent(false));
                thread = new Thread(() =>
                {
                    eventPool["CB_Queue"].WaitOne();
                });
                threadPool.Add("CB_Queue", thread);
                thread.IsBackground = true;
                thread.Start();

                eventPool.Add("CB_Accept", new ManualResetEvent(false));
                thread = new Thread(() =>
                {
                    bool isAccepted = false;
                    while (true)
                    {
                        eventPool["CB_Accept"].WaitOne();
                        var gameflow = leagueClient.Get_Gameflow();
                        // Already find match and not accept yet
                        if (gameflow == "\"ReadyCheck\"" && !isAccepted)
                        {
                            match.Accept_MatchMaking();
                            isAccepted = true;
                        }
                        else if (gameflow != "\"ReadyCheck\"")
                        {
                            isAccepted = false;
                        }
                        Thread.Sleep(200);
                    }
                });
                threadPool.Add("CB_Accept", thread);
                thread.IsBackground = true;
                thread.Start();

                eventPool.Add("CB_PickLane", new ManualResetEvent(false));
                thread = new Thread(() =>
                {
                    string preLane = null;
                    while (true)
                    {
                        eventPool["CB_PickLane"].WaitOne();
                        if (leagueClient.Get_Gameflow() != "\"ChampSelect\"")
                        {
                            preLane = null;
                        }
                        else
                        {
                            if (lane != preLane)
                            {
                                champSelect.Pick_Selected_Lane(lane, times);
                                preLane = lane;
                            }
                        }

                        Thread.Sleep(500);
                    }
                });
                threadPool.Add("CB_PickLane", thread);
                thread.IsBackground = true;
                thread.Start();

                eventPool.Add("CB_PickChamp", new ManualResetEvent(false));
                thread = new Thread(() =>
                {
                    int?preChampionId = null;
                    while (true)
                    {
                        eventPool["CB_PickChamp"].WaitOne();
                        if (leagueClient.Get_Gameflow() != "\"ChampSelect\"")
                        {
                            preChampionId = null;
                        }
                        else
                        {
                            if (championId != preChampionId)
                            {
                                champSelect.Pick_Champion(championId, isLock);
                                preChampionId = championId;
                            }
                        }
                        Thread.Sleep(500);
                    }
                });
                threadPool.Add("CB_PickChamp", thread);
                thread.IsBackground = true;
                thread.Start();

                eventPool.Add("CB_ChangeSpell", new ManualResetEvent(false));
                thread = new Thread(() =>
                {
                    while (true)
                    {
                        eventPool["CB_ChangeSpell"].WaitOne();
                    }
                });
                threadPool.Add("CB_ChangeSpell", thread);
                thread.IsBackground = true;
                thread.Start();

                eventPool.Add("CB_ChangeRune", new ManualResetEvent(false));
                thread = new Thread(() =>
                {
                    string preChampion = null;
                    while (true)
                    {
                        eventPool["CB_ChangeRune"].WaitOne();
                        if (leagueClient.Get_Gameflow() == "\"ChampSelect\"")
                        {
                            var championId = champSelect.Get_My_Pick_ChampionId();
                            var position   = champSelect.Get_My_Position();
                            string champion;
                            if (championId != null)
                            {
                                champion = leagueClient.Get_Owned_Champions_Dict().FirstOrDefault(x => x.Value == championId).Key;
                                if (champion != null && champion != preChampion)
                                {
                                    rune.Set_Rune(champion, position);
                                    preChampion = champion;
                                }
                            }
                        }
                        Thread.Sleep(500);
                    }
                });
                threadPool.Add("CB_ChangeRune", thread);
                thread.IsBackground = true;
                thread.Start();

                rkThread = new Thread(() =>
                {
                    bool isShowed = false;
                    while (true)
                    {
                        if (leagueClient.Get_Gameflow() == "\"ChampSelect\"")
                        {
                            if (isShowed == false)
                            {
                                Thread.Sleep(300);
                                isShowed = true;
                                summoner.Show_Teammates_Ranked();
                            }
                        }
                        else
                        {
                            isShowed = false;
                        }
                        Thread.Sleep(2000);
                    }
                });
                rkThread.IsBackground = true;
                rkThread.Start();
            }
            catch { }
        }