Advertisement
Guest User

GLQ_PlayerResurrectionTimer.cs

a guest
Sep 11th, 2017
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.15 KB | None | 0 0
  1. // http://www.ownedcore.com/forums/diablo-3/turbohud/turbohud-plugin-review-zone/633886-v7-3-english-glq-playerresurrectiontimer.html
  2.  
  3. using Turbo.Plugins.Default;
  4. using System.Linq;
  5.  
  6. // namespace Turbo.Plugins.glq
  7. namespace Turbo.Plugins.User.Player
  8. {
  9.     public class GLQ_PlayerResurrectionTimer : BasePlugin, IInGameTopPainter, INewAreaHandler
  10.     {
  11.         private bool[] Dead;
  12.         private int[] DeadTimes;
  13.         private double[] DeadTime;
  14.         private double[] CurrentTime;
  15.         private double[] GhostTime;
  16.         private double[] CurrentGhostTime;
  17.        
  18.         public string DeathSymbol { get; set; }
  19.         public IFont TextFontDeath { get; set; }
  20.         public IFont TextFontDeathTime { get; set; }
  21.         public IFont TextFontGhostTime { get; set; }
  22.         public IBrush DeadTimeBorderBrush { get; set; }
  23.         public IBrush DeadBorderBrush { get; set; }
  24.         public IBrush GhostBorderBrush { get; set; }
  25.        
  26.         public GLQ_PlayerResurrectionTimer()
  27.         {
  28.             Enabled = true;
  29.         }
  30.        
  31.         public override void Load(IController hud)
  32.         {
  33.             base.Load(hud);
  34.            
  35.             Dead = new bool[4];
  36.             DeadTimes = new int[4];
  37.             DeadTime = new double[4];
  38.             CurrentTime = new double[4];
  39.             GhostTime = new double[4];
  40.             CurrentGhostTime = new double[4];
  41.            
  42.             DeathSymbol = "\u271F"; //✟
  43.             TextFontDeath = Hud.Render.CreateFont("tahoma", 35, 200, 255, 255, 255, true, false, true);
  44.             TextFontDeathTime = Hud.Render.CreateFont("tahoma", 12, 200, 255, 0, 0, true, false, true);
  45.             TextFontGhostTime = Hud.Render.CreateFont("tahoma", 12, 200, 128, 255, 255, true, false, true);
  46.             DeadTimeBorderBrush = Hud.Render.CreateBrush(200, 255, 0, 0, -2);
  47.             DeadBorderBrush = Hud.Render.CreateBrush(200, 255, 255, 255, -2);
  48.             GhostBorderBrush = Hud.Render.CreateBrush(200, 128, 255, 255, -2);
  49.         }
  50.        
  51.         public void OnNewArea(bool newGame, ISnoArea area)
  52.         {
  53.             if (newGame)
  54.             {
  55.                 for (int i = 0; i < 4; i++)
  56.                 {
  57.                     DeadTimes[i] = 0;
  58.                     GhostTime[i] = 0;
  59.                 }
  60.             }
  61.         }
  62.        
  63.         private IQuest riftQuest
  64.         {
  65.             get
  66.             {
  67.                 return Hud.Game.Quests.FirstOrDefault(q => q.SnoQuest.Sno == 337492) ?? // rift
  68.                        Hud.Game.Quests.FirstOrDefault(q => q.SnoQuest.Sno == 382695);   // gr
  69.             }
  70.         }
  71.        
  72.         public void PaintTopInGame(ClipState clipState)
  73.         {
  74.             if (clipState != ClipState.BeforeClip) return;
  75.            
  76.             bool inGR = Hud.Game.SpecialArea == SpecialArea.GreaterRift;
  77.             // var layout = TextFontDeath.GetTextLayout(DeathSymbol);
  78.             var secondsLeft = (Hud.Game.CurrentTimedEventEndTick - (double)Hud.Game.CurrentGameTick) / 60.0d;
  79.            
  80.             if (riftQuest == null || (riftQuest != null && riftQuest.State == QuestState.none))
  81.             {
  82.                 for (int i = 0; i < 4; i++)
  83.                 {
  84.                     DeadTimes[i] = 0;
  85.                     GhostTime[i] = 0;
  86.                 }
  87.             }
  88.            
  89.             foreach (var player in Hud.Game.Players)
  90.             {
  91.                 DrawPlayerDeadTimer(player, inGR, secondsLeft);
  92.             }
  93.         }
  94.        
  95.         private void DrawPlayerDeadTimer(IPlayer player, bool inGR, double secondsLeft)
  96.         {
  97.             var portrait = player.PortraitUiElement.Rectangle;
  98.             var x = portrait.Left + portrait.Width * 1.1f;
  99.             var y = portrait.Top + portrait.Height / 4;
  100.             var layout = TextFontDeath.GetTextLayout(DeathSymbol);
  101.            
  102.             // if (player.IsDead)           // wrong ghost timers sometimes
  103.             if (player.IsDeadSafeCheck)     // better
  104.             {
  105.                 if (Dead[player.Index] == false)
  106.                 {
  107.                     DeadTime[player.Index] = Hud.Game.CurrentGameTick;
  108.                     if (inGR) DeadTimes[player.Index]++;
  109.                     Dead[player.Index] = true;
  110.                 }
  111.                
  112.                 // Dead[player.Index] = true;
  113.                 CurrentTime[player.Index] = GetDeadCountdown(DeadTimes[player.Index], secondsLeft, inGR) - (Hud.Game.CurrentGameTick - DeadTime[player.Index]) / 60.0d;
  114.                
  115.                 if (CurrentTime[player.Index] < 0.5)
  116.                 {
  117.                     y = portrait.Top + portrait.Height / 4;
  118.                     layout = TextFontDeath.GetTextLayout(DeathSymbol);
  119.                     DeadBorderBrush.DrawRectangle(portrait.Left, portrait.Top, portrait.Width, portrait.Height);
  120.                     TextFontDeath.DrawText(layout, x, y);
  121.                     CurrentTime[player.Index] = 0;
  122.                 }
  123.                 else
  124.                 {
  125.                     y = portrait.Top + portrait.Height / 3.5f;
  126.                     layout = TextFontDeathTime.GetTextLayout("Death: " + CurrentTime[player.Index].ToString("f0") + "s");
  127.                     DeadTimeBorderBrush.DrawRectangle(portrait.Left, portrait.Top, portrait.Width, portrait.Height);
  128.                     TextFontDeathTime.DrawText(layout, x, y);
  129.                 }
  130.             }
  131.             else
  132.             {
  133.                 if (Dead[player.Index])
  134.                 {
  135.                     GhostTime[player.Index] = Hud.Game.CurrentGameTick + 3 * 60;
  136.                     Dead[player.Index] = false;
  137.                 }
  138.                
  139.                 // Dead[player.Index] = false;
  140.                 CurrentGhostTime[player.Index] = (GhostTime[player.Index] - Hud.Game.CurrentGameTick) / 60.0d;
  141.                
  142.                 if (CurrentGhostTime[player.Index] > 0)
  143.                 {
  144.                     y = portrait.Top + portrait.Height / 3.5f;
  145.                     layout = TextFontGhostTime.GetTextLayout("Ghost: " + CurrentGhostTime[player.Index].ToString("f0") + "s");
  146.                     if (CurrentGhostTime[player.Index] < 1) layout = TextFontGhostTime.GetTextLayout("Ghost: " + CurrentGhostTime[player.Index].ToString("f1") + "s");
  147.                     TextFontGhostTime.DrawText(layout, x, y);
  148.                     GhostBorderBrush.DrawRectangle(portrait.Left, portrait.Top, portrait.Width, portrait.Height);
  149.                 }
  150.                 else
  151.                 {
  152.                     CurrentGhostTime[player.Index] = 0;
  153.                 }
  154.             }
  155.         }
  156.        
  157.         private double GetDeadCountdown(int DeadTimes,double secondsLeft ,bool inGR)
  158.         {
  159.             double Times = 0;
  160.             if(!inGR) return 0 + 3.5;
  161.             if (DeadTimes == 1) Times = 0 + 3.5;
  162.             if (DeadTimes == 2) Times = 5 + 3.5;
  163.             if (DeadTimes == 3) Times = 10 + 3.5;
  164.             if (DeadTimes == 4) Times = 15 + 3.5;
  165.             if (DeadTimes == 5) Times = 20 + 3.5;
  166.             if (DeadTimes == 6) Times = 25 + 3.5;
  167.             if (DeadTimes >= 7) Times = 30 + 3.5;
  168.             if(secondsLeft<=0)
  169.             {
  170.                 Times = 0 + 3.5;
  171.             }
  172.             return Times;
  173.         }
  174.     }
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement