RNNCode

HealthBarOnElitePlugin_Mod

Sep 15th, 2024 (edited)
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.57 KB | None | 0 0
  1. // Mod of the plugin HealthBarOnElitePlugin of BM. The original can be found:
  2. // https://www.ownedcore.com/forums/diablo-3/turbohud/turbohud-community-plugins/612943-english-bm-healthbaroneliteplugin.html
  3. using Turbo.Plugins.Default;
  4. using System.Linq;
  5.  
  6. namespace Turbo.Plugins.BM
  7. {
  8.     public class HealthBarOnElitePlugin_Mod : BasePlugin, IInGameTopPainter, ICustomizer
  9.     {
  10.         private IBrush DefaultBrush { get; set; } = null;
  11.         private IBrush BorderBrush { get; set; } = null;
  12.  
  13.         private IBrush BackGroundBrush { get; set; }
  14.         private IBrush InvulnerableBrush { get; set; }
  15.  
  16.         private IBrush ChampionBrush { get; set; }
  17.         private IBrush RareBrush { get; set; }
  18.         private IBrush JuggerBrush { get; set; }
  19.         private IBrush BossBrush { get; set; }
  20.         private IBrush GrayBrush { get; set; }
  21.         private IBrush GrayBorder { get; set; }
  22.         private IBrush RareMinionBrush { get; set; }
  23.  
  24.         private IBrush NormalBorderBrush { get; set; }
  25.         private IBrush ShieldBorderBrush { get; set; }
  26.         private IBrush InvisibleBorderBrush { get; set; }
  27.  
  28.         private IFont TextFont { get; set; }
  29.         private IFont TextFontHaunt { get; set; }
  30.         private IFont TextFontLocust { get; set; }
  31.  
  32.         private float WidthR { get; set; } = 0;
  33.         private float HeightR { get; set; } = 0;
  34.  
  35.         public float SizeFont { get; set; }
  36.         public float YOffset { get; set; } = 0f;
  37.         public float YOffsetExtraBoss { get; set; } = 0f;
  38.  
  39.         public HealthBarOnElitePlugin_Mod()
  40.         {
  41.             Enabled = true;
  42.         }
  43.  
  44.         public override void Load(IController hud)
  45.         {
  46.             base.Load(hud);
  47.             Order = 30005;
  48.  
  49.             SizeFont = 9.0f;
  50.  
  51.             BackGroundBrush = Hud.Render.CreateBrush(255, 100, 100, 100, 0);
  52.             InvulnerableBrush = Hud.Render.CreateBrush(200, 0, 0, 0, 0);
  53.  
  54.             ChampionBrush = Hud.Render.CreateBrush(255, 0, 128, 255, 0);
  55.             RareBrush = Hud.Render.CreateBrush(255, 255, 148, 20, 0);
  56.             JuggerBrush = Hud.Render.CreateBrush(255, 255, 50, 0, 0);
  57.             BossBrush = Hud.Render.CreateBrush(255, 150, 50, 255, 0);
  58.  
  59.             RareMinionBrush = Hud.Render.CreateBrush(255, 0, 155, 135, 0);
  60.  
  61.             GrayBrush = Hud.Render.CreateBrush(235, 120, 120, 120, 0);
  62.             GrayBorder = Hud.Render.CreateBrush(220, 50, 50, 50, -1);
  63.  
  64.             NormalBorderBrush = Hud.Render.CreateBrush(255, 0, 100, 0, -1);
  65.             ShieldBorderBrush = Hud.Render.CreateBrush(255, 255, 255, 0, -1);
  66.             InvisibleBorderBrush = Hud.Render.CreateBrush(255, 255, 255, 255, -1);
  67.         }
  68.  
  69.         public void Customize()
  70.         {
  71.             TextFont        = Hud.Render.CreateFont("tahoma", SizeFont, 255, 255, 255, 255, false, false, true);
  72.             TextFontLocust  = Hud.Render.CreateFont("tahoma", SizeFont + 1f, 255, 0, 200, 0, true, false, 255, 0, 0, 0, true);
  73.             TextFontHaunt   = Hud.Render.CreateFont("tahoma", SizeFont + 1f, 255, 255, 0, 0, true, false, 255, 0, 0, 0, true);
  74.         }
  75.  
  76.         public void PaintTopInGame(ClipState clipState)
  77.         {
  78.             if (clipState != ClipState.BeforeClip) return;
  79.             if (!Hud.Game.IsInGame) return;
  80.             //var monsters = Hud.Game.AliveMonsters.Where(m => (m.Rarity == ActorRarity.Champion || m.Rarity == ActorRarity.Rare || m.Rarity == ActorRarity.Boss || m.Rarity == ActorRarity.Unique) && (m.SummonerAcdDynamicId == 0));
  81.             var monsters = Hud.Game.AliveMonsters.Where(m => (m.Rarity != ActorRarity.Normal && m.Rarity != ActorRarity.Hireling) && (m.SummonerAcdDynamicId == 0)).OrderBy(o => o.MaxHealth);
  82.             if (monsters.Any())
  83.             {
  84.                 float percent = 100; string hptext = string.Empty; HeightR = TextFont.GetTextLayout("100]").Metrics.Height * 0.90f;
  85.                 foreach(var monster in monsters)
  86.                 {
  87.                     percent = (float) (monster.CurHealth/monster.MaxHealth);
  88.                     if ((percent < 0) || (percent > 100)) { percent = 1; hptext = "bug"; }
  89.                     else { hptext = ValueToString(percent * 100 , ValueFormat.NormalNumberNoDecimal); }
  90.  
  91.                     WidthR = (monster.Rarity == ActorRarity.RareMinion)? TextFont.GetTextLayout("100]").Metrics.Width * 0.90f : TextFont.GetTextLayout("100]").Metrics.Width * 2.5f;
  92.  
  93.                     var x = monster.FloorCoordinate.ToScreenCoordinate().X - WidthR/2;          var y = monster.FloorCoordinate.ToScreenCoordinate().Y - HeightR/2 + YOffset;
  94.                     BorderBrush = NormalBorderBrush;
  95.                     if (monster.Invulnerable)
  96.                     {
  97.                         if (monster.Invisible) { BorderBrush = InvisibleBorderBrush; }
  98.                         else if ( monster.Attackable && monster.AffixSnoList.Any(a => a.Affix == MonsterAffix.Shielding) ) { BorderBrush = ShieldBorderBrush; }
  99.                         InvulnerableBrush.DrawRectangle(x, y, WidthR, HeightR);
  100.                     }
  101.                     else
  102.                     {
  103.                         if (monster.Rarity == ActorRarity.RareMinion) { DefaultBrush = RareMinionBrush; }
  104.                         else if (monster.Rarity == ActorRarity.Champion) { DefaultBrush = ChampionBrush; }
  105.                         else if (monster.Rarity == ActorRarity.Rare) { DefaultBrush = (monster.AffixSnoList.Any(a => a.Affix == MonsterAffix.Juggernaut))? JuggerBrush : RareBrush; }
  106.                         else { DefaultBrush = BossBrush; if (monster.Rarity == ActorRarity.Boss) y+= YOffsetExtraBoss; }
  107.                         BackGroundBrush.DrawRectangle(x, y, WidthR, HeightR);
  108.                         DefaultBrush.DrawRectangle(x, y, percent * WidthR, HeightR);
  109.                     }
  110.                     BorderBrush.DrawRectangle(x - 1, y - 1, WidthR + 2, HeightR + 2);
  111.  
  112.                     var layout = TextFont.GetTextLayout(hptext);
  113.                     TextFont.DrawText(layout, x + (WidthR - layout.Metrics.Width)/2f, y + (HeightR - layout.Metrics.Height)/2f);
  114.                     if (monster.Locust)
  115.                     {
  116.                         layout = TextFontLocust.GetTextLayout("L");
  117.                         TextFontLocust.DrawText(layout, x - layout.Metrics.Width - 5 , y + (HeightR - layout.Metrics.Height)/2f);
  118.                     }
  119.                     if (monster.Haunted)
  120.                     {
  121.                         layout = TextFontHaunt.GetTextLayout("H");
  122.                         TextFontHaunt.DrawText(layout, x + WidthR + 4, y + (HeightR - layout.Metrics.Height)/2f);
  123.                     }
  124.                 }
  125.             }
  126.         }
  127.     }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment