context: using System;
  using System.Collections.Generic;
  using System.Drawing;
  using System.Linq;
  using LeagueSharp;
  using LeagueSharp.Common;
  using SebbyLib;
  using SurvivorSeriesAIO.Core;
  using SurvivorSeriesAIO.Utility;
  using Orbwalking = SebbyLib.Orbwalking;
  
  using EloBuddy; 
   using LeagueSharp.Common; 
   namespace SurvivorSeriesAIO.Champions
  {
      internal class Irelia : ChampionBase
      {
          public Items.Item
              Sheen = new Items.Item(2057),
              Trinity = new Items.Item(3078),
              Gauntlet = new Items.Item(3025),
              LichBane = new Items.Item(3100);
  
          public List<Spell> SpellList = new List<Spell>();
  
          public Irelia(IRootMenu menu, Orbwalking.Orbwalker Orbwalker) : base(menu, Orbwalker)
          {
              // manual override - default is spell values from LeagueSharp.Data
              R.SetSkillshot(0.25f, 45, 1600, false, SkillshotType.SkillshotLine);
              // Subsriptions
              Game.OnUpdate += Game_OnUpdate;
              Obj_AI_Base.OnSpellCast += WUsage;
              Drawing.OnDraw += Drawing_OnDraw;
  
              Config = new Configuration(menu.Champion);
              InitHpbarOverlay();
          }
  
          public Configuration Config { get; }
  
          private void InitHpbarOverlay()
          {
              DrawDamage.DamageToUnit = CalculateDamage;
              DrawDamage.Enabled = () => Config.DrawComboDamage.GetValue<bool>();
              DrawDamage.Fill = () => Config.FillColor.GetValue<Circle>().Active;
              DrawDamage.FillColor = () => Config.FillColor.GetValue<Circle>().Color;
          }
  
          private void WUsage(Obj_AI_Base sender, GameObjectProcessSpellCastEventArgs args)
          {
              if (sender.IsMe && args.SData.IsAutoAttack() && args.Target is AIHeroClient &&
                  (Orbwalker.ActiveMode == Orbwalking.OrbwalkingMode.Combo) && W.IsReady())
                  W.Cast();
          }
  
          private void JungleClear()
          {
              if (Player.ManaPercent < Config.JungleClearManaManager.GetValue<Slider>().Value)
                  return;
  
              var jgcq = Config.JGCQ.GetValue<bool>();
              var jgcw = Config.JGCW.GetValue<bool>();
              var jgce = Config.JGCE.GetValue<bool>();
  
              var mob =
                  MinionManager.GetMinions(Player.ServerPosition, Q.Range, MinionTypes.All, MinionTeam.Neutral,
                      MinionOrderTypes.MaxHealth).FirstOrDefault();
              if (mob == null)
                  return;
  
              if (jgcq && Q.Instance.IsReady())
                  Q.CastOnUnit(mob);
              if (jgce && E.Instance.IsReady())
                  E.CastOnUnit(mob);
              if (jgcw && W.Instance.IsReady())
                  W.Cast();
          }
  
          public float GetSheenDamage(Obj_AI_Base target)
          {
              float totalDamage = 0;
  
              if (Items.HasItem(3057, Player))
              {
                  if (Items.CanUseItem(3057))
                      totalDamage +=
                          (float) Player.CalcDamage(target, Damage.DamageType.Physical, Player.TotalAttackDamage);
              }
              else if (Items.HasItem(3025, Player))
              {
                  if (Items.CanUseItem(3025))
                      totalDamage +=
                          (float) Player.CalcDamage(target, Damage.DamageType.Physical, Player.TotalAttackDamage);
              }
              else if (Items.HasItem(3078, Player))
              {
                  if (Items.CanUseItem(3078))
                      totalDamage +=
                          (float) Player.CalcDamage(target, Damage.DamageType.Physical, Player.TotalAttackDamage*2);
              }
              else if (Items.HasItem(3100, Player))
              {
                  if (Items.CanUseItem(3100))
                      totalDamage +=
                          (float)
                          Player.CalcDamage(target, Damage.DamageType.Magical,
                              75/Player.TotalAttackDamage*100 + 50/Player.TotalMagicalDamage*100);
              }
              return totalDamage;
          }
  
          public void Combo()
          {
              var useq = Config.comboQ.GetValue<bool>();
              var usew = Config.comboW.GetValue<bool>();
              var usee = Config.comboE.GetValue<bool>();
              var useR = Config.comboR.GetValue<bool>();
              var target = TargetSelector.GetTarget(Q.Range, TargetSelector.DamageType.Physical);
              //var targetextend = TargetSelector.GetTarget();
              if ((target == null) || !target.IsValidTarget())
                  return;
  
              //Chat.Print("Q Damage: " + Q.GetDamage(target) + " Sheen Damage:" + GetSheenDamage(target));
              //var distancebetweenmeandtarget = ObjectManager.Player.ServerPosition.Distance(target.ServerPosition);
              /*if (Q.IsReady() && target.Distance(Player.Position) > 650)
              {
                  var gapclosingMinion = ObjectManager.Get<Obj_AI_Minion>().Where(m => m.ServerPosition.Distance(ObjectManager.Player.ServerPosition) < 650 &&
                      m.IsEnemy && m.ServerPosition.Distance(target.ServerPosition) < distancebetweenmeandtarget && m.Health > 1 && m.Health < Q.GetDamage(m) + GetSheenDamage(m)).OrderBy(m => m.Position.Distance(target.ServerPosition)).FirstOrDefault();
                  if (gapclosingMinion != null)
                  {
                      Q.Cast(gapclosingMinion);
                  }
              }*/
  
              if (target.IsValidTarget(Q.Range) && !target.IsValidTarget(Player.AttackRange) && Q.IsReady() && useq)
              {
                  Q.CastOnUnit(target);
                  if (E.Instance.IsReady() && target.IsValidTarget(E.Range) && usee)
                      E.CastOnUnit(target);
                  if (W.Instance.IsReady() && usew && target.IsValidTarget(Player.AttackRange))
                      // Yes lads E.Range is intentionally here :gosh:
                      W.Cast();
                  if (target.IsValidTarget(R.Range) && useR)
                  {
                      var pred = R.GetPrediction(target);
                      if ((pred.Hitchance >= HitChance.High) && HasRBuff())
                      {
                          if (OktwCommon.CollisionYasuo(Player.Position, pred.CastPosition))
                              return;
                          R.Cast(pred.CastPosition);
                      }
                  }
              }
              else if (target.IsValidTarget(E.Range))
              {
                  if (Q.Instance.IsReady() && useq)
                      Q.CastOnUnit(target);
                  if (E.Instance.IsReady() && usee && target.IsValidTarget(E.Range))
                      E.CastOnUnit(target);
                  if (W.Instance.IsReady() && usew && target.IsValidTarget(Player.AttackRange))
                      // Yes lads E.Range is intentionally here :gosh:
                      W.Cast();
                  if (R.Instance.IsReady() && useR && target.IsValidTarget(R.Range))
                  {
                      var pred = R.GetPrediction(target);
                      if (pred.Hitchance >= HitChance.High)
                      {
                          if (OktwCommon.CollisionYasuo(Player.Position, pred.CastPosition))
                              return;
                          R.Cast(pred.CastPosition);
                      }
                  }
              }
          }
  
          public void LaneClear()
          {
              if (Player.ManaPercent < Config.LaneClearManaManager.GetValue<Slider>().Value)
                  return;
              var lcq = Config.LCQ.GetValue<bool>();
              var lcw = Config.LCW.GetValue<bool>();
              var lce = Config.LCE.GetValue<bool>();
              var lcwslider = Config.LCWSlider.GetValue<Slider>().Value;
  
              var minionq =
                  Cache.GetMinions(Player.Position, Q.Range)
                      .FirstOrDefault(x => Q.GetDamage(x) + GetSheenDamage(x) > x.Health);
  
              var minionwe = Cache.GetMinions(Player.Position, 275);
  
              if (minionq == null)
                  return;
  
              if (lcq && Q.Instance.IsReady())
                  Q.CastOnUnit(minionq);
  
              if (minionwe == null)
                  return;
  
              foreach (var minion in minionwe)
              {
                  if (W.Instance.IsReady() && lcw && (minion.HealthPercent > 5) && (minionwe.Count > lcwslider))
                      W.Cast();
                  if (E.Instance.IsReady() && lce && (minion.Health < E.GetDamage(minion)) && lce)
                      E.CastOnUnit(minion);
              }
          }
  
          public void Harass()
          {
              if (Player.ManaPercent < Config.HarassManaManager.GetValue<Slider>().Value)
                  return;
  
              var harassq = Config.harassQ.GetValue<bool>();
              var harasse = Config.harassE.GetValue<bool>();
  
              var target = TargetSelector.GetTarget(Q.Range, TargetSelector.DamageType.Physical);
  
              if ((target == null) || !target.IsValidTarget())
                  return;
  
              if (Q.IsReady() && harassq)
              {
                  Q.CastOnUnit(target);
                  if (harasse && E.IsReady())
                  {
                      E.CastOnUnit(target);
                      Orbwalker.ForceTarget(target);
                  }
                  else
                  {
                      Orbwalker.ForceTarget(target);
                  }
              }
  
              if (harasse && E.IsReady() && !Q.IsReady())
                  if (target.IsValidTarget(E.Range))
                  {
                      E.CastOnUnit(target);
                      Orbwalker.ForceTarget(target);
                  }
          }
  
          private void KSChecking()
          {
              if (Config.KSCheck.GetValue<bool>())
              {
                  var target = TargetSelector.GetTarget(Q.Range, TargetSelector.DamageType.Physical);
  
                  if ((target == null) || !target.IsValidTarget())
                      return;
  
                  if ((target.Health < Q.GetDamage(target) + GetSheenDamage(target)) && Q.IsReady())
                      Q.CastOnUnit(target);
  
                  if ((target.Health < E.GetDamage(target)) && E.IsReady())
                      E.CastOnUnit(target);
              }
          }
  
          public bool HasRBuff() => Player.HasBuff("ireliatranscendentbladesspell");
  
          public bool Stunnable(AIHeroClient enemy)
          {
              return enemy.HealthPercent > Player.HealthPercent;
          }
  
          private float CalculateDamage(AIHeroClient enemy)
          {
              float damage = 0;
  
              if (Q.Instance.IsReady() && (Player.Mana > Q.Instance.SData.Mana))
                  damage += Q.GetDamage(enemy) + GetSheenDamage(enemy);
              if (W.Instance.IsReady() && (Player.Mana > W.Instance.SData.Mana))
                  damage += W.GetDamage(enemy);
              if (E.Instance.IsReady() && (Player.Mana > E.Instance.SData.Mana))
  
gt:                 damage += E.GetDamage(enemy);