context: using System;
  using System.Collections.Generic;
  using System.Linq;
  using LeagueSharp;
  using LeagueSharp.Common;
  using SharpDX;
  using SebbyLib;
  
  using EloBuddy; 
  using LeagueSharp.Common; 
  namespace OneKeyToWin_AIO_Sebby.Champions
  {
      class Velkoz : Base
      {
          private Spell  QSplit, QDummy;
          private MissileClient QMissile = null;
          private List<Vector3> pointList;
  
          public Velkoz()
          {
              Q = new Spell(SpellSlot.Q, 1180);
              QSplit = new Spell(SpellSlot.Q, 1000);
              QDummy = new Spell(SpellSlot.Q, (float)Math.Sqrt(Math.Pow(Q.Range, 2) + Math.Pow(QSplit.Range, 2)));
              W = new Spell(SpellSlot.W, 1000);
              E = new Spell(SpellSlot.E, 800);
              R = new Spell(SpellSlot.R, 1500);
  
              Q.SetSkillshot(0.25f, 70f, 1300f, true, SkillshotType.SkillshotLine);
              QSplit.SetSkillshot(0.1f, 70f, 2100f, true, SkillshotType.SkillshotLine);
              QDummy.SetSkillshot(0.5f, 55f, 1200, false, SkillshotType.SkillshotLine);
              W.SetSkillshot(0.25f, 85f, 1700f, false, SkillshotType.SkillshotLine);
              E.SetSkillshot(1f, 180f, float.MaxValue, false, SkillshotType.SkillshotCircle);
              R.SetSkillshot(0.1f, 80f, float.MaxValue, false, SkillshotType.SkillshotLine);
  
              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("Draw").AddItem(new MenuItem("onlyRdy", "Draw when skill rdy", true).SetValue(true));
  
              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("harassQ", "Harass Q", true).SetValue(true));
              Config.SubMenu(Player.ChampionName).SubMenu("Q Config").AddItem(new MenuItem("QHarassMana", "Harass Mana", true).SetValue(new Slider(30, 100, 0)));
  
              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(false));
              Config.SubMenu(Player.ChampionName).SubMenu("E Config").AddItem(new MenuItem("EInterrupter", "Auto E Interrupter", true).SetValue(true));
              Config.SubMenu(Player.ChampionName).SubMenu("E Config").SubMenu("E Gap Closer").AddItem(new MenuItem("EmodeGC", "Gap Closer position mode", true).SetValue(new StringList(new[] { "Dash end position", "Player position", "Prediction" }, 0)));
              foreach (var enemy in HeroManager.Enemies)
                  Config.SubMenu(Player.ChampionName).SubMenu("E Config").SubMenu("E Gap Closer").SubMenu("Cast on enemy:").AddItem(new MenuItem("EGCchampion" + enemy.ChampionName, enemy.ChampionName, true).SetValue(true));
  
              Config.SubMenu(Player.ChampionName).SubMenu("R Config").AddItem(new MenuItem("autoR", "Auto R KS", true).SetValue(true));
  
              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("jungleQ", "Jungle clear Q", true).SetValue(true));
              Config.SubMenu(Player.ChampionName).SubMenu("Farm").AddItem(new MenuItem("jungleW", "Jungle clear W", true).SetValue(true));
              Config.SubMenu(Player.ChampionName).SubMenu("Farm").AddItem(new MenuItem("jungleE", "Jungle clear E", true).SetValue(true));
  
              Game.OnUpdate += Game_OnGameUpdate;
              GameObject.OnCreate += Obj_AI_Base_OnCreate;
              Drawing.OnDraw += Drawing_OnDraw;
              Interrupter2.OnInterruptableTarget += Interrupter2_OnInterruptableTarget;
              AntiGapcloser.OnEnemyGapcloser += AntiGapcloser_OnEnemyGapcloser;
          }
  
          private void AntiGapcloser_OnEnemyGapcloser(ActiveGapcloser gapcloser)
          {
              var t = gapcloser.Sender;
              if (E.IsReady() && t.IsValidTarget(E.Range) && Config.Item("EGCchampion" + t.ChampionName, true).GetValue<bool>())
              {
                  if (Config.Item("EmodeGC", true).GetValue<StringList>().SelectedIndex == 0)
                      E.Cast(gapcloser.End);
                  else if (Config.Item("EmodeGC", true).GetValue<StringList>().SelectedIndex == 1)
                      E.Cast(Player.Position);
                  else
                      E.Cast(t.ServerPosition);
              }
          }
  
          private void Interrupter2_OnInterruptableTarget(AIHeroClient sender, Interrupter2.InterruptableTargetEventArgs args)
          {
              if (E.IsReady() && sender.IsValidTarget(E.Range) && Config.Item("EInterrupter", true).GetValue<bool>())
              {
                  E.Cast(sender);
              }
          }
  
          private void Obj_AI_Base_OnCreate(GameObject sender, EventArgs args)
          {
              if (sender.IsValid<MissileClient>() && sender.IsAlly)
              {
                  MissileClient missile = (MissileClient)sender;
                  if (missile.SData.Name != null && missile.SData.Name == "VelkozQMissile")
                      QMissile = missile;
              }
          }
  
          private void Game_OnGameUpdate(EventArgs args)
          {
              if (Player.IsChannelingImportantSpell())
              {
                  if (Config.Item("autoR", true).GetValue<bool>())
                  {
                      var t = TargetSelector.GetTarget(R.Range + 150, TargetSelector.DamageType.Magical);
                      if (t.IsValidTarget() && OktwCommon.ValidUlt(t))
                      {
                          ObjectManager.Player.Spellbook.UpdateChargeableSpell(SpellSlot.R, R.GetPrediction(t, true).CastPosition, false, false);
                      }
                  }
                  OktwCommon.blockMove = true;
                  OktwCommon.blockAttack = true;
                  SebbyLib.Orbwalking.Attack = false;
                  SebbyLib.Orbwalking.Move = false;
              }
              else 
              {
                  if (R.IsReady() && Config.Item("autoR", true).GetValue<bool>())
                      LogicR();
                  OktwCommon.blockMove = false;
                  OktwCommon.blockAttack = false;
                  SebbyLib.Orbwalking.Attack = true;
                  SebbyLib.Orbwalking.Move = true;
              }
  
              if (Program.LagFree(4))
              {
                  //R.Cast(Game.CursorPos);
              }
  
              if (Program.LagFree(0))
              {
                  SetMana();
                  Jungle();
              }
  
              if (Q.IsReady() && Config.Item("autoQ", true).GetValue<bool>())
                  LogicQ();
  
              if (Program.LagFree(3) && E.IsReady() && Config.Item("autoE", true).GetValue<bool>())
                  LogicE();
  
              if (Program.LagFree(4))
              {
                  if(W.IsReady() && Config.Item("autoW", true).GetValue<bool>())
                      LogicW();
                  
              }
          }
  
          private void LogicR()
          {
              var t = TargetSelector.GetTarget(R.Range, TargetSelector.DamageType.Magical);
              if (t.IsValidTarget()  && Player.CountEnemiesInRange(400) == 0 && !Player.UnderTurret(true))
              {
                  //900 - 100%
                  //1500 - 10 %
                  var rDmg = OktwCommon.GetKsDamage(t, R);
                  var distance = Player.Distance(t);
  
                  if (distance > 900 && OktwCommon.CanMove(t))
                  {
                      float adjust = (R.Range - distance) / 600;
                      rDmg = rDmg * adjust;
                  }
  
                  if(rDmg > t.Health && OktwCommon.ValidUlt(t))
                  {
                      R.Cast(t);
                  }
              }
          }
  
          private void LogicE()
          {
              var t = TargetSelector.GetTarget(E.Range, TargetSelector.DamageType.Magical);
              if (t.IsValidTarget())
              {
                  if (Program.Combo && Player.Mana > RMANA + EMANA)
                      Program.CastSpell(E, t);
                  else if (Program.Harass && OktwCommon.CanHarras() && Config.Item("harassE", true).GetValue<bool>() && Config.Item("Harass" + t.ChampionName).GetValue<bool>() && Player.Mana > RMANA + EMANA + WMANA + EMANA)
                      Program.CastSpell(E, t);
                  else
                  {
                      var eDmg = OktwCommon.GetKsDamage(t, E);
                      var qDmg = Q.GetDamage(t);
                      if (qDmg + eDmg > t.Health)
                      {
                          if(eDmg > t.Health)
                              Program.CastSpell(E, t);
                          else if (Player.Mana > QMANA + EMANA)
                              Program.CastSpell(E, t);
                          return;
                      }
                  }
                  if (!Program.None && Player.Mana > RMANA + EMANA)
                  {
                      foreach (var enemy in HeroManager.Enemies.Where(enemy => enemy.IsValidTarget(E.Range) && !OktwCommon.CanMove(enemy)))
                          E.Cast(enemy);
                  }
              }
              else if (FarmSpells && Config.Item("farmE", true).GetValue<bool>())
              {
                  var minionList = Cache.GetMinions(Player.ServerPosition, E.Range);
                  var farmPosition = E.GetCircularFarmLocation(minionList, E.Width);
  
                  if (farmPosition.MinionsHit >= FarmMinions)
                      E.Cast(farmPosition.Position);
              }
          }
  
          private void LogicW()
          {
              var t = TargetSelector.GetTarget(W.Range, TargetSelector.DamageType.Magical);
              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 wDmg = OktwCommon.GetKsDamage(t, W);
                      var qDmg = Q.GetDamage(t);
                      if (wDmg > t.Health)
                          Program.CastSpell(W, t);
                      else if (qDmg + wDmg > t.Health && Player.Mana > QMANA + WMANA)
                          Program.CastSpell(W, t);
                  }
                  if (!Program.None && 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 minionList = Cache.GetMinions(Player.ServerPosition, W.Range);
                  var farmPosition = W.GetLineFarmLocation(minionList, W.Width);
  
                  if (farmPosition.MinionsHit >= FarmMinions)
                      W.Cast(farmPosition.Position);
              }
          }
  
          private void LogicQ()
          {
              var t = TargetSelector.GetTarget(QDummy.Range, TargetSelector.DamageType.Magical);
              if (t.IsValidTarget())
              {
                  if (Q.Instance.Name == "VelkozQ" && Utils.TickCount - Q.LastCastAttemptT > 150)
                  {
                      if (Program.LagFree(1) || Program.LagFree(2))
                      {
                          QSplit.Collision = true;
                          if (Program.Combo && Player.Mana > RMANA + QMANA )
                              CastQ(t);
                          else if (Program.Harass && OktwCommon.CanHarras() && Config.Item("harassQ", true).GetValue<bool>() && Config.Item("Harass" + t.ChampionName).GetValue<bool>() && Player.ManaPercent > Config.Item("QHarassMana", true).GetValue<Slider>().Value)
                              CastQ(t);
                          else
                          {
                              var qDmg = OktwCommon.GetKsDamage(t, Q);
                              var wDmg = W.GetDamage(t);
                              if (qDmg > t.Health )
                                  CastQ(t);
                              else if(qDmg + wDmg > t.Health && Player.Mana > QMANA + WMANA)
                                  CastQ(t);
                          }
                          if (!Program.None && Player.Mana > RMANA + QMANA)
                          {
  
                              foreach (var enemy in HeroManager.Enemies.Where(enemy => enemy.IsValidTarget(QDummy.Range) && !OktwCommon.CanMove(enemy)))
                                  CastQ(t);
                          }
                      }
                  }
                  else
                  {
                      DetonateQ(t);
                  }
              }
          }
  
          private void CastQ(Obj_AI_Base t)
          {
              var Qpred = Q.GetPrediction(t);
              if (Qpred.Hitchance >= HitChance.High)
              {
                  Program.CastSpell(Q, t);
              }
              else
              {
                  var pred = QDummy.GetPrediction(t);
                  if (pred.Hitchance >= HitChance.High)
                  {
                      if (Program.LagFree(1))
                          pointList = AimQ(pred.CastPosition);
                      if (Program.LagFree(2))
                          BestAim(pred.CastPosition);
                  }
              }
          }
  
          private void DetonateQ(Obj_AI_Base t)
          {
  
gt:             if (QMissile != null && QMissile.IsValid)