context: using System;
  using System.Collections.Generic;
  using System.Drawing;
  using System.Linq;
  using System.Reflection;
  using System.Threading;
  using AutoJungle.Data;
  using System.IO;
  using LeagueSharp;
  using System.Text;
  using LeagueSharp.Common;
  using SharpDX;
  using Color = System.Drawing.Color;
  using System.Resources;
  
  using EloBuddy;
  using LeagueSharp.Common;
  using System.Threading.Tasks;
  
  namespace AutoJungle
  {
      internal class Program
      {
          public static GameInfo _GameInfo = null;
  
          public static Menu menu;
  
          public static float UpdateLimiter, ResetTimer, GameStateChanging;
  
          public static AIHeroClient player;
  
          public static Random Random = new Random(Environment.TickCount);
  
          public static ItemHandler ItemHandler;
  
          public static Vector3 pos;
  
          public static OrbwalkingForBots.Orbwalker orbwalker;
  
          public static ResourceManager resourceM;
          public static string culture;
          public static String[] languages = new String[] { "English", "Chinese (Simplified)", "Chinese (Traditional)" };
          public static String[] languagesShort = new String[] { "en", "cn", "tw" };
          public static string fileName, path;
  
          #region Main
  
          private static void Game_OnGameUpdate(EventArgs args)
          {
              if (_GameInfo.SmiteableMob != null)
              {
                  Jungle.CastSmite(_GameInfo.SmiteableMob);
              }
              CastHighPrioritySpells();
              if (ShouldSkipUpdate())
              {
                  return;
              }
              SetGameInfo();
              if (_GameInfo.WaitOnFountain)
              {
                  return;
              }
  
              if (menu.Item("WaitAtLvlTWO", true).GetValue<bool>() && Jungle.smite != null &&
              Jungle.smite.Instance.Ammo == 0 && player.Level == 2 && _GameInfo.GameState == State.Positioning &&
              player.HealthPercent < 55 && player.Distance(_GameInfo.MonsterList.First().Position) < 700)
              {
                  _GameInfo.afk = 0;
                  return;
              }
  
              //Checking Afk
              if (CheckAfk())
              {
                  return;
              }
              if (HighPriorityPositioning())
              {
                  MoveToPos();
                  return;
              }
  
              //Check the camp, maybe its cleared
              CheckCamp();
              if (Debug)
              {
                  /* Console.WriteLine("Items: ");
                  foreach (var i in player.InventoryItems)
                  {
                      Console.WriteLine("\t Name: {0}, ID: {1}({2})", i.DisplayName, i.Id, (int) i.Id);
                  }*/
                  _GameInfo.Show();
              }
              //Shopping
              if (Shopping())
              {
                  return;
              }
  
              //Recalling
              if (RecallHander())
              {
                  return;
              }
              if (menu.Item("UseTrinket").GetValue<bool>())
              {
                  PlaceWard();
              }
              MoveToPos();
  
              CastSpells();
          }
  
          private static void CastHighPrioritySpells()
          {
              var target = _GameInfo.Target;
              switch (ObjectManager.Player.ChampionName)
              {
                  case "Jax":
                      var eActive = player.HasBuff("JaxCounterStrike");
                      if (_GameInfo.GameState == State.Jungling || _GameInfo.GameState == State.LaneClear)
                      {
                          var targetMob = _GameInfo.Target;
                          if (Champdata.E.IsReady() && targetMob.IsValidTarget(350) &&
                              (player.ManaPercent > 40 || player.HealthPercent < 60 || player.Level == 1) && !eActive &&
                              _GameInfo.DamageCount >= 2 || _GameInfo.DamageTaken > player.Health * 0.2f)
                          {
                              Champdata.E.Cast();
                          }
                          return;
                      }
                      if (_GameInfo.GameState == State.FightIng)
                      {
                           if (Champdata.E.IsReady() && Champdata.R.IsReady() &&
                              ((Champdata.Q.CanCast(target) && !eActive) || (target.IsValidTarget(350)) ||
                               ((_GameInfo.DamageCount >= 2 || _GameInfo.DamageTaken > player.Health * 0.2f) || !eActive)))
                          {
                              Champdata.E.Cast();
                          }
                          return;
                      }
                      break;
  
                  case "Kayle":
                      var rActive3 = player.HasBuff("JudicatorIntervention");
                      if (_GameInfo.GameState == State.FightIng)
                      {
                          var targetHero = _GameInfo.Target;
                          if (Champdata.R.IsReady() && targetHero.IsValidTarget(525) &&
                              player.HealthPercent <= 25 && !rActive3)
                          {
                              Champdata.R.Cast();
                          }
                          return;
                      }
                      if (_GameInfo.GameState == State.Jungling || _GameInfo.GameState == State.LaneClear)
                      {
                          var targetMob = _GameInfo.Target;
                          if (Champdata.R.IsReady() && targetMob.IsValidTarget(525) &&
                              player.HealthPercent <= 25 && !rActive3)
                          {
                              Champdata.R.Cast();
                          }
                          return;
                      }
                      break;
  /*
                  case "Nunu":
                      var rActive = player.HasBuff("AbsoluteZero");
                      if (_GameInfo.GameState == State.FightIng)
                      {
                          var targetHero = _GameInfo.Target;
                          if (player.Spellbook.IsChanneling && (targetHero.IsValidTarget(650)))
                          {
                              return;
                          }
                      }
                      break;
  */
                  case "Udyr":
                      var rActive2 = player.HasBuff("UdyrPhoenixStance");
                      if (_GameInfo.GameState == State.Jungling || _GameInfo.GameState == State.LaneClear)
                      {
                          var targetMob = _GameInfo.Target;
                          if (Champdata.R.IsReady() && targetMob.IsValidTarget(135) &&
                              (player.ManaPercent > 25 || player.Level == 1) && !rActive2)
                          {
                              Champdata.R.Cast();
                          }
                          return;
                      }
                      break;
              }
          }
  
          private static bool HighPriorityPositioning()
          {
              if (player.ChampionName == "Skarner")
              {
                  var capturablePoints =
                      ObjectManager.Get<Obj_AI_Base>()
                          .Where(o => o.Distance(player) < 700 && !o.IsAlly && o.Name == "SkarnerPassiveCrystal")
                          .OrderBy(o => o.Distance(player))
                          .FirstOrDefault();
                  if (capturablePoints != null)
                  {
                      _GameInfo.MoveTo = capturablePoints.Position;
                      _GameInfo.GameState = State.Positioning;
                      return true;
                  }
              }
              return false;
          }
  
          private static void PlaceWard()
          {
              if (_GameInfo.ClosestWardPos.IsValid() && Items.CanUseItem(3340))
              {
                  Items.UseItem(3340, _GameInfo.ClosestWardPos);
              }
          }
  
          private static bool CheckAfk()
          {
              if (player.IsMoving || player.Spellbook.IsAutoAttacking || player.IsRecalling() || player.Level == 1)
              {
                  _GameInfo.afk = 0;
              }
              else
              {
                  _GameInfo.afk++;
              }
              if (_GameInfo.afk > 15 && !player.InFountain())
              {
                  player.Spellbook.CastSpell(SpellSlot.Recall);
                  return true;
              }
              return false;
          }
  
          private static void CheckCamp()
          {
  
gt:             MonsterInfo nextMob = GetNextMob();