Пример #1
0
        private void SetModuleForItem(Item item)
        {
            ItemAttributes attrs = ItemUtils.GetItemAttributes(item.ItemID);
            // decide and create item module accordingly.
            Type itemType = ItemControllers.FirstOrDefault(
                x => item.ItemID == (x.GetCustomAttribute(typeof(ItemAttribute)) as ItemAttribute).ItemID);

            if (itemType != null)
            {
                if (ItemModules[item.Slot] == null || !(ItemModules[item.Slot].GetType().IsAssignableFrom(itemType)))
                {
                    ItemModules[item.Slot]?.Dispose();
                    ItemModules[item.Slot] = itemType.GetMethod("Create")
                                             .Invoke(null, new object[] { this.leds.Length, this.gameState, item.Slot, this.lightingMode, this.preferredCastMode })
                                             as ItemModule;
                    ItemModules[item.Slot].RequestActivation += OnItemActivated;
                    ItemModules[item.Slot].NewFrameReady     += OnNewFrameReceived;
                    ItemCooldownController.AssignItemIdToSlot(item.Slot, item.ItemID);
                    if (item.ItemID == WardingTotemModule.ITEM_ID)
                    {
                        WardingTotemModule.Current = ItemModules[item.Slot] as WardingTotemModule; // HACK to make it accessible to HUDModule
                    }
                    // TODO: Show an item buy animation here?
                }
                ItemModules[item.Slot].UpdateGameState(gameState);
            }
            else
            {
                ItemModules[item.Slot]?.Dispose();
                ItemModules[item.Slot] = null;
            }
        }
Пример #2
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();
        }
Пример #3
0
 public void Dispose()
 {
     masterCancelToken.Cancel();
     animationModule.StopCurrentAnimation();
     championModule?.Dispose();
     ItemCooldownController.Dispose();
 }
Пример #4
0
 public void Dispose()
 {
     masterCancelToken.Cancel();
     animationModule.StopCurrentAnimation();
     championModule?.Dispose();
     for (int i = 0; i < ItemModules.Length; i++)
     {
         ItemModules[i]?.Dispose();
         ItemModules[i] = null;
     }
     ItemUtils.Dispose();
     ItemCooldownController.Dispose();
 }
Пример #5
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);
        }