context: using EloBuddy; 
   using LeagueSharp.Common; 
   namespace Flowers_ADC_Series.Pluging
  {
      using Common;
      using System;
      using System.Linq;
      using LeagueSharp;
      using LeagueSharp.Common;
      using SharpDX;
      using Color = System.Drawing.Color;
      using Orbwalking = Orbwalking;
      using static Common.Common;
  
      internal class Graves : Program
      {
          private readonly float SearchERange;
          private new readonly Menu Menu = Championmenu;
  
          public Graves()
          {
              Q = new Spell(SpellSlot.Q, 800f);
              W = new Spell(SpellSlot.W, 900f);
              E = new Spell(SpellSlot.E, 425f);
              R = new Spell(SpellSlot.R, 1050f);
  
              Q.SetSkillshot(0.25f, 40f, 3000f, false, SkillshotType.SkillshotLine);
              W.SetSkillshot(0.25f, 250f, 1000f, false, SkillshotType.SkillshotCircle);
              R.SetSkillshot(0.25f, 100f, 2100f, false, SkillshotType.SkillshotLine);
  
              SearchERange = E.Range + Orbwalking.GetRealAutoAttackRange(Me) - 100;
  
              var ComboMenu = Menu.AddSubMenu(new Menu("Combo", "Combo"));
              {
                  ComboMenu.AddItem(new MenuItem("ComboQ", "Use Q", true).SetValue(true));
                  ComboMenu.AddItem(new MenuItem("ComboW", "Use W", true).SetValue(true));
                  ComboMenu.AddItem(new MenuItem("ComboE", "Use E", true).SetValue(true));
                  ComboMenu.AddItem(new MenuItem("ComboECheck", "Use E| Safe Check", true).SetValue(true));
                  ComboMenu.AddItem(new MenuItem("ComboR", "Use R", true).SetValue(false));
                  ComboMenu.AddItem(
                      new MenuItem("ComboRCount", "Use R| Min Hit Count >= x", true).SetValue(new Slider(4, 1, 5)));
              }
  
              var HarassMenu = Menu.AddSubMenu(new Menu("Harass", "Harass"));
              {
                  HarassMenu.AddItem(new MenuItem("HarassQ", "Use Q", true).SetValue(true));
                  HarassMenu.AddItem(
                      new MenuItem("HarassMana", "When Player ManaPercent >= x%", true).SetValue(new Slider(60)));
              }
  
              var LaneClearMenu = Menu.AddSubMenu(new Menu("LaneClear", "LaneClear"));
              {
                  LaneClearMenu.AddItem(new MenuItem("LaneClearQ", "Use Q", true).SetValue(true));
                  LaneClearMenu.AddItem(
                      new MenuItem("LaneClearQCount", "Use Q| Min Hit Count >= x", true).SetValue(new Slider(3, 1, 5)));
                  LaneClearMenu.AddItem(
                      new MenuItem("LaneClearMana", "When Player ManaPercent >= x%", true).SetValue(new Slider(60)));
              }
  
              var JungleClearMenu = Menu.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(20)));
              }
  
              var KillStealMenu = Menu.AddSubMenu(new Menu("KillSteal", "KillSteal"));
              {
                  KillStealMenu.AddItem(new MenuItem("KillStealQ", "KillSteal Q", true).SetValue(true));
                  KillStealMenu.AddItem(new MenuItem("KillStealW", "KillSteal W", true).SetValue(true));
                  KillStealMenu.AddItem(new MenuItem("KillStealR", "KillSteal R", true).SetValue(true));
                  foreach (var target in HeroManager.Enemies)
                  {
                      KillStealMenu.AddItem(new MenuItem("KillStealR" + target.ChampionName.ToLower(),
                          "Kill: " + target.ChampionName, true).SetValue(true));
                  }
              }
  
              var MiscMenu = Menu.AddSubMenu(new Menu("Misc", "Misc"));
              {
                  MiscMenu.AddItem(new MenuItem("GapW", "Use W| Anti GapCloser", true).SetValue(true));
              }
  
              var DrawMenu = Menu.AddSubMenu(new Menu("Drawings", "Drawings"));
              {
                  DrawMenu.AddItem(new MenuItem("DrawQ", "Draw Q Range", true).SetValue(false));
                  DrawMenu.AddItem(new MenuItem("DrawW", "Draw W Range", true).SetValue(false));
                  DrawMenu.AddItem(new MenuItem("DrawE", "Draw E Range", true).SetValue(false));
                  DrawMenu.AddItem(new MenuItem("DrawR", "Draw R Range", true).SetValue(false));
                  DrawMenu.AddItem(new MenuItem("DrawDamage", "Draw ComboDamage", true).SetValue(true));
              }
  
              Game.OnUpdate += OnUpdate;
              Obj_AI_Base.OnSpellCast += OnSpellCast;
              AntiGapcloser.OnEnemyGapcloser += OnEnemyGapcloser;
              Drawing.OnDraw += OnDraw;
          }
  
          private void OnUpdate(EventArgs Args)
          {
              if (Me.IsDead)
              {
                  return;
              }
  
              KillSteal();
  
              switch (Orbwalker.ActiveMode)
              {
                  case Orbwalking.OrbwalkingMode.Combo:
                      Combo();
                      break;
                  case Orbwalking.OrbwalkingMode.Mixed:
                      Harass();
                      break;
                  case Orbwalking.OrbwalkingMode.LaneClear:
                      LaneClear();
                      JungleClear();
                      break;
              }
          }
  
          private void KillSteal()
          {
              if (Menu.Item("KillStealQ", true).GetValue<bool>() && Q.IsReady())
              {
                  foreach (
                      var target in
                      HeroManager.Enemies.Where(
                          x => x.IsValidTarget(Q.Range) && CheckTargetSureCanKill(x) && x.Health < Q.GetDamage(x)))
                  {
                      Q.CastTo(target);
                  }
              }
  
              if (Menu.Item("KillStealW", true).GetValue<bool>() && W.IsReady())
              {
                  foreach (
                      var target in
                      HeroManager.Enemies.Where(
                          x => x.IsValidTarget(W.Range) && CheckTargetSureCanKill(x) && x.Health < W.GetDamage(x)))
                  {
                      W.CastTo(target);
                  }
              }
  
              if (Menu.Item("KillStealR", true).GetValue<bool>() && R.IsReady())
              {
                  foreach (
                      var target in
                      HeroManager.Enemies.Where(
                          x => x.IsValidTarget(R.Range) && CheckTargetSureCanKill(x) && 
                          Menu.Item("KillStealR" + x.ChampionName.ToLower(), true).GetValue<bool>()
                          && x.Health < R.GetDamage(x) &&
                          x.DistanceToPlayer() > Orbwalking.GetRealAutoAttackRange(Me) + 100))
                  {
                      R.CastTo(target);
                  }
              }
          }
  
          private void Combo()
          {
              var target = TargetSelector.GetTarget(R.Range, TargetSelector.DamageType.Physical);
  
              if (CheckTarget(target, R.Range))
              {
                  if (Menu.Item("ComboQ", true).GetValue<bool>() && Q.IsReady() && target.IsValidTarget(Q.Range))
                  {
                      Q.CastTo(target);
                  }
  
                  if (Menu.Item("ComboE", true).GetValue<bool>() && E.IsReady() && target.IsValidTarget(SearchERange))
                  {
                      if (CanCaseE(target, Game.CursorPos))
                      {
                          E.Cast(Game.CursorPos);
                      }
                  }
  
                  if (Menu.Item("ComboW", true).GetValue<bool>() && W.IsReady() && target.IsValidTarget(W.Range))
                  {
                      W.CastTo(target);
                  }
  
                  if (Menu.Item("ComboR", true).GetValue<bool>() && R.IsReady() && !Q.IsReady() 
                      && target.IsValidTarget(R.Range))
                  {
                      R.CastIfWillHit(target, Menu.Item("ComboRCount", true).GetValue<Slider>().Value);
                  }
              }
          }
  
          private void Harass()
          {
              if (Me.UnderTurret(true))
              {
                  return;
              }
  
              if (Me.ManaPercent >= Menu.Item("HarassMana", true).GetValue<Slider>().Value)
              {
                  var target = TargetSelector.GetTarget(Q.Range, TargetSelector.DamageType.Magical);
  
                  if (Menu.Item("HarassQ", true).GetValue<bool>() && Q.IsReady() && CheckTarget(target, Q.Range))
                  {
                      Q.CastTo(target);
                  }
              }
          }
  
          private void LaneClear()
          {
              if (Me.ManaPercent >= Menu.Item("LaneClearMana", true).GetValue<Slider>().Value)
              {
                  if (Menu.Item("LaneClearQ", true).GetValue<bool>() && Q.IsReady())
                  {
                      var Minions = MinionManager.GetMinions(Me.Position, Q.Range);
  
                      if (Minions.Any())
                      {
  
gt:                         var QFarm = Q.GetLineFarmLocation(Minions);