Пример #1
0
        private async Task OnGameInitialized()      // TODO: Handle summoner spells
        {
            animationModule.StopCurrentAnimation(); // stops the current anim

            // Queries the game information
            await QueryPlayerInfo(true);

            // Set trinket initial cooldowns
            double avgChampLevel = ItemCooldownController.GetAverageChampionLevel(this.gameState);

            // note: this assumes the program is run BEFORE the game starts, or else it won't be very accurate.
            ItemCooldownController.SetCooldown(OracleLensModule.ITEM_ID, OracleLensModule.GetCooldownDuration(avgChampLevel));
            ItemCooldownController.SetCooldown(FarsightAlterationModule.ITEM_ID, FarsightAlterationModule.GetCooldownDuration(avgChampLevel));

            // Load champion module. Different modules will be loaded depending on the champion.
            // If there is no suitable module for the selected champion, just the health bar will be displayed.

            string champName = gameState.PlayerChampion.RawChampionName.ToLower();

            Type champType = ChampionControllers.FirstOrDefault(
                x => champName.ToLower()
                .Contains((x.GetCustomAttribute(typeof(ChampionAttribute)) as ChampionAttribute)
                          .ChampionName.ToLower()));                    // find champion module

            if (champType != null)
            {
                championModule = champType.GetMethod("Create")
                                 .Invoke(null, new object[] { this.leds.Length, this.gameState, this.lightingMode, this.preferredCastMode })
                                 as ChampionModule;
                championModule.NewFrameReady        += OnNewFrameReceived;
                championModule.TriedToCastOutOfMana += OnAbilityCastNoMana;
            }
            CurrentLEDSource = championModule;

            // Sets up a task to always check for updated player info
            _ = Task.Run(async() =>
            {
                while (true)
                {
                    if (masterCancelToken.IsCancellationRequested)
                    {
                        return;
                    }
                    await QueryPlayerInfo();
                    await Task.Delay(150);
                }
            });

            // start frame timer
            _ = Task.Run(FrameTimer);
        }
        private LeagueOfLegendsModule(int ledCount)
        {
            // League of Legends integration Initialization
            Process[] pname = Process.GetProcessesByName("League of Legends");
            if (pname.Length == 0)
            {
                throw new InvalidOperationException("Game client is not open.");
            }

            // Queries the game information
            QueryPlayerInfo();

            // LED Initialization
            //reverseOrder = reverse;
            this.leds = new Led[ledCount];
            for (int i = 0; i < ledCount; i++)
            {
                leds[i] = new Led();
            }

            // Load animation module
            animationModule = AnimationModule.Create(ledCount);
            animationModule.NewFrameReady += OnNewFrameReceived;

            // Load champion module. Different modules will be loaded depending on the champion.
            // If there is no suitable module for the selected champion, just the health bar will be displayed.

            // TODO: Make this easily extendable when there are many champion modules
            if (playerChampion.RawChampionName.ToLower().Contains("velkoz"))
            {
                championModule = VelKozModule.Create(ledCount, activePlayer);
                championModule.NewFrameReady        += OnNewFrameReceived;
                championModule.TriedToCastOutOfMana += OnAbilityCastNoMana;
            }
            CurrentLEDSource = championModule;

            // Sets up a task to always check for updated player info
            Task.Run(async() =>
            {
                while (true)
                {
                    QueryPlayerInfo();
                    await Task.Delay(150);
                }
            });

            // start frame timer
            Task.Run(FrameTimer);
        }