Esempio n. 1
0
        private LeagueOfLegendsModule(int ledCount, LightingMode mode, AbilityCastPreference castMode)
        {
            // League of Legends integration Initialization

            // Init Item Attributes
            ItemUtils.Init();
            ItemCooldownController.Init();

            this.preferredCastMode = castMode;

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

            // Load animation module
            animationModule = AnimationModule.Create(this.leds.Length);
            animationModule.NewFrameReady += OnNewFrameReceived;
            CurrentLEDSource = animationModule;

            PlayLoadingAnimation();
            WaitForGameInitialization();
        }
Esempio n. 2
0
        /// <summary>
        /// Briefly tests the lighting and returns it to the previously active module after a few seconds
        /// </summary>
        public void DoLightingTest()
        {
            // TODO: Broken, doesn't return to previous module

            if (CurrentLEDModule is BlinkWhiteModule)
            {
                return;
            }

            Task.Run(async() =>
            {
                Debug.WriteLine("Testing lights");
                ProcessListenerService.Stop();
                await Task.Delay(100);
                LEDModule lastActiveModule = CurrentLEDModule;
                LEDModule blinkModule      = BlinkWhiteModule.Create();
                blinkModule.NewFrameReady += UpdateLEDDisplay;
                CurrentLEDModule           = blinkModule;
                await Task.Delay(5000);
                ProcessListenerService.Start();
                if (CurrentLEDModule is BlinkWhiteModule)
                {
                    CurrentLEDModule = lastActiveModule;
                }
            }).ContinueWith((t) => Debug.WriteLine(t.Exception.Message + " // " + t.Exception.StackTrace), TaskContinuationOptions.OnlyOnFaulted);
        }
Esempio n. 3
0
 /// <summary>
 /// Called when the player tried to cast an ability but was out of mana.
 /// </summary>
 private void OnAbilityCastNoMana()
 {
     CurrentLEDSource = animationModule;
     animationModule.ColorBurst(NoManaColor, 0.3f).ContinueWith((t) =>
     {
         CurrentLEDSource = championModule;
     });
 }
Esempio n. 4
0
        /*/// <summary>
         * /// Sets the light controller to be used
         * /// </summary>
         * public void SetController(LightControllerType type, int ledCount = 0, bool reverseOrder = false)
         * {
         *  ((IDisposable)lightController).Dispose();
         *  if (type == LightControllerType.LED_Strip)
         *  {
         *      lightController = SACNController.Create();
         *      this.preferredMode = LightingMode.Line;
         *  }
         *  else if (type == LightControllerType.RazerChroma)
         *  {
         *      lightController = RazerChromaController.Create();
         *      this.preferredMode = LightingMode.Keyboard;
         *  }
         *  RestartManager(this.preferredMode, ledCount, reverseOrder);
         * }*/

        private void RestartManager() // TODO: Keep game state (i.e. league of legends cooldowns etc)
        {
            UninitLeds();
            CurrentLEDModule = null; // restart the whole service (force module reload)
            ProcessListenerService.Stop();
            InitLeds(reverseOrder);
            ProcessListenerService.Start();
        }
Esempio n. 5
0
        protected BaseGameModule(GameState gameState, AbilityCastPreference castMode)
        {
            PreferredCastMode = castMode;

            GameState = gameState;
            // Load animation module
            Animator         = AnimationModule.Create();
            CurrentLEDSource = Animator;
        }
Esempio n. 6
0
 /// <summary>
 /// Called by a <see cref="LEDModule"/> when a new frame is available to be processed.
 /// </summary>
 /// <param name="s">Module that sent the message</param>
 /// <param name="data">LED data</param>
 private void OnNewFrameReceived(object s, Led[] data, LightingMode mode)
 {
     if ((s is ChampionModule && CurrentLEDSource is ItemModule && !((ItemModule)CurrentLEDSource).IsPriorityItem)) // Champion modules take priority over item casts... for the moment
     {
         CurrentLEDSource = (LEDModule)s;
     }
     if (s != CurrentLEDSource)
     {
         return;                        // If it's from a different source that what we're listening too, ignore it
     }
     NewFrameReady?.Invoke(this, data, mode);
     msSinceLastExternalFrameReceived = 0;
 }
