context: #region License
  
  /*
   Copyright 2014 - 2015 Nikita Bernthaler
   Varus.cs is part of SFXChallenger.
  
   SFXChallenger is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
  
   SFXChallenger is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   GNU General Public License for more details.
  
   You should have received a copy of the GNU General Public License
   along with SFXChallenger. If not, see <http://www.gnu.org/licenses/>.
  */
  
  #endregion License
  
  #region
  
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using LeagueSharp;
  using LeagueSharp.Common;
  using SFXChallenger.Abstracts;
  using SFXChallenger.Enumerations;
  using SFXChallenger.Helpers;
  using SFXChallenger.Library;
  using SFXChallenger.Library.Logger;
  using SFXChallenger.Managers;
  using SFXChallenger.SFXTargetSelector;
  using SharpDX;
  using Collision = LeagueSharp.Common.Collision;
  using Color = System.Drawing.Color;
  using DamageType = SFXChallenger.Enumerations.DamageType;
  using MinionManager = SFXChallenger.Library.MinionManager;
  using MinionOrderTypes = SFXChallenger.Library.MinionOrderTypes;
  using MinionTeam = SFXChallenger.Library.MinionTeam;
  using MinionTypes = SFXChallenger.Library.MinionTypes;
  using Orbwalking = SFXChallenger.Wrappers.Orbwalking;
  using Spell = SFXChallenger.Wrappers.Spell;
  using TargetSelector = SFXChallenger.SFXTargetSelector.TargetSelector;
  using Utils = SFXChallenger.Helpers.Utils;
  
  #endregion
  
  namespace SFXChallenger.Champions
  {
      internal class Varus : Champion
      {
          private float _lastLaneClearQStart;
          private float _rSpreadRadius = 450f;
          private MenuItem _wStacks;
  
          protected override ItemFlags ItemFlags
          {
              get { return ItemFlags.Offensive | ItemFlags.Defensive | ItemFlags.Flee; }
          }
  
          protected override ItemUsageType ItemUsage
          {
              get { return ItemUsageType.AfterAttack; }
          }
  
          protected override void OnLoad()
          {
              AntiGapcloser.OnEnemyGapcloser += OnEnemyGapcloser;
              Drawing.OnDraw += OnDrawingDraw;
          }
  
          protected override void AddToMenu()
          {
              var ultimateMenu = UltimateManager.AddToMenu(Menu, true, false, false, true, false, false, true, true, true);
  
              ultimateMenu.AddItem(
                  new MenuItem(ultimateMenu.Name + ".radius", "Range").SetValue(new Slider(450, 100, 600))).ValueChanged
                  +=
                  delegate(object sender, OnValueChangeEventArgs args)
                  {
                      _rSpreadRadius = args.GetNewValue<Slider>().Value;
                  };
  
              _rSpreadRadius = Menu.Item(Menu.Name + ".ultimate.radius").GetValue<Slider>().Value;
  
              var comboMenu = Menu.AddSubMenu(new Menu("Combo", Menu.Name + ".combo"));
              HitchanceManager.AddToMenu(
                  comboMenu.AddSubMenu(new Menu("Hitchance", comboMenu.Name + ".hitchance")), "combo",
                  new Dictionary<string, HitChance>
                  {
                      { "Q", HitChance.High },
                      { "E", HitChance.High },
                      { "R", HitChance.VeryHigh }
                  });
              comboMenu.AddItem(
                  new MenuItem(comboMenu.Name + ".q-fast-cast-min", "Fast Cast @ Health %").SetValue(new Slider(25)));
              comboMenu.AddItem(new MenuItem(comboMenu.Name + ".q-range", "Q " + "Out of Range").SetValue(true));
              comboMenu.AddItem(new MenuItem(comboMenu.Name + ".q-always", "Q " + "Always").SetValue(false));
              comboMenu.AddItem(new MenuItem(comboMenu.Name + ".q-stacks", "Q " + "Stacks >="))
                  .SetValue(new Slider(3, 1, 3));
              comboMenu.AddItem(new MenuItem(comboMenu.Name + ".q-min", "Q Min.").SetValue(new Slider(3, 1, 3)));
              comboMenu.AddItem(new MenuItem(comboMenu.Name + ".q", "Use Q").SetValue(true));
              comboMenu.AddItem(new MenuItem(comboMenu.Name + ".e-always", "E " + "Always").SetValue(true));
              comboMenu.AddItem(new MenuItem(comboMenu.Name + ".e-stacks", "E " + "Stacks >="))
                  .SetValue(new Slider(3, 1, 3));
              comboMenu.AddItem(new MenuItem(comboMenu.Name + ".e-min", "E Min.").SetValue(new Slider(3, 1, 3)));
              comboMenu.AddItem(new MenuItem(comboMenu.Name + ".e", "Use E").SetValue(true));
  
              var harassMenu = Menu.AddSubMenu(new Menu("Harass", Menu.Name + ".harass"));
              HitchanceManager.AddToMenu(
                  harassMenu.AddSubMenu(new Menu("Hitchance", harassMenu.Name + ".hitchance")), "harass",
                  new Dictionary<string, HitChance> { { "Q", HitChance.High }, { "E", HitChance.High } });
              ManaManager.AddToMenu(harassMenu, "harass", ManaCheckType.Minimum, ManaValueType.Percent);
              harassMenu.AddItem(
                  new MenuItem(harassMenu.Name + ".q-fast-cast-min", "Fast Cast @ Health %").SetValue(new Slider(25)));
              harassMenu.AddItem(new MenuItem(harassMenu.Name + ".q-range", "Q " + "Out of Range").SetValue(true));
              harassMenu.AddItem(new MenuItem(harassMenu.Name + ".q-always", "Q " + "Always").SetValue(false));
              harassMenu.AddItem(new MenuItem(harassMenu.Name + ".q-stacks", "Q " + "Stacks >="))
                  .SetValue(new Slider(3, 1, 3));
              harassMenu.AddItem(new MenuItem(harassMenu.Name + ".q-min", "Q Min.").SetValue(new Slider(3, 1, 3)));
              harassMenu.AddItem(new MenuItem(harassMenu.Name + ".q", "Use Q").SetValue(true));
              harassMenu.AddItem(new MenuItem(harassMenu.Name + ".e-always", "E " + "Always").SetValue(false));
              harassMenu.AddItem(new MenuItem(harassMenu.Name + ".e-stacks", "E " + "Stacks >="))
                  .SetValue(new Slider(3, 1, 3));
              harassMenu.AddItem(new MenuItem(harassMenu.Name + ".e-min", "E Min.").SetValue(new Slider(3, 1, 3)));
              harassMenu.AddItem(new MenuItem(harassMenu.Name + ".e", "Use E").SetValue(true));
  
              var laneclearMenu = Menu.AddSubMenu(new Menu("Lane Clear", Menu.Name + ".lane-clear"));
              ManaManager.AddToMenu(laneclearMenu, "lane-clear", ManaCheckType.Minimum, ManaValueType.Percent);
              laneclearMenu.AddItem(new MenuItem(laneclearMenu.Name + ".q", "Use Q").SetValue(true));
              laneclearMenu.AddItem(new MenuItem(laneclearMenu.Name + ".e", "Use E").SetValue(true));
              laneclearMenu.AddItem(new MenuItem(laneclearMenu.Name + ".min", "Min.").SetValue(new Slider(3, 1, 5)));
  
              var fleeMenu = Menu.AddSubMenu(new Menu("Flee", Menu.Name + ".flee"));
              fleeMenu.AddItem(new MenuItem(fleeMenu.Name + ".e", "Use E").SetValue(true));
  
              var killstealMenu = Menu.AddSubMenu(new Menu("Killsteal", Menu.Name + ".killsteal"));
              killstealMenu.AddItem(new MenuItem(killstealMenu.Name + ".q", "Use Q").SetValue(true));
              killstealMenu.AddItem(new MenuItem(killstealMenu.Name + ".range", "Out of Range").SetValue(true));
  
              var miscMenu = Menu.AddSubMenu(new Menu("Misc", Menu.Name + ".miscellaneous"));
              HeroListManager.AddToMenu(
                  miscMenu.AddSubMenu(new Menu("E Gapcloser", miscMenu.Name + "e-gapcloser")), "e-gapcloser", false, false,
                  true, false);
  
              Weights.AddItem(new Weights.Item("w-stacks", "W " + "Stacks", 13, true, t => GetWStacks(t) + 1));
  
              IndicatorManager.AddToMenu(DrawingManager.Menu, true);
              IndicatorManager.Add("Q", hero => Q.IsReady() ? Q.GetDamage(hero, 1) : 0);
              IndicatorManager.Add(E);
              IndicatorManager.Add(R);
              IndicatorManager.Finale();
  
              _wStacks = DrawingManager.Add("W " + "Stacks", true);
          }
  
          protected override void SetupSpells()
          {
              Q = new Spell(SpellSlot.Q, 925f);
              Q.SetSkillshot(0.25f, 70f, 1800f, false, SkillshotType.SkillshotLine);
              Q.SetCharged("VarusQ", "VarusQ", 925, 1700, 1.5f);
  
              W = new Spell(SpellSlot.W, 0f, DamageType.Magical);
  
              E = new Spell(SpellSlot.E, 950f);
              E.SetSkillshot(0.25f, 250f, 1500f, false, SkillshotType.SkillshotCircle);
  
              R = new Spell(SpellSlot.R, 1075f);
              R.SetSkillshot(0.25f, 120f, 1950f, false, SkillshotType.SkillshotLine);
          }
  
          protected override void OnPreUpdate() {}
  
          protected override void OnPostUpdate()
          {
              Orbwalker.SetAttack(!Q.IsCharging);
              if (UltimateManager.Assisted() && R.IsReady())
              {
                  if (Menu.Item(Menu.Name + ".ultimate.assisted.move-cursor").GetValue<bool>())
                  {
                      Orbwalking.MoveTo(Game.CursorPos, Orbwalker.HoldAreaRadius);
                  }
  
                  if (
                      !RLogic(
                          TargetSelector.GetTarget(R), R.GetHitChance("combo"),
                          Menu.Item(Menu.Name + ".ultimate.assisted.min").GetValue<Slider>().Value,
                          Menu.Item(Menu.Name + ".combo.q").GetValue<bool>() && Q.IsReady(),
                          Menu.Item(Menu.Name + ".combo.e").GetValue<bool>() && E.IsReady()))
                  {
                      RLogicSingle(
                          Menu.Item(Menu.Name + ".combo.q").GetValue<bool>() && Q.IsReady(),
                          Menu.Item(Menu.Name + ".combo.e").GetValue<bool>() && E.IsReady());
                  }
              }
  
              if (UltimateManager.Auto() && R.IsReady())
              {
                  if (
                      !RLogic(
                          TargetSelector.GetTarget(R), R.GetHitChance("combo"),
                          Menu.Item(Menu.Name + ".ultimate.auto.min").GetValue<Slider>().Value,
                          Menu.Item(Menu.Name + ".combo.q").GetValue<bool>() && Q.IsReady(),
                          Menu.Item(Menu.Name + ".combo.e").GetValue<bool>() && E.IsReady(), UltimateModeType.Auto))
                  {
                      RLogicSingle(
                          Menu.Item(Menu.Name + ".combo.q").GetValue<bool>() && Q.IsReady(),
                          Menu.Item(Menu.Name + ".combo.e").GetValue<bool>() && E.IsReady());
                  }
              }
          }
  
          private void OnEnemyGapcloser(ActiveGapcloser args)
          {
              try
              {
                  if (!args.Sender.IsEnemy)
                  {
                      return;
                  }
  
                  if (HeroListManager.Check("e-gapcloser", args.Sender) && args.End.Distance(Player.Position) < E.Range &&
                      E.IsReady())
                  {
                      var target = TargetSelector.GetTarget(E.Range * 0.85f, E.DamageType);
                      if (target == null || args.Sender.NetworkId.Equals(target.NetworkId))
                      {
                          E.Cast(args.End);
                      }
                  }
                  if (UltimateManager.Gapcloser(args.Sender))
                  {
                      RLogic(
                          args.Sender, HitChance.High, 1,
                          Menu.Item(Menu.Name + ".combo.q").GetValue<bool>() && Q.IsReady(),
                          Menu.Item(Menu.Name + ".combo.e").GetValue<bool>() && E.IsReady());
                  }
              }
              catch (Exception ex)
              {
                  Global.Logger.AddItem(new LogItem(ex));
              }
          }
  
          protected override void Combo()
          {
              var q = Menu.Item(Menu.Name + ".combo.q").GetValue<bool>();
              var e = Menu.Item(Menu.Name + ".combo.e").GetValue<bool>();
              var r = UltimateManager.Combo();
  
              if (e && !Q.IsCharging && E.IsReady())
              {
                  var target = TargetSelector.GetTarget(E);
  
gt:                 if (target != null)