Advertisement
HaKache

PartyCooldownPlugin

Nov 20th, 2019
587
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.65 KB | None | 0 0
  1. // PartyCooldownPlugin by HaKache
  2. // Shows chosen skills on CD under players feet using CooldownPainter.
  3.  
  4. using System;
  5. using System.Linq;
  6. using System.Globalization;
  7. using SharpDX.DirectInput;
  8. using SharpDX;
  9. using Turbo.Plugins.Default;
  10. using System.Collections.Generic;
  11.  
  12. namespace Turbo.Plugins.Extended.Addons
  13. {
  14.     public class PartyCooldownPlugin : BasePlugin, IInGameTopPainter
  15.     {
  16.         public CooldownPainter SkillPainter { get; set; }
  17.         public CooldownPainter MySkillPainter { get; set; }
  18.         public IFont GreenFont { get; set; }
  19.         public IFont RedFont { get; set; }
  20.  
  21.         public TopLabelDecorator Label { get; set; }
  22.         public List<uint> WatchedSnos;
  23.  
  24.         public bool ShowSelf { get; set; }
  25.         public bool ShowOnlyMe { get; set; }
  26.         public bool ShowInTown { get; set; }
  27.         public bool OnlyInGR { get; set; }
  28.         public bool PersonalCooldowns { get; set; }
  29.  
  30.         public float Offset { get; set; }
  31.         private readonly int[] _skillOrder = { 2, 3, 4, 5, 0, 1 };
  32.  
  33.         public PartyCooldownPlugin()
  34.         {
  35.             Enabled = true;
  36.         }
  37.  
  38.         public override void Load(IController hud)
  39.         {
  40.             base.Load(hud);
  41.  
  42.             ShowSelf = false;
  43.             ShowInTown = true;
  44.             OnlyInGR = false;
  45.             ShowOnlyMe = false;
  46.             PersonalCooldowns = true;
  47.  
  48.             Offset = 0.055f; // 0 = Middle - Negative = Up - Positive = Down
  49.  
  50.         WatchedSnos = new List<uint>();
  51.  
  52.         // Add skills to the watch list below
  53.         // --- Necromancer
  54.             WatchedSnos.Add(465350); // Simulacrum  
  55.             WatchedSnos.Add(465839); // Land of the Dead
  56.  
  57.         // --- Barb
  58.         //WatchedSnos.Add(79528); // Ignore Pain
  59.         //WatchedSnos.Add(79607); // Wrath of the Berserker
  60.         //WatchedSnos.Add(375483); // Warcry
  61.  
  62.         // --- Monk
  63.         //WatchedSnos.Add(317076); // Inner Sanctuary
  64.  
  65.         // --- Witch Doctor
  66.         //WatchedSnos.Add(106237); // Spirit Walk
  67.  
  68.         // --- Demon Hunter
  69.         //WatchedSnos.Add(365311); // Companion
  70.  
  71.         // --- Wizard
  72.         WatchedSnos.Add(134872); // Archon
  73.         //WatchedSnos.Add(243141);  // BH
  74.  
  75.             GreenFont = Hud.Render.CreateFont("tahoma", 6f, 255, 128, 255, 0, true, false, 220, 0, 0, 0, true);
  76.             RedFont = Hud.Render.CreateFont("tahoma", 6f, 255, 255, 30, 50, true, false, 220, 0, 0, 0, true);
  77.  
  78.             SkillPainter = new CooldownPainter(Hud, true)
  79.             {
  80.                 TextureOpacity = 0.7f,
  81.                 CooldownFont = Hud.Render.CreateFont("tahoma", 6f, 255, 255, 255, 255, true, false, 220, 0, 0, 0, true),
  82.             };
  83.  
  84.             MySkillPainter = new CooldownPainter(Hud, true)
  85.             {
  86.                 TextureOpacity = 0.15f,
  87.                 CooldownFont = Hud.Render.CreateFont("tahoma", 6f, 255, 255, 255, 255, true, false, 220, 0, 0, 0, true),
  88.             };
  89.  
  90.         }
  91.  
  92.         public void PaintTopInGame(ClipState clipState)
  93.         {
  94.     if (clipState != ClipState.BeforeClip || !ShowInTown && Hud.Game.Me.IsInTown || OnlyInGR && Hud.Game.SpecialArea != SpecialArea.GreaterRift) return;
  95.  
  96.     float iconSize = 30f;
  97.  
  98.         foreach (var player in Hud.Game.Players.Where(p => p.HasValidActor).OrderBy(p => p.HeroId))
  99.         {
  100.             var xPos = player.ScreenCoordinate.X - Hud.Window.Size.Width * 0.015f;
  101.  
  102.                 if (player.IsMe && !ShowSelf || !player.IsMe && ShowOnlyMe) continue;
  103.                 var found = false;
  104.                 foreach (var i in _skillOrder)
  105.                 {
  106.                     var skill = player.Powers.SkillSlots[i];
  107.                     if (skill == null || !WatchedSnos.Contains(skill.SnoPower.Sno)) continue;
  108.                     found = true;
  109.  
  110.     if (skill.SnoPower.Sno != 134872) {
  111.         var rect = new RectangleF(xPos, player.ScreenCoordinate.Y + Hud.Window.Size.Height * Offset, iconSize, iconSize);
  112.         SkillPainter.Paint(skill, rect);
  113.                     xPos += iconSize + 1f;
  114.             }
  115.     else if (skill.SnoPower.Sno == 134872)
  116.     {
  117.         double archonCooldown = 0;
  118.         double archonTimeLeft = 0;
  119.  
  120.         archonCooldown = (skill.CooldownFinishTick - Hud.Game.CurrentGameTick) / 60.0d;
  121.         var archonBuff = player.Powers.GetBuff(Hud.Sno.SnoPowers.Wizard_Archon.Sno);
  122.         if (archonBuff != null) { archonTimeLeft = archonBuff.TimeLeftSeconds[2]; }
  123.  
  124.         var txtdrawn = false; var drawn = false;
  125.         foreach (var iicon in Hud.Sno.SnoPowers.Wizard_Archon.Icons) {
  126.         var Texture = Hud.Texture.GetTexture(iicon.TextureId);
  127.         if (Texture != null && (archonCooldown > 0.0 || archonTimeLeft != 0) && !drawn) {
  128.             Texture.Draw(xPos, player.ScreenCoordinate.Y + Hud.Window.Size.Height * Offset, iconSize, iconSize, 0.7f);
  129.                         Hud.Texture.BuffFrameTexture.Draw(xPos, player.ScreenCoordinate.Y + Hud.Window.Size.Height * Offset, iconSize, iconSize, 0.7f);
  130.             drawn = true;
  131.                 }
  132.             }
  133.         if (archonTimeLeft == 0 && archonCooldown > 0.0 && !txtdrawn)
  134.         {
  135.             var layout = RedFont.GetTextLayout(archonCooldown.ToString("0"));
  136.             RedFont.DrawText(layout, xPos + (iconSize - layout.Metrics.Width) / 2, player.ScreenCoordinate.Y + Hud.Window.Size.Height * Offset + (iconSize - layout.Metrics.Height) / 2);
  137.             txtdrawn = true;
  138.         }
  139.         if (archonTimeLeft != 0 && !txtdrawn)
  140.         {
  141.             var layout = GreenFont.GetTextLayout(archonTimeLeft.ToString("0"));
  142.             GreenFont.DrawText(layout, xPos + (iconSize - layout.Metrics.Width) / 2, player.ScreenCoordinate.Y + Hud.Window.Size.Height * Offset + (iconSize - layout.Metrics.Height) / 2);
  143.             txtdrawn = true;
  144.         }
  145.                     xPos += iconSize + 1f;
  146.     }
  147.  
  148.                 }
  149.                 if (found)
  150.                     xPos += iconSize + 1f;
  151.             }
  152.  
  153.     if (PersonalCooldowns) {
  154.  
  155.         var uiSkillX = Hud.Window.Size.Width * 0.446f;
  156.         var uiSkillY = Hud.Window.Size.Height * 0.473f;
  157.         iconSize = 25f;
  158.  
  159.             var player = Hud.Game.Me;
  160.  
  161.     foreach (var i in _skillOrder)
  162.     {
  163.         var skill = player.Powers.SkillSlots[i];
  164.  
  165.     if (player.Powers.SkillSlots[2] != null) {
  166.                 var rect = new RectangleF(uiSkillX + 5f, uiSkillY, iconSize, iconSize);
  167.         MySkillPainter.Paint(player.Powers.SkillSlots[2], rect);
  168.             }
  169.     if (player.Powers.SkillSlots[3] != null) {
  170.                 var rect = new RectangleF(uiSkillX + 21f, uiSkillY + 29f, iconSize, iconSize);
  171.         MySkillPainter.Paint(player.Powers.SkillSlots[3], rect);
  172.             }
  173.     if (player.Powers.SkillSlots[4] != null) {
  174.                 var rect = new RectangleF(uiSkillX + 51f, uiSkillY + 44f, iconSize, iconSize);
  175.         MySkillPainter.Paint(player.Powers.SkillSlots[4], rect);
  176.             }
  177.  
  178.     if (player.Powers.SkillSlots[5] != null) {
  179.                 var rect = new RectangleF(uiSkillX + 131f, uiSkillY + 44f, iconSize, iconSize);
  180.         MySkillPainter.Paint(player.Powers.SkillSlots[5], rect);
  181.             }
  182.     if (player.Powers.SkillSlots[0] != null) {
  183.                 var rect = new RectangleF(uiSkillX + 161f, uiSkillY + 29f, iconSize, iconSize);
  184.         MySkillPainter.Paint(player.Powers.SkillSlots[0], rect);
  185.             }
  186.     if (player.Powers.SkillSlots[1] != null) {
  187.                 var rect = new RectangleF(uiSkillX + 177f, uiSkillY, iconSize, iconSize);
  188.         MySkillPainter.Paint(player.Powers.SkillSlots[1], rect);
  189.             }
  190.         }
  191.     }
  192.  
  193.  
  194.         }
  195.     }
  196.  
  197.     public class CooldownPainter : ITransparentCollection
  198.     {
  199.         public bool Enabled { get; set; }
  200.         public IController Hud { get; set; }
  201.  
  202.         public IFont CooldownFont { get; set; }
  203.         public IFont GreenFont { get; set; }
  204.         public IFont RedFont { get; set; }
  205.  
  206.         public float TextureOpacity { get; set; }
  207.  
  208.         private readonly IWatch _lastTownEliteSimulation;
  209.  
  210.         public CooldownPainter(IController hud, bool setDefaultStyle)
  211.         {
  212.             Enabled = true;
  213.             Hud = hud;
  214.  
  215.             _lastTownEliteSimulation = Hud.Time.CreateWatch();
  216.  
  217.             if (setDefaultStyle)
  218.             {
  219.                 TextureOpacity = 0.2f;
  220.                 CooldownFont = Hud.Render.CreateFont("tahoma", 6f, 255, 255, 255, 255, true, false, 220, 0, 0, 0, true);
  221.             }
  222.  
  223.             GreenFont = Hud.Render.CreateFont("tahoma", 6f, 255, 128, 255, 0, true, false, 220, 0, 0, 0, true);
  224.             RedFont = Hud.Render.CreateFont("tahoma", 6f, 255, 255, 30, 50, true, false, 220, 0, 0, 0, true);
  225.         }
  226.  
  227.         public void Paint(IPlayerSkill skill, RectangleF rect)
  228.         {
  229.             if (skill == null) return;
  230.         if (!skill.IsOnCooldown) return;
  231.  
  232.             if (TextureOpacity > 0)
  233.             {
  234.                 var texture = Hud.Texture.GetTexture(skill.SnoPower.NormalIconTextureId);
  235.                 if (texture != null)
  236.                 {
  237.                     texture.Draw(rect.X, rect.Y, rect.Width, rect.Height, TextureOpacity);
  238.                     Hud.Texture.BuffFrameTexture.Draw(rect.X, rect.Y, rect.Width, rect.Height, TextureOpacity);
  239.                 }
  240.             }
  241.  
  242.             if (skill.IsOnCooldown && (skill.CooldownFinishTick > Hud.Game.CurrentGameTick))
  243.             {
  244.                 var remaining = (skill.CooldownFinishTick - Hud.Game.CurrentGameTick) / 60.0d;
  245.                 var text = remaining > 1.0f ? remaining.ToString("F0", CultureInfo.InvariantCulture) : remaining.ToString("F0", CultureInfo.InvariantCulture);
  246.                 var textLayout = CooldownFont.GetTextLayout(text);
  247.                 CooldownFont.DrawText(textLayout, rect.X + (rect.Width - (float)Math.Ceiling(textLayout.Metrics.Width)) / 2.0f, rect.Y + (rect.Height - textLayout.Metrics.Height) / 2);
  248.         }
  249.  
  250.             var rune = skill.Rune;
  251.             if (rune == byte.MaxValue) rune = 0; else rune += 1;
  252.         }
  253.  
  254.         public IEnumerable<ITransparent> GetTransparents()
  255.         {
  256.             yield return CooldownFont;
  257.         }
  258.  
  259.     }
  260. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement