context: // --------------------------------------------------------------------------------------------------------------------
  // <copyright file="Program.cs.cs" company="SurvivorSeriesBrand">
  //      Copyright (c) SurvivorSeriesBrand. All rights reserved.
  // </copyright>
  // --------------------------------------------------------------------------------------------------------------------
  
  using System;
  using System.Drawing;
  using System.Linq;
  using LeagueSharp;
  using LeagueSharp.Common;
  using SebbyLib;
  using SharpDX;
  using Color = SharpDX.Color;
  using HitChance = SebbyLib.Prediction.HitChance;
  using Orbwalking = SebbyLib.Orbwalking;
  using Prediction = SebbyLib.Prediction.Prediction;
  using PredictionInput = SebbyLib.Prediction.PredictionInput;
  
  using EloBuddy; 
  using LeagueSharp.Common; 
  namespace SurvivorBrand
  {
      internal class Program
      {
          public static void Game_OnGameLoad()
          {
              if (Player.ChampionName != ChampionName)
                  return;
  
              #region Spells
  
              Q = new Spell(SpellSlot.Q, 1050f);
              W = new Spell(SpellSlot.W, 900f);
              E = new Spell(SpellSlot.E, 625f);
              R = new Spell(SpellSlot.R, 750f);
              Q.SetSkillshot(0.25f, 60f, 1600f, true, SkillshotType.SkillshotLine);
              W.SetSkillshot(1.15f, 230f, float.MaxValue, false, SkillshotType.SkillshotCircle);
              R.SetTargetted(0.25f, 2000f);
  
              #endregion
  
              #region SummonerSpells
  
              IgniteSlot = Player.GetSpellSlot("summonerdot");
  
              #endregion
  
              #region Menu
  
              Menu = new Menu("SurvivorBrand", "SurvivorBrand", true);
  
              var OrbwalkerMenu = Menu.AddSubMenu(new Menu("Orbwalker", "Orbwalker"));
              Orbwalker = new Orbwalking.Orbwalker(OrbwalkerMenu);
  
              var TargetSelectorMenu = Menu.AddSubMenu(new Menu("Target Selector", "TargetSelector"));
              TargetSelector.AddToMenu(TargetSelectorMenu);
  
              var ComboMenu = Menu.AddSubMenu(new Menu("Combo", "Combo"));
              ComboMenu.AddItem(new MenuItem("ComboUseQ", "Use Q").SetValue(true));
              ComboMenu.AddItem(new MenuItem("ComboUseW", "Use W").SetValue(true));
              ComboMenu.AddItem(new MenuItem("ComboUseE", "Use E").SetValue(true));
              ComboMenu.AddItem(new MenuItem("ComboUseR", "Use R").SetValue(true));
              ComboMenu.AddItem(new MenuItem("ComboUseRKillable", "Use R Only if Killable").SetValue(true));
              // ComboMenu.AddItem(new MenuItem("ComboUseIgnite", "Use Ignite").SetValue(true));
  
              var HarassMenu = Menu.AddSubMenu(new Menu("Harass", "Harass"));
              HarassMenu.AddItem(new MenuItem("harassQ", "Use Q").SetValue(true));
              HarassMenu.AddItem(new MenuItem("harassW", "Use W").SetValue(true));
              HarassMenu.AddItem(new MenuItem("harassE", "Use E").SetValue(true));
              HarassMenu.AddItem(new MenuItem("HarassBlockAA", "Block AA's in Harass Mode").SetValue(true));
              HarassMenu.AddItem(new MenuItem("HarassManaManager", "Mana Manager (%)").SetValue(new Slider(30, 1, 100)));
  
              var JungleClearMenu = Menu.AddSubMenu(new Menu("JungleClear", "JungleClear"));
              JungleClearMenu.AddItem(new MenuItem("UseQJC", "Use Q").SetValue(true));
              JungleClearMenu.AddItem(new MenuItem("UseWJC", "Use W").SetValue(true));
              JungleClearMenu.AddItem(new MenuItem("UseEJC", "Use E").SetValue(true));
              JungleClearMenu.AddItem(new MenuItem("JungleClearManaManager", "JungleClear Mana Manager").SetValue(new Slider(50, 0, 100)));
  
              var LaneClearMenu = Menu.AddSubMenu(new Menu("Lane Clear", "LaneClear"));
              LaneClearMenu.AddItem(new MenuItem("laneclearW", "Use W").SetValue(true));
              LaneClearMenu.AddItem(new MenuItem("laneclearE", "Use E").SetValue(true));
              LaneClearMenu.AddItem(
                  new MenuItem("LaneClearWMinions", "Minimum Enemies inside W").SetValue(new Slider(2, 1, 10)));
              LaneClearMenu.AddItem(
                  new MenuItem("LaneClearManaManager", "Mana Manager (%)").SetValue(new Slider(30, 1, 100)));
  
              var KillStealMenu = Menu.AddSubMenu(new Menu("Kill Steal", "KillSteal"));
              KillStealMenu.AddItem(
                  new MenuItem("KillStealWithAvSpells", "KS with available spells (Q/W/E)").SetValue(true));
  
              var MiscMenu = Menu.AddSubMenu(new Menu("Misc", "Misc"));
              MiscMenu.AddItem(new MenuItem("PrioritizeStunned", "Prioritize Stunned Targets?").SetValue(true));
              MiscMenu.AddItem(
                  new MenuItem("StunTargetKey", "Stun the target if possible while holding Key -> 'G'").SetValue(
                      new KeyBind("G".ToCharArray()[0], KeyBindType.Press)));
              MiscMenu.AddItem(new MenuItem("QAblazedEnemy", "Auto Q if Target's [ABlazed]").SetValue(true));
              MiscMenu.AddItem(new MenuItem("QGapC", "Auto Stun GapClosers").SetValue(true));
              MiscMenu.AddItem(new MenuItem("InterruptEQ", "Auto E-Q to Interrupt").SetValue(false));
              MiscMenu.AddItem(new MenuItem("QOnlyAblazed", "Use Q Only if Enemy is Ablazed").SetValue(false));
              MiscMenu.AddItem(
                  new MenuItem("NearbyREnemies", "Use R in Combo if X Enemies are nearby 'X' ->").SetValue(new Slider(1, 0,
                      5)));
  
              var AutoLevelerMenu = Menu.AddSubMenu(new Menu("AutoLeveler Menu", "AutoLevelerMenu"));
              AutoLevelerMenu.AddItem(new MenuItem("AutoLevelUp", "AutoLevel Up Spells?").SetValue(true));
              AutoLevelerMenu.AddItem(
                  new MenuItem("AutoLevelUp1", "First: ").SetValue(new StringList(new[] {"Q", "W", "E", "R"}, 3)));
              AutoLevelerMenu.AddItem(
                  new MenuItem("AutoLevelUp2", "Second: ").SetValue(new StringList(new[] {"Q", "W", "E", "R"}, 0)));
              AutoLevelerMenu.AddItem(
                  new MenuItem("AutoLevelUp3", "Third: ").SetValue(new StringList(new[] {"Q", "W", "E", "R"}, 1)));
              AutoLevelerMenu.AddItem(
                  new MenuItem("AutoLevelUp4", "Fourth: ").SetValue(new StringList(new[] {"Q", "W", "E", "R"}, 2)));
              AutoLevelerMenu.AddItem(
                  new MenuItem("AutoLvlStartFrom", "AutoLeveler Start from Level: ").SetValue(new Slider(2, 6, 1)));
  
              var DrawingMenu = Menu.AddSubMenu(new Menu("Drawing", "Drawing"));
              DrawingMenu.AddItem(new MenuItem("DrawQ", "Draw Q Range").SetValue(true));
              DrawingMenu.AddItem(
                  new MenuItem("DrawPassiveBombOnEnemy", "Draw Passive Bomb on Enemy (Range) (Soon)").SetValue(true));
              DrawingMenu.AddItem(new MenuItem("DrawW", "Draw W Range").SetValue(true));
              DrawingMenu.AddItem(new MenuItem("DrawE", "Draw E Range").SetValue(true));
              DrawingMenu.AddItem(new MenuItem("DrawR", "Draw R Range").SetValue(true));
  
              #endregion
  
              #region Skin Changer
  
              var SkinChangerMenu =
                  Menu.AddSubMenu(new Menu(":: Skin Changer", "SkinChanger").SetFontStyle(FontStyle.Bold, Color.Chartreuse));
              var SkinChanger =
                  SkinChangerMenu.AddItem(
                      new MenuItem("UseSkinChanger", ":: Use SkinChanger?").SetValue(true)
                          .SetFontStyle(FontStyle.Bold, Color.Crimson));
              var SkinID =
                  SkinChangerMenu.AddItem(
                      new MenuItem("SkinID", ":: Skin").SetValue(new Slider(5, 0, 5))
                          .SetFontStyle(FontStyle.Bold, Color.Crimson));
              SkinID.ValueChanged += (sender, eventArgs) =>
              {
                  if (!SkinChanger.GetValue<bool>())
                      return;
  
                  //Player.SetSkin(Player.BaseSkinName, eventArgs.GetNewValue<Slider>().Value);
              };
  
              #endregion
  
              #region DrawHPDamage
  
              var dmgAfterShave =
                  DrawingMenu.AddItem(new MenuItem("SurvivorBrand.DrawComboDamage", "Draw Combo Damage").SetValue(true));
              var drawFill =
                  DrawingMenu.AddItem(new MenuItem("SurvivorBrand.DrawColour", "Fill Color", true).SetValue(
                      new Circle(true, System.Drawing.Color.FromArgb(204, 255, 0, 1))));
              DrawDamage.DamageToUnit = CalculateDamage;
              DrawDamage.Enabled = dmgAfterShave.GetValue<bool>();
              DrawDamage.Fill = drawFill.GetValue<Circle>().Active;
              DrawDamage.FillColor = drawFill.GetValue<Circle>().Color;
              dmgAfterShave.ValueChanged +=
                  delegate(object sender, OnValueChangeEventArgs eventArgs)
                  {
                      DrawDamage.Enabled = eventArgs.GetNewValue<bool>();
                  };
  
              drawFill.ValueChanged += delegate(object sender, OnValueChangeEventArgs eventArgs)
              {
                  DrawDamage.Fill = eventArgs.GetNewValue<Circle>().Active;
                  DrawDamage.FillColor = eventArgs.GetNewValue<Circle>().Color;
              };
  
              #endregion
  
              Menu.AddToMainMenu();
  
              #region Subscriptions
  
              Game.OnUpdate += OnUpdate;
              Interrupter2.OnInterruptableTarget += Interrupter2_OnInterruptableTarget;
              Obj_AI_Base.OnLevelUp += Obj_AI_Base_OnLevelUp;
              AntiGapcloser.OnEnemyGapcloser += AntiGapcloser_OnEnemyGapcloser;
              Drawing.OnDraw += OnDraw;
              Chat.Print("<font color='#800040'>[SurvivorSeries] Brand</font> <font color='#ff6600'>Loaded.</font>");
              // Add AntiGapCloser + Interrupter + Killsteal //
  
              #endregion
          }
  
          private static void OnDraw(EventArgs args)
          {
              if (Player.IsDead)
                  return;
              //var m = TargetSelector.GetTarget(Q.Range, TargetSelector.DamageType.Magical);
              if (Menu.Item("DrawQ").GetValue<bool>())
                  Render.Circle.DrawCircle(Player.Position, Q.Range, System.Drawing.Color.Aqua);
              //if (Menu.Item("DrawPassiveBombOnEnemy").GetValue<bool>())
              //    Render.Circle.DrawCircle(m.Position, 420f, Color.Orange);
              if (Menu.Item("DrawW").GetValue<bool>())
                  Render.Circle.DrawCircle(Player.Position, W.Range, System.Drawing.Color.MediumPurple);
              if (Menu.Item("DrawE").GetValue<bool>())
                  Render.Circle.DrawCircle(Player.Position, E.Range, System.Drawing.Color.LightPink);
              if (Menu.Item("DrawR").GetValue<bool>())
                  Render.Circle.DrawCircle(Player.Position, R.Range, System.Drawing.Color.MediumVioletRed);
          }
  
          private static void AABlock()
          {
              Orbwalker.SetAttack(!Menu.Item("HarassBlockAA").GetValue<bool>());
              //SebbyLib.OktwCommon.blockAttack = Menu.Item("CBlockAA").GetValue<bool>();
          }
  
          private static void JungleClear()
          {
              if (Player.ManaPercent < Menu.Item("JungleClearManaManager").GetValue<Slider>().Value)
                  return;
              var jgcq = Menu.Item("UseQJC").GetValue<bool>();
              var jgcw = Menu.Item("UseWJC").GetValue<bool>();
              var jgce = Menu.Item("UseEJC").GetValue<bool>();
  
              var mob =
                  MinionManager.GetMinions(Player.ServerPosition, W.Range, MinionTypes.All, MinionTeam.Neutral,
                      MinionOrderTypes.MaxHealth).FirstOrDefault();
              if (mob == null || !mob.IsValidTarget())
                  return;
  
              if (jgcw && W.IsReady())
                  W.Cast(mob.Position);
              if (jgcq && Q.IsReady())
                  Q.Cast(mob);
              if (jgce && E.IsReady())
                  E.CastOnUnit(mob);
          }
  
          private static void OnUpdate(EventArgs args)
          {
              if (Player.IsDead || Player.IsRecalling())
                  return;
              // Checks
              RManaCost();
              // Combo
              if (Orbwalker.ActiveMode == Orbwalking.OrbwalkingMode.Combo)
                  Combo();
              //Lane
              if (Orbwalker.ActiveMode == Orbwalking.OrbwalkingMode.LaneClear) // LaneClear mode broken? kappa
              {
                  JungleClear();
                  LaneClear();
              }
              if (Orbwalker.ActiveMode == Orbwalking.OrbwalkingMode.Mixed)
              {
                  AABlock();
                  Harass();
              }
              if (Orbwalker.ActiveMode == Orbwalking.OrbwalkingMode.None)
              {
                  Orbwalker.SetMovement(true);
                  Orbwalker.SetAttack(true);
              }
              if (Menu.Item("StunTargetKey").GetValue<KeyBind>().Active)
              {
                  Orbwalking.MoveTo(Game.CursorPos);
                  if (Orbwalker.ActiveMode == Orbwalking.OrbwalkingMode.None)
                  {
                      var t = TargetSelector.GetTarget(Q.Range, TargetSelector.DamageType.Magical);
                      if (!t.IsValidTarget() || (t == null))
                          return;
                      // Wait till the enemy has BrandABlaze from the W or E casting and then cast Q.
                      if (t.HasBuff("brandablaze"))
                      {
                          if (Q.IsReady())
                              SebbySpell(Q, t);
                      }
                      else
                      {
                          if (Q.IsReady() && E.IsReady())
                              E.CastOnUnit(t);
                          if (t.HasBuff("brandablaze") && Q.IsReady())
                              SebbySpell(Q, t);
                      }
                  }
              }
  
              //AutoLeveler
              if (Menu.Item("AutoLevelUp").GetValue<bool>())
              {
                  lvl1 = Menu.Item("AutoLevelUp1").GetValue<StringList>().SelectedIndex;
                  lvl2 = Menu.Item("AutoLevelUp2").GetValue<StringList>().SelectedIndex;
                  lvl3 = Menu.Item("AutoLevelUp3").GetValue<StringList>().SelectedIndex;
                  lvl4 = Menu.Item("AutoLevelUp4").GetValue<StringList>().SelectedIndex;
              }
          }
  
          private static void AntiGapcloser_OnEnemyGapcloser(ActiveGapcloser gapcloser)
          {
              if (!Menu.Item("QGapC", true).GetValue<bool>() || (Player.Mana < Q.Instance.SData.Mana + E.Instance.SData.Mana))
                  return;
  
              var t = gapcloser.Sender;
  
              if (t.IsValidTarget(E.Range) && (t.HasBuff("brandablaze") || E.IsReady()))
              {
                  E.CastOnUnit(t);
                  if (Q.IsReady())
                      Q.Cast(t);
              }
          }
  
          private static void Interrupter2_OnInterruptableTarget(AIHeroClient t,
              Interrupter2.InterruptableTargetEventArgs args)
          {
              if (!Menu.Item("InterruptEQ", true).GetValue<bool>() ||
                  (Player.Mana < Q.Instance.SData.Mana + E.Instance.SData.Mana))
                  return;
  
              if (t.IsValidTarget(E.Range) && (t.HasBuff("brandablaze") || E.IsReady()))
              {
                  E.CastOnUnit(t);
                  if (Q.IsReady())
                      Q.Cast(t);
              }
          }
  
          private static void Obj_AI_Base_OnLevelUp(Obj_AI_Base sender, EventArgs args)
          {
              if (!sender.IsMe || !Menu.Item("AutoLevelUp").GetValue<bool>() ||
                  (ObjectManager.Player.Level < Menu.Item("AutoLvlStartFrom").GetValue<Slider>().Value))
                  return;
              if ((lvl2 == lvl3) || (lvl2 == lvl4) || (lvl3 == lvl4))
                  return;
              var delay = 700;
              LeagueSharp.Common.Utility.DelayAction.Add(delay, () => LevelUp(lvl1));
              LeagueSharp.Common.Utility.DelayAction.Add(delay + 50, () => LevelUp(lvl2));
              LeagueSharp.Common.Utility.DelayAction.Add(delay + 100, () => LevelUp(lvl3));
              LeagueSharp.Common.Utility.DelayAction.Add(delay + 150, () => LevelUp(lvl4));
          }
  
          private static void LevelUp(int indx)
          {
              if (ObjectManager.Player.Level < 4)
              {
                  if ((indx == 0) && (ObjectManager.Player.Spellbook.GetSpell(SpellSlot.Q).Level == 0))
                      ObjectManager.Player.Spellbook.LevelSpell(SpellSlot.Q);
                  if ((indx == 1) && (ObjectManager.Player.Spellbook.GetSpell(SpellSlot.W).Level == 0))
                      ObjectManager.Player.Spellbook.LevelSpell(SpellSlot.W);
                  if ((indx == 2) && (ObjectManager.Player.Spellbook.GetSpell(SpellSlot.E).Level == 0))
                      ObjectManager.Player.Spellbook.LevelSpell(SpellSlot.E);
              }
              else
              {
                  if (indx == 0)
                      ObjectManager.Player.Spellbook.LevelSpell(SpellSlot.Q);
                  if (indx == 1)
                      ObjectManager.Player.Spellbook.LevelSpell(SpellSlot.W);
                  if (indx == 2)
                      ObjectManager.Player.Spellbook.LevelSpell(SpellSlot.E);
                  if (indx == 3)
                      ObjectManager.Player.Spellbook.LevelSpell(SpellSlot.R);
              }
          }
  
          private static float BonusDmg(AIHeroClient target)
          {
              return
                  (float)
                  Player.CalcDamage(target, Damage.DamageType.Magical, target.MaxHealth*0.08 - target.HPRegenRate*5);
          }
  
          private static bool LogQUse(Obj_AI_Base m)
          {
              if (m.HasBuff("brandablaze"))
                  return true;
              if ((E.Instance.CooldownExpires - Game.Time + 2 >= Q.Instance.Cooldown) &&
                  (W.Instance.CooldownExpires - Game.Time + 2 >= Q.Instance.Cooldown))
                  return true;
              return false;
          }
  
          private static void QUsage()
          {
              var m = TargetSelector.GetTarget(Q.Range, TargetSelector.DamageType.Magical);
              if (!m.IsValidTarget())
                  return;
              // Q Improvement + KS Below
              if (OktwCommon.GetKsDamage(m, Q) + BonusDmg(m) > m.Health)
                  SebbySpell(Q, m);
              if (Menu.Item("QOnlyAblazed").GetValue<bool>())
              {
                  foreach (
                      var enemy in
                      HeroManager.Enemies.Where(enemy => enemy.IsValidTarget(Q.Range) && enemy.HasBuff("brandablaze")))
                      SebbySpell(Q, enemy);
              }
              else
              {
                  if (m.HasBuff("brandablaze") && Menu.Item("QAblazedEnemy").GetValue<bool>())
                  {
                      var spreadTarget = m;
  
                      foreach (
                          var enemy in
                          HeroManager.Enemies.Where(enemy => enemy.IsValidTarget(Q.Range) && enemy.HasBuff("brandablaze"))
                      )
                          m = enemy;
  
  
gt:                     if ((spreadTarget == m) && !LogQUse(m))