Advertisement
RNNCode

BloodIsPowerPlugin

Mar 31st, 2020 (edited)
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.98 KB | None | 0 0
  1. using Turbo.Plugins.Default;
  2. using System;
  3. using System.Linq;
  4. using SharpDX;
  5.  
  6. namespace Turbo.Plugins.RNN
  7. {
  8.     public class BloodIsPowerPlugin : BasePlugin, IInGameTopPainter, IAfterCollectHandler, INewAreaHandler
  9.     {  
  10.         private IFont FontText { get; set; }
  11.         private float Last { get; set; } = 0f;
  12.         private float Lost { get; set; } = 0f;
  13.         private IBrush Brush1 { get; set; }
  14.         private IBrush Brush2 { get; set; }
  15.         private IBrush Brush3 { get; set; }
  16.         private int[] state { get; set; }
  17.         private int MyIndex { get; set; } = -1;
  18.         private int ticks { get; set; } = 0;
  19.         private bool Remainder { get; set; } = true;
  20.        
  21.         public bool ShowCircles { get; set; }
  22.         public bool ShowOnlyOnCooldown { get; set; }
  23.         public bool ShowBar { get; set; }
  24.        
  25.         public BloodIsPowerPlugin()
  26.         {
  27.             Enabled = true;
  28.         }
  29.         public override void Load(IController hud)
  30.         {
  31.             base.Load(hud);
  32.             Order = 31001;
  33.             ShowCircles = false;        // Show a circle instead of an icon
  34.             ShowOnlyOnCooldown = false; // Hide the icon when the skill is not on cooldown
  35.             ShowBar = true;             // Show bar with the amount of health lost
  36.            
  37.             FontText = Hud.Render.CreateFont("tahoma", 6, 255, 200, 175, 150, false, false, 255, 0, 0, 0, true);
  38.             Brush1 = hud.Render.CreateBrush(255, 255, 0, 0, 0);
  39.             Brush2 = hud.Render.CreateBrush(255, 255, 255, 255, 1);
  40.             Brush3 = hud.Render.CreateBrush(255, 0, 0, 0, 1);
  41.             state = new int[] {0,0,0,0,0,0,0};
  42.         }  
  43.  
  44.         public void OnNewArea(bool newGame, ISnoArea area)  
  45.         {
  46.             if (newGame || (MyIndex != Hud.Game.Me.Index) )   // Fix partialment the newGame limitation
  47.             {
  48.                 MyIndex = Hud.Game.Me.Index;
  49.                 Last = 0;   Lost = 0;
  50.                 for(var i = 0; i < 7; i++) state[i] = 0;
  51.                 ticks = Hud.Game.CurrentGameTick;
  52.             }
  53.         }
  54.        
  55.         public void AfterCollect()  
  56.         {
  57.             if (!ShowBar) return;
  58.             if (!Hud.Game.IsInGame ) return;
  59.             if (Hud.Game.Me.HeroClassDefinition.HeroClass != HeroClass.Necromancer) return;
  60.             if (Hud.Game.Me.Powers.UsedPassives.Any(p => p.Sno == Hud.Sno.SnoPowers.Necromancer_Passive_BloodIsPower.Sno)) // 465037
  61.             {          
  62.                 if (Hud.Game.Me.IsDead)
  63.                 {
  64.                     if (Last > 0)
  65.                     {
  66.                         Last = 0;   Lost = 0;
  67.                         for(var i = 0; i < 7; i++) state[i] = 0;
  68.                     }
  69.                 }
  70.                 else
  71.                 {  
  72.                     if (Hud.Game.Me.Defense.HealthCur > Last)   { Last = Hud.Game.Me.Defense.HealthCur; }
  73.                     else if (Hud.Game.Me.Defense.HealthCur != Last)
  74.                     {
  75.                         IBuff buff = Hud.Game.Me.Powers.GetBuff(465037);
  76.                         if (buff != null)  
  77.                         {
  78.                             var recibido = false; var pendiente = false;
  79.                             foreach (var skill in Hud.Game.Me.Powers.CurrentSkills)
  80.                             {
  81.                                 int i = 1 + (int) skill.Key;
  82.                                 var n = buff.IconCounts[i];
  83.                                 if (n == 1)
  84.                                 {                          
  85.                                     if (n != state[i])
  86.                                     {
  87.                                         state[i] = n;
  88.                                         recibido = true;
  89.                                     }                      
  90.                                 }
  91.                                 else
  92.                                 {
  93.                                     if (n != state[i]) state[i] = n;
  94.                                     if (skill.IsOnCooldown && ((Hud.Game.CurrentGameTick - skill.CooldownStartTick) > 60))  pendiente = true;
  95.                                 }
  96.                             }
  97.  
  98.                             if (recibido) { Lost = Remainder? Math.Max(0,Lost - Hud.Game.Me.Defense.HealthMax): 0 ; ticks = Hud.Game.CurrentGameTick; }
  99.                             else if (Hud.Game.Me.Defense.HealthCur < Last)
  100.                             {                  
  101.                                 Lost += Last - Hud.Game.Me.Defense.HealthCur ;
  102.                                 if (Lost > Hud.Game.Me.Defense.HealthMax)  
  103.                                 {
  104.                                     if (pendiente) { Lost = Hud.Game.Me.Defense.HealthMax * 0.98f; }
  105.                                     else { Lost = Remainder? (Lost - Hud.Game.Me.Defense.HealthMax) : 0 ; ticks = Hud.Game.CurrentGameTick; }
  106.                                 }                              
  107.                             }
  108.                             Last = Hud.Game.Me.Defense.HealthCur;
  109.                         }
  110.                     }                                          
  111.                 }                              
  112.             }          
  113.         }  
  114.  
  115.         public void PaintTopInGame(ClipState clipState)
  116.         {
  117.             if (clipState != ClipState.BeforeClip) return;
  118.             if (!Hud.Game.IsInGame) return;
  119.             if (Hud.Game.Me.HeroClassDefinition.HeroClass != HeroClass.Necromancer) return;
  120.             if (Hud.Game.Me.Powers.UsedPassives.Any(p => p.Sno == Hud.Sno.SnoPowers.Necromancer_Passive_BloodIsPower.Sno)) // 465037
  121.             {
  122.                 IBuff buff = Hud.Game.Me.Powers.GetBuff(465037);
  123.                 if (buff != null)  
  124.                 {              
  125.                     foreach (var skill in Hud.Game.Me.Powers.CurrentSkills)
  126.                     {
  127.                         if (ShowOnlyOnCooldown && !skill.IsOnCooldown) continue;
  128.                         if (buff.IconCounts[1 + (int) skill.Key] == 1)
  129.                         {
  130.                             var ui = Hud.Render.GetPlayerSkillUiElement(skill.Key);
  131.                             var rect = new RectangleF((float)Math.Round(ui.Rectangle.X) + 0.5f, (float)Math.Round(ui.Rectangle.Y) + 0.5f, (float)Math.Round(ui.Rectangle.Width), (float)Math.Round(ui.Rectangle.Height));
  132.                             if (ShowCircles)
  133.                             {
  134.                                 var d = rect.Width * 0.08f ; var r = rect.Width * 0.06f;
  135.                                 Brush1.DrawEllipse(rect.X + d , rect.Y + d , r, r);
  136.                                 Brush2.DrawEllipse(rect.X + d , rect.Y + d , r, r);
  137.                             }
  138.                             else
  139.                             {                              
  140.                                 var d = rect.Width * 0.08f ; var r = rect.Width * 0.24f;
  141.                                 Hud.Texture.GetTexture(1161431971).Draw(rect.X + d, rect.Y + d - 1, r, r); // Hud.Sno.SnoPowers.Necromancer_Passive_BloodIsPower.NormalIconTextureId  = 1161431971
  142.                                 Hud.Texture.BuffFrameTexture.Draw(rect.X + d, rect.Y + d - 1, r, r);
  143.                             }                          
  144.                         }
  145.                     }
  146.                
  147.                     if (ShowBar)
  148.                     {                                                      
  149.                         var uiRect = Hud.Render.GetUiElement("Root.NormalLayer.game_dialog_backgroundScreenPC.game_progressBar_healthBall").Rectangle;
  150.                         var x = uiRect.X + uiRect.Width + 4; var y = uiRect.Y + uiRect.Height * 0.94f;
  151.                         ((Math.Abs(Hud.Game.CurrentGameTick - ticks) > 30)?Brush3:Brush2).DrawRectangle(x, y, 4, - uiRect.Height * 0.40f );
  152.                         Brush1.DrawRectangle(x, y, 4, - uiRect.Height * 0.40f *  (Hud.Game.Me.Defense.HealthMax - Lost) / Hud.Game.Me.Defense.HealthMax );
  153.                         var layout = FontText.GetTextLayout( "-" + ( Lost / Hud.Game.Me.Defense.HealthMax * 100).ToString("F0") + "%");
  154.                         FontText.DrawText(layout,x - layout.Metrics.Width - 2 , y - layout.Metrics.Height/2  );
  155.                     }                  
  156.                 }              
  157.             }          
  158.         }          
  159.     }  
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement