/// <summary> /// Updates the maximum minimum value. /// </summary> /// <param name="item"> /// The item. /// </param> /// <param name="heroes"> /// The heroes. /// </param> /// <param name="simulation"> /// Indicates whether to use simluation. /// </param> public void UpdateMaxMinValue(WeightItemWrapper item, List <AIHeroClient> heroes, bool simulation = false) { var min = float.MaxValue; var max = float.MinValue; foreach (var hero in heroes) { var value = item.GetValue(hero); if (value < min) { min = value; } if (value > max) { max = value; } } if (!simulation) { item.MinValue = Math.Min(max, min); item.MaxValue = Math.Max(max, min); } else { item.SimulationMinValue = Math.Min(max, min); item.SimulationMaxValue = Math.Max(max, min); } }
/// <summary> /// Sets the weight. /// </summary> /// <param name="weightItem"> /// The weight item. /// </param> /// <param name="weight"> /// The weight. /// </param> public void SetMenuWeight(WeightItemWrapper weightItem, int weight) { var item = this.weightsMenu[weightItem.Name]; if (item != null) { weightItem.Weight = Math.Max(MinWeight, Math.Min(MaxWeight, weight)); item.GetValue <MenuSlider>().Value = weightItem.Weight; } }
/// <summary> /// Calculates the weight. /// </summary> /// <param name="item"> /// The item. /// </param> /// <param name="hero"> /// The hero. /// </param> /// <param name="simulation">Indicates whether to enable simulation.</param> /// <returns> /// The <see cref="float" />. /// </returns> public float Calculate(WeightItemWrapper item, AIHeroClient hero, bool simulation = false) { 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 * item.GetValue(hero) / maxValue) + minWeight : item.Weight * item.GetValue(hero) / maxValue; return(float.IsNaN(weight) || float.IsInfinity(weight) ? MinWeight : Math.Min(MaxWeight, Math.Min(item.Weight, Math.Max(MinWeight, Math.Max(weight, minWeight))))); }