Ejemplo n.º 1
0
 public static float CalculatedWeight(Item item,
                                      Targets.Item target,
                                      bool simulation    = false,
                                      bool forceRealTime = false)
 {
     try
     {
         var minValue = simulation ? item.SimulationMinValue : item.MinValue;
         var maxValue = simulation ? item.SimulationMaxValue : item.MaxValue;
         if (item.Weight <= MinWeight || maxValue <= 0)
         {
             return(MinWeight);
         }
         var minWeight = minValue > 0 ? item.Weight / (maxValue / minValue) : MinWeight;
         var weight    = item.Inverted
             ? item.Weight - item.Weight * GetValue(item, target, forceRealTime) / maxValue + minWeight
             : item.Weight * GetValue(item, target, forceRealTime) / maxValue;
         return(float.IsNaN(weight) || float.IsInfinity(weight)
             ? MinWeight
             : Math.Min(MaxWeight, Math.Min(item.Weight, Math.Max(MinWeight, Math.Max(weight, minWeight)))));
     }
     catch
     {
         // Ignored
     }
     return(MinWeight);
 }
Ejemplo n.º 2
0
 public static float GetValue(Item item, Targets.Item target)
 {
     try
     {
         var value = item.GetValueFunc(target.Hero);
         return(value > 1 ? value : 1);
     }
     catch (Exception ex)
     {
         Global.Logger.AddItem(new LogItem(ex));
         return(item.Inverted ? item.MaxValue : item.MinValue);
     }
 }
Ejemplo n.º 3
0
        private static void OnCorePreUpdate(EventArgs args)
        {
            try
            {
                if (_mainMenu == null || TargetSelector.Mode != TargetSelectorModeType.Weights)
                {
                    return;
                }

                var highestEnabled =
                    _mainMenu.Item(_mainMenu.Name + ".drawing.weights.highest-target.enabled").GetValue <bool>();
                var weightsSimple = _mainMenu.Item(_mainMenu.Name + ".drawing.weights.simple").GetValue <bool>();
                if (highestEnabled || weightsSimple)
                {
                    var enemies = Targets.Items.Where(h => h.Hero.IsValidTarget(Range)).ToList();
                    foreach (var weight in Items.Where(w => w.Weight > 0))
                    {
                        UpdateMaxMinValue(weight, enemies, true);
                    }
                    foreach (var target in enemies)
                    {
                        var totalWeight = Items.Where(w => w.Weight > 0).Sum(w => CalculatedWeight(w, target, true));

                        if (_mainMenu != null)
                        {
                            var heroPercent =
                                _mainMenu.Item(_mainMenu.Name + ".weights.heroes." + target.Hero.ChampionName)
                                .GetValue <Slider>()
                                .Value;

                            totalWeight = heroPercent > 0 ? totalWeight / 100 * heroPercent : 0;
                        }

                        target.SimulatedWeight = totalWeight;
                    }
                    _drawingTargets = enemies.OrderByDescending(t => t.SimulatedWeight).ToList();
                    if (Game.Time - _lastBestTargetSwitch >= BestTargetSwitchDelay)
                    {
                        _bestTarget           = _drawingTargets.FirstOrDefault();
                        _lastBestTargetSwitch = Game.Time;
                    }
                }
            }
            catch (Exception ex)
            {
                Global.Logger.AddItem(new LogItem(ex));
            }
        }
Ejemplo n.º 4
0
 public static float CalculatedWeight(Item item, Targets.Item target, bool simulation = false)
 {
     try
     {
         if (item.Weight == 0)
         {
             return(0);
         }
         var weight = item.Weight *
                      (item.Inverted
                          ? (simulation ? item.SimulationMinValue : item.MinValue)
                          : GetValue(item, target)) / (item.Inverted ? GetValue(item, target) : item.MaxValue);
         return(float.IsNaN(weight) || float.IsInfinity(weight) ? MinWeight : weight);
     }
     catch (Exception ex)
     {
         Global.Logger.AddItem(new LogItem(ex));
     }
     return(0);
 }
Ejemplo n.º 5
0
 public static float GetValue(Item item, Targets.Item target, bool forceRealTime = false)
 {
     try
     {
         if (ItemCache.MaxAge > 0 && !forceRealTime)
         {
             var cacheValue = ItemCache[item.UniqueName];
             if (cacheValue != null)
             {
                 return((float)cacheValue);
             }
         }
         var value = item.ValueFunction(target.Hero);
         value = Math.Max(0, value);
         ItemCache.AddOrUpdate(item.UniqueName, value);
         return(value);
     }
     catch
     {
         return(item.Inverted ? item.MaxValue : item.MinValue);
     }
 }
