context: using System;
  using System.Collections.Generic;
  using System.Linq;
  using Color = System.Drawing.Color;
  using LeagueSharp;
  using LeagueSharp.Common;
  using UnderratedAIO.Helpers;
  using Environment = UnderratedAIO.Helpers.Environment;
  
  
  using EloBuddy; 
   using LeagueSharp.Common; 
   namespace UnderratedAIO.Champions
  {
      internal class Nasus
      {
          public static Menu config;
          public static Orbwalking.Orbwalker orbwalker;
          public static AutoLeveler autoLeveler;
          public static Spell Q, W, E, R;
          public static readonly AIHeroClient player = ObjectManager.Player;
  
          public Nasus()
          {
              InitNocturne();
              InitMenu();
              //Chat.Print("<font color='#9933FF'>Soresu </font><font color='#FFFFFF'>- Nasus</font>");
              Drawing.OnDraw += Game_OnDraw;
              Game.OnUpdate += Game_OnGameUpdate;
              Helpers.Jungle.setSmiteSlot();
              HpBarDamageIndicator.DamageToUnit = ComboDamage;
              Orbwalking.BeforeAttack += Orbwalking_BeforeAttack;
              Orbwalking.OnAttack += Orbwalking_OnAttack;
              Orbwalking.AfterAttack += Orbwalking_AfterAttack;
          }
  
          private void Orbwalking_AfterAttack(AttackableUnit unit, AttackableUnit target)
          {
              var tar = target as Obj_AI_Base;
              if (Q.IsReady() && unit.IsMe && tar is AIHeroClient &&
                  orbwalker.ActiveMode == Orbwalking.OrbwalkingMode.Combo && tar.HasBuffOfType(BuffType.Slow) &&
                  target.Health > Q.GetDamage(tar) + player.GetAutoAttackDamage(tar) + 50)
              {
                  Q.Cast();
                  Orbwalking.ResetAutoAttackTimer();
              }
          }
  
          private void Orbwalking_OnAttack(AttackableUnit unit, AttackableUnit target)
          {
              if (unit.IsMe && Q.IsReady() &&
                  ((config.Item("autoQ").GetValue<bool>() &&
                    target.Health < Q.GetDamage((Obj_AI_Base) target) + player.GetAutoAttackDamage((Obj_AI_Base) target)) ||
                   (orbwalker.ActiveMode == Orbwalking.OrbwalkingMode.LaneClear && target.Health > 1000 &&
                    config.Item("useqLC").GetValue<bool>())))
              {
                  Q.Cast();
              }
          }
  
          private void Orbwalking_BeforeAttack(Orbwalking.BeforeAttackEventArgs args)
          {
              var target = args.Target as Obj_AI_Base;
              if (Q.IsReady() && target != null &&
                  ((target is AIHeroClient && orbwalker.ActiveMode == Orbwalking.OrbwalkingMode.Combo &&
                    !target.HasBuffOfType(BuffType.Slow)) ||
                   target.Health < Q.GetDamage(target) + player.GetAutoAttackDamage(target)))
              {
                  Q.Cast();
              }
          }
  
          private void Game_OnGameUpdate(EventArgs args)
          {
              if (FpsBalancer.CheckCounter())
              {
                  return;
              }
              AIHeroClient target = DrawHelper.GetBetterTarget(950, TargetSelector.DamageType.Physical);
              switch (orbwalker.ActiveMode)
              {
                  case Orbwalking.OrbwalkingMode.Combo:
                      Combo(target);
                      break;
                  case Orbwalking.OrbwalkingMode.Mixed:
                      Harass(target);
                      break;
                  case Orbwalking.OrbwalkingMode.LaneClear:
                      Clear();
                      break;
                  case Orbwalking.OrbwalkingMode.LastHit:
                      if (Q.IsReady())
                      {
                          useQ();
                      }
                      break;
                  default:
                      break;
              }
          }
  
          private void Combo(AIHeroClient target)
          {
              if (target == null)
              {
                  return;
              }
              var cmbdmg = ComboDamage(target) + ItemHandler.GetItemsDamage(target);
              if (config.Item("useItems").GetValue<bool>())
              {
                  ItemHandler.UseItems(target, config, cmbdmg);
              }
              if (!config.Item("Rdamage").GetValue<bool>())
              {
                  cmbdmg += R.GetDamage(target) * 15;
              }
              var bonusDmg = Environment.Hero.GetAdOverTime(player, target, 5);
              if ((config.Item("user").GetValue<bool>() && player.Distance(target) < player.AttackRange + 50 &&
                   cmbdmg + bonusDmg > target.Health && target.Health > bonusDmg + 200 && player.HealthPercent < 50) ||
                  (config.Item("usertf").GetValue<Slider>().Value <= player.CountEnemiesInRange(600) &&
                   player.HealthPercent < 80))
              {
                  R.Cast();
              }
              var ignitedmg = (float) player.GetSummonerSpellDamage(target, Damage.SummonerSpell.Ignite);
              bool hasIgnite = player.Spellbook.CanUseSpell(player.GetSpellSlot("SummonerDot")) == SpellState.Ready;
              if (config.Item("useIgnite").GetValue<bool>() && ignitedmg > target.Health && hasIgnite &&
                  !E.CanCast(target))
              {
                  player.Spellbook.CastSpell(player.GetSpellSlot("SummonerDot"), target);
              }
              if (config.Item("usew").GetValue<bool>() && W.CanCast(target))
              {
                  if (((config.Item("keepManaForR").GetValue<bool>() && R.IsReady()) || !R.IsReady()) &&
                      player.Mana > R.Instance.SData.Mana + W.Instance.SData.Mana)
                  {
                      W.Cast(target);
                  }
              }
              if (((config.Item("keepManaForR").GetValue<bool>() && R.IsReady()) || !R.IsReady()) &&
                  (player.Mana > R.Instance.SData.Mana + E.Instance.SData.Mana ||
                   (E.IsReady() && E.GetDamage(target) > target.Health)))
              {
                  if (config.Item("usee").GetValue<bool>() && E.IsReady() &&
                      ((config.Item("useeslow").GetValue<bool>() && NasusW(target)) ||
                       !config.Item("useeslow").GetValue<bool>()))
                  {
                      var ePred = E.GetPrediction(target);
                      if (E.Range > ePred.CastPosition.Distance(player.Position) &&
                          target.Distance(ePred.CastPosition) < 400)
                      {
                          E.Cast(ePred.CastPosition);
                      }
                      else
                      {
                          if (ePred.CastPosition.Distance(player.Position) < 925 &&
                              target.Distance(ePred.CastPosition) < 400)
                          {
                              E.Cast(player.Position.Extend(target.Position, E.Range));
                          }
                      }
                  }
              }
          }
  
          private void Clear()
          {
              if (Q.IsReady())
              {
                  useQ();
              }
              if (NasusQ && player.CountEnemiesInRange(Orbwalking.GetRealAutoAttackRange(player)) == 0)
              {
                  var minion =
                      MinionManager.GetMinions(
                          Orbwalking.GetRealAutoAttackRange(player), MinionTypes.All, MinionTeam.NotAlly)
                          .FirstOrDefault(m => m.Health > 5 && m.Health < Q.GetDamage(m) + player.GetAutoAttackDamage(m));
                  orbwalker.ForceTarget(minion);
              }
              float perc = config.Item("minmana").GetValue<Slider>().Value / 100f;
              if (player.Mana < player.MaxMana * perc)
              {
                  return;
              }
              MinionManager.FarmLocation bestPositionE =
                  E.GetCircularFarmLocation(MinionManager.GetMinions(E.Range, MinionTypes.All, MinionTeam.NotAlly), 400f);
              if (config.Item("useeLC").GetValue<bool>() && E.IsReady() &&
                  bestPositionE.MinionsHit >= config.Item("ehitLC").GetValue<Slider>().Value)
              {
                  E.Cast(bestPositionE.Position);
              }
          }
  
          private void useQ()
          {
              var minions =
                  MinionManager.GetMinions(Orbwalking.GetRealAutoAttackRange(player), MinionTypes.All, MinionTeam.NotAlly)
                      .FirstOrDefault(
                          m =>
                              m.Health > 5 &&
                              HealthPrediction.LaneClearHealthPrediction(m, 1000) <
                              Q.GetDamage(m) + player.GetAutoAttackDamage(m));
              if (minions != null)
              {
                  Q.Cast();
              }
          }
  
          private void Harass(AIHeroClient target)
          {
              if (Q.IsReady())
              {
                  useQ();
              }
              float perc = config.Item("minmanaH").GetValue<Slider>().Value / 100f;
              if (player.Mana < player.MaxMana * perc)
              {
                  return;
              }
              if (target == null)
              {
                  return;
              }
  
gt:             if (config.Item("useeH").GetValue<bool>() && E.IsReady())