context: using System;
  using System.Collections.Generic;
  using System.Drawing;
  using System.Linq;
  using LeagueSharp;
  using LeagueSharp.Common;
  
  using EloBuddy; 
  using LeagueSharp.Common; 
  namespace Shen.Modes
  {
      using PortAIO.Properties;
  
      using SharpDX;
      using SharpDX.Direct3D9;
  
      internal class ModeSelector
      {
          enum TargetSelect
          {
              Shen,
              LeagueSharp
          }
  
          public static Menu LocalMenu;
          public static Font Text;
  
          private static TargetSelect Selector => LocalMenu.Item("TS").GetValue<StringList>().SelectedIndex == 0
              ? TargetSelect.Shen
              : TargetSelect.LeagueSharp;
  
          public static void Initialize(LeagueSharp.Common.Menu mainMenu)
          {
              
              new Render.Sprite(Resources.selectedchampion, new Vector2())
              {
                  PositionUpdate = () => DrawPosition,
                  Scale = new Vector2(1f, 1f),
                  VisibleCondition = sender => DrawSprite
              }.Add();
  
              
              Text = new Font(Drawing.Direct3DDevice, new FontDescription{FaceName = "Malgun Gothic", Height = 21, OutputPrecision = FontPrecision.Default, Weight = FontWeight.Bold, Quality = FontQuality.ClearTypeNatural });
  
              LocalMenu = new Menu("Target Selector", "AssassinTargetSelector").SetFontStyle(FontStyle.Regular,SharpDX.Color.Cyan);
  
              var menuTargetSelector = new Menu("Target Selector", "TargetSelector");
              {
                  LeagueSharp.Common.TargetSelector.AddToMenu(menuTargetSelector);
              }
              
              LocalMenu.AddItem(
                  new MenuItem("TS", "Active Target Selector:").SetValue(
                      new StringList(new[] { "Shen Target Selector", "L# Target Selector" })))
                  .SetFontStyle(FontStyle.Regular, SharpDX.Color.GreenYellow)
                  .ValueChanged += (sender, args) =>
                  {
                      LocalMenu.Items.ForEach(
                          i =>
                          {
                              i.Show();
                              switch (args.GetNewValue<StringList>().SelectedIndex)
                              {
                                  case 0:
                                      {
                                          if (i.Tag == 22)
                                          {
                                              i.Show(false);
                                          }
                                          break;
                                      }
  
                                  case 1:
                                      {
                                          if (i.Tag == 11 || i.Tag == 12)
                                          {
                                              i.Show(false);
                                          }
                                          break;
                                      }
                              }
                          });
                  };
  
              menuTargetSelector.Items.ForEach(i =>
              {
                  LocalMenu.AddItem(i);
                  i.SetTag(22);
              });
  
              
              LocalMenu.AddItem(new MenuItem("Set", "Target Select Mode:").SetValue(new StringList(new[] { "Single Target Select", "Multi Target Select" }))).SetFontStyle(FontStyle.Regular, SharpDX.Color.LightCoral).SetTag(11);
              
  
              LocalMenu.AddItem(new MenuItem("ModeSelector.Range", "Range (Recommend: Max):"))
                  .SetValue(new Slider((int)(  Shen.Champion.PlayerSpells.E.Range * 3), 
                                          (int)Shen.Champion.PlayerSpells.E.Range, 
                                          (int)(Shen.Champion.PlayerSpells.Q.Range * 5))).SetTag(11);
  
              LocalMenu.AddItem(new MenuItem("Targets", "Targets:").SetFontStyle(FontStyle.Regular, SharpDX.Color.Aqua).SetTag(11));
              foreach (AIHeroClient e in HeroManager.Enemies)
              {
                  LocalMenu.AddItem(
                      new MenuItem("enemy_" + e.ChampionName, $"{Shen.Common.DrawHelper.MenuTab}Focus {e.ChampionName}")
                          .SetValue(false)).SetTag(12);
  
              }
  
              //foreach (var langItem in HeroManager.Enemies.Select(e =>LocalMenu.AddItem(new MenuItem("enemy_" + e.ChampionName,string.Format("{0}Focus {1}", GameUtils.MenuTab, e.ChampionName)).SetValue(false)).SetTag(12)))
  
              LocalMenu.AddItem(new MenuItem("Draw.Title", "Drawings").SetFontStyle(FontStyle.Regular, SharpDX.Color.Aqua).SetTag(11));
              LocalMenu.AddItem(new MenuItem("Draw.Range", Shen.Common.DrawHelper.MenuTab + "ModeSelector.Range").SetValue(new Circle(true,System.Drawing.Color.Gray)).SetTag(11));
              LocalMenu.AddItem(new MenuItem("Draw.Enemy", Shen.Common.DrawHelper.MenuTab + "ActiveJungle Enemy").SetValue(new Circle(true,System.Drawing.Color.GreenYellow)).SetTag(11));
              LocalMenu.AddItem(new MenuItem("Draw.Status", Shen.Common.DrawHelper.MenuTab + "Show Enemy:").SetValue(new StringList(new[] { "Off", "Text", "Picture", "Line", "All" }, 0)));
  
              mainMenu.AddSubMenu(LocalMenu);
  
              Game.OnWndProc += Game_OnWndProc;
              Drawing.OnDraw += Drawing_OnDraw;
  
              RefreshMenuItemsStatus();
          }
  
          private static void RefreshMenuItemsStatus()
          {
  
              LocalMenu.Items.ForEach(
                  i =>
                  {
                      i.Show();
                      switch (Selector)
                      {
                          case TargetSelect.Shen:
                              if (i.Tag == 22)
                              {
                                  i.Show(false);
                              }
                              break;
                          case TargetSelect.LeagueSharp:
                              if (i.Tag == 11)
                              {
                                  i.Show(false);
                              }
                              break;
                      }
                  });
          }
  
          public static void ClearAssassinList()
          {
              foreach (AIHeroClient enemy in ObjectManager.Get<AIHeroClient>().Where(enemy => enemy.IsEnemy))
              {
                  LocalMenu.Item("enemy_" + enemy.ChampionName).SetValue(false);
              }
          }
  
          private static void Game_OnWndProc(WndEventArgs args)
          {
              if (Selector != TargetSelect.Shen)
              {
                  return;
              }
  
              if (args.Msg == 0x201)
              {
                  foreach (var objAiHero in from hero in HeroManager.Enemies
                                            where
                                                hero.Distance(Game.CursorPos) < 150f && hero != null && hero.IsVisible && !hero.IsDead
                                            orderby
                                                hero.Distance(Game.CursorPos) descending
                                            select
                                                hero)
                  {
                      if (objAiHero != null && objAiHero.IsVisible && !objAiHero.IsDead)
                      {
                          int set = MenuConfig.LocalMenu.Item("Set").GetValue<StringList>().SelectedIndex;
  
                          switch (set)
                          {
                              case 0:
                                  {
                                      ClearAssassinList();
                                      MenuConfig.LocalMenu.Item("enemy_" + objAiHero.ChampionName).SetValue(true);
                                      break;
                                  }
                              case 1:
                                  {
                                      var menuStatus =
                                          MenuConfig.LocalMenu.Item("enemy_" + objAiHero.ChampionName).GetValue<bool>();
                                      MenuConfig.LocalMenu.Item("enemy_" + objAiHero.ChampionName).SetValue(!menuStatus);
                                      break;
                                  }
                          }
                      }
                  }
              }
          }
  
          public static bool In<T>(T source, params T[] list)
          {
              return list.Equals(source);
          }
  
          public static bool NotIn<T>(T source, params T[] list)
          {
              return !list.Equals(source);
          }
  
          public static AIHeroClient GetTarget(float vDefaultRange = 0,
              LeagueSharp.Common.TargetSelector.DamageType vDefaultDamageType = LeagueSharp.Common.TargetSelector.DamageType.Physical,
              IEnumerable<AIHeroClient> ignoredChamps = null)
          {
              //if (Selector != TargetSelect.Shen)
              //{
              //    return TargetSelector.GetTarget(vDefaultRange, vDefaultDamageType);
              //}
  
              vDefaultRange = Math.Abs(vDefaultRange) < 0.00001
                  ? Shen.Champion.PlayerSpells.Q.Range
                  : LocalMenu.Item("ModeSelector.Range").GetValue<Slider>().Value;
  
              if (ignoredChamps == null)
              {
                  ignoredChamps = new List<AIHeroClient>();
              }
  
              var vEnemy =
                  HeroManager.Enemies.FindAll(hero => ignoredChamps.All(ignored => ignored.NetworkId != hero.NetworkId))
                      .Where(e => e.IsValidTarget(vDefaultRange))
                      .Where(e => LocalMenu.Item("enemy_" + e.ChampionName) != null)
                      .Where(e => LocalMenu.Item("enemy_" + e.ChampionName).GetValue<bool>())
  
gt:                     .Where(e => ObjectManager.Player.Distance(e) < vDefaultRange);