Advertisement
RNNCode

GLQ_SpiritBarragePhantasmPlugin

May 6th, 2020 (edited)
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.08 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, IInGameWorldPainter, 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 = 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.
  47.                        
  48.            
  49.             BrushDash = hud.Render.CreateBrush(150, 0, 128, 255, 3, SharpDX.Direct2D1.DashStyle.Dash);
  50.             BrushSolid = hud.Render.CreateBrush(255, 0, 128, 255, 2);          
  51.             FontText = Hud.Render.CreateFont("tahoma", 9f, 255, 100, 255, 150, true, false, 128, 0, 0, 0, true);
  52.             BrushCounter = hud.Render.CreateBrush(255, 0, 128, 255, 0);
  53.             TimeLeftClockBrush = Hud.Render.CreateBrush(220, 0, 0, 0, 0);  
  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.         public void Customize()
  64.         {
  65.             if ((CircleSeconds < 1) || (CircleSeconds > 5))     { CircleSeconds = 2; }             
  66.         }
  67.        
  68.         public void OnNewArea(bool newGame, ISnoArea area)
  69.         {  
  70.             if (newGame || (MyIndex != Hud.Game.Me.Index) )   // Fix partialment the newGame limitation
  71.             {
  72.                 MyIndex = Hud.Game.Me.Index;
  73.                 Phantasms.Clear();
  74.             }
  75.         }
  76.  
  77.         private void DrawTimeLeftClock(RectangleF rect, double elapsed, double timeLeft)   // plugins\Default\BuffLists\Painter\BuffPainter.cs
  78.         {
  79.             if ((timeLeft > 0) && (elapsed >= 0) && (TimeLeftClockBrush != null))
  80.             {
  81.                 var endAngle = Convert.ToInt32(360.0d / (timeLeft + elapsed) * elapsed);
  82.                 var startAngle = 0;
  83.                 TimeLeftClockBrush.Opacity = 1 - (float)(0.5f / (timeLeft + elapsed) * elapsed);
  84.                 var rad = rect.Width; // * 0.45f;
  85.                 using (var pg = Hud.Render.CreateGeometry())
  86.                 {
  87.                     using (var gs = pg.Open())
  88.                     {
  89.                         gs.BeginFigure(rect.Center, FigureBegin.Filled);
  90.                         for (var angle = startAngle; angle <= endAngle; angle++)
  91.                         {
  92.                             var mx = rad * (float)Math.Cos((angle - 90) * Math.PI / 180.0f);
  93.                             var my = rad * (float)Math.Sin((angle - 90) * Math.PI / 180.0f);
  94.                             var vec = new Vector2(rect.Center.X + mx, rect.Center.Y + my);
  95.                             gs.AddLine(vec);
  96.                         }
  97.  
  98.                         gs.EndFigure(FigureEnd.Closed);
  99.                         gs.Close();
  100.                     }
  101.                     TimeLeftClockBrush.DrawGeometry(pg);
  102.                 }
  103.             }
  104.         }
  105.        
  106.         public void PaintWorld(WorldLayer layer)
  107.         {
  108.             if (!Hud.Game.IsInGame) return;        
  109.             if (layer != WorldLayer.Ground) return;
  110.            
  111.             var actors = Hud.Game.Actors.Where(a => a.SnoActor.Sno == ActorSnoEnum._wd_spiritbarragerune_aoe_ghostmodel && (ShowOthers || (a.SummonerAcdDynamicId == Hud.Game.Me.SummonerId)) );
  112.             if (actors.Any())
  113.             {              
  114.                 foreach (var actor in actors)
  115.                 {
  116.                     if (!Phantasms.ContainsKey(actor.AnnId)) { Phantasms[actor.AnnId] = actor.CreatedAtInGameTick; }
  117.                     var duration = Hud.Game.Players.Any(p => actor.SummonerAcdDynamicId == p.SummonerId && p.Powers.BuffIsActive(484270))? 10d:5d;                     
  118.                     var elapsed = (Hud.Game.CurrentGameTick - Phantasms[actor.AnnId]) / 60d;
  119.                     if (elapsed < (duration + 0.1) )
  120.                     {
  121.                         BrushSolid.DrawWorldEllipse(10, -1, actor.FloorCoordinate);
  122.                         if  (ShowExplosionCircle && ((duration - elapsed) <= CircleSeconds) )
  123.                         {
  124.                             BrushDash.DrawWorldEllipse(15, -1, actor.FloorCoordinate);
  125.                         }
  126.                         if (actor.IsOnScreen)
  127.                         {  
  128.                             var timeleft = duration - elapsed;
  129.                             var x = actor.FloorCoordinate.ToScreenCoordinate().X;
  130.                             var y = actor.FloorCoordinate.ToScreenCoordinate().Y;
  131.                             var radiusc = radius_countdown / 1200.0f * Hud.Window.Size.Height;             
  132.                             BrushCounter.DrawEllipse(x , y , radiusc , radiusc);               
  133.                             DrawTimeLeftClock(new RectangleF(x - radiusc/2, y - radiusc/2 , radiusc, radiusc), elapsed , timeleft );
  134.                        
  135.                             var layout = FontText.GetTextLayout( (timeleft < 0)?"0.0":timeleft.ToString((timeleft > 1)?"F0":"F1") );
  136.                             FontText.DrawText(layout, x - layout.Metrics.Width/2 , y - layout.Metrics.Height/2 - 1);   
  137.                         }                  
  138.                     }
  139.                 }
  140.                 if (ShowCounter)
  141.                 {
  142.                     var uiRect = Hud.Render.GetUiElement("Root.NormalLayer.game_dialog_backgroundScreenPC.game_progressBar_manaBall").Rectangle;                           
  143.                     PhantomCountDecorator.Paint(uiRect.Left + uiRect.Width * 0.20f, uiRect.Top - uiRect.Height * 0.20f, uiRect.Width * 0.60f, uiRect.Height * 0.15f, "Phantom:" + actors.Count());
  144.                 }
  145.             }          
  146.         }
  147.     }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement