context: using System;
  using System.Collections.Generic;
  using System.Linq;
  using LeagueSharp;
  using LeagueSharp.Common;
  using SharpDX;
  using Color = System.Drawing.Color;
  
  using EloBuddy; 
   using LeagueSharp.Common; 
   namespace Diana_Masterrace
  {
      public class LXOrbwalker
      {
  
          private static readonly string[] AttackResets = { "meditate", "dariusnoxiantacticsonh", "fioraflurry", "garenq", "hecarimrapidslash", "jaxempowertwo", "jaycehypercharge", "leonashieldofdaybreak", "luciane", "lucianq", "monkeykingdoubleattack", "mordekaisermaceofspades", "nasusq", "nautiluspiercinggaze", "netherblade", "parley", "poppydevastatingblow", "powerfist", "renektonpreexecute", "rengarq", "shyvanadoubleattack", "sivirw", "takedown", "talonnoxiandiplomacy", "trundletrollsmash", "vaynetumble", "vie", "volibearq", "xenzhaocombotarget", "yorickspectral" };
          private static readonly string[] NoAttacks = { "jarvanivcataclysmattack", "monkeykingdoubleattack", "shyvanadoubleattack", "shyvanadoubleattackdragon", "zyragraspingplantattack", "zyragraspingplantattack2", "zyragraspingplantattackfire", "zyragraspingplantattack2fire" };
          private static readonly string[] Attacks = { "caitlynheadshotmissile", "frostarrow", "garenslash2", "kennenmegaproc", "lucianpassiveattack", "masteryidoublestrike", "quinnwenhanced", "renektonexecute", "renektonsuperexecute", "rengarnewpassivebuffdash", "trundleq", "xenzhaothrust", "viktorqbuff", "xenzhaothrust2", "xenzhaothrust3" };
  
  
          public static Menu Menu;
          public static AIHeroClient MyHero = ObjectManager.Player;
          public static Obj_AI_Base ForcedTarget = null;
          public static IEnumerable<AIHeroClient> AllEnemys = ObjectManager.Get<AIHeroClient>().Where(hero => hero.IsEnemy);
          public static IEnumerable<AIHeroClient> AllAllys = ObjectManager.Get<AIHeroClient>().Where(hero => hero.IsAlly);
          public static bool CustomOrbwalkMode;
  
          public delegate void BeforeAttackEvenH(BeforeAttackEventArgs args);
          public delegate void OnTargetChangeH(Obj_AI_Base oldTarget, Obj_AI_Base newTarget);
          public delegate void AfterAttackEvenH(Obj_AI_Base unit, Obj_AI_Base target);
          public delegate void OnAttackEvenH(Obj_AI_Base unit, Obj_AI_Base target);
  
          public static event BeforeAttackEvenH BeforeAttack;
          public static event OnTargetChangeH OnTargetChange;
          public static event AfterAttackEvenH AfterAttack;
          public static event OnAttackEvenH OnAttack;
  
          public enum Mode
          {
              Combo,
              Harass,
              LaneClear,
              LaneFreeze,
              Lasthit,
              Flee,
              None,
          }
  
          private static bool _drawing = true;
          private static bool _attack = true;
          private static bool _movement = true;
          private static bool _disableNextAttack;
          private const float LaneClearWaitTimeMod = 2f;
          private static int _lastAATick;
          private static Obj_AI_Base _lastTarget;
          private static Spell _movementPrediction;
          private static int _lastMovement;
  
          public static float cantMoveTill = 0;
  
          public static void AddToMenu(Menu menu)
          {
              _movementPrediction = new Spell(SpellSlot.Unknown, GetAutoAttackRange());
              _movementPrediction.SetTargetted(MyHero.BasicAttack.SpellCastTime, MyHero.BasicAttack.MissileSpeed);
  
              Menu = menu;
  
              var menuDrawing = new Menu("Drawing", "lxOrbwalker_Draw");
              menuDrawing.AddItem(new MenuItem("lxOrbwalker_Draw_AARange", "AA Circle").SetValue(new Circle(true, Color.FloralWhite)));
              menuDrawing.AddItem(new MenuItem("lxOrbwalker_Draw_AARange_Enemy", "AA Circle Enemy").SetValue(new Circle(true, Color.Pink)));
              menuDrawing.AddItem(new MenuItem("lxOrbwalker_Draw_Holdzone", "Holdzone").SetValue(new Circle(true, Color.FloralWhite)));
              menuDrawing.AddItem(new MenuItem("lxOrbwalker_Draw_MinionHPBar", "Minion HPBar").SetValue(new Circle(true, Color.Black)));
              menuDrawing.AddItem(new MenuItem("lxOrbwalker_Draw_MinionHPBar_thickness", "^ HPBar Thickness").SetValue(new Slider(1, 1, 3)));
              menuDrawing.AddItem(new MenuItem("lxOrbwalker_Draw_hitbox", "Show HitBoxes").SetValue(new Circle(true, Color.FloralWhite)));
              menuDrawing.AddItem(new MenuItem("lxOrbwalker_Draw_Lasthit", "Minion Lasthit").SetValue(new Circle(true, Color.Lime)));
              menuDrawing.AddItem(new MenuItem("lxOrbwalker_Draw_nearKill", "Minion nearKill").SetValue(new Circle(true, Color.Gold)));
              menu.AddSubMenu(menuDrawing);
  
              var menuMisc = new Menu("Misc", "lxOrbwalker_Misc");
              menuMisc.AddItem(new MenuItem("lxOrbwalker_Misc_Holdzone", "Hold Position").SetValue(new Slider(50, 100, 0)));
              menuMisc.AddItem(new MenuItem("lxOrbwalker_Misc_Farmdelay", "Farm Delay").SetValue(new Slider(0, 200, 0)));
              menuMisc.AddItem(new MenuItem("lxOrbwalker_Misc_ExtraWindUp", "Extra Winduptime").SetValue(new Slider(80, 200, 0)));
              menuMisc.AddItem(new MenuItem("lxOrbwalker_Misc_AutoWindUp", "Autoset Windup").SetValue(false));
              menuMisc.AddItem(new MenuItem("lxOrbwalker_Misc_Priority_Unit", "Priority Unit").SetValue(new StringList(new[] { "Minion", "Hero" })));
              menuMisc.AddItem(new MenuItem("lxOrbwalker_Misc_Humanizer", "Humanizer Delay").SetValue(new Slider(50, 100, 0)));
              menuMisc.AddItem(new MenuItem("lxOrbwalker_Misc_AllMovementDisabled", "Disable All Movement").SetValue(false));
              menuMisc.AddItem(new MenuItem("lxOrbwalker_Misc_AllAttackDisabled", "Disable All Attacks").SetValue(false));
  
              menu.AddSubMenu(menuMisc);
  
              var menuMelee = new Menu("Melee", "lxOrbwalker_Melee");
              menuMelee.AddItem(new MenuItem("lxOrbwalker_Melee_Prediction", "Movement Prediction").SetValue(false));
              menu.AddSubMenu(menuMelee);
  
              var menuModes = new Menu("Orbwalk Mode", "lxOrbwalker_Modes");
              {
                  var modeCombo = new Menu("Combo", "lxOrbwalker_Modes_Combo");
                  modeCombo.AddItem(new MenuItem("Combo_Key", "Key").SetValue(new KeyBind(32, KeyBindType.Press)));
                  modeCombo.AddItem(new MenuItem("Combo_move", "Movement").SetValue(true));
                  modeCombo.AddItem(new MenuItem("Combo_attack", "Attack").SetValue(true));
                  modeCombo.AddItem(new MenuItem("Move_target", "Move to target").SetValue(true));
                  menuModes.AddSubMenu(modeCombo);
  
                  var modeHarass = new Menu("Harass", "lxOrbwalker_Modes_Harass");
                  modeHarass.AddItem(new MenuItem("Harass_Key", "Key").SetValue(new KeyBind("C".ToCharArray()[0], KeyBindType.Press)));
                  modeHarass.AddItem(new MenuItem("Harass_move", "Movement").SetValue(true));
                  modeHarass.AddItem(new MenuItem("Harass_attack", "Attack").SetValue(true));
                  modeHarass.AddItem(new MenuItem("Harass_Lasthit", "Lasthit Minions").SetValue(true));
                  menuModes.AddSubMenu(modeHarass);
  
                  var modeLaneClear = new Menu("LaneClear", "lxOrbwalker_Modes_LaneClear");
                  modeLaneClear.AddItem(new MenuItem("LaneClear_Key", "Key").SetValue(new KeyBind("V".ToCharArray()[0], KeyBindType.Press)));
                  modeLaneClear.AddItem(new MenuItem("LaneClear_move", "Movement").SetValue(true));
                  modeLaneClear.AddItem(new MenuItem("LaneClear_attack", "Attack").SetValue(true));
                  menuModes.AddSubMenu(modeLaneClear);
  
                  var modeLaneFreeze = new Menu("LaneFreeze", "lxOrbwalker_Modes_LaneFreeze");
                  modeLaneFreeze.AddItem(new MenuItem("LaneFreeze_Key", "Key").SetValue(new KeyBind("Z".ToCharArray()[0], KeyBindType.Press)));
                  modeLaneFreeze.AddItem(new MenuItem("LaneFreeze_move", "Movement").SetValue(true));
                  modeLaneFreeze.AddItem(new MenuItem("LaneFreeze_attack", "Attack").SetValue(true));
                  menuModes.AddSubMenu(modeLaneFreeze);
  
                  var modeLasthit = new Menu("LastHit", "lxOrbwalker_Modes_LastHit");
                  modeLasthit.AddItem(new MenuItem("LastHit_Key", "Key").SetValue(new KeyBind("X".ToCharArray()[0], KeyBindType.Press)));
                  modeLasthit.AddItem(new MenuItem("LastHit_move", "Movement").SetValue(true));
                  modeLasthit.AddItem(new MenuItem("LastHit_attack", "Attack").SetValue(true));
                  menuModes.AddSubMenu(modeLasthit);
  
                  var modeFlee = new Menu("Flee", "lxOrbwalker_Modes_Flee");
                  modeFlee.AddItem(new MenuItem("Flee_Key", "Key").SetValue(new KeyBind("A".ToCharArray()[0], KeyBindType.Press)));
                  menuModes.AddSubMenu(modeFlee);
              }
              menu.AddSubMenu(menuModes);
  
  
              Drawing.OnDraw += OnDraw;
              Game.OnUpdate += OnUpdate;
              Obj_AI_Base.OnProcessSpellCast += OnProcessSpell;
              GameObject.OnCreate += MissileClient_OnCreate;
          }
  
          private static void MissileClient_OnCreate(GameObject sender, EventArgs args)
          {
              if (sender.IsMe)
              {
                  var obj = (AIHeroClient)sender;
                  if (obj.IsMelee())
                      return;
              }
              if (!(sender is MissileClient) || !sender.IsValid)
                  return;
              var missile = (MissileClient)sender;
              if (missile.SpellCaster is AIHeroClient && missile.SpellCaster.IsValid && IsAutoAttack(missile.SData.Name))
                  FireAfterAttack(missile.SpellCaster, _lastTarget);
          }
  
          private static void OnUpdate(EventArgs args)
          {
              CheckAutoWindUp();
              if (CurrentMode == Mode.None || MenuGUI.IsChatOpen)
                  return;
              var target = GetPossibleTarget();
              if (Menu.Item("Move_target").GetValue<bool>() && target != null && target is AIHeroClient)
              {
                  if (target.Path.Count() == 0)
                      Orbwalk(target.Position.To2D().Extend(target.Direction.To2D(), 140).To3D(), target);
                  else
                      Orbwalk(target.Position.To2D().Extend(target.Path[0].To2D(), 140).To3D(), target);
              }
              else
              {
                  Orbwalk(Game.CursorPos, target);
              }
          }
  
          public static void Orbwalk(Vector3 goalPosition, Obj_AI_Base target)
          {
              if (target != null && CanAttack() && IsAllowedToAttack())
              {
                  _disableNextAttack = false;
                  FireBeforeAttack(target);
                  if (!_disableNextAttack)
                  {
                      if (EloBuddy.Player.IssueOrder(GameObjectOrder.AttackUnit, target))
                          _lastAATick = Environment.TickCount + Game.Ping / 2;
                  }
              }
              if (!CanMove() || !IsAllowedToMove())
                  return;
              if (MyHero.IsMelee() && target != null && target.Distance(MyHero,false) < GetAutoAttackRange(MyHero, target)
                  && Menu.Item("lxOrbwalker_Melee_Prediction").GetValue<bool>() && target is AIHeroClient
                  && Game.CursorPos.Distance(target.Position) < 300)
              {
                  _movementPrediction.Delay = MyHero.BasicAttack.SpellCastTime;
                  _movementPrediction.Speed = MyHero.BasicAttack.MissileSpeed;
  
                  MoveTo(_movementPrediction.GetPrediction(target).UnitPosition);
              }
              else
              {
                  MoveTo(goalPosition);
              }
  
          }
  
          private static void MoveTo(Vector3 position, float holdAreaRadius = -1)
          {
              var delay = Menu.Item("lxOrbwalker_Misc_Humanizer").GetValue<Slider>().Value;
              if (Environment.TickCount - _lastMovement < delay)
                  return;
              _lastMovement = Environment.TickCount;
  
              if (!CanMove())
                  return;
              if (holdAreaRadius < 0)
                  holdAreaRadius = Menu.Item("lxOrbwalker_Misc_Holdzone").GetValue<Slider>().Value;
              if (MyHero.ServerPosition.Distance(position) < holdAreaRadius)
              {
  
gt:                 if (MyHero.Path.Count() > 1)