Esempio n. 7
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);
        }
        /// <param name="ledCount">Number of lights in the LED strip</param>
        /// <param name="reverseOrder">Set to true if you want the lights to be reverse in order (i.e. Color for LED 0 will be applied to the last LED in the strip)</param>
        public LedManager(int ledCount, bool reverseOrder)
        {
            this.leds = new Led[ledCount];
            for (int i = 0; i < this.leds.Length; i++)
            {
                this.leds[i] = new Led();
            }
            this.reverseOrder = reverseOrder;

            LEDModule lolModule = LeagueOfLegendsModule.Create(ledCount);

            lolModule.NewFrameReady += UpdateLEDDisplay;
            UpdateLEDDisplay(this, this.leds);
        }
Esempio n. 9
0
 private void OnProcessChanged(string name)
 {
     if (name == "League of Legends" && !(CurrentLEDModule is LeagueOfLegendsModule)) // TODO: Account for client disconnections
     {
         LEDModule lolModule = LeagueOfLegendsModule.Create(preferredMode, ledCount, ModuleOptions.ContainsKey("lol") ? ModuleOptions["lol"] : new Dictionary <string, string>());
         lolModule.NewFrameReady += UpdateLEDDisplay;
         CurrentLEDModule         = lolModule;
     }
     else if (name.Length == 0)
     {
         CurrentLEDModule = null;
         return;
     }
 }
        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);
        }
Esempio n. 11
0
 private void OnChampionKill(Event ev)
 {
     if (ev.KillerName == gameState.ActivePlayer.SummonerName)
     {
         CurrentLEDSource = animationModule;
         if (customKillAnimation != null)
         {
             animationModule.RunAnimationOnce(customKillAnimation, false, 0.1f).ContinueWith((t) =>
             {
                 CurrentLEDSource    = championModule;
                 customKillAnimation = null;
             });
         }
         else
         {
             animationModule.ColorBurst(KillColor, 0.01f).ContinueWith((t) =>
             {
                 CurrentLEDSource = championModule;
             });
         }
     }
 }
Esempio n. 12
0
 private void OnProcessChanged(string name, int pid)
 {
     if (name == "League of Legends" && !(CurrentLEDModule is LeagueOfLegendsModule)) // TODO: Account for client disconnections
     {
         LEDModule lolModule = LeagueOfLegendsModule.Create(ModuleOptions.ContainsKey("lol") ? ModuleOptions["lol"] : new Dictionary <string, string>());
         lolModule.NewFrameReady += UpdateLEDDisplay;
         CurrentLEDModule         = lolModule;
     }
     else if (name == "RocketLeague" && !(CurrentLEDModule is RocketLeagueModule)) // TODO: Account for client disconnections
     {
         LEDModule rlModule = RocketLeagueModule.Create(ModuleOptions.ContainsKey("rocketleague") ? ModuleOptions["rocketleague"] : new Dictionary <string, string>());
         rlModule.NewFrameReady += UpdateLEDDisplay;
         CurrentLEDModule        = rlModule;
     }
     else if (name.Length == 0)
     {
         if (!(CurrentLEDModule is BlinkWhiteModule)) // if we're not testing
         {
             CurrentLEDModule = null;
         }
         return;
     }
 }
Esempio n. 13
0
 private void OnItemActivated(object s, EventArgs e)
 {
     CurrentLEDSource = (LEDModule)s;
 }
Esempio n. 14
0
 private void RestartManager()
 {
     InitLeds(this.preferredMode, this.ledCount, this.reverseOrder);
     CurrentLEDModule = null;
     ProcessListenerService.Restart();
 }
Esempio n. 15
0
 private void RestartManager(LightingMode preferredMode, int ledCount, bool reverseOrder) // TODO: Keep game state (i.e. league of legends cooldowns etc)
 {
     InitLeds(this.preferredMode, ledCount, reverseOrder);
     CurrentLEDModule = null; // restart the whole service (force module reload)
     ProcessListenerService.Restart();
 }
Esempio n. 16
0
 protected BaseRLModule()
 {
     // Load animation module
     Animator         = AnimationModule.Create();
     CurrentLEDSource = Animator;
 }