context: using EloBuddy; 
   using LeagueSharp.SDK; 
   namespace Valvrave_Sharp.Plugin
  {
      #region
  
      using System;
      using System.Collections.Generic;
      using System.Drawing;
      using System.Linq;
      using System.Windows.Forms;
  
      using LeagueSharp;
      using LeagueSharp.Data.Enumerations;
      using LeagueSharp.SDK;
      using LeagueSharp.SDK.Enumerations;
      using LeagueSharp.SDK.UI;
      using LeagueSharp.SDK.Utils;
  
      using Valvrave_Sharp.Core;
  
      using Menu = LeagueSharp.SDK.UI.Menu;
  
      #endregion
  
      internal class Kennen : Program
      {
          #region Static Fields
  
          private static readonly Items.Item Wooglet = new Items.Item(3090, 0);
  
          private static readonly Items.Item Zhonya = new Items.Item(3157, 0);
  
          private static bool haveE, haveR;
  
          #endregion
  
          #region Constructors and Destructors
  
          public Kennen()
          {
              Q = new Spell(SpellSlot.Q, 1050).SetSkillshot(0.19f, 50, 1700, true, SkillshotType.SkillshotLine);
              W = new Spell(SpellSlot.W, 800).SetTargetted(0.25f, float.MaxValue);
              E = new Spell(SpellSlot.E, 0);
              R = new Spell(SpellSlot.R, 550).SetTargetted(0.25f, float.MaxValue);
              Q.DamageType = W.DamageType = R.DamageType = DamageType.Magical;
              Q.MinHitChance = HitChance.VeryHigh;
  
              var comboMenu = MainMenu.Add(new Menu("Combo", "Combo"));
              {
                  comboMenu.Bool("Ignite", "Use Ignite");
                  comboMenu.Bool("Q", "Use Q");
                  comboMenu.Bool("W", "Use W");
                  comboMenu.Separator("R Settings");
                  comboMenu.Bool("R", "Use R");
                  comboMenu.Slider("RHpU", "If Enemies Hp < (%) And Hit >= 2", 60);
                  comboMenu.Slider("RCountA", "Or Count >=", 3, 1, 5);
                  comboMenu.Separator("Zhonya Settings For R Combo");
                  comboMenu.Bool("Zhonya", "Use Zhonya");
                  comboMenu.Slider("ZhonyaHpU", "If Hp < (%)", 20);
              }
              var hybridMenu = MainMenu.Add(new Menu("Hybrid", "Hybrid"));
              {
                  hybridMenu.Bool("Q", "Use Q");
                  hybridMenu.Separator("W Settings");
                  hybridMenu.Bool("W", "Use W");
                  hybridMenu.Slider("WMpA", "If Mp >=", 100, 0, 200);
                  hybridMenu.Separator("Auto Q Settings");
                  hybridMenu.KeyBind("AutoQ", "KeyBind", Keys.T, KeyBindType.Toggle);
                  hybridMenu.Slider("AutoQMpA", "If Mp >=", 100, 0, 200);
              }
              var lhMenu = MainMenu.Add(new Menu("LastHit", "Last Hit"));
              {
                  lhMenu.Bool("Q", "Use Q");
              }
              var ksMenu = MainMenu.Add(new Menu("KillSteal", "Kill Steal"));
              {
                  ksMenu.Bool("Q", "Use Q");
                  ksMenu.Bool("W", "Use W");
              }
              var drawMenu = MainMenu.Add(new Menu("Draw", "Draw"));
              {
                  drawMenu.Bool("Q", "Q Range", false);
                  drawMenu.Bool("W", "W Range", false);
                  drawMenu.Bool("R", "R Range", false);
              }
              MainMenu.KeyBind("FleeE", "Use E To Flee", Keys.C);
  
              Game.OnUpdate += OnUpdate;
              Drawing.OnEndScene += OnEndScene;
              Obj_AI_Base.OnBuffGain += (sender, args) =>
                  {
                      if (!sender.IsMe)
                      {
                          return;
                      }
                      switch (args.Buff.DisplayName)
                      {
                          case "KennenLightningRush":
                              haveE = true;
                              break;
                          case "KennenShurikenStorm":
                              haveR = true;
                              break;
                      }
                  };
              Obj_AI_Base.OnBuffLose += (sender, args) =>
                  {
                      if (!sender.IsMe)
                      {
                          return;
                      }
                      switch (args.Buff.DisplayName)
                      {
                          case "KennenLightningRush":
                              haveE = false;
                              break;
                          case "KennenShurikenStorm":
                              haveR = false;
                              break;
                      }
                  };
          }
  
          #endregion
  
          #region Properties
  
          private static List<AIHeroClient> GetWTarget
              =>
                  Variables.TargetSelector.GetTargets(W.Range, W.DamageType)
                      .Where(i => HaveW(i) && W.CanHitCircle(i))
                      .ToList();
  
          #endregion
  
          #region Methods
  
          private static void AutoQ()
          {
              if (!Q.IsReady() || !MainMenu["Hybrid"]["AutoQ"].GetValue<MenuKeyBind>().Active
                  || Player.Mana < MainMenu["Hybrid"]["AutoQMpA"])
              {
                  return;
              }
              Q.CastingBestTarget();
          }
  
          private static void Combo()
          {
              if (MainMenu["Combo"]["R"])
              {
                  if (R.IsReady())
                  {
                      var target =
                          Variables.TargetSelector.GetTargets(R.Range + 50, R.DamageType)
                              .Where(i => R.CanHitCircle(i))
                              .ToList();
                      if (target.Count > 0
                          && ((target.Count > 1 && target.Any(i => i.Health + i.MagicShield <= R.GetDamage(i)))
                              || (target.Count > 1
                                  && target.Sum(i => i.HealthPercent) / target.Count <= MainMenu["Combo"]["RHpU"])
                              || target.Count >= MainMenu["Combo"]["RCountA"]) && R.Cast())
                      {
                          return;
                      }
                  }
                  else if (haveR && MainMenu["Combo"]["Zhonya"] && Player.HealthPercent < MainMenu["Combo"]["ZhonyaHpU"]
                           && Player.CountEnemyHeroesInRange(W.Range) > 0)
                  {
                      if (Zhonya.IsReady)
                      {
                          Zhonya.Cast();
                      }
                      if (Wooglet.IsReady)
                      {
                          Wooglet.Cast();
                      }
                  }
              }
              if (MainMenu["Combo"]["Q"] && Q.CastingBestTarget().IsCasted())
              {
                  return;
              }
              if (MainMenu["Combo"]["W"] && W.IsReady())
              {
                  var target = GetWTarget;
                  if (target.Count > 0)
                  {
                      if (haveR)
                      {
                          if ((target.Count(i => HaveW(i, true)) > 1
                               || target.Any(i => i.Health + i.MagicShield <= W.GetDamage(i, DamageStage.Empowered))
                               || target.Count > 2 || (target.Count(i => HaveW(i, true)) > 0 && target.Count > 1))
                              && W.Cast())
                          {
                              return;
                          }
                      }
                      else if (W.Cast())
                      {
                          return;
                      }
                  }
              }
              var subTarget = W.GetTarget();
              if (subTarget != null && MainMenu["Combo"]["Ignite"] && Common.CanIgnite && subTarget.HealthPercent < 30
                  && subTarget.DistanceToPlayer() <= IgniteRange)
              {
                  Player.Spellbook.CastSpell(Ignite, subTarget);
              }
          }
  
          private static bool HaveW(Obj_AI_Base target, bool checkCanStun = false)
          {
              var buff = target.GetBuffCount("KennenMarkOfStorm");
              return buff > 0 && (!checkCanStun || buff == 2);
          }
  
          private static void Hybrid()
          {
  
gt:             if (MainMenu["Hybrid"]["Q"] && Q.CastingBestTarget().IsCasted())