context: using System;
  using System.Collections.Generic;
  using System.Drawing;
  using System.Linq;
  using System.Resources;
  using LeagueSharp;
  using LeagueSharp.Common;
  using Leblanc.Champion;
  using Color = SharpDX.Color;
  using Leblanc.Common;
  using SharpDX;
  
  using EloBuddy; 
   using LeagueSharp.Common; 
   namespace Leblanc.Modes
  {
  
      enum ActiveComboMode
      {
          Mode2xQ,
          Mode2xW,
          ModeAuto
      }
  
      enum ComboMode
      {
          Mode2xQ = 0,
          Mode2xW = 1,
          ModeAuto = 2
  
      }
  
  
  
      enum ComboStatus
      {
          Completed,
          NotCompleted
      }
  
      enum CanMakeCombo
      {
          Yes,
          No
      }
  
      internal class ModeCombo
      {
          public static Menu MenuLocal { get; private set; }
          public static Menu MenuHunt { get; private set; }
          private static Spell Q => Champion.PlayerSpells.Q;
          private static Spell W => Champion.PlayerSpells.W;
          private static Spell E => Champion.PlayerSpells.E;
          private static Spell R => Champion.PlayerSpells.R;
          private static Spell Q2 => Champion.PlayerSpells.Q2;
          private static Spell W2 => Champion.PlayerSpells.W2;
          private static Spell E2 => Champion.PlayerSpells.E2;
  
          private static int LastComboChangeKeyTick = 0;
  
          public static SpellSlot IgniteSlot = ObjectManager.Player.GetSpellSlot("SummonerDot");
  
          //public static AIHeroClient Target => GetTarget ?? TargetSelector.GetTarget(Q.Range * 2, TargetSelector.DamageType.Magical);
          //public static AIHeroClient Target => HeroManager.Enemies.Where(e => !e.IsDead && e.IsVisible && e.IsValidTarget(E.Range) && !e.HasImmortalBuff()).OrderBy(e => e.Health - GetComboDamage(e)).FirstOrDefault();
          public static AIHeroClient Target => CommonTargetSelector.GetTarget(E.Range);
          //public static AIHeroClient Target => HeroManager.Enemies.Where(e => !e.IsDead && e.IsVisible && e.IsValidTarget(E.Range)).OrderBy(e => e.Health - GetComboDamage(e)).FirstOrDefault();
  
  
          //public static AIHeroClient Target => TargetSelector.GetTarget(Q.Range * 2, TargetSelector.DamageType.Magical);
  
          private static ActiveComboMode ActiveComboMode { get; set; }
          public static List<Vector2> ListWJumpPositions = new List<Vector2>();
          
  
          internal class ListJumpPositions
          {
              public Vector2 Position { get; set; }
              public string Name { get; set; }
          }
  
          private static readonly List<ListJumpPositions> ExistingJumpPositions = new List<ListJumpPositions>();
  
  
          public static ComboMode ComboMode
          {
              get
              {
                  switch (MenuLocal.Item("Combo.Mode").GetValue<StringList>().SelectedIndex)
                  {
                      case 0:
                          ActiveComboMode = ActiveComboMode.Mode2xQ;
                          return ComboMode.Mode2xQ;
                      case 1:
                          ActiveComboMode = ActiveComboMode.Mode2xW;
                          return ComboMode.Mode2xW;
                  }
  
                  return ComboMode.Mode2xQ;
              }
          }
  
          public static void Init()
          {
  
              MenuLocal = new LeagueSharp.Common.Menu("Combo", "Combo").SetFontStyle(FontStyle.Regular, Color.GreenYellow);
              {
                  MenuLocal.AddItem(new MenuItem("Combo.Mode", "Combo Mode:").SetValue(new StringList(new[] { "Q : R", "W : R", "Auto" }, 0)).SetFontStyle(FontStyle.Regular, Color.GreenYellow)).ValueChanged +=
                      (sender, args) =>
                      {
                          MenuLocal.Item("Combo.Mode.Auto").Show(args.GetNewValue<StringList>().SelectedIndex == 2); 
                      };
  
  
                  string[] strWrKill = new string[3];
                  {
                      for (var i = 1; i < 4; i++)
                      {
                          strWrKill[i - 1] = "Min. Hit Enemy >= " + (i + 1);
                      }
  
                      MenuLocal.AddItem(new MenuItem("Combo.Mode.Auto", CommonHelper.Tab + "W : R for Multi Targets:").SetValue(new StringList(strWrKill, 0))).SetFontStyle(FontStyle.Regular, Color.Aqua);
                  }
  
  
                  //MenuLocal.AddItem(new MenuItem("Combo.Mode.Auto", CommonHelper.Tab +  "Min. Enemy Count for W : R Combo").SetValue(new Slider(2, 2, 5))).SetFontStyle(FontStyle.Regular, Color.IndianRed);
                  //MenuLocal.AddItem(new MenuItem("Combo.Mode.QR", CommonHelper.Tab + "Q x R for Single Target:").SetValue(new StringList(new[] {"if 1 v 1", "if Priority Target are killable", "Both"}, 0)));
  
                  //string[] strWrKill = new string[2];
                  //{
                  //    for (var i = 1; i < 3; i++)
                  //    {
                  //        strWrKill[i - 1] = "Min. Killable Enemy >= " + i ;
                  //    }
  
                  //    MenuLocal.AddItem(new MenuItem("Combo.Mode.WR.Kill", CommonHelper.Tab + "W x R for Multi Targets:").SetValue(new StringList(strWrKill, 0)));
                  //}
  
                  //MenuLocal.AddItem(new MenuItem("ComboMode.Key", "   Quick Change Combo Mode With Mouse Scroll Button").SetValue(true)).SetFontStyle(FontStyle.Regular, SharpDX.Color.IndianRed);
                  MenuLocal.AddItem(new MenuItem("Combo.UseW", "W:").SetValue(new StringList(new[] {"Off", "On"}, 1)).SetFontStyle(FontStyle.Regular, Champion.PlayerSpells.W.MenuColor()));
                  MenuLocal.AddItem(new MenuItem("Combo.UseW.Far", "W: Jump for killable distant enemy").SetValue(new StringList(new[] { "Off", "On" }, 1)).SetFontStyle(FontStyle.Regular, Champion.PlayerSpells.W.MenuColor()));
  
                  MenuLocal.AddItem(new MenuItem("Combo.UseE", "E:").SetValue(new StringList(new[]{"Off", "On"}, 1)).SetFontStyle(FontStyle.Regular, Champion.PlayerSpells.W.MenuColor()));
                  MenuLocal.AddItem(new MenuItem("Combo.Ignite", "Ignite:").SetValue(new StringList(new[] { "Off", "On" }, 1)).SetFontStyle(FontStyle.Regular, Champion.PlayerSpells.W.MenuColor()));
                  Modes.ModeConfig.MenuConfig.AddSubMenu(MenuLocal);
              }
  
              Game.OnUpdate += GameOnOnUpdate;
              Game.OnWndProc += Game_OnWndProc;
              Drawing.OnDraw += DrawingOnOnDraw;
              Drawing.OnDraw += DrawingHutMode;
              Orbwalking.BeforeAttack += args =>
              {
                  args.Process = !Modes.ModeConfig.MenuKeys.Item("Key.ComboAA").GetValue<KeyBind>().Active;
              };
          }
  
          private static int GetWHits(Obj_AI_Base target, List<Obj_AI_Base> targets = null)
          {
              if (targets != null && ComboMode == ComboMode.Mode2xW)
              {
                  targets = targets.Where(t => t.IsValidTarget((W.Range + W.Width))).ToList();
                  var pred = W.GetPrediction(target);
                  if (pred.Hitchance >= HitChance.Medium)
                  {
                      var circle = new Geometry.Polygon.Circle(pred.UnitPosition, target.BoundingRadius + W.Width);
                      circle.Draw(System.Drawing.Color.Aqua, 5);
  
                      return 1 + (from t in targets.Where(x => x.NetworkId != target.NetworkId)
                          let pred2 = W.GetPrediction(t)
                          where pred2.Hitchance >= HitChance.Medium
                          select new Geometry.Polygon.Circle(pred2.UnitPosition, t.BoundingRadius*0.9f)).Count(
                              circle2 => circle2.Points.Any(p => circle.IsInside(p)));
                  }
              }
  
              if (W.IsInRange(target))
              {
                  return 1;
              }
              return 0;
          }
  
          private static void DrawingHutMode(EventArgs args)
          {
              if (ObjectManager.Player.IsDead)
              {
                  return;
              }
  
              if (!Modes.ModeDraw.MenuLocal.Item("Draw.Enable").GetValue<bool>())
              {
                  return;
              }
  
  
              foreach (var e in HeroManager.Enemies.Where(e => !e.IsDead && e.IsVisible))
              {
                  //if (MenuHunt.Item("Hunt." + e.ChampionName).GetValue<bool>())
                  //{
                  //    Common.CommonGeometry.DrawBox(new Vector2(e.HPBarPosition.X + 140, e.HPBarPosition.Y + 4), 65, 18, System.Drawing.Color.FromArgb(100, 255, 0, 0), 1, System.Drawing.Color.Black);
                  //    Common.CommonGeometry.DrawText(CommonGeometry.Text, "Hunt: On!", e.HPBarPosition.X + 145, e.HPBarPosition.Y + 6, SharpDX.Color.Wheat);if (e.IsValidTarget(W.Range*2 + Q.Range))
                  //    {
                  //        var pol = new LeagueSharp.Common.Geometry.Polygon.Line(ObjectManager.Player.Position, e.Position,
                  //            ObjectManager.Player.Distance(e.Position));
  
                  //        pol.Draw(System.Drawing.Color.IndianRed, 2);
  
                  //        Vector3[] x = new[] {ObjectManager.Player.Position, e.Position};
                  //        var aX =
                  //            Drawing.WorldToScreen(new Vector3(CommonHelper.CenterOfVectors(x).X,
                  //                CommonHelper.CenterOfVectors(x).Y, CommonHelper.CenterOfVectors(x).Z));
                  //        Drawing.DrawText(aX.X - 15, aX.Y - 15, System.Drawing.Color.White, e.ChampionName);
                  //    }
                  //}
  
                  if (e.Health < GetComboDamage(e))
                  {
                      Common.CommonGeometry.DrawText(CommonGeometry.Text, "Combo Kill", e.HPBarPosition.X + 8, e.HPBarPosition.Y + 36, SharpDX.Color.GreenYellow);
                  }
              }
          }
  
          public static int GetPriority(string championName)
          {
              string[] low =
              {
                  "Alistar", "Amumu", "Bard", "Blitzcrank", "Braum", "Cho'Gath", "Dr. Mundo", "Garen", "Gnar",
                  "Hecarim", "Janna", "Jarvan IV", "Leona", "Lulu", "Malphite", "Nami", "Nasus", "Nautilus", "Nunu",
                  "Olaf", "Rammus", "Renekton", "Sejuani", "Shen", "Shyvana", "Singed", "Sion", "Skarner", "Sona",
                  "Soraka", "Tahm", "Taric", "Thresh", "Volibear", "Warwick", "MonkeyKing", "Yorick", "Zac", "Zyra"
              };
  
              string[] medium =
              {
                  "Aatrox", "Akali", "Darius", "Diana", "Ekko", "Elise", "Evelynn", "Fiddlesticks", "Fiora", "Fizz",
                  "Galio", "Gangplank", "Gragas", "Heimerdinger", "Irelia", "Jax", "Jayce", "Kassadin", "Kayle", "Kha'Zix",
                  "Lee Sin", "Lissandra", "Maokai", "Mordekaiser", "Morgana", "Nocturne", "Nidalee", "Pantheon", "Poppy",
                  "RekSai", "Rengar", "Riven", "Rumble", "Ryze", "Shaco", "Swain", "Trundle", "Tryndamere", "Udyr",
                  "Urgot", "Vladimir", "Vi", "XinZhao", "Zilean"
              };
  
              string[] high =
              {
                  "Ahri", "Anivia", "Annie", "Ashe", "Azir", "Brand", "Caitlyn", "Cassiopeia", "Corki", "Draven", "Ezreal",
                  "Graves", "Jhin", "Jinx", "Kalista", "Karma", "Karthus", "Katarina", "Kennen", "KogMaw", "Leblanc",
                  "Lucian", "Lux", "Malzahar", "MasterYi", "MissFortune", "Orianna", "Quinn", "Sivir", "Syndra", "Talon",
                  "Teemo", "Tristana", "TwistedFate", "Twitch", "Varus", "Vayne", "Veigar", "VelKoz", "Viktor", "Xerath",
                  "Yasuo", "Zed", "Ziggs"
              };
  
              if (medium.Contains(championName))
              {
                  return 2;
              }
  
              if (high.Contains(championName))
              {
                  return 3;
              }
  
              return 1;
          }
  
          private static void Game_OnWndProc(WndEventArgs args)
          {
              if (ModeConfig.MenuKeys.Item("Key.ChangeCombo").GetValue<KeyBind>().Active && Environment.TickCount > LastComboChangeKeyTick + 250)
              {
                  var newValue = MenuLocal.Item("Combo.Mode").GetValue<StringList>().SelectedIndex + 1;
                  if (newValue == MenuLocal.Item("Combo.Mode").GetValue<StringList>().SList.Length)
                  {
                      newValue = 0;
                  }
  
                  MenuLocal.Item("Combo.Mode").SetValue(new StringList(new[] { "Q : R", "W : R", "Auto"}, newValue));
  
                  LastComboChangeKeyTick = Environment.TickCount;
              }
              //if (args.Msg != 0x20a)
              //{
              //    return;
              //}
  
              //if (!MenuLocal.Item("ComboMode.Key").GetValue<bool>())
              //{
              //    return;
              //}
  
              //var newValue = MenuLocal.Item("Combo.Mode").GetValue<StringList>().SelectedIndex + 1;
              //if (newValue == MenuLocal.Item("Combo.Mode").GetValue<StringList>().SList.Length)
              //{
              //    newValue = 0;
              //}
  
              //MenuLocal.Item("Combo.Mode").SetValue(new StringList(new[] {"Off", "Q:R", "W:R", "Custom"}, newValue));
          }
  
          private static void DrawingOnOnDraw(EventArgs args)
          {
              if (Shop.IsOpen)
              {
                  return;
              }
  
              //if (Target.IsValidTarget(Q.Range*2))
              //{
              //    var wComboHits = GetWHits(Target, HeroManager.Enemies.Where(e => e.IsValidTarget(W.Range + W.Width)).Cast<Obj_AI_Base>().ToList());
              //}
              if (ObjectManager.Player.IsDead)
              {
                  return;
              }
  
              if (!Modes.ModeDraw.MenuLocal.Item("Draw.Enable").GetValue<bool>())
              {
                  return;
              }
  
  
              var nTarget = CommonTargetSelector.GetTarget(Q.Range, TargetSelector.DamageType.Magical);
              if (nTarget.IsValidTarget() && nTarget.Health < ComboDamage2xW(nTarget))
              {
  
                  Render.Circle.DrawCircle(nTarget.Position, 105f, System.Drawing.Color.AliceBlue);
  
              }
  
              var xComboString = "Combo Mode: ";
              System.Drawing.Color xComboColor = System.Drawing.Color.FromArgb(100, 255, 200, 37);
  
              string[] vComboString = new[]
              {
                  "Q : R", "W : R", "Auto"
              };
  
              System.Drawing.Color[] vComboColor = new[]
              {
                  System.Drawing.Color.FromArgb(255, 4, 0, 255),
                  System.Drawing.Color.FromArgb(198, 255, 0, 0),
                  System.Drawing.Color.FromArgb(198, 71, 255, 31),
              };
  
              var nComboMode = MenuLocal.Item("Combo.Mode").GetValue<StringList>().SelectedIndex;
              xComboString = xComboString + vComboString[MenuLocal.Item("Combo.Mode").GetValue<StringList>().SelectedIndex];
              xComboColor = vComboColor[MenuLocal.Item("Combo.Mode").GetValue<StringList>().SelectedIndex];
              
              //switch (xCombo)
              //{
              //    case 1: 
              //        xComboStr += "Q : R";
              //        color = System.Drawing.Color.FromArgb(100, 4, 0, 255);
              //        break;
  
              //    case 2: 
              //        xComboStr += "W : R";
              //        color = System.Drawing.Color.FromArgb(100, 255, 0, 0);
              //        break;
  
              //    case 3: 
              //        xComboStr += "E : R";
              //        color = System.Drawing.Color.FromArgb(100, 0, 255, 8);
              //        break;
              //}
              //Drawing.DrawText(Drawing.Width * 0.45f, Drawing.Height * 0.80f, Color.GreenYellow, xComboStr);
  
              Common.CommonGeometry.DrawBox(new Vector2(Drawing.Width * 0.45f, Drawing.Height * 0.80f), 115, 18, xComboColor, 1, System.Drawing.Color.Black);
              Common.CommonGeometry.DrawText(CommonGeometry.Text, xComboString, Drawing.Width * 0.455f, Drawing.Height * 0.803f, SharpDX.Color.Wheat);
  
              //Common.CommonGeometry.DrawBox( new Vector2((int) ObjectManager.Player.HPBarPosition.X + 145, (int) ObjectManager.Player.HPBarPosition.Y + 5), 115, 18, xComboColor, 1, System.Drawing.Color.Black);
              //Common.CommonGeometry.DrawText(CommonGeometry.Text, xComboString, ObjectManager.Player.HPBarPosition.X + 150, ObjectManager.Player.HPBarPosition.Y + 7, SharpDX.Color.Wheat);
  
                  //if (nComboMode == 3)
                  //{
                  //    string[] qComboMenuItemStr = new[] { "Just 1 v 1 Mode", "if Priority Target are killable", "Both" };
                  //    var qComboString = qComboMenuItemStr[MenuLocal.Item("Combo.Mode.QR").GetValue<StringList>().SelectedIndex];
  
                  //    //Common.CommonGeometry.DrawBox(new Vector2((int)ObjectManager.Player.HPBarPosition.X + 145,(int)ObjectManager.Player.HPBarPosition.Y + 5 + 20), 180, 15, System.Drawing.Color.FromArgb(100, 252, 252, 252), 1,System.Drawing.Color.DimGray);
                  //    Common.CommonGeometry.DrawText(CommonGeometry.TextSmall, "Q x R : " + qComboString, ObjectManager.Player.HPBarPosition.X + 150, ObjectManager.Player.HPBarPosition.Y + 7 + 20,SharpDX.Color.White);
  
  
                  //    int x = MenuLocal.Item("Combo.Mode.WR.Kill").GetValue<StringList>().SelectedIndex + 1;
                  //    var wComboStrinKill = "Min. Killable Enemy Count >= " + x;
                  //    //Common.CommonGeometry.DrawBox(new Vector2((int)ObjectManager.Player.HPBarPosition.X + 145,(int)ObjectManager.Player.HPBarPosition.Y + 5 + 20 + 16), 180, 15, System.Drawing.Color.FromArgb(100, 252, 252, 252), 1,System.Drawing.Color.DimGray);
                  //    Common.CommonGeometry.DrawText(CommonGeometry.TextSmall, "W x R : " + wComboStrinKill,ObjectManager.Player.HPBarPosition.X + 150, ObjectManager.Player.HPBarPosition.Y + 7 + 20 + 17,SharpDX.Color.White);
  
                  //}
          
  
              return;
              var t = CommonTargetSelector.GetTarget(W.Range + Q.Range - 20, TargetSelector.DamageType.Magical);
              if (!t.IsValidTarget(W.Range + Q.Range - 20))
              {
                  return;
              }
  
              if (t.IsValidTarget(W.Range))
              {
                  return;
              }
  
              bool canJump = false;
  
              if (ComboMode == ComboMode.Mode2xQ)
              {
                  if ((t.Health < ComboDamage2xQ(t) && Q.IsReady() && R.IsReady()) ||
                      (t.Health < Q.GetDamage(t) && Q.IsReady()))
                  {
                      canJump = true;
                  }
              }
  
              if (canJump && W.IsReady() && !W.StillJumped())
              {
                  var x = GetJumpPosition(t, W.Range);
                  if (Modes.ModeConfig.Orbwalker.ActiveMode == Orbwalking.OrbwalkingMode.Combo)
                  {
                      W.Cast(x);
                  }
                  return;
              }
          }
  
          private static void GameOnOnUpdate(EventArgs args)
          {
              //if (W.IsReady() && Target.IsValidTarget())
              //{
              //    var pre = W.GetPrediction(Target, true);
              //    if (pre.Hitchance >= HitChance.High)
              //        W.Cast(pre.CastPosition, true);
              //}
              //return;
  
              if (!Target.IsValidTarget(2000))
              {
                  return;
              }
  
              if (Modes.ModeConfig.MenuKeys.Item("Key.ComboAA").GetValue<KeyBind>().Active)
              {
                  EloBuddy.Player.IssueOrder(GameObjectOrder.MoveTo, Game.CursorPos);
                  ExecuteComboMode();
              }
  
              if (!Target.IsValidTarget() || Modes.ModeConfig.Orbwalker.ActiveMode != Orbwalking.OrbwalkingMode.Combo)
              {
                  return;
              }
  
              ExecuteComboMode();
          }
  
  
          static void ExecuteComboMode()
          {
              if (Target.IsValidTarget(Q.Range) && CommonHelper.SpellRStatus == CommonHelper.SpellRName.R2xQ && Target.Health < ComboDamage2xQ(Target))
              {
                  Q2.CastOnUnit(Target);
              }
  
              if (Target.IsValidTarget(W.Range) && CommonHelper.SpellRStatus == CommonHelper.SpellRName.R2xW && Target.Health < ComboDamage2xW(Target))
              {
                  PlayerSpells.CastW2(Target.Position);
              }
  
              //ExecuteFarCombo();
  
              if (MenuLocal.Item("Combo.Ignite").GetValue<StringList>().SelectedIndex == 1)
              {
  
gt:                 if (IgniteSlot != SpellSlot.Unknown &&