Esempio n. 1
0
        public static Obj_AI_Hero GetTarget(
            Obj_AI_Base champion,
            float range,
            DamageType type,
            bool ignoreShieldSpells = true,
            IEnumerable <Obj_AI_Hero> ignoredChamps = null,
            Vector3?rangeCheckFrom = null,
            TargetSelectionConditionDelegate conditions = null)
        {
            try
            {
                if (ignoredChamps == null)
                {
                    ignoredChamps = new List <Obj_AI_Hero>();
                }

                var damageType = (Damage.DamageType)Enum.Parse(typeof(Damage.DamageType), type.ToString());

                if (_configMenu != null &&
                    IsValidTarget(
                        SelectedTarget,
                        _configMenu.Item("ForceFocusSelected").GetValue <bool>() ? float.MaxValue : range,
                        type,
                        ignoreShieldSpells,
                        rangeCheckFrom))
                {
                    return(SelectedTarget);
                }

                if (_configMenu != null &&
                    IsValidTarget(
                        SelectedTarget,
                        _configMenu.Item("ForceFocusSelectedKeys").GetValue <bool>() ? float.MaxValue : range,
                        type,
                        ignoreShieldSpells,
                        rangeCheckFrom))
                {
                    if (_configMenu.Item("ForceFocusSelectedK").GetValue <KeyBind>().Active ||
                        _configMenu.Item("ForceFocusSelectedK2").GetValue <KeyBind>().Active)
                    {
                        return(SelectedTarget);
                    }
                }

                if (_configMenu != null && _configMenu.Item("TargetingMode") != null &&
                    Mode == TargetingMode.AutoPriority)
                {
                    var menuItem = _configMenu.Item("TargetingMode").GetValue <StringList>();
                    Enum.TryParse(menuItem.SList[menuItem.SelectedIndex], out Mode);
                }

                var targets =
                    HeroManager.Enemies.FindAll(
                        hero =>
                        ignoredChamps.All(ignored => ignored.NetworkId != hero.NetworkId) &&
                        IsValidTarget(hero, range, type, ignoreShieldSpells, rangeCheckFrom) &&
                        (conditions == null || conditions(hero)) &&
                        (!Orbwalking.YasuoInGame || range > 0 || ObjectManager.Player.IsMelee || !Orbwalking.CollisionYasuo(ObjectManager.Player.Position, hero.Position)));
                switch (Mode)
                {
                case TargetingMode.LowHP:
                    return(targets.MinOrDefault(hero => hero.Health));

                case TargetingMode.MostAD:
                    return(targets.MaxOrDefault(hero => hero.BaseAttackDamage + hero.FlatPhysicalDamageMod));

                case TargetingMode.MostAP:
                    return(targets.MaxOrDefault(hero => hero.BaseAbilityDamage + hero.FlatMagicDamageMod));

                case TargetingMode.Closest:
                    return
                        (targets.MinOrDefault(
                             hero =>
                             (rangeCheckFrom.HasValue ? rangeCheckFrom.Value : champion.ServerPosition).Distance(
                                 hero.ServerPosition,
                                 true)));

                case TargetingMode.NearMouse:
                    return(targets.MinOrDefault(hero => hero.Distance(Game.CursorPos, true)));

                case TargetingMode.AutoPriority:
                    return
                        (targets.MaxOrDefault(
                             hero =>
                             champion.CalcDamage(hero, damageType, 100) / (1 + hero.Health) * GetPriority(hero)));

                case TargetingMode.LessAttack:
                    return
                        (targets.MaxOrDefault(
                             hero =>
                             champion.CalcDamage(hero, Damage.DamageType.Physical, 100) / (1 + hero.Health)
                             * GetPriority(hero)));

                case TargetingMode.LessCast:
                    return
                        (targets.MaxOrDefault(
                             hero =>
                             champion.CalcDamage(hero, Damage.DamageType.Magical, 100) / (1 + hero.Health)
                             * GetPriority(hero)));

                case TargetingMode.MostStack:
                    return
                        (targets.MaxOrDefault(
                             hero =>
                             champion.CalcDamage(hero, damageType, 100) / (1 + hero.Health) * GetPriority(hero)
                             + (1 + hero.Buffs.Where(b => StackNames.Contains(b.Name.ToLower())).Sum(t => t.Count))));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            return(null);
        }