Ejemplo n.º 6
0
        private static void OnCorePreUpdate(EventArgs args)
        {
            try
            {
                if (_mainMenu == null || TargetSelector.Mode != TargetSelectorModeType.Weights)
                {
                    return;
                }

                var highestEnabled =
                    _mainMenu.Item(_mainMenu.Name + ".drawing.weights.highest-target.enabled").GetValue<bool>();
                var weightsSimple = _mainMenu.Item(_mainMenu.Name + ".drawing.weights.simple").GetValue<bool>();
                if (highestEnabled || weightsSimple)
                {
                    var enemies = Targets.Items.Where(h => h.Hero.IsValidTarget(Range)).ToList();
                    foreach (var weight in Items.Where(w => w.Weight > 0))
                    {
                        UpdateMaxMinValue(weight, enemies, true);
                    }
                    foreach (var target in enemies)
                    {
                        var totalWeight = 0f;
                        foreach (var weight in Items.Where(w => w.Weight > 0))
                        {
                            var lastWeight = CalculatedWeight(weight, target, true);
                            if (lastWeight > 0)
                            {
                                if (_mainMenu != null)
                                {
                                    var heroMultiplicator =
                                        _mainMenu.Item(_mainMenu.Name + ".weights.heroes." + target.Hero.ChampionName)
                                            .GetValue<Slider>()
                                            .Value;
                                    if (heroMultiplicator > 1)
                                    {
                                        lastWeight += Average * heroMultiplicator;
                                    }
                                }
                                totalWeight += lastWeight;
                            }
                        }
                        target.SimulatedWeight = totalWeight;
                    }
                    _drawingTargets = enemies.OrderByDescending(t => t.SimulatedWeight).ToList();
                    if (Game.Time - _lastBestTargetSwitch >= BestTargetSwitchDelay)
                    {
                        _bestTarget = _drawingTargets.FirstOrDefault();
                        _lastBestTargetSwitch = Game.Time;
                    }
                }
            }
            catch (Exception ex)
            {
                Global.Logger.AddItem(new LogItem(ex));
            }
        }
        public static IEnumerable<Obj_AI_Hero> GetTargets(float range,
            DamageType damageType = DamageType.True,
            bool ignoreShields = true,
            Vector3 from = default(Vector3),
            IEnumerable<Obj_AI_Hero> ignoredChampions = null)
        {
            try
            {
                Weights.Range = Math.Max(range, Weights.Range);

                var selectedTarget = Selected.GetTarget(range, damageType, ignoreShields, from);
                if (selectedTarget != null)
                {
                    return new List<Obj_AI_Hero> { selectedTarget };
                }

                var targets =
                    Humanizer.FilterTargets(Targets.Items)
                        .Where(
                            h => ignoredChampions == null || ignoredChampions.All(i => i.NetworkId != h.Hero.NetworkId))
                        .Where(h => IsValidTarget(h.Hero, range, damageType, ignoreShields, from))
                        .ToList();

                if (targets.Count > 0)
                {
                    var t = GetOrderedChampions(targets).ToList();
                    if (Mode == TargetSelectorModeType.Weights && Weights.ForceFocus)
                    {
                        t = Weights.FilterTargets(t, range, damageType, ignoreShields, from).ToList();
                    }
                    if (t.Count > 0)
                    {
                        if (Selected.Target != null && Selected.Focus && t.Count > 1)
                        {
                            t = t.OrderByDescending(x => x.Hero.NetworkId.Equals(Selected.Target.NetworkId)).ToList();
                        }
                        _lastTarget = t.First();
                        _lastTarget.LastTargetSwitch = Game.Time;
                        return t.Select(h => h.Hero).ToList();
                    }
                }
            }
            catch (Exception ex)
            {
                Global.Logger.AddItem(new LogItem(ex));
            }
            return new List<Obj_AI_Hero>();
        }
Ejemplo n.º 8
0
 public Item(Obj_AI_Hero sender, Targets.Item target)
 {
     Sender    = sender;
     Target    = target;
     Timestamp = Game.Time;
 }