private static void Game_OnTick(EventArgs args)
 {
     if (Orbwalker.ActiveModesFlags.HasFlag(Orbwalker.ActiveModes.Combo))
     {
         StateHandler.Combo();
     }
     if (Orbwalker.ActiveModesFlags.HasFlag(Orbwalker.ActiveModes.Harass))
     {
         StateHandler.Harass();
     }
     if (Orbwalker.ActiveModesFlags.HasFlag(Orbwalker.ActiveModes.LastHit))
     {
         StateHandler.LastHit();
     }
     if (Orbwalker.ActiveModesFlags.HasFlag(Orbwalker.ActiveModes.LaneClear))
     {
         StateHandler.LaneClear();
     }
     if (Orbwalker.ActiveModesFlags.HasFlag(Orbwalker.ActiveModes.JungleClear))
     {
         StateHandler.Jungle();
     }
 }
        private static void Obj_AI_Base_OnSpellCast(Obj_AI_Base sender, GameObjectProcessSpellCastEventArgs args)
        {
            if (!sender.IsMe)
            {
                return;
            }
            var target = args.Target as Obj_AI_Base;

            // Hydra
            if (args.SData.Name.ToLower().Contains("itemtiamatcleave"))
            {
                Orbwalker.ResetAutoAttack();
                if (Riven.W.IsReady())
                {
                    var target2 = TargetSelector.GetTarget(Riven.W.Range, DamageType.Physical);
                    if (target2 != null || Orbwalker.ActiveModesFlags != Orbwalker.ActiveModes.None)
                    {
                        Player.CastSpell(SpellSlot.W);
                    }
                }
                return;
            }

            //W
            if (args.SData.Name.ToLower().Contains(Riven.W.Name.ToLower()))
            {
                if (Orbwalker.ActiveModesFlags.HasFlag(Orbwalker.ActiveModes.Combo))
                {
                    if (Player.Instance.HasBuff("RivenFengShuiEngine") && Riven.R.IsReady() &&
                        Riven.ComboMenu["Combo.R2"].Cast <CheckBox>().CurrentValue)
                    {
                        var target2 = TargetSelector.GetTarget(Riven.R.Range, DamageType.Physical);
                        if (target2 != null &&
                            (target2.Distance(Player.Instance) < Riven.W.Range &&
                             target2.Health >
                             Player.Instance.CalculateDamageOnUnit(target2, DamageType.Physical, DamageHandler.WDamage()) ||
                             target2.Distance(Player.Instance) > Riven.W.Range) &&
                            Player.Instance.CalculateDamageOnUnit(target2, DamageType.Physical,
                                                                  DamageHandler.RDamage(target2) + DamageHandler.WDamage()) > target2.Health)
                        {
                            Riven.R.Cast(target2);
                        }
                    }
                }

                target = (Orbwalker.ActiveModesFlags.HasFlag(Orbwalker.ActiveModes.Combo) ||
                          Orbwalker.ActiveModesFlags.HasFlag(Orbwalker.ActiveModes.Harass))
                    ? TargetSelector.GetTarget(Riven.E.Range + Riven.W.Range, DamageType.Physical)
                    : (Obj_AI_Base)Orbwalker.LastTarget;
                if (Riven.Q.IsReady() && Orbwalker.ActiveModesFlags != Orbwalker.ActiveModes.None && target != null)
                {
                    Player.CastSpell(SpellSlot.Q, target.Position);
                    return;
                }
                return;
            }

            //E
            if (args.SData.Name.ToLower().Contains(Riven.E.Name.ToLower()))
            {
                if (Orbwalker.ActiveModesFlags.HasFlag(Orbwalker.ActiveModes.Combo))
                {
                    if (Player.Instance.HasBuff("RivenFengShuiEngine") && Riven.R.IsReady() &&
                        Riven.ComboMenu["Combo.R2"].Cast <CheckBox>().CurrentValue)
                    {
                        var target2 = TargetSelector.GetTarget(Riven.R.Range, DamageType.Physical);
                        if (target2 != null &&
                            Player.Instance.CalculateDamageOnUnit(target2, DamageType.Physical,
                                                                  (DamageHandler.RDamage(target2))) > target2.Health)
                        {
                            Riven.R.Cast(target2);
                            return;
                        }
                    }
                    if ((Riven.IsRActive || StateHandler.EnableR) && Riven.R.IsReady() &&
                        !Player.Instance.HasBuff("RivenFengShuiEngine") &&
                        Riven.ComboMenu["Combo.R"].Cast <CheckBox>().CurrentValue)
                    {
                        Player.CastSpell(SpellSlot.R);
                    }
                    target = TargetSelector.GetTarget(Riven.W.Range, DamageType.Physical);
                    if (target != null && Player.Instance.Distance(target) < Riven.W.Range)
                    {
                        Player.CastSpell(SpellSlot.W);
                        return;
                    }
                }
            }

            //Q
            if (args.SData.Name.ToLower().Contains(Riven.Q.Name.ToLower()))
            {
                if (Orbwalker.ActiveModesFlags.HasFlag(Orbwalker.ActiveModes.Combo))
                {
                    if (Player.Instance.HasBuff("RivenFengShuiEngine") && Riven.R.IsReady() &&
                        Riven.ComboMenu["Combo.R2"].Cast <CheckBox>().CurrentValue)
                    {
                        var target2 = TargetSelector.GetTarget(Riven.R.Range, DamageType.Physical);
                        if (target2 != null &&
                            (target2.Distance(Player.Instance) < 300 &&
                             target2.Health >
                             Player.Instance.CalculateDamageOnUnit(target2, DamageType.Physical, DamageHandler.QDamage()) ||
                             target2.Distance(Player.Instance) > 300) &&
                            Player.Instance.CalculateDamageOnUnit(target2, DamageType.Physical,
                                                                  DamageHandler.RDamage(target2) + DamageHandler.QDamage()) > target2.Health)
                        {
                            Riven.R.Cast(target2);
                        }
                    }
                }
                return;
            }

            if (args.SData.IsAutoAttack() && target != null)
            {
                if (Riven.MiscMenu["HumanizerDelay"].Cast <Slider>().CurrentValue == 0)
                {
                    if (Orbwalker.ActiveModesFlags.HasFlag(Orbwalker.ActiveModes.Combo))
                    {
                        StateHandler.ComboAfterAa(target);
                    }

                    if (Orbwalker.ActiveModesFlags.HasFlag(Orbwalker.ActiveModes.Harass))
                    {
                        StateHandler.HarassAfterAa(target);
                    }

                    if (Orbwalker.ActiveModesFlags.HasFlag(Orbwalker.ActiveModes.JungleClear) && target.IsJungleMinion())
                    {
                        StateHandler.JungleAfterAa(target);
                    }

                    if (Orbwalker.ActiveModesFlags.HasFlag(Orbwalker.ActiveModes.LastHit) && target.IsLaneMinion())
                    {
                        StateHandler.LastHitAfterAa(target);
                    }

                    if (Orbwalker.ActiveModesFlags.HasFlag(Orbwalker.ActiveModes.LaneClear) && target.IsLaneMinion())
                    {
                        StateHandler.LaneClearAfterAa(target);
                    }
                }
                else
                {
                    Core.DelayAction(() =>
                    {
                        if (Orbwalker.ActiveModesFlags.HasFlag(Orbwalker.ActiveModes.Combo))
                        {
                            StateHandler.ComboAfterAa(target);
                        }

                        if (Orbwalker.ActiveModesFlags.HasFlag(Orbwalker.ActiveModes.Harass))
                        {
                            StateHandler.HarassAfterAa(target);
                        }

                        if (Orbwalker.ActiveModesFlags.HasFlag(Orbwalker.ActiveModes.JungleClear) &&
                            target.IsJungleMinion())
                        {
                            StateHandler.JungleAfterAa(target);
                        }

                        if (Orbwalker.ActiveModesFlags.HasFlag(Orbwalker.ActiveModes.LastHit) && target.IsLaneMinion())
                        {
                            StateHandler.LastHitAfterAa(target);
                        }

                        if (Orbwalker.ActiveModesFlags.HasFlag(Orbwalker.ActiveModes.LaneClear) && target.IsLaneMinion())
                        {
                            StateHandler.LaneClearAfterAa(target);
                        }
                    }, Riven.MiscMenu["HumanizerDelay"].Cast <Slider>().CurrentValue);
                }
            }
        }