context: using System;
  using System.Linq;
  using LeagueSharp;
  using LeagueSharp.Common;
  using SharpDX;
  using SebbyLib;
  
  using EloBuddy; 
   using LeagueSharp.Common; 
   namespace OneKeyToWin_AIO_Sebby.Champions
  {
      class Brand : Base
      {
          public Brand()
          {
              Q = new Spell(SpellSlot.Q, 1000);
              W = new Spell(SpellSlot.W, 940);
              E = new Spell(SpellSlot.E, 625);
              R = new Spell(SpellSlot.R, 750);
  
              Q.SetSkillshot(0.25f, 60f, 1600f, true, SkillshotType.SkillshotLine);
              W.SetSkillshot(1.15f, 230f, float.MaxValue, false, SkillshotType.SkillshotCircle);
              R.SetTargetted(0.25f, 2000f);
  
              Config.SubMenu(Player.ChampionName).SubMenu("Draw").AddItem(new MenuItem("noti", "Show notification & line", true).SetValue(true));
              Config.SubMenu(Player.ChampionName).SubMenu("Draw").AddItem(new MenuItem("onlyRdy", "Draw only ready spells", true).SetValue(true));
              Config.SubMenu(Player.ChampionName).SubMenu("Draw").AddItem(new MenuItem("qRange", "Q range", true).SetValue(false));
              Config.SubMenu(Player.ChampionName).SubMenu("Draw").AddItem(new MenuItem("wRange", "W range", true).SetValue(false));
              Config.SubMenu(Player.ChampionName).SubMenu("Draw").AddItem(new MenuItem("eRange", "E range", true).SetValue(false));
              Config.SubMenu(Player.ChampionName).SubMenu("Draw").AddItem(new MenuItem("rRange", "R range", true).SetValue(false));
  
              Config.SubMenu(Player.ChampionName).SubMenu("Q Config").AddItem(new MenuItem("autoQ", "Auto Q", true).SetValue(true));
              Config.SubMenu(Player.ChampionName).SubMenu("Q Config").AddItem(new MenuItem("QAblazed", "Q only if ablazed", true).SetValue(true));
              Config.SubMenu(Player.ChampionName).SubMenu("Q Config").AddItem(new MenuItem("harassQ", "Harass Q", true).SetValue(true));
  
              Config.SubMenu(Player.ChampionName).SubMenu("Q Config").AddItem(new MenuItem("gapQ", "Gapcloser E + Q", true).SetValue(true));
              Config.SubMenu(Player.ChampionName).SubMenu("Q Config").AddItem(new MenuItem("intQ", "Interrupt spells E + Q", true).SetValue(true));
  
              Config.SubMenu(Player.ChampionName).SubMenu("W Config").AddItem(new MenuItem("autoW", "Auto W", true).SetValue(true));
              Config.SubMenu(Player.ChampionName).SubMenu("W Config").AddItem(new MenuItem("harassW", "Harass W", true).SetValue(true));
  
              Config.SubMenu(Player.ChampionName).SubMenu("E Config").AddItem(new MenuItem("autoE", "Auto E", true).SetValue(true));
              Config.SubMenu(Player.ChampionName).SubMenu("E Config").AddItem(new MenuItem("harassE", "Harass E", true).SetValue(true));
              Config.SubMenu(Player.ChampionName).SubMenu("E Config").AddItem(new MenuItem("minionE", "use E on ablazed minion", true).SetValue(true));
  
              Config.SubMenu(Player.ChampionName).SubMenu("R Config").AddItem(new MenuItem("autoR", "Auto R", true).SetValue(true));
              Config.SubMenu(Player.ChampionName).SubMenu("R Config").AddItem(new MenuItem("rCount", "Auto R if can hit x enemies", true).SetValue(new Slider(3, 0, 5)));
  
              Config.SubMenu(Player.ChampionName).SubMenu("Farm").AddItem(new MenuItem("farmE", "Lane clear E", true).SetValue(true));
              Config.SubMenu(Player.ChampionName).SubMenu("Farm").AddItem(new MenuItem("farmW", "Lane clear W", true).SetValue(true));
              Config.SubMenu(Player.ChampionName).SubMenu("Farm").AddItem(new MenuItem("jungleE", "Jungle clear E", true).SetValue(true));
              Config.SubMenu(Player.ChampionName).SubMenu("Farm").AddItem(new MenuItem("jungleQ", "Jungle clear Q", true).SetValue(true));
              Config.SubMenu(Player.ChampionName).SubMenu("Farm").AddItem(new MenuItem("jungleW", "Jungle clear W", true).SetValue(true));
  
              Game.OnUpdate += Game_OnGameUpdate;
              Drawing.OnDraw += Drawing_OnDraw;
              Interrupter2.OnInterruptableTarget += Interrupter2_OnInterruptableTarget;
              AntiGapcloser.OnEnemyGapcloser += AntiGapcloser_OnEnemyGapcloser;
          }
  
          private void AntiGapcloser_OnEnemyGapcloser(ActiveGapcloser gapcloser)
          {
              if (!Config.Item("gapQ", true).GetValue<bool>() || Player.Mana <  QMANA + EMANA)
                  return;
  
              var t = gapcloser.Sender;
  
              if ( t.IsValidTarget(E.Range) && (t.HasBuff("brandablaze") || E.IsReady()))
              {
  
                  E.CastOnUnit(t);
                  if (Q.IsReady())
                      Q.Cast(t);
              }
          }
  
          private void Interrupter2_OnInterruptableTarget(AIHeroClient t, Interrupter2.InterruptableTargetEventArgs args)
          {
              if (!Config.Item("intQ", true).GetValue<bool>() || Player.Mana < QMANA + EMANA)
                  return;
  
              if (t.IsValidTarget(E.Range) && (t.HasBuff("brandablaze") || E.IsReady()))
              { 
                  E.CastOnUnit(t);
                  if (Q.IsReady())
                      Q.Cast(t);
              }
          }
  
          private void Game_OnGameUpdate(EventArgs args)
          {
              if (Program.Combo)
              {
                  if (!E.IsReady())
                      SebbyLib.Orbwalking.Attack = true;
  
                  else
                      SebbyLib.Orbwalking.Attack = false;
              }
              else
                  SebbyLib.Orbwalking.Attack = true;
  
              if (Program.LagFree(0))
              {
                  SetMana();
                  Jungle();
              }
  
              if (Program.LagFree(1) && E.IsReady() && Config.Item("autoE", true).GetValue<bool>())
                  LogicE();
              if (Program.LagFree(2) && Q.IsReady() && Config.Item("autoQ", true).GetValue<bool>())
                  LogicQ();
              if (Program.LagFree(3) && W.IsReady()  && Config.Item("autoW", true).GetValue<bool>())
                  LogicW();
              if (Program.LagFree(4) && R.IsReady() && Config.Item("autoR", true).GetValue<bool>())
                  LogicR();
          }
  
          private void LogicQ()
          {
              var t = TargetSelector.GetTarget(Q.Range, TargetSelector.DamageType.Physical);
              if (t.IsValidTarget())
              {
                  if (OktwCommon.GetKsDamage(t, Q) + BonusDmg(t) + OktwCommon.GetEchoLudenDamage(t) > t.Health)
                      Program.CastSpell(Q, t);
  
                  if (!t.HasBuff("brandablaze") && Config.Item("QAblazed", true).GetValue<bool>())
                  {
                      var otherEnemy = t;
  
                      foreach (var enemy in HeroManager.Enemies.Where(enemy => enemy.IsValidTarget(Q.Range) && enemy.HasBuff("brandablaze")))
                          t = enemy;
  
                      if (otherEnemy == t && !LogicQuse(t))
                          return;
                  }
  
                  if(Program.Combo && Player.Mana > RMANA + QMANA )
                      Program.CastSpell(Q, t);
                  else if (Program.Harass && Config.Item("harassQ", true).GetValue<bool>()  && Player.Mana > RMANA + EMANA + WMANA + EMANA && Config.Item("Harass" + t.ChampionName).GetValue<bool>())
                      Program.CastSpell(Q, t);
  
                  if (Player.Mana > RMANA + QMANA)
                  {
                      foreach (var enemy in HeroManager.Enemies.Where(enemy => enemy.IsValidTarget(Q.Range) && !OktwCommon.CanMove(enemy)))
                          Q.Cast(enemy);
                  }
              }
          }
  
          private bool LogicQuse(Obj_AI_Base t)
          {
              if (t.HasBuff("brandablaze"))
                  return true;
              else if (E.Instance.CooldownExpires - Game.Time + 2 >= Q.Instance.Cooldown && W.Instance.CooldownExpires - Game.Time + 2 >= Q.Instance.Cooldown)
                  return true;
              else
                  return false;
          }
  
          private void LogicW()
          {
              var t = TargetSelector.GetTarget(W.Range, TargetSelector.DamageType.Physical);
              if (t.IsValidTarget())
              {
                  if (Program.Combo && Player.Mana > RMANA + WMANA)
                      Program.CastSpell(W, t);
                  else if (Program.Harass && Config.Item("harassW", true).GetValue<bool>() && Config.Item("Harass" + t.ChampionName).GetValue<bool>()  && Player.Mana > RMANA + WMANA + EMANA + QMANA + WMANA && OktwCommon.CanHarras())
                      Program.CastSpell(W, t);
                  else
                  {
                      var qDmg = Q.GetDamage(t);
                      var wDmg = OktwCommon.GetKsDamage(t, W) + BonusDmg(t);
                      if (wDmg > t.Health)
                      {
                          Program.CastSpell(W, t);
                      }
                      else if (wDmg + qDmg > t.Health && Player.Mana > QMANA + EMANA)
                          Program.CastSpell(W, t);
                  }
  
                  if (Player.Mana > RMANA + WMANA)
                  {
                      foreach (var enemy in HeroManager.Enemies.Where(enemy => enemy.IsValidTarget(W.Range) && !OktwCommon.CanMove(enemy)))
                          W.Cast(enemy, true);
                  }
              }
              else if (FarmSpells && Config.Item("farmW", true).GetValue<bool>())
              {
                  var allMinions = Cache.GetMinions(Player.ServerPosition, W.Range);
                  var farmPos = W.GetCircularFarmLocation(allMinions, W.Width);
                  if (farmPos.MinionsHit >= FarmMinions)
                      W.Cast(farmPos.Position);
              }
          }
  
          private void LogicE()
          {
              var t = TargetSelector.GetTarget(E.Range, TargetSelector.DamageType.Physical);
              if (t.IsValidTarget())
              {
                  if (Program.Combo && Player.Mana > RMANA + EMANA)
                      E.CastOnUnit(t);
                  else if (Program.Harass && Config.Item("harassE", true).GetValue<bool>() && Player.Mana > RMANA + EMANA + WMANA + EMANA && Config.Item("Harass" + t.ChampionName).GetValue<bool>())
                      E.CastOnUnit(t);
                  else
                  {
                      var eDmg = OktwCommon.GetKsDamage(t, E) + BonusDmg(t) + OktwCommon.GetEchoLudenDamage(t);
                      var wDmg = W.GetDamage(t);
                      if (eDmg > t.Health)
                          E.CastOnUnit(t);
  
gt:                     else if (wDmg + eDmg > t.Health && Player.Mana > WMANA + EMANA)