context: using System;
  using System.Collections.Generic;
  using System.Linq;
  using Color = System.Drawing.Color;
  using LeagueSharp;
  using LeagueSharp.Common;
  using SharpDX.Direct3D9;
  using UnderratedAIO.Helpers;
  using Environment = UnderratedAIO.Helpers.Environment;
  
  
  using EloBuddy; 
  using LeagueSharp.Common; 
  namespace UnderratedAIO.Champions
  {
      internal class Volibear
      {
          public static Menu config;
          public static Orbwalking.Orbwalker orbwalker;
          
          public static Spell Q, W, E, R;
          public static float[] MsBuff = new float[5] { 0.3f, 0.35f, 0.4f, 0.45f, 0.5f };
          private float passivetime = 0f;
          private bool passivecd = false;
          public static readonly AIHeroClient player = ObjectManager.Player;
  
          public Volibear()
          {
              InitVolibear();
              InitMenu();
              //Chat.Print("<font color='#9933FF'>Soresu </font><font color='#FFFFFF'>- Volibear</font>");
              Drawing.OnDraw += Game_OnDraw;
              Game.OnUpdate += Game_OnGameUpdate;
              Jungle.setSmiteSlot();
              
          }
  
          private void Game_OnGameUpdate(EventArgs args)
          {
              var hasbuff = player.HasBuff("volibearpassivecd");
              if (hasbuff && !passivecd)
              {
                  passivecd = true;
                  passivetime = Game.Time;
              }
              if (!hasbuff)
              {
                  passivecd = false;
                  passivetime = 0f;
              }
              if (false)
              {
                  return;
              }
              switch (orbwalker.ActiveMode)
              {
                  case Orbwalking.OrbwalkingMode.Combo:
                      Combo();
                      break;
                  case Orbwalking.OrbwalkingMode.Mixed:
                      Harass();
                      break;
                  case Orbwalking.OrbwalkingMode.LaneClear:
                      Clear();
                      break;
                  case Orbwalking.OrbwalkingMode.LastHit:
                      break;
                  default:
                      break;
              }
              var enemyForKs = HeroManager.Enemies.FirstOrDefault(h => W.CanCast(h) && Wdmg(h) > h.Health);
              if (enemyForKs != null && W.IsReady() && config.Item("ksW").GetValue<bool>())
              {
                  W.CastOnUnit(enemyForKs);
              }
          }
  
          private void Harass()
          {
              float perc = config.Item("minmanaH").GetValue<Slider>().Value / 100f;
              if (player.Mana < player.MaxMana * perc)
              {
                  return;
              }
              AIHeroClient target = DrawHelper.GetBetterTarget(E.Range, TargetSelector.DamageType.Physical);
              if (target == null)
              {
                  return;
              }
              if (config.Item("usewH").GetValue<bool>() && W.CanCast(target) && CanW &&
                  (config.Item("maxHealthH").GetValue<Slider>().Value / 100f) * target.MaxHealth > target.Health)
              {
                  W.Cast(target);
              }
              if (config.Item("useeH").GetValue<bool>() && E.CanCast(target))
              {
                  E.Cast(target);
              }
          }
  
          private void Clear()
          {
              var mob = Jungle.GetNearest(player.Position);
              if (mob != null && config.Item("usewLCSteal").GetValue<bool>() && CanW && W.CanCast(mob) &&
                  player.CalcDamage(mob, Damage.DamageType.Physical, Wdmg(mob)) > mob.Health)
              {
                  W.Cast(mob);
              }
              if (mob != null && config.Item("usewbsmite").GetValue<bool>() && CanW && W.CanCast(mob) &&
                  Jungle.SmiteReady(config.Item("useSmite").GetValue<KeyBind>().Active) &&
                  player.CalcDamage(mob, Damage.DamageType.Physical, Wdmg(mob)) + Jungle.smiteDamage(mob) > mob.Health)
              {
                  W.Cast(mob);
              }
              float perc = config.Item("minmana").GetValue<Slider>().Value / 100f;
              if (player.Mana < player.MaxMana * perc)
              {
                  return;
              }
              var minions = MinionManager.GetMinions(W.Range, MinionTypes.All, MinionTeam.NotAlly);
              if (config.Item("useeLC").GetValue<bool>() && E.IsReady() &&
                  config.Item("ehitLC").GetValue<Slider>().Value <= minions.Count)
              {
                  E.Cast();
              }
          }
  
          public static float MsBonus(AIHeroClient target)
          {
              float msBonus = 1f;
  
              if (Q.IsReady() && !QEnabled)
              {
                  if (
                      ObjectManager.Get<AIHeroClient>()
                          .FirstOrDefault(h => h.IsEnemy && player.Distance(h) < 2000 && player.IsFacing(h)) != null)
                  {
                      msBonus += MsBuff[Q.Level - 1];
                  }
                  else
                  {
                      msBonus += 0.15f;
                  }
              }
              return msBonus;
          }
  
          private void Combo()
          {
              AIHeroClient target = DrawHelper.GetBetterTarget(1490, TargetSelector.DamageType.Physical);
              if (target == null)
              {
                  return;
              }
              if (config.Item("selected").GetValue<bool>())
              {
                  target = CombatHelper.SetTarget(target, TargetSelector.GetSelectedTarget());
                  orbwalker.ForceTarget(target);
              }
              if (config.Item("useItems").GetValue<bool>())
              {
                  ItemHandler.UseItems(target, config, ComboDamage(target));
              }
              if (config.Item("useq").GetValue<bool>() && Q.IsReady() && !QEnabled &&
                  player.Distance(target) >= config.Item("useqmin").GetValue<Slider>().Value &&
                  player.Distance(target) < (player.MoveSpeed * MsBonus(target)) * 3.0f)
              {
                  Q.Cast();
              }
              if (config.Item("usew").GetValue<bool>() && CanW && W.CanCast(target) &&
                  (player.CalcDamage(target, Damage.DamageType.Physical, Wdmg(target)) > target.Health ||
                   player.HealthPercent < 10))
              {
                  W.Cast(target);
              }
              if (config.Item("usee").GetValue<bool>() && E.CanCast(target) &&
                  ((config.Item("useenotccd").GetValue<bool>() &&
                    (!target.HasBuffOfType(BuffType.Snare) && !target.HasBuffOfType(BuffType.Slow) &&
                     !target.HasBuffOfType(BuffType.Stun) && !target.HasBuffOfType(BuffType.Suppression))) ||
                   !config.Item("useenotccd").GetValue<bool>()))
              {
                  E.Cast();
              }
              if (R.IsReady() && player.HealthPercent > 20 &&
                  ((config.Item("user").GetValue<bool>() && player.Distance(target) < 200 &&
                    ComboDamage(target) + R.GetDamage(target) * 10 > target.Health && ComboDamage(target) < target.Health) ||
                   (config.Item("usertf").GetValue<Slider>().Value <= player.CountEnemiesInRange(300))))
              {
                  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 &&
                  !W.CanCast(target))
              {
                  player.Spellbook.CastSpell(player.GetSpellSlot("SummonerDot"), target);
              }
          }
  
          private static bool QEnabled
          {
              get { return player.Buffs.Any(buff => buff.Name == "VolibearQ"); }
          }
  
          private static bool CanW
          {
              get { return player.Buffs.Any(buff => buff.Name == "volibearwparticle"); }
          }
  
          private void Game_OnDraw(EventArgs args)
          {
              float msBonus = 1f;
  
gt:             if (Q.IsReady() && !QEnabled)