Advertisement
zjqyf

GLQ_PlayerResurrectionTimer.cs

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