private static void OnEndScene(EventArgs args)
{
if (!HealthbarEnabled && !PercentEnabled)
{
return;
}
foreach (var unit in EntityManager.Heroes.Enemies.Where(u => u.IsValidTarget() && u.IsHPBarRendered))
{
// Get damage to unit
var damage = DamageToUnit(unit, false);
// Continue on 0 damage
if (damage <= 0)
{
continue;
}
if (HealthbarEnabled)
{
// Get remaining HP after damage applied in percent and the current percent of health
var damagePercentage = ((unit.TotalShieldHealth() - damage) > 0
? (unit.TotalShieldHealth() - damage)
: 0)
/ (unit.MaxHealth + unit.AllShield + unit.AttackShield + unit.MagicShield);
var currentHealthPercentage = unit.TotalShieldHealth()
/ (unit.MaxHealth + unit.AllShield + unit.AttackShield
+ unit.MagicShield);
// Calculate start and end point of the bar indicator
var startPoint = new Vector2(
(int)(unit.HPBarPosition.X + BarOffset.X + damagePercentage * BarWidth),
(int)(unit.HPBarPosition.Y + BarOffset.Y) - 5);
var endPoint =
new Vector2(
(int)(unit.HPBarPosition.X + BarOffset.X + currentHealthPercentage * BarWidth) + 1,
(int)(unit.HPBarPosition.Y + BarOffset.Y) - 5);
// Draw the line
Drawing.DrawLine(startPoint, endPoint, LineThickness, DrawingColor);
}
if (PercentEnabled)
{
// Get damage in percent and draw next to the health bar
Drawing.DrawText(
unit.HPBarPosition,
Color.MediumVioletRed,
string.Concat(Math.Ceiling((damage / unit.TotalShieldHealth()) * 100), "%"),
10);
}
}
}