context: #region
  
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Security.AccessControl;
  using System.Threading;
  using LeagueSharp;
  using LeagueSharp.Common;
  using SharpDX;
  using Color = System.Drawing.Color;
  
  #endregion
  
  namespace Xerath
  {
      internal class Program
      {
          public const string ChampionName = "Xerath";
  
          //Orbwalker instance
          public static Orbwalking.Orbwalker Orbwalker;
  
          //Spells
          public static List<Spell> SpellList = new List<Spell>();
  
          public static Spell Q;
          public static Spell W;
          public static Spell E;
          public static Spell R;
  
          //Menu
          public static Menu Config;
  
          private static Obj_AI_Hero Player;
  
          private static Vector2 PingLocation;
          private static int LastPingT = 0;
          private static bool AttacksEnabled
          {
              get
              {
                  if (IsCastingR)
                  {
                      return false;
                  }
  
  
                  if (!ObjectManager.Player.CanAttack)
                  {
                      return false;
                  }
  
  
                  if (Config.Item("ComboActive").GetValue<KeyBind>().Active)
                  {
                      return IsPassiveUp || (!Q.IsReady() && !W.IsReady() && !E.IsReady());
                  }
                      
  
                  return true;
              }
          }
  
          public static bool IsPassiveUp
          {
              get { return ObjectManager.Player.HasBuff("xerathascended2onhit"); }
          }
  
          public static bool IsCastingR
          {
              get
              {
                  return ObjectManager.Player.HasBuff("XerathLocusOfPower2") ||
                         (ObjectManager.Player.LastCastedSpellName().Equals("XerathLocusOfPower2", StringComparison.InvariantCultureIgnoreCase) &&
                          Utils.TickCount - ObjectManager.Player.LastCastedSpellT() < 500);
              }
          }
  
          public static class RCharge
          {
              public static int CastT;
              public static int Index;
              public static Vector3 Position;
              public static bool TapKeyPressed;
          }
  
          private static void Main(string[] args)
          {
              CustomEvents.Game.OnGameLoad += Game_OnGameLoad;
          }
  
          private static void Game_OnGameLoad(EventArgs args)
          {
              Player = ObjectManager.Player;
  
              if (Player.ChampionName != ChampionName) return;
  
              //Create the spells
              Q = new Spell(SpellSlot.Q, 1550);
              W = new Spell(SpellSlot.W, 1000);
              E = new Spell(SpellSlot.E, 1150);
              R = new Spell(SpellSlot.R, 675);
  
              Q.SetSkillshot(0.6f, 95f, float.MaxValue, false, SkillshotType.SkillshotLine);
              W.SetSkillshot(0.7f, 125f, float.MaxValue, false, SkillshotType.SkillshotCircle);
              E.SetSkillshot(0.25f, 60f, 1400f, true, SkillshotType.SkillshotLine);
              R.SetSkillshot(0.7f, 130f, float.MaxValue, false, SkillshotType.SkillshotCircle);
  
              Q.SetCharged("XerathArcanopulseChargeUp", "XerathArcanopulseChargeUp", 750, 1550, 1.5f);
  
              SpellList.Add(Q);
              SpellList.Add(W);
              SpellList.Add(E);
              SpellList.Add(R);
  
              //Create the menu
              Config = new Menu(ChampionName, ChampionName, true);
  
              //Orbwalker submenu
              Config.AddSubMenu(new Menu("Orbwalking", "Orbwalking"));
  
              //Add the target selector to the menu as submenu.
              var targetSelectorMenu = new Menu("Target Selector", "Target Selector");
              TargetSelector.AddToMenu(targetSelectorMenu);
              Config.AddSubMenu(targetSelectorMenu);
  
              //Load the orbwalker and add it to the menu as submenu.
              Orbwalker = new Orbwalking.Orbwalker(Config.SubMenu("Orbwalking"));
  
              //Combo menu:
              Config.AddSubMenu(new Menu("Combo", "Combo"));
              Config.SubMenu("Combo").AddItem(new MenuItem("UseQCombo", "Use Q").SetValue(true));
              Config.SubMenu("Combo").AddItem(new MenuItem("UseWCombo", "Use W").SetValue(true));
              Config.SubMenu("Combo").AddItem(new MenuItem("UseECombo", "Use E").SetValue(true));
              Config.SubMenu("Combo")
                  .AddItem(
                      new MenuItem("ComboActive", "Combo!").SetValue(
                          new KeyBind(Config.Item("Orbwalk").GetValue<KeyBind>().Key, KeyBindType.Press)));
  
              //Misc
              Config.AddSubMenu(new Menu("R", "R"));
              Config.SubMenu("R").AddItem(new MenuItem("EnableRUsage", "Auto use charges").SetValue(true));
              Config.SubMenu("R").AddItem(new MenuItem("rMode", "Mode").SetValue(new StringList(new[] { "Normal", "Custom delays", "OnTap"})));
              Config.SubMenu("R").AddItem(new MenuItem("rModeKey", "OnTap key").SetValue(new KeyBind('T', KeyBindType.Press)));
              Config.SubMenu("R").AddSubMenu(new Menu("Custom delays", "Custom delays"));
              for (int i = 1; i <= 5; i++)
                  Config.SubMenu("R").SubMenu("Custom delays").AddItem(new MenuItem("Delay"+i, "Delay"+i).SetValue(new Slider(0, 1500, 0)));
              Config.SubMenu("R").AddItem(new MenuItem("PingRKillable", "Ping on killable targets (only local)").SetValue(true));
              Config.SubMenu("R").AddItem(new MenuItem("BlockMovement", "Block right click while casting R").SetValue(false));
              Config.SubMenu("R").AddItem(new MenuItem("OnlyNearMouse", "Focus only targets near mouse").SetValue(false));
              Config.SubMenu("R").AddItem(new MenuItem("MRadius", "Radius").SetValue(new Slider(700, 1500, 300)));
  
              //Harass menu:
              Config.AddSubMenu(new Menu("Harass", "Harass"));
              Config.SubMenu("Harass").AddItem(new MenuItem("UseQHarass", "Use Q").SetValue(true));
              Config.SubMenu("Harass").AddItem(new MenuItem("UseWHarass", "Use W").SetValue(false));
              Config.SubMenu("Harass")
                  .AddItem(
                      new MenuItem("HarassActive", "Harass!").SetValue(
                          new KeyBind(Config.Item("Farm").GetValue<KeyBind>().Key, KeyBindType.Press)));
              Config.SubMenu("Harass")
                  .AddItem(
                      new MenuItem("HarassActiveT", "Harass (toggle)!").SetValue(new KeyBind('Y',
                          KeyBindType.Toggle)));
  
              //Farming menu:
              Config.AddSubMenu(new Menu("Farm", "Farm"));
              Config.SubMenu("Farm")
                  .AddItem(
                      new MenuItem("UseQFarm", "Use Q").SetValue(
                          new StringList(new[] { "Freeze", "LaneClear", "Both", "No" }, 2)));
              Config.SubMenu("Farm")
                  .AddItem(
                      new MenuItem("UseWFarm", "Use W").SetValue(
                          new StringList(new[] { "Freeze", "LaneClear", "Both", "No" }, 1)));
              Config.SubMenu("Farm")
                  .AddItem(
                      new MenuItem("FreezeActive", "Freeze!").SetValue(
                          new KeyBind(Config.Item("Farm").GetValue<KeyBind>().Key, KeyBindType.Press)));
              Config.SubMenu("Farm")
                  .AddItem(
                      new MenuItem("LaneClearActive", "LaneClear!").SetValue(
                          new KeyBind(Config.Item("LaneClear").GetValue<KeyBind>().Key, KeyBindType.Press)));
  
              //JungleFarm menu:
              Config.AddSubMenu(new Menu("JungleFarm", "JungleFarm"));
              Config.SubMenu("JungleFarm").AddItem(new MenuItem("UseQJFarm", "Use Q").SetValue(true));
              Config.SubMenu("JungleFarm").AddItem(new MenuItem("UseWJFarm", "Use W").SetValue(true));
              Config.SubMenu("JungleFarm")
                  .AddItem(
                      new MenuItem("JungleFarmActive", "JungleFarm!").SetValue(
                          new KeyBind(Config.Item("LaneClear").GetValue<KeyBind>().Key, KeyBindType.Press)));
  
              //Misc
              Config.AddSubMenu(new Menu("Misc", "Misc"));
              Config.SubMenu("Misc").AddItem(new MenuItem("InterruptSpells", "Interrupt spells").SetValue(true));
              Config.SubMenu("Misc").AddItem(new MenuItem("AutoEGC", "AutoE gapclosers").SetValue(true));
              Config.SubMenu("Misc").AddItem(new MenuItem("UseVHHC", "Use very high hit chance").SetValue(true));
  
              //Damage after combo:
              var dmgAfterComboItem = new MenuItem("DamageAfterR", "Draw damage after (3 - 5)xR").SetValue(true);
              Utility.HpBarDamageIndicator.DamageToUnit += hero => (float)Player.GetSpellDamage(hero, SpellSlot.R) * new int[] {0, 3, 4, 5 }[Player.GetSpell(SpellSlot.R).Level];
              Utility.HpBarDamageIndicator.Enabled = dmgAfterComboItem.GetValue<bool>();
              dmgAfterComboItem.ValueChanged += delegate(object sender, OnValueChangeEventArgs eventArgs)
              {
                  Utility.HpBarDamageIndicator.Enabled = eventArgs.GetNewValue<bool>();
              };
  
              //Drawings menu:
  
gt:             Config.AddSubMenu(new Menu("Drawings", "Drawings"));