SHARE
TWEET

DAV_PartyCDPlugin

s4000 May 4th, 2019 (edited) 1,031 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Linq;
  3. using SharpDX.DirectInput;
  4. using SharpDX;
  5. using Turbo.Plugins.Default;
  6. using System.Globalization;
  7. using System.Collections.Generic;
  8.  
  9. namespace Turbo.Plugins.DavPlayer
  10. {
  11.     public class DAV_PartyCDPlugin : BasePlugin, IInGameTopPainter {
  12.         public DAV_SkillPainter SkillPainter { get; set; }
  13.         public IFont ClassFont { get; set; }
  14.         public List<uint> WatchedSnos;
  15.  
  16.         public float StartXPos { get; set; }
  17.         public float StartYPos { get; set; }
  18.         public float IconSize { get; set; }
  19.         private float _size;
  20.         private float HudWidth { get { return Hud.Window.Size.Width; } }
  21.         private float HudHeight { get { return Hud.Window.Size.Height; } }
  22.         private Dictionary<HeroClass, string> _classShortName;
  23.  
  24.         public DAV_PartyCDPlugin() {
  25.             Enabled = true;
  26.         }
  27.        
  28.         public override void Load(IController hud) {
  29.             base.Load(hud);
  30.            
  31.             StartYPos = 0.005f;
  32.             StartXPos = 0.625f;
  33.             IconSize = 0.05f;
  34.             _size = HudWidth * 0.02f;
  35.  
  36.             ClassFont = Hud.Render.CreateFont("tahoma", 7, 255, 255, 255, 255, true, false, 255, 0, 0, 0, true);
  37.             SkillPainter = new DAV_SkillPainter(Hud);
  38.             _classShortName = new Dictionary<HeroClass, string> {
  39.                 {HeroClass.Barbarian, "\n(Barb)"},
  40.                 {HeroClass.Monk, "\n(Monk)"},
  41.                 {HeroClass.Necromancer, "\n(Necro)"},
  42.                 {HeroClass.Wizard, "\n(Wiz)"},
  43.                 {HeroClass.WitchDoctor, "\n(WD)"},
  44.                 {HeroClass.Crusader, "\n(Sader)"},
  45.                 {HeroClass.DemonHunter, "\n(DH)"}
  46.             };
  47.            
  48.             WatchedSnos = new List<uint> {
  49.                 //--- Crusader
  50.                 Hud.Sno.SnoPowers.Crusader_AkaratsChampion.Sno,
  51.                
  52.                 //--- Necromancer
  53.                 Hud.Sno.SnoPowers.Necromancer_Simulacrum.Sno,
  54.                 Hud.Sno.SnoPowers.Necromancer_LandOfTheDead.Sno,
  55.  
  56.                 //--- Barb
  57.             //  Hud.Sno.SnoPowers.Barbarian_IgnorePain.Sno,
  58.             //  Hud.Sno.SnoPowers.Barbarian_WrathOfTheBerserker.Sno,
  59.             //  Hud.Sno.SnoPowers.Barbarian_WarCry.Sno,
  60.  
  61.                 //--- Monk
  62.             //  Hud.Sno.SnoPowers.Monk_InnerSanctuary.Sno,
  63.                 Hud.Sno.SnoPowers.Monk_Epiphany.Sno,
  64.  
  65.                 //--- Witch Doctor
  66.             //  Hud.Sno.SnoPowers.WitchDoctor_SpiritWalk.Sno,
  67.             //  Hud.Sno.SnoPowers.WitchDoctor_BigBadVoodoo.Sno,
  68.  
  69.                 //--- Demon Hunter
  70.                  Hud.Sno.SnoPowers.DemonHunter_Companion.Sno,
  71.             //   Hud.Sno.SnoPowers.DemonHunter_Sentry.Sno,
  72.  
  73.                 //--- Wizard
  74.                 Hud.Sno.SnoPowers.Wizard_Archon.Sno,
  75.             //  Hud.Sno.SnoPowers.Wizard_BlackHole.Sno
  76.             };   
  77.         }
  78.        
  79.         public void PaintTopInGame(ClipState clipState) {
  80.             if (clipState != ClipState.BeforeClip) return;
  81.  
  82.             var xPos = HudWidth * StartXPos;
  83.             var index = 0;
  84.             foreach (var player in Hud.Game.Players.OrderBy(p => p.HeroClassDefinition.HeroClass)) {
  85.                 var foundCarrySkill = false;
  86.                 var flagIsFirstIterator = true;
  87.                 var yPos = HudHeight * StartYPos;
  88.                
  89.                 foreach (var skill in player.Powers.UsedSkills.OrderBy(p => p.SnoPower.Sno)) {
  90.                     if (skill == null || !WatchedSnos.Contains(skill.SnoPower.Sno)) continue;
  91.                    
  92.                     foundCarrySkill = true;
  93.                     if (flagIsFirstIterator) {
  94.                         var layout = ClassFont.GetTextLayout(player.BattleTagAbovePortrait + _classShortName[player.HeroClassDefinition.HeroClass]);
  95.                         ClassFont.DrawText(layout, xPos, yPos);
  96.                         flagIsFirstIterator = false;
  97.                         yPos += 0.035f * HudHeight;
  98.                     }
  99.                    
  100.                     var rect = new SharpDX.RectangleF(xPos, yPos, _size, _size);
  101.                     SkillPainter.Paint(skill, rect);
  102.                     yPos += _size*1.1f;
  103.                 }
  104.                
  105.                 var CheatDeathBuff = player.Powers.GetBuff(Hud.Sno.SnoPowers.WitchDoctor_Passive_SpiritVessel.Sno);
  106.                 switch (player.HeroClassDefinition.HeroClass) {
  107.                     case HeroClass.Crusader: CheatDeathBuff = player.Powers.GetBuff(Hud.Sno.SnoPowers.Crusader_Passive_Indestructible.Sno); break;
  108.                     case HeroClass.Barbarian: CheatDeathBuff = player.Powers.GetBuff(Hud.Sno.SnoPowers.Barbarian_Passive_NervesOfSteel.Sno); break;
  109.                     case HeroClass.Monk: CheatDeathBuff = player.Powers.GetBuff(Hud.Sno.SnoPowers.Monk_Passive_NearDeathExperience.Sno); break;
  110.                     case HeroClass.Necromancer: CheatDeathBuff = player.Powers.GetBuff(Hud.Sno.SnoPowers.Necromancer_Passive_FinalService.Sno); break;
  111.                     case HeroClass.DemonHunter: CheatDeathBuff = player.Powers.GetBuff(Hud.Sno.SnoPowers.DemonHunter_Passive_Awareness.Sno); break;
  112.                     case HeroClass.Wizard: CheatDeathBuff = player.Powers.GetBuff(Hud.Sno.SnoPowers.Wizard_Passive_UnstableAnomaly.Sno); break;
  113.                 }
  114.                
  115.                 if (CheatDeathBuff != null && CheatDeathBuff.TimeLeftSeconds[1] > 0.0) {
  116.                     if (flagIsFirstIterator) {
  117.                         var layout = ClassFont.GetTextLayout(player.BattleTagAbovePortrait + _classShortName[player.HeroClassDefinition.HeroClass]);
  118.                         ClassFont.DrawText(layout, xPos, yPos);
  119.                         foundCarrySkill = true;
  120.                         yPos += 0.03f * HudHeight;
  121.                     }
  122.                     var Texture = Hud.Texture.GetTexture(Hud.Sno.SnoPowers.WitchDoctor_Passive_SpiritVessel.Icons[1].TextureId);
  123.                     switch (player.HeroClassDefinition.HeroClass) {
  124.                         case HeroClass.Crusader: Texture = Hud.Texture.GetTexture(Hud.Sno.SnoPowers.Crusader_Passive_Indestructible.Icons[1].TextureId); break;
  125.                         case HeroClass.Barbarian: Texture = Hud.Texture.GetTexture(Hud.Sno.SnoPowers.Barbarian_Passive_NervesOfSteel.Icons[1].TextureId); break;
  126.                         case HeroClass.Monk: Texture = Hud.Texture.GetTexture(Hud.Sno.SnoPowers.Monk_Passive_NearDeathExperience.Icons[1].TextureId); break;
  127.                         case HeroClass.Necromancer: Texture = Hud.Texture.GetTexture(Hud.Sno.SnoPowers.Necromancer_Passive_FinalService.Icons[1].TextureId); break;
  128.                         case HeroClass.DemonHunter: Texture = Hud.Texture.GetTexture(Hud.Sno.SnoPowers.DemonHunter_Passive_Awareness.Icons[1].TextureId); break;
  129.                         case HeroClass.Wizard: Texture = Hud.Texture.GetTexture(Hud.Sno.SnoPowers.Wizard_Passive_UnstableAnomaly.Icons[1].TextureId); break;
  130.                     }
  131.                     if (Texture != null) Texture.Draw(xPos, yPos, _size, _size);
  132.                     var layout2 = ClassFont.GetTextLayout(CheatDeathBuff.TimeLeftSeconds[1].ToString("0"));
  133.                     ClassFont.DrawText(layout2, xPos + (_size - (float)Math.Ceiling(layout2.Metrics.Width)) / 2, yPos + (_size - layout2.Metrics.Height) / 2);
  134.                 }
  135.                
  136.                 if (foundCarrySkill) xPos += _size * 2.5f;
  137.                 index++;
  138.             }
  139.         }
  140.     }
  141.    
  142.     public class DAV_SkillPainter : ITransparentCollection {
  143.         public bool Enabled { get; set; }
  144.         public IController Hud { get; set; }
  145.  
  146.         public IFont CDFont { get; set; }
  147.         public IFont BuffFont { get; set; }
  148.  
  149.         public DAV_SkillPainter(IController hud) {
  150.             Enabled = true;
  151.             Hud = hud;
  152.  
  153.             CDFont = Hud.Render.CreateFont("arial", 9, 255, 255, 255, 255, true, false, 255, 0, 0, 0, true);
  154.             BuffFont = Hud.Render.CreateFont("arial", 9, 255, 51, 255, 51, true, false, 255, 0, 0, 0, true);
  155.         }
  156.  
  157.         public void Paint(IPlayerSkill skill, RectangleF rect) {
  158.             if (skill == null) return;
  159.  
  160.             var texture = Hud.Texture.GetTexture(skill.SnoPower.NormalIconTextureId);
  161.             if (texture != null) texture.Draw(rect.X, rect.Y, rect.Width, rect.Height);
  162.  
  163.             if (skill.BuffIsActive) {
  164.                 var ActiveTime = 0.0d;
  165.                 for (var i = 2; i >= 0; i--) {
  166.                     ActiveTime= skill.Buff.TimeLeftSeconds[i];
  167.                     if (ActiveTime > 0)
  168.                         break;
  169.                 }
  170.                
  171.                 if (ActiveTime > 0) {
  172.                     var bufftext = ActiveTime.ToString(ActiveTime > 3.0f ? "F0" : "F1", CultureInfo.InvariantCulture);
  173.                     var bufftextLayout = BuffFont.GetTextLayout(bufftext);
  174.                     BuffFont.DrawText(bufftextLayout, rect.X, rect.Y);
  175.                 }
  176.             }
  177.            
  178.             var remainingSeconds = (skill.CooldownFinishTick - Hud.Game.CurrentGameTick) / 60.0d;
  179.             if (skill != null && skill.SnoPower.Sno == Hud.Sno.SnoPowers.Wizard_Archon.Sno && skill.BuffIsActive) {
  180.                 var ActiveTime = skill.Buff.TimeLeftSeconds[2];
  181.                
  182.                 if (ActiveTime > 0)
  183.                     remainingSeconds = skill.CalculateCooldown(skill.Rune == 3.0? 100 : 120) - 20 + ActiveTime;
  184.             }
  185.                
  186.             if (remainingSeconds <= 0) return;
  187.                
  188.             var text = remainingSeconds.ToString(remainingSeconds > 3.0f ? "F0" : "F1", CultureInfo.InvariantCulture);
  189.             var textLayout = CDFont.GetTextLayout(text);
  190.             var x = rect.X + rect.Width - (float)Math.Ceiling(textLayout.Metrics.Width);
  191.             var y = rect.Y + rect.Height - textLayout.Metrics.Height;
  192.             CDFont.DrawText(textLayout, x, y);
  193.         }
  194.  
  195.         public IEnumerable<ITransparent> GetTransparents() {
  196.             yield return CDFont;
  197.             yield return BuffFont;
  198.         }
  199.     }
  200. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top