context: using EloBuddy; 
  using LeagueSharp.Common; 
  namespace Flowers_ADC_Series.Pluging
  {
      using ADCCOMMON;
      using System;
      using System.Linq;
      using LeagueSharp;
      using LeagueSharp.Common;
      using SharpDX;
      using Color = System.Drawing.Color;
      
  
      internal class Vayne : Logic
      {
          public Vayne()
          {
              Q = new Spell(SpellSlot.Q, 300f);
              E = new Spell(SpellSlot.E, 650f);
              R = new Spell(SpellSlot.R);
  
              E.SetTargetted(0.25f, 1600f);
  
              var comboMenu = Menu.AddSubMenu(new Menu("Combo", "Combo"));
              {
                  comboMenu.AddItem(new MenuItem("ComboQ", "Use Q", true).SetValue(true));
                  comboMenu.AddItem(new MenuItem("AQALogic", "Use AA-Q-AA Logic", true).SetValue(true));
                  comboMenu.AddItem(new MenuItem("ComboE", "Use E", true).SetValue(true));
                  comboMenu.AddItem(new MenuItem("ComboR", "Use R", true).SetValue(true));
                  comboMenu.AddItem(
                      new MenuItem("ComboRCount", "Use R|When Enemies Counts >= x", true).SetValue(new Slider(3, 1, 5)));
                  comboMenu.AddItem(
                      new MenuItem("ComboRHp", "Use R|Or Player HealthPercent <= x%", true).SetValue(new Slider(45)));
              }
  
              var harassMenu = Menu.AddSubMenu(new Menu("Harass", "Harass"));
              {
                  harassMenu.AddItem(new MenuItem("HarassQ", "Use Q", true).SetValue(true));
                  harassMenu.AddItem(
                      new MenuItem("HarassQ2Passive", "Use Q|Only Target have 2 Passive", true).SetValue(true));
                  harassMenu.AddItem(new MenuItem("HarassE", "Use E|Only Target have 2 Passive", true).SetValue(false));
                  harassMenu.AddItem(
                      new MenuItem("HarassMana", "When Player ManaPercent >= x%", true).SetValue(new Slider(60)));
              }
  
              var clearMenu = Menu.AddSubMenu(new Menu("Clear", "Clear"));
              {
                  var laneClearMenu = clearMenu.AddSubMenu(new Menu("LaneClear", "LaneClear"));
                  {
                      laneClearMenu.AddItem(new MenuItem("LaneClearQ", "Use Q", true).SetValue(true));
                      laneClearMenu.AddItem(new MenuItem("LaneClearQTurret", "Use Q|Attack Tower", true).SetValue(true));
                      laneClearMenu.AddItem(
                          new MenuItem("LaneClearMana", "When Player ManaPercent >= %", true).SetValue(new Slider(60)));
                  }
  
                  var jungleClearMenu = clearMenu.AddSubMenu(new Menu("JungleClear", "JungleClear"));
                  {
                      jungleClearMenu.AddItem(new MenuItem("JungleClearQ", "Use Q", true).SetValue(true));
                      jungleClearMenu.AddItem(new MenuItem("JungleClearE", "Use E", true).SetValue(true));
                      jungleClearMenu.AddItem(
                          new MenuItem("JungleClearMana", "When Player ManaPercent >= x%", true).SetValue(new Slider(30)));
                  }
  
                  clearMenu.AddItem(new MenuItem("asdqweqwe", " ", true));
                  ManaManager.AddSpellFarm(clearMenu);
              }
  
              var miscMenu = Menu.AddSubMenu(new Menu("Misc", "Misc"));
              {
                  var qMenu = miscMenu.AddSubMenu(new Menu("Q Settings", "Q Settings"));
                  {
                      qMenu.AddItem(new MenuItem("QCheck", "Use Q|Safe Check?", true).SetValue(true));
                      qMenu.AddItem(new MenuItem("QTurret", "Use Q|Dont Cast To Turret", true).SetValue(true));
                      qMenu.AddItem(new MenuItem("QMelee", "Use Q|Anti Melee", true).SetValue(true));
                  }
  
                  var eMenu = miscMenu.AddSubMenu(new Menu("E Settings", "E Settings"));
                  {
                      var condemnMenu = eMenu.AddSubMenu(new Menu("Condemn Settings", "Condemn Settings"));
                      {
                          condemnMenu.AddItem(
                              new MenuItem("EMode", "Use E Mode:", true).SetValue(
                                  new StringList(new[] {"Default", "VHR", "Marksman", "SharpShooter", "OKTW"})));
                          condemnMenu.AddItem(
                              new MenuItem("ComboEPush", "Use E|Push Tolerance", true).SetValue(new Slider(0, -50, 50)));
                      }
  
                      var interruptMenu = eMenu.AddSubMenu(new Menu("Interrupt Settings", "Interrupt Settings"));
                      {
                          interruptMenu.AddItem(new MenuItem("Interrupt", "Interrupt Danger Spells", true).SetValue(false));
                          interruptMenu.AddItem(new MenuItem("AntiAlistar", "Interrupt Alistar W", true).SetValue(true));
                          interruptMenu.AddItem(new MenuItem("AntiRengar", "Interrupt Rengar Jump", true).SetValue(true));
                          interruptMenu.AddItem(new MenuItem("AntiKhazix", "Interrupt Khazix R", true).SetValue(true));
                      }
  
                      var antigapcloserMenu =
                          eMenu.AddSubMenu(new Menu("AntiGapcloser Settings", "AntiGapcloser Settings"));
                      {
                          antigapcloserMenu.AddItem(new MenuItem("Gapcloser", "Anti Gapcloser", true).SetValue(false));
                          foreach (var target in HeroManager.Enemies)
                          {
                              antigapcloserMenu.AddItem(
                                  new MenuItem("AntiGapcloser" + target.ChampionName.ToLower(), target.ChampionName, true)
                                      .SetValue(false));
                          }
                      }
  
                      var autocondemnMenu = eMenu.AddSubMenu(new Menu("AutoCondemn Settings", "AutoCondemn Settings"));
                      {
                          autocondemnMenu.AddItem(new MenuItem("AutoE", "Auto E?", true).SetValue(false));
                          foreach (var target in HeroManager.Enemies)
                          {
                              autocondemnMenu.AddItem(new MenuItem("AutoE" + target.ChampionName.ToLower(),
                                  target.ChampionName, true).SetValue(true));
                          }
                      }
                  }
  
                  var rMenu = miscMenu.AddSubMenu(new Menu("R Settings", "R Settings"));
                  {
                      rMenu.AddItem(new MenuItem("AutoR", "Auto R?", true).SetValue(true));
                      rMenu.AddItem(
                          new MenuItem("AutoRCount", "Auto R|When Enemies Counts >= x", true).SetValue(new Slider(3, 1, 5)));
                      rMenu.AddItem(
                          new MenuItem("AutoRRange", "Auto R|Search Enemies Range", true).SetValue(new Slider(600, 500, 1200)));
                  }
  
                  miscMenu.AddItem(new MenuItem("Forcus", "Force 2 Passive Target", true).SetValue(true));
              }
  
              var utilityMenu = Menu.AddSubMenu(new Menu("Utility", "Utility"));
              {
                  var skinMenu = utilityMenu.AddSubMenu(new Menu("Skin Change", "Skin Change"));
                  {
                      SkinManager.AddToMenu(skinMenu, 10);
                  }
  
                  var autoLevelMenu = utilityMenu.AddSubMenu(new Menu("Auto Levels", "Auto Levels"));
                  {
                      LevelsManager.AddToMenu(autoLevelMenu);
                  }
  
                  var itemsMenu = utilityMenu.AddSubMenu(new Menu("Items", "Items"));
                  {
                      ItemsManager.AddToMenu(itemsMenu);
                  }
              }
  
              var drawMenu = Menu.AddSubMenu(new Menu("Drawings", "Drawings"));
              {
                  drawMenu.AddItem(new MenuItem("DrawE", "Draw E Range", true).SetValue(false));
                  ManaManager.AddDrawFarm(drawMenu);
                  //DamageIndicator.AddToMenu(drawMenu);
              }
  
              Obj_AI_Base.OnProcessSpellCast += OnProcessSpellCast;
              Game.OnUpdate += OnUpdate;
              Orbwalking.BeforeAttack += BeforeAttack;
              Orbwalking.AfterAttack += AfterAttack;
              Interrupter2.OnInterruptableTarget += OnInterruptableTarget;
              AntiGapcloser.OnEnemyGapcloser += OnEnemyGapcloser;
              GameObject.OnCreate += OnCreate;
              Drawing.OnDraw += OnDraw;
          }
  
          private void OnProcessSpellCast(Obj_AI_Base sender, GameObjectProcessSpellCastEventArgs Args)
          {
              if (sender == null || !sender.IsEnemy || !sender.IsMelee || sender.Type != Me.Type || Args.Target == null)
              {
                  return;
              }
  
              if (Args.Target.IsMe)
              {
                  if (Menu.GetBool("QMelee") && Q.IsReady())
                  {
                      Q.Cast(Me.Position.Extend(sender.Position, -Q.Range));
                  }
              }
          }
  
          private void OnUpdate(EventArgs args)
          {
              if (Me.IsDead || Me.IsRecalling())
              {
                  return;
              }
  
              AutoLogic();
  
              switch (Orbwalker.ActiveMode)
              {
                  case Orbwalking.OrbwalkingMode.Combo:
                      Combo();
                      break;
                  case Orbwalking.OrbwalkingMode.Mixed:
                      Harass();
                      break;
                  case Orbwalking.OrbwalkingMode.LaneClear:
                      FarmHarass();
                      LaneClear();
                      JungleClear();
                      break;
              }
          }
  
          private void AutoLogic()
          {
              if (Menu.GetBool("AutoE") && E.IsReady() && !Me.UnderTurret(true))
              {
                  if (Orbwalker.ActiveMode != Orbwalking.OrbwalkingMode.Combo)
                  {
                      foreach (
                          var target in
                          HeroManager.Enemies.Where(
                              x =>
                                  x.IsValidTarget(E.Range) && !x.HasBuffOfType(BuffType.SpellShield) &&
                                  Menu.GetBool("AutoE" + x.ChampionName.ToLower())))
                      {
                          if (target.Check(E.Range))
                          {
                              ELogic(target);
                          }
                      }
                  }
              }
  
              if (Menu.GetBool("AutoR") && R.IsReady() && 
                  Me.CountEnemiesInRange(Menu.GetSlider("AutoRRange")) >= Menu.GetSlider("AutoRCount"))
              {
                  R.Cast();
              }
          }
  
          private void Combo()
          {
              if (Me.Spellbook.IsAutoAttacking)
              {
                  return;             
              }
  
              if (Menu.GetBool("ComboR") && R.IsReady())
              {
                  if (Me.CountEnemiesInRange(800) >= Menu.GetSlider("ComboRCount"))
                  {
                      R.Cast();
                  }
  
                  if (Me.CountEnemiesInRange(600) >= 1 && Me.HealthPercent <= Menu.GetSlider("ComboRHp"))
                  {
                      R.Cast();
                  }
              }
  
              if (Menu.GetBool("ComboE") && E.IsReady())
              {
                  var target = TargetSelector.GetTarget(E.Range, TargetSelector.DamageType.Physical);
  
                  if (target.Check(E.Range))
                  {
                      ELogic(target);
                  }
              }
  
              if (Menu.GetBool("ComboQ") && Q.IsReady())
              {
                  var target = TargetSelector.GetTarget(800, TargetSelector.DamageType.Physical);
  
                  if (target.Check(800f))
                  {
                      if (Menu.GetBool("AQALogic") && Orbwalking.InAutoAttackRange(target))
                      {
                          return;
                      }
  
                      QLogic(target);
                  }
              }
          }
  
          private void Harass()
          {
              if (ManaManager.HasEnoughMana(Menu.GetSlider("HarassMana")))
              {
                  if (Menu.GetBool("HarassE") && E.IsReady())
                  {
                      var target = TargetSelector.GetTarget(E.Range, TargetSelector.DamageType.Physical);
  
                      if (target.Check(E.Range) && target.HasBuff("VayneSilveredDebuff") &&
                          target.GetBuffCount("VayneSilveredDebuff") == 2)
                      {
                          E.CastOnUnit(target);
                      }
                  }
  
                  if (Menu.GetBool("HarassQ") && Q.IsReady())
                  {
                      var target = TargetSelector.GetTarget(800f, TargetSelector.DamageType.Magical);
  
                      if (target.Check(800f))
                      {
                          QLogic(target);
                      }
                  }
              }
          }
  
          private void FarmHarass()
          {
              if (ManaManager.SpellHarass)
              {
                  Harass();
              }
          }
  
          private void LaneClear()
          {
              if (ManaManager.HasEnoughMana(Menu.GetSlider("LaneClearMana")) && ManaManager.SpellFarm)
              {
                  if (Menu.GetBool("LaneClearQ") && Q.IsReady())
                  {
                      var minions =
                          MinionManager.GetMinions(Me.Position, 700)
                              .Where(m => m.Health < Q.GetDamage(m) + Me.GetAutoAttackDamage(m));
  
                      var minion = minions.FirstOrDefault();
  
                      if (minion != null)
                      {
                          if (minion.Distance(Me.Position.Extend(Game.CursorPos, Q.Range)) <=
                              Orbwalking.GetRealAutoAttackRange(Me))
                          {
                              Q.Cast(Me.Position.Extend(Game.CursorPos, Q.Range));
                              Orbwalker.ForceTarget(minions.FirstOrDefault());
                          }
                      }
                  }
              }
          }
  
          private void JungleClear()
          {
              if (ManaManager.HasEnoughMana(Menu.GetSlider("JungleClearMana")) && ManaManager.SpellFarm)
              {
                  if (Menu.GetBool("JungleClearE") && E.IsReady())
                  {
                      var mob =
                          MinionManager.GetMinions(Me.Position, E.Range, MinionTypes.All, MinionTeam.Neutral,
                                  MinionOrderTypes.MaxHealth)
                              .FirstOrDefault(
                                  x =>
                                      !x.Name.ToLower().Contains("mini") && !x.Name.ToLower().Contains("baron") &&
                                      !x.Name.ToLower().Contains("dragon") && !x.Name.ToLower().Contains("crab") &&
                                      !x.Name.ToLower().Contains("herald"));
  
                      if (mob != null && mob.IsValidTarget(E.Range))
                      {
                          E.CastOnUnit(mob, true);
                      }
                  }
              }
          }
  
          private void BeforeAttack(Orbwalking.BeforeAttackEventArgs Args)
          {
  
gt:             if (Orbwalker.ActiveMode == Orbwalking.OrbwalkingMode.Combo ||