Advertisement
s4000

DAV_PartyCDPlugin

May 4th, 2019
3,331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.17 KB | None | 0 0
  1. using SharpDX;
  2. using SharpDX.DirectInput;
  3. using System;
  4. using System.Linq;
  5. using System.Globalization;
  6. using System.Collections.Generic;
  7. using Turbo.Plugins.Default;
  8.  
  9. namespace Turbo.Plugins.DAV
  10. {
  11.     public class DAV_PartyCDPlugin : BasePlugin, IInGameTopPainter {
  12.         public float xPos { get; set; }
  13.         public float yPos { get; set; }
  14.         public float iconSize { get; set; }
  15.         public IFont ClassFont { get; set; }
  16.         public Dictionary<HeroClass, string> _classShortName;
  17.         public DAV_SkillPainter SkillPainter { get; set; }
  18.         public List<uint> WatchedSnos;
  19.  
  20.         private Dictionary<HeroClass, Tuple<uint,ITexture>> classCheatDeath;
  21.  
  22.         public DAV_PartyCDPlugin() {
  23.             Enabled = true;
  24.         }
  25.  
  26.         public override void Load(IController hud) {
  27.             base.Load(hud);
  28.  
  29.             xPos = Hud.Window.Size.Width * 0.625f;
  30.             yPos = Hud.Window.Size.Height * 0.005f;
  31.             iconSize = Hud.Window.Size.Height / 27;
  32.  
  33.             ClassFont = Hud.Render.CreateFont("arial", 7, 255, 255, 255, 255, true, false, 255, 0, 0, 0, true);
  34.             SkillPainter = new DAV_SkillPainter(Hud);
  35.  
  36.             _classShortName = new Dictionary<HeroClass, string> {
  37.                 {HeroClass.Barbarian, "\n(Barb)"},
  38.                 {HeroClass.Monk, "\n(Monk)"},
  39.                 {HeroClass.Necromancer, "\n(Necro)"},
  40.                 {HeroClass.Wizard, "\n(Wiz)"},
  41.                 {HeroClass.WitchDoctor, "\n(WD)"},
  42.                 {HeroClass.Crusader, "\n(Sader)"},
  43.                 {HeroClass.DemonHunter, "\n(DH)"}
  44.             };
  45.  
  46.             classCheatDeath = new Dictionary<HeroClass, Tuple<uint, ITexture>> {
  47.                 {HeroClass.Barbarian, new Tuple<uint, ITexture>(Hud.Sno.SnoPowers.Barbarian_Passive_NervesOfSteel.Sno, Hud.Texture.GetTexture(3216866912))},
  48.                 {HeroClass.Monk, new Tuple<uint, ITexture>(Hud.Sno.SnoPowers.Monk_Passive_NearDeathExperience.Sno, Hud.Texture.GetTexture(2406461858))},
  49.                 {HeroClass.Necromancer, new Tuple<uint, ITexture>(Hud.Sno.SnoPowers.Necromancer_Passive_FinalService.Sno, Hud.Texture.GetTexture(725994273))},
  50.                 {HeroClass.Wizard, new Tuple<uint, ITexture>(Hud.Sno.SnoPowers.Wizard_Passive_UnstableAnomaly.Sno, Hud.Texture.GetTexture(4122255698))},
  51.                 {HeroClass.WitchDoctor, new Tuple<uint, ITexture>(Hud.Sno.SnoPowers.WitchDoctor_Passive_SpiritVessel.Sno, Hud.Texture.GetTexture(4048913488))},
  52.                 {HeroClass.Crusader, new Tuple<uint, ITexture>(Hud.Sno.SnoPowers.Crusader_Passive_Indestructible.Sno, Hud.Texture.GetTexture(1659761171))},
  53.                 {HeroClass.DemonHunter, new Tuple<uint, ITexture>(Hud.Sno.SnoPowers.DemonHunter_Passive_Awareness.Sno, Hud.Texture.GetTexture(542514827))}
  54.             };
  55.  
  56.             WatchedSnos = new List<uint> {
  57.                 //--- Crusader
  58.                 Hud.Sno.SnoPowers.Crusader_AkaratsChampion.Sno,
  59.  
  60.                 //--- Necromancer
  61.                 Hud.Sno.SnoPowers.Necromancer_Simulacrum.Sno,
  62.                 Hud.Sno.SnoPowers.Necromancer_LandOfTheDead.Sno,
  63.  
  64.                 //--- Barb
  65.                 Hud.Sno.SnoPowers.Barbarian_GroundStomp.Sno,
  66.             //  Hud.Sno.SnoPowers.Barbarian_IgnorePain.Sno,
  67.             //  Hud.Sno.SnoPowers.Barbarian_WrathOfTheBerserker.Sno,
  68.             //  Hud.Sno.SnoPowers.Barbarian_WarCry.Sno,
  69.  
  70.                 //--- Monk
  71.             //  Hud.Sno.SnoPowers.Monk_InnerSanctuary.Sno,
  72.                 Hud.Sno.SnoPowers.Monk_Epiphany.Sno,
  73.                 Hud.Sno.SnoPowers.Monk_Serenity.Sno,
  74.  
  75.                 //--- Witch Doctor
  76.             //  Hud.Sno.SnoPowers.WitchDoctor_SpiritWalk.Sno,
  77.             //  Hud.Sno.SnoPowers.WitchDoctor_BigBadVoodoo.Sno,
  78.  
  79.                 //--- Demon Hunter
  80.                  Hud.Sno.SnoPowers.DemonHunter_Companion.Sno,
  81.  
  82.                 //--- Wizard
  83.                 Hud.Sno.SnoPowers.Wizard_Archon.Sno,
  84.             };
  85.         }
  86.  
  87.         public void PaintTopInGame(ClipState clipState) {
  88.             if (clipState != ClipState.BeforeClip) return;
  89.  
  90.             var xref = xPos;
  91.             foreach (var player in Hud.Game.Players.OrderBy(p => p.HeroClassDefinition.HeroClass)) {
  92.                 var foundCarrySkill = false;
  93.                 var flagIsFirstIterator = true;
  94.                 var yref = yPos;
  95.  
  96.                 foreach (var skill in player.Powers.UsedSkills.OrderBy(p => p.SnoPower.Sno)) {
  97.                     if (skill == null || !WatchedSnos.Contains(skill.SnoPower.Sno)) continue;
  98.  
  99.                     foundCarrySkill = true;
  100.                     if (flagIsFirstIterator) {
  101.                         var layout = ClassFont.GetTextLayout(player.BattleTagAbovePortrait + _classShortName[player.HeroClassDefinition.HeroClass]);
  102.                         ClassFont.DrawText(layout, xref, yref);
  103.                         flagIsFirstIterator = false;
  104.                         yref += layout.Metrics.Height + 2f;
  105.                     }
  106.  
  107.                     var rect = new SharpDX.RectangleF(xref, yref, iconSize, iconSize);
  108.                     SkillPainter.Paint(skill, rect);
  109.  
  110.                     yref += iconSize + 2f;
  111.                 }
  112.  
  113.                 var CheatDeathBuff = player.Powers.GetBuff(classCheatDeath[player.HeroClassDefinition.HeroClass].Item1);
  114.                 if (CheatDeathBuff?.TimeLeftSeconds[1] > 0.0) {
  115.                     if (flagIsFirstIterator) {
  116.                         var layout = ClassFont.GetTextLayout(player.BattleTagAbovePortrait + _classShortName[player.HeroClassDefinition.HeroClass]);
  117.                         ClassFont.DrawText(layout, xref, yref);
  118.                         foundCarrySkill = true;
  119.                         yref += layout.Metrics.Height + 2f;
  120.                     }
  121.                     classCheatDeath[player.HeroClassDefinition.HeroClass].Item2?.Draw(xref, yref, iconSize, iconSize);
  122.  
  123.                     var layout2 = ClassFont.GetTextLayout(CheatDeathBuff.TimeLeftSeconds[1].ToString("0"));
  124.                     ClassFont.DrawText(layout2, xref + (iconSize - layout2.Metrics.Width) / 2, yref + (iconSize - layout2.Metrics.Height) / 2);
  125.                 }
  126.  
  127.                 if (foundCarrySkill)
  128.                     xref += iconSize * 2.5f;
  129.             }
  130.         }
  131.     }
  132.  
  133.     public class DAV_SkillPainter {
  134.         public IController Hud { get; set; }
  135.         public IFont CDFont { get; set; }
  136.         public IFont BuffFont { get; set; }
  137.  
  138.         public DAV_SkillPainter(IController hud) {
  139.             Hud = hud;
  140.             CDFont = Hud.Render.CreateFont("arial", 9, 255, 255, 255, 255, true, false, 255, 0, 0, 0, true);
  141.             BuffFont = Hud.Render.CreateFont("arial", 9, 255, 51, 255, 51, true, false, 255, 0, 0, 0, true);
  142.         }
  143.  
  144.         public void Paint(IPlayerSkill skill, RectangleF rect) {
  145.             if (skill == null) return;
  146.  
  147.             var texture = Hud.Texture.GetTexture(skill.SnoPower.NormalIconTextureId);
  148.             texture?.Draw(rect.X, rect.Y, rect.Width, rect.Height);
  149.  
  150.             if (skill.BuffIsActive) {
  151.                 var ActiveTime = 0.0d;
  152.                 for (var i = 2; i >= 0; i--) {
  153.                     ActiveTime= skill.Buff.TimeLeftSeconds[i];
  154.                     if (ActiveTime > 0) {
  155.                         BuffFont.DrawText(ActiveTime.ToString(ActiveTime > 3.0f ? "F0" : "F1"), rect.X + 2, rect.Y + 2);
  156.                         break;
  157.                     }
  158.                 }
  159.             }
  160.  
  161.             var remainingSeconds = (skill.CooldownFinishTick - Hud.Game.CurrentGameTick) / 60.0d;
  162.             if (skill?.SnoPower.Sno == Hud.Sno.SnoPowers.Wizard_Archon.Sno && skill.BuffIsActive) {
  163.                 var ActiveTime = skill.Buff.TimeLeftSeconds[2];
  164.  
  165.                 if (ActiveTime > 0)
  166.                     remainingSeconds = skill.CalculateCooldown(skill.Rune == 3.0 ? 100 : 120) - 20 + ActiveTime;
  167.             }
  168.  
  169.             if (remainingSeconds <= 0) return;
  170.  
  171.             var textLayout = CDFont.GetTextLayout(remainingSeconds.ToString(remainingSeconds > 3.0f ? "F0" : "F1"));
  172.             CDFont.DrawText(textLayout, rect.Right - textLayout.Metrics.Width - 2, rect.Bottom - textLayout.Metrics.Height - 2);
  173.         }
  174.     }
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement