Advertisement
jarppaaja

CurseMeter

Aug 20th, 2019
648
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.91 KB | None | 0 0
  1. // CurseMeter.cs "$Revision: 2567 $" "$Date: 2019-08-29 09:15:36 +0300 (to, 29 elo 2019) $"
  2. // https://www.ownedcore.com/forums/diablo-3/turbohud/turbohud-community-plugins/797381-cursemeter.html
  3. // CurseMeter - https://pastebin.com/sNdA8Rn6
  4. // Modifiers  - https://pastebin.com/drejrEcm
  5. // Runes      - https://pastebin.com/vSfQm5x6
  6. using System;
  7. using System.Linq;
  8. using SharpDX;
  9. using Turbo.Plugins.Default;
  10. using Turbo.Plugins.User;
  11.  
  12. namespace Turbo.Plugins.JarJar.DefaultUI
  13. {
  14.     public class CurseMeter : BasePlugin, IInGameTopPainter
  15.     {
  16.         private const int FRAILTY = 0;
  17.         private const int DECREPIFY = 1;
  18.         private const int LEECH = 2;
  19.         private const int CURSE_COUNT = 3;
  20.  
  21.         public float offsetX { get; set; } = 0.60f;             // Percent-X pos
  22.         public float offsetY { get; set; } = 0.025f;            // Percent-Y pos
  23.         public float BarH { get; set; } = 16.0f;                // Bar height
  24.         public float BarW { get; set; } = 192.0f;               // Bar width
  25.  
  26.         public bool ShowOnlyInGr { get; set; } = false;
  27.         public double CurseDetectionRange { get; set; } = 50f;  // Set to -1f to query all monsters
  28.  
  29.         public string[] TextLabel { get; set; } = new string[3]
  30.             {
  31.                 "Frailty {0}/{1} {2:0}%  ",
  32.                 "Decrepify {0}/{1} {2:0}%  ",
  33.                 "Leech {0}/{1} {2:0}%  ",
  34.             };
  35.         public IFont[] TextFont { get; set; } = new IFont[CURSE_COUNT];
  36.         public IBrush[] BarBrush { get; set; } = new IBrush[CURSE_COUNT];
  37.         public IBrush BorderBrush { get; set; }
  38.  
  39.         private readonly ISnoPower[] cursePower = new ISnoPower[CURSE_COUNT];
  40.         private readonly uint[] curseModifier = new uint[CURSE_COUNT]
  41.         {
  42.             Modifiers.Frailty,
  43.             Modifiers.Decrepify,
  44.             Modifiers.Leech,
  45.         };
  46.         private readonly int[] curseCount = new int[CURSE_COUNT];
  47.         private float barOffset = 0f;
  48.  
  49.         public CurseMeter() { Enabled = true; Order = 500; }    // Overlaps with WorkToDoEstimate!
  50.  
  51.         public override void Load(IController hud)
  52.         {
  53.             base.Load(hud);
  54.             var curseColor = new Color[CURSE_COUNT];
  55.             curseColor[FRAILTY] = Color.Aquamarine;
  56.             curseColor[DECREPIFY] = Color.CadetBlue;
  57.             curseColor[LEECH] = Color.HotPink;
  58.             for (var i = 0; i < curseColor.Length; ++i)
  59.             {
  60.                 var textColor = curseColor[i];
  61.                 TextFont[i] = Hud.Render.CreateFont("tahoma", 8f, 255, textColor.R, textColor.G, textColor.B, true, false, 220, 32, 32, 32, true);
  62.                 BarBrush[i] = Hud.Render.CreateBrush(255, textColor.R, textColor.G, textColor.B, 0);
  63.             }
  64.             var borderColor = Color.Red;
  65.             BorderBrush = hud.Render.CreateBrush(255, borderColor.R, borderColor.G, borderColor.B, -1);
  66.  
  67.             var p = Hud.Sno.SnoPowers;
  68.             cursePower[FRAILTY] = p.Necromancer_Frailty;
  69.             cursePower[DECREPIFY] = p.Necromancer_Decrepify;
  70.             cursePower[LEECH] = p.Necromancer_Leech;
  71.         }
  72.  
  73.         public void PaintTopInGame(ClipState clipState)
  74.         {
  75.             if (clipState != ClipState.BeforeClip)
  76.                 return;
  77.             if ((Hud.Game.MapMode == MapMode.WaypointMap) || (Hud.Game.MapMode == MapMode.ActMap) || (Hud.Game.MapMode == MapMode.Map))
  78.                 return;
  79.             if (Hud.Game.Me.HeroClassDefinition.HeroClass != HeroClass.Necromancer)
  80.                 return;
  81.             if (ShowOnlyInGr)
  82.             {
  83.                 if (!(Hud.Game.SpecialArea == SpecialArea.Rift || Hud.Game.SpecialArea == SpecialArea.GreaterRift || Hud.Game.SpecialArea == SpecialArea.ChallengeRift || Hud.Game.RiftPercentage > 0.0))
  84.                     return;
  85.             }
  86.             var monsterCount = 0;
  87.             Array.Clear(curseCount, 0, curseCount.Length);
  88.             var monsters = CurseDetectionRange > 0d
  89.                 ? Hud.Game.AliveMonsters.Where(x => x.NormalizedXyDistanceToMe < CurseDetectionRange)
  90.                 : Hud.Game.AliveMonsters;
  91.             foreach (var monster in monsters)
  92.             {
  93.                 monsterCount += 1;
  94.                 for (var i = 0; i < CURSE_COUNT; ++i)
  95.                 {
  96.                     if (monster.GetAttributeValue(Hud.Sno.Attributes.Power_Buff_2_Visual_Effect_None, curseModifier[i]) != -1d)
  97.                     {
  98.                         curseCount[i] += 1;
  99.                     }
  100.                 }
  101.             }
  102.             var player = Hud.Game.Me;
  103.             var textX = Hud.Window.Size.Width * offsetX;
  104.             var posY = Hud.Window.Size.Height * offsetY;
  105.  
  106.             var grimScythe = player.Powers.GetUsedSkill(Hud.Sno.SnoPowers.Necromancer_GrimScythe);
  107.             var cursedScythe = grimScythe?.Rune == Runes.Necromancer.GrimScythe.CursedScythe;
  108.             for (var i = 0; i < CURSE_COUNT; ++i)
  109.             {
  110.                 if (cursedScythe || player.Powers.GetUsedSkill(cursePower[i]) != null)
  111.                 {
  112.                     var percent = monsterCount == 0 ? 0f : (float)curseCount[i] / monsterCount;
  113.                     var text = string.Format(TextLabel[i], curseCount[i], monsterCount, percent * 100f);
  114.                     var layout = TextFont[i].GetTextLayout(text);
  115.                     TextFont[i].DrawText(layout, textX, posY);
  116.                     if (percent > 0f)
  117.                     {
  118.                         if (barOffset < layout.Metrics.Width)
  119.                         {
  120.                             barOffset = layout.Metrics.Width;
  121.                         }
  122.                         var x = textX + barOffset;
  123.                         BarBrush[i].DrawRectangle(x, posY, BarW * percent, BarH);
  124.                         BorderBrush.DrawRectangle(x, posY, BarW, BarH);
  125.                     }
  126.                     posY += layout.Metrics.Height;
  127.                 }
  128.             }
  129.         }
  130.     }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement