Advertisement
RNNCode

glq_SpiritBarragePhantasmPlugin

May 6th, 2020 (edited)
705
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.42 KB | None | 0 0
  1. // Modified. Original (by glq): https://www.ownedcore.com/forums/diablo-3/turbohud/turbohud-discussions/618926-damage-count-down-circle-of-spirit-barrage-post3728819.html#post3728819
  2. using System;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5. using Turbo.Plugins.Default;
  6. using SharpDX;
  7. using SharpDX.Direct2D1;
  8.  
  9. namespace Turbo.Plugins.glq
  10. {
  11.     public class SpiritBarragePhantasmPlugin : BasePlugin, IInGameTopPainter, ICustomizer, INewAreaHandler
  12.     {
  13.  
  14.         private Dictionary<uint,int> Phantasms { get;set; } = new Dictionary<uint,int>();
  15.         private int MyIndex { get; set; } = -1;
  16.        
  17.         private TopLabelWithTitleDecorator PhantomCountDecorator { get; set; }
  18.  
  19.         private IBrush BrushSolid { get; set; }
  20.         private IBrush BrushDash { get; set; }
  21.         private IBrush BrushCounter { get; set; }      
  22.         private IBrush TimeLeftClockBrush { get; set; }
  23.  
  24.         private IFont FontText { get; set; }       
  25.  
  26.         public int radius_countdown { get; set; } = 25;
  27.        
  28.         public bool ShowOthers {get; set;}
  29.         public bool ShowCounter {get; set;}
  30.         public bool ShowExplosionCircle {get; set;}
  31.         public int CircleSeconds {get; set;}
  32.    
  33.         public SpiritBarragePhantasmPlugin()
  34.         {
  35.             Enabled = true;
  36.         }
  37.  
  38.         public override void Load(IController hud)
  39.         {
  40.             base.Load(hud);
  41.             Order = 1001;
  42.            
  43.             ShowOthers = true;          // Also show for other players.
  44.             ShowCounter = true;         // Counter
  45.             ShowExplosionCircle = true; // Show  additional circle the last "CircleSeconds"
  46.             CircleSeconds = 2;          // 1 .. 5 ,  Draw additional circle the last CircleSeconds. Will check if you use The Barber
  47.    
  48.             BrushDash = hud.Render.CreateBrush(150, 0, 128, 255, 3, SharpDX.Direct2D1.DashStyle.Dash);
  49.             BrushSolid = hud.Render.CreateBrush(220, 0, 128, 255, 2);          
  50.             BrushCounter = hud.Render.CreateBrush(255, 0, 128, 255, 0);
  51.             TimeLeftClockBrush = Hud.Render.CreateBrush(220, 0, 0, 0, 0);
  52.            
  53.             FontText = Hud.Render.CreateFont("tahoma", 9f, 255, 100, 255, 150, true, false, 128, 0, 0, 0, true);
  54.                                            
  55.             PhantomCountDecorator = new TopLabelWithTitleDecorator(Hud)
  56.             {
  57.                 BackgroundBrush = Hud.Render.CreateBrush(80, 134, 238, 240, 0),
  58.                 BorderBrush = Hud.Render.CreateBrush(255, 0, 0, 0, -1),
  59.                 TextFont = Hud.Render.CreateFont("tahoma", 8, 255, 255, 0, 0, true, false, true),
  60.             };
  61.                    
  62.         }
  63.  
  64.         public void Customize()
  65.         {
  66.             if ((CircleSeconds < 1) || (CircleSeconds > 5))     { CircleSeconds = 2; }             
  67.         }
  68.  
  69.         public void OnNewArea(bool newGame, ISnoArea area)
  70.         {  
  71.             if (newGame || (MyIndex != Hud.Game.Me.Index) )   // Fix partialment the newGame limitation
  72.             {
  73.                 MyIndex = Hud.Game.Me.Index;
  74.                 Phantasms.Clear();
  75.             }
  76.         }
  77.  
  78.         private void DrawTimeLeftClock(RectangleF rect, double elapsed, double timeLeft)   // plugins\Default\BuffLists\Painter\BuffPainter.cs
  79.         {
  80.             if ((timeLeft > 0) && (elapsed >= 0) && (TimeLeftClockBrush != null))
  81.             {
  82.                 var endAngle = Convert.ToInt32(360.0d / (timeLeft + elapsed) * elapsed);
  83.                 var startAngle = 0;
  84.                 TimeLeftClockBrush.Opacity = 1 - (float)(0.5f / (timeLeft + elapsed) * elapsed);
  85.                 var rad = rect.Width; // * 0.45f;
  86.                 using (var pg = Hud.Render.CreateGeometry())
  87.                 {
  88.                     using (var gs = pg.Open())
  89.                     {
  90.                         gs.BeginFigure(rect.Center, FigureBegin.Filled);
  91.                         for (var angle = startAngle; angle <= endAngle; angle++)
  92.                         {
  93.                             var mx = rad * (float)Math.Cos((angle - 90) * Math.PI / 180.0f);
  94.                             var my = rad * (float)Math.Sin((angle - 90) * Math.PI / 180.0f);
  95.                             var vec = new Vector2(rect.Center.X + mx, rect.Center.Y + my);
  96.                             gs.AddLine(vec);
  97.                         }
  98.  
  99.                         gs.EndFigure(FigureEnd.Closed);
  100.                         gs.Close();
  101.                     }
  102.  
  103.                     TimeLeftClockBrush.DrawGeometry(pg);
  104.                 }
  105.             }
  106.         }
  107.        
  108.         public void PaintTopInGame(ClipState clipState)
  109.         {
  110.             if (clipState != ClipState.BeforeClip) return;         
  111.             if (!Hud.Game.IsInGame) return;
  112.            
  113.             var actors = Hud.Game.Actors.Where(a => a.SnoActor.Sno == ActorSnoEnum._wd_spiritbarragerune_aoe_ghostmodel);                                      
  114.             if (actors.Any())
  115.             {
  116.                 foreach(var a in actors)
  117.                 {
  118.                   if (!Phantasms.ContainsKey(a.AnnId)) { Phantasms[a.AnnId] = a.CreatedAtInGameTick; }
  119.                 }
  120.                 var total = 0;
  121.                 foreach(var player in Hud.Game.Players)
  122.                 {                  
  123.                     if (!ShowOthers && !player.IsMe) continue;
  124.                     var actorsPlayer = actors.Where(a => a.SummonerAcdDynamicId == player.SummonerId).OrderByDescending(a => Phantasms[a.AnnId]);
  125.                     var c = 0;
  126.                     foreach (var actor in actorsPlayer)
  127.                     {
  128.                         if (c++ == 3) break;
  129.                         total++;   
  130.                         var duration = player.Powers.BuffIsActive(484270)? 10d : 5d;                       
  131.                         var elapsed = (Hud.Game.CurrentGameTick - Phantasms[actor.AnnId]) / 60d;
  132.                         if (elapsed < (duration + 0.1) )
  133.                         {
  134.                             BrushSolid.DrawWorldEllipse(10, -1, actor.FloorCoordinate);
  135.                             if  (ShowExplosionCircle && player.Powers.BuffIsActive(454932) && ( (duration - elapsed) <= CircleSeconds))
  136.                             {
  137.                                 BrushDash.DrawWorldEllipse(15, -1, actor.FloorCoordinate);
  138.                             }
  139.                             if (actor.IsOnScreen)
  140.                             {
  141.                                 var timeleft = duration - elapsed;  var x = actor.FloorCoordinate.ToScreenCoordinate().X; var y = actor.FloorCoordinate.ToScreenCoordinate().Y;
  142.                                 var radiusc = radius_countdown / 1200.0f * Hud.Window.Size.Height;
  143.                                
  144.                                 BrushCounter.DrawEllipse(x , y , radiusc , radiusc);               
  145.                                 DrawTimeLeftClock(new RectangleF(x - radiusc/2, y - radiusc/2 , radiusc, radiusc), elapsed , timeleft );
  146.                                
  147.                                 var layout = FontText.GetTextLayout( (timeleft < 0)?"0.0":timeleft.ToString((timeleft > 1)?"F0":"F1") );
  148.                                 FontText.DrawText(layout, x - layout.Metrics.Width/2 , y - layout.Metrics.Height/2 - 1);   
  149.                             }                          
  150.                         }
  151.                     }                                  
  152.                 }
  153.                 if (ShowCounter)
  154.                 {
  155.                     var uiRect = Hud.Render.GetUiElement("Root.NormalLayer.game_dialog_backgroundScreenPC.game_progressBar_manaBall").Rectangle;                           
  156.                     PhantomCountDecorator.Paint(uiRect.Left + uiRect.Width * 0.20f, uiRect.Top - uiRect.Height * 0.20f, uiRect.Width * 0.60f, uiRect.Height * 0.15f, "Phantom:" + total);
  157.                 }
  158.             }          
  159.         }
  160.     }
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement