context: #region
  
  using System;
  using System.Collections.Generic;
  using System.Drawing;
  using System.Linq;
  using LeagueSharp;
  using LeagueSharp.Common;
  
  using Marksman.Utils;
  using SharpDX;
  using Color = System.Drawing.Color;
  
  
  #endregion
  
  using EloBuddy; 
   using LeagueSharp.Common; 
   namespace Marksman.Champions
  {
      internal class Corki : Champion
      {
          public Spell Q, W, E;
          public Spell R1, R2;
  
          public Corki()
          {
              Utils.Utils.PrintMessage("Corki loaded");
  
              Q = new Spell(SpellSlot.Q, 825f, TargetSelector.DamageType.Magical) { MinHitChance = HitChance.High };
              Q.SetSkillshot(0.35f, 240f, 1300f, false, SkillshotType.SkillshotCircle);
  
              W = new Spell(SpellSlot.W, 600f, TargetSelector.DamageType.Magical);
              W.SetSkillshot(0.35f, 140f, 1500f, false, SkillshotType.SkillshotLine);
  
              E = new Spell(SpellSlot.E, 700f);
              E.SetSkillshot(0f, 45 * (float)Math.PI / 180, 1500, false, SkillshotType.SkillshotCone);
  
              R1 = new Spell(SpellSlot.R, 1300f, TargetSelector.DamageType.Magical) { MinHitChance = HitChance.High };
              R1.SetSkillshot(0.2f, 40f, 2000f, true, SkillshotType.SkillshotLine);
  
              R2 = new Spell(SpellSlot.R, 1500f, TargetSelector.DamageType.Magical) { MinHitChance = HitChance.VeryHigh };
              R2.SetSkillshot(0.2f, 40f, 2000f, true, SkillshotType.SkillshotLine);
          }
  
          public override void Drawing_OnDraw(EventArgs args)
          {
              Circle drawKillableMinions = GetValue<Circle>("Lane.UseQ.DrawKM");
              if (drawKillableMinions.Active && Q.IsReady() && Orbwalker.ActiveMode != Orbwalking.OrbwalkingMode.Combo)
              {
                  foreach (Obj_AI_Base m in
                      MinionManager.GetMinions(ObjectManager.Player.ServerPosition, Q.Range)
                          .Where(x => E.CanCast(x) && x.Health < Q.GetDamage(x)))
                  {
                      Render.Circle.DrawCircle(m.Position, (float)(m.BoundingRadius * 2), drawKillableMinions.Color, 5);
                  }
              }
              //if (JungleClearActive || LaneClearActive)
              //{
              //    IEnumerable<Obj_AI_Base> list = ObjectManager.Get<Obj_AI_Minion>().Where(w => w.IsValidTarget(Q.Range));
              //    IEnumerable<Obj_AI_Base> mobs;
              //    if (JungleClearActive)
              //    {
              //        mobs = list.Where(w => w.Team == GameObjectTeam.Neutral);
              //        if (GetValue<StringList>("Jungle.UseQ").SelectedIndex == 1)
              //        {
  
              //            IEnumerable<Obj_AI_Base> oMob = (from fMobs in mobs
              //                from fBigBoys in
              //                    new[]
              //                    {
              //                        "SRU_Blue", "SRU_Gromp", "SRU_Murkwolf", "SRU_Razorbeak", "SRU_Red",
              //                        "SRU_Krug", "SRU_Dragon", "SRU_Baron", "Sru_Crab"
              //                    }
              //                where fBigBoys == fMobs.BaseSkinName
              //                select fMobs).AsEnumerable();
  
  
              //            mobs = oMob;
              //        }
              //    }
              //    else
              //    {
              //        mobs = list;
              //    }
  
  
              //    var objAiBases = mobs as IList<Obj_AI_Base> ?? mobs.ToList();
              //    List<Obj_AI_Base> m1 = objAiBases.ToList();
  
              //    foreach (var m in objAiBases)
              //    {
              //        var locLine = W.GetLineFarmLocation(m1);
              //        if (locLine.MinionsHit >= 3 && W.IsInRange(locLine.Position.To3D()))
              //        {
              //            Render.Circle.DrawCircle(m.Position, 105f, Color.Red);
              //            W.Cast(locLine.Position);
              //            return;
              //        }
  
              //        var locCircular = Q.GetCircularFarmLocation(m1, Q.Width);
              //        if (locCircular.MinionsHit >= 3 && Q.IsInRange(locCircular.Position.To3D()))
              //        {
              //            Render.Circle.DrawCircle(locCircular.Position.To3D(), 105f, Color.Red);
              //            Q.Cast(locCircular.Position);
              //            return;
              //        }
              //    }
              //}
              //return;
  
              Spell[] spellList = { Q, E };
              foreach (Spell spell in spellList)
              {
                  Circle menuItem = GetValue<Circle>("Draw" + spell.Slot);
                  if (menuItem.Active)
                      Render.Circle.DrawCircle(ObjectManager.Player.Position, spell.Range, menuItem.Color);
              }
  
              var drawR = GetValue<Circle>("DrawR1");
              if (drawR.Active)
              {
                  Render.Circle.DrawCircle(ObjectManager.Player.Position, R1.Range, drawR.Color);
              }
          }
  
          public override void GameOnUpdate(EventArgs args)
          {
              if (R1.IsReady() && GetValue<bool>("UseRM"))
              {
                  bool bigRocket = HasBigRocket();
                  foreach (
                      AIHeroClient hero in
                          ObjectManager.Get<AIHeroClient>()
                              .Where(
                                  hero =>
                                      hero.IsValidTarget(bigRocket ? R2.Range : R1.Range) &&
                                      R1.GetDamage(hero) * (bigRocket ? 1.5f : 1f) > hero.Health))
                  {
                      if (bigRocket)
                      {
                          R2.Cast(hero, false, true);
                      }
                      else
                      {
                          R1.Cast(hero, false, true);
                      }
                  }
              }
  
              if ((!ComboActive && !HarassActive) || !Orbwalking.CanMove(100)) return;
  
              var useQ = GetValue<bool>("UseQ" + (ComboActive ? "C" : "H"));
              var useE = GetValue<bool>("UseE" + (ComboActive ? "C" : "H"));
              var useR = GetValue<bool>("UseR" + (ComboActive ? "C" : "H"));
              var rLim = GetValue<Slider>("Rlim" + (ComboActive ? "C" : "H")).Value;
  
              if (useQ && Q.IsReady())
              {
                  var t = TargetSelector.GetTarget(Q.Range, TargetSelector.DamageType.Magical);
                  if (t != null)
                      if (Q.Cast(t, false, true) == Spell.CastStates.SuccessfullyCasted)
                          return;
              }
  
              if (useE && E.IsReady())
              {
                  var t = TargetSelector.GetTarget(E.Range, TargetSelector.DamageType.Physical);
                  if (t.IsValidTarget())
                      if (E.Cast(t, false, true) == Spell.CastStates.SuccessfullyCasted)
                          return;
              }
  
              if (useR && R1.IsReady() && ObjectManager.Player.Spellbook.GetSpell(SpellSlot.R).Ammo > rLim)
              {
                  bool bigRocket = HasBigRocket();
                  AIHeroClient t = TargetSelector.GetTarget(bigRocket ? R2.Range : R1.Range, TargetSelector.DamageType.Magical);
  
                  if (t.IsValidTarget())
                  {
                      if (bigRocket)
                      {
                          R2.Cast(t, false, true);
                      }
                      else
                      {
                          R1.Cast(t, false, true);
                      }
                  }
              }
          }
  
          public override void ExecuteLane()
          {
              int laneQValue = GetValue<StringList>("Lane.UseQ").SelectedIndex;
              if (laneQValue != 0 && Q.IsReady())
              {
                  Vector2 minions = Q.GetCircularFarmMinions(laneQValue);
                  if (minions != Vector2.Zero)
                  {
                      Q.Cast(minions);
                  }
              }
  
              int laneEValue = GetValue<StringList>("Lane.UseE").SelectedIndex;
              if (laneEValue != 0 && E.IsReady())
              {
                  int minCount = E.GetMinionCountsInRange();
                  if (minCount >= laneEValue)
                  {
                      E.Cast();
                  }
              }
  
              int laneRValue = GetValue<StringList>("Lane.UseR").SelectedIndex;
              if (laneRValue != 0 && ObjectManager.Player.Spellbook.GetSpell(SpellSlot.R).Ammo >= GetValue<Slider>("Lane.UseR.Lim").Value)
              {
                  int rocketType = GetValue<StringList>("Lane.UseR.Bomb").SelectedIndex;
                  if (R1.IsReady() && (rocketType == 0 || rocketType == 2) && !HasBigRocket())
                  {
  
gt:                     Vector2 minions = R1.GetCircularFarmMinions(laneRValue);