Advertisement
RNNCode

HealthBarOnElitePlugin_Mod

Apr 17th, 2020 (edited)
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.65 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.  
  23.         private IBrush NormalBorderBrush { get; set; }
  24.         private IBrush ShieldBorderBrush { get; set; }
  25.         private IBrush InvisibleBorderBrush { get; set; }
  26.  
  27.         private IFont TextFont { get; set; }
  28.         private IFont TextFontHaunt { get; set; }
  29.         private IFont TextFontLocust { get; set; }
  30.  
  31.         private float WidthR { get; set; } = 0;
  32.         private float HeightR { get; set; } = 0;
  33.  
  34.         public float SizeFont { get; set; }
  35.         public float YOffset { get; set; } = 0f;
  36.         public float YOffsetExtraBoss { get; set; } = 0f;
  37.  
  38.         public HealthBarOnElitePlugin_Mod()
  39.         {
  40.             Enabled = true;
  41.         }
  42.  
  43.         public override void Load(IController hud)
  44.         {
  45.             base.Load(hud);
  46.             Order = 30005;
  47.  
  48.             SizeFont = 9.0f;
  49.  
  50.             BackGroundBrush = Hud.Render.CreateBrush(255, 100, 100, 100, 0);
  51.             InvulnerableBrush = Hud.Render.CreateBrush(200, 0, 0, 0, 0);
  52.  
  53.             ChampionBrush = Hud.Render.CreateBrush(255, 0, 128, 255, 0);
  54.             RareBrush = Hud.Render.CreateBrush(255, 255, 148, 20, 0);
  55.             JuggerBrush = Hud.Render.CreateBrush(255, 255, 50, 0, 0);
  56.             BossBrush = Hud.Render.CreateBrush(255, 150, 50, 255, 0);
  57.  
  58.             GrayBrush = Hud.Render.CreateBrush(235, 120, 120, 120, 0);
  59.             GrayBorder = Hud.Render.CreateBrush(220, 50, 50, 50, -1);
  60.  
  61.             NormalBorderBrush = Hud.Render.CreateBrush(255, 0, 100, 0, -1);
  62.             ShieldBorderBrush = Hud.Render.CreateBrush(255, 255, 255, 0, -1);
  63.             InvisibleBorderBrush = Hud.Render.CreateBrush(255, 255, 255, 255, -1);
  64.         }
  65.  
  66.         public void Customize()
  67.         {
  68.             TextFont        = Hud.Render.CreateFont("tahoma", SizeFont, 255, 255, 255, 255, false, false, true);
  69.             TextFontLocust  = Hud.Render.CreateFont("tahoma", SizeFont + 1f, 255, 0, 200, 0, true, false, 255, 0, 0, 0, true);
  70.             TextFontHaunt   = Hud.Render.CreateFont("tahoma", SizeFont + 1f, 255, 255, 0, 0, true, false, 255, 0, 0, 0, true);
  71.         }
  72.  
  73.         public void PaintTopInGame(ClipState clipState)
  74.         {
  75.             if (clipState != ClipState.BeforeClip) return;
  76.             if (!Hud.Game.IsInGame) return;
  77.             //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));
  78.             var monsters = Hud.Game.AliveMonsters.Where(m => (m.Rarity != ActorRarity.Normal && m.Rarity != ActorRarity.Hireling) && (m.SummonerAcdDynamicId == 0));
  79.             if (monsters.Any())
  80.             {
  81.                 float percent = 100; string hptext = string.Empty; WidthR = TextFont.GetTextLayout("100]").Metrics.Width; HeightR = TextFont.GetTextLayout("100]").Metrics.Height * 0.90f;
  82.                 foreach(var monster in monsters)
  83.                 {
  84.                     percent = (float) (monster.CurHealth/monster.MaxHealth);
  85.                     if ((percent < 0) || (percent > 100)) { percent = 1; hptext = "bug"; }
  86.                     else { hptext = ValueToString(percent * 100 , ValueFormat.NormalNumberNoDecimal); }
  87.                     var x = monster.FloorCoordinate.ToScreenCoordinate().X - WidthR/2;          var y = monster.FloorCoordinate.ToScreenCoordinate().Y - HeightR/2 + YOffset;
  88.                     if (monster.Rarity != ActorRarity.RareMinion)
  89.                     {
  90.                         BorderBrush = NormalBorderBrush;
  91.                         if (monster.Invulnerable)
  92.                         {
  93.                             if (monster.Invisible) { BorderBrush = InvisibleBorderBrush; }
  94.                             else if ( monster.Attackable && monster.AffixSnoList.Any(a => a.Affix == MonsterAffix.Shielding) ) { BorderBrush = ShieldBorderBrush; }
  95.                             InvulnerableBrush.DrawRectangle(x, y, WidthR, HeightR);
  96.                         }
  97.                         else
  98.                         {
  99.                             if (monster.Rarity == ActorRarity.Champion) { DefaultBrush = ChampionBrush; }
  100.                             else if (monster.Rarity == ActorRarity.Rare) { DefaultBrush = (monster.AffixSnoList.Any(a => a.Affix == MonsterAffix.Juggernaut))? JuggerBrush : RareBrush; }
  101.                             else { DefaultBrush = BossBrush; if (monster.Rarity == ActorRarity.Boss) y+= YOffsetExtraBoss; }
  102.                             BackGroundBrush.DrawRectangle(x, y, WidthR, HeightR);
  103.                             DefaultBrush.DrawRectangle(x, y, percent * WidthR, HeightR);
  104.                         }
  105.                         BorderBrush.DrawRectangle(x - 1, y - 1, WidthR + 2, HeightR + 2);
  106.                     }
  107.                     else
  108.                     {
  109.                         GrayBrush.DrawEllipse(monster.FloorCoordinate.ToScreenCoordinate().X,  monster.FloorCoordinate.ToScreenCoordinate().Y + YOffset, WidthR/2f , HeightR/2f );
  110.                         GrayBorder.DrawEllipse(monster.FloorCoordinate.ToScreenCoordinate().X,  monster.FloorCoordinate.ToScreenCoordinate().Y + YOffset, WidthR/2f + 1 , HeightR/2f + 1);
  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
Advertisement