Advertisement
zjqyf

TrialsOfTempestsIcon.cs

Jul 20th, 2020
535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.43 KB | None | 0 0
  1. using Turbo.Plugins.Default;
  2. using System;
  3. using SharpDX;
  4. namespace Turbo.Plugins.RNN
  5. {
  6. public class TrialsOfTempestsIcon : BasePlugin, IInGameTopPainter
  7. {
  8. private uint[] Textures { get; set; } = new uint[7] { 3405442230, 2639019912, 4122635698, 1541236666, 3513867492, 928374825, 569405584 }; // 0,1,2-火,3-冰,4-毒,5-物理,6-射线
  9. private IBrush[] Brushes { get; set; }
  10. private ITexture TextureBG { get; set; }
  11. private long[] timers { get; set; } = new long[] { 0, 0, 0, 0 };
  12. private double[] t { get; set; } = new double[] { 0, 0, 0, 0 };
  13. private bool[] reset { get; set; } = new bool[] { false, false, false, false };
  14. private float SizeIconWidth { get; set; }
  15. private float SizeIconHeight { get; set; }
  16. private SharpDX.DirectWrite.TextLayout layout { get; set; } = null;
  17. private IFont FontStacks0 { get; set; }
  18. private IFont FontStacks1 { get; set; }
  19. private IFont FontStacksY { get; set; }
  20. private IFont FontStacksG { get; set; }
  21. private IFont FontCounter { get; set; }
  22. private IFont FontTimeLeft { get; set; }
  23. private IBrush BrushBorder { get; set; }
  24. public IBrush AlmostGoneBorderBrush { get; set; }
  25. public IFont AlmostGoneTimeLeftFont { get; set; }
  26.  
  27. private RectangleF Buff;
  28. public float Opacity { get; set; }
  29. public float SizeMultiplier { get; set; }
  30. public TrialsOfTempestsIcon()
  31. {
  32. Enabled = true;
  33. }
  34.  
  35. public override void Load(IController hud)
  36. {
  37. base.Load(hud);
  38. Order = 30001;
  39. Opacity = 1f;
  40. SizeMultiplier = 1f;
  41.  
  42. TextureBG = Hud.Texture.GetTexture(3144819863);
  43.  
  44. var tr = 1.0f;
  45. BrushBorder = Hud.Render.CreateBrush(255, 255, 255, 255, tr);
  46. AlmostGoneBorderBrush = Hud.Render.CreateBrush(220, 255, 0, 0, 3);
  47. Brushes = new IBrush[7] // 0,1,2-火,3-冰,4-毒,5-物理,6-射线
  48. {
  49. BrushBorder,
  50. BrushBorder,
  51. Hud.Render.CreateBrush( 255, 255, 0, 0, tr),
  52. BrushBorder,
  53. Hud.Render.CreateBrush( 255, 0, 255, 0, tr),
  54. Hud.Render.CreateBrush( 255, 80, 80, 80, tr),
  55. Hud.Render.CreateBrush( 255, 0, 128, 255, tr),
  56. };
  57.  
  58. FontStacks1 = Hud.Render.CreateFont("tahoma", 8f * SizeMultiplier, 255, 255, 255, 255, false, false, 255, 0, 0, 0, true);
  59. FontStacksY = Hud.Render.CreateFont("tahoma", 8f * SizeMultiplier, 255, 255, 255, 0, false, false, 255, 0, 0, 0, true);
  60. FontStacksG = Hud.Render.CreateFont("tahoma", 8f * SizeMultiplier, 255, 195, 195, 195, false, false, 255, 0, 0, 0, true);
  61. FontCounter = Hud.Render.CreateFont("tahoma", 9f * SizeMultiplier, 255, 255, 255, 255, false, false, 255, 0, 0, 0, true);
  62. FontTimeLeft = Hud.Render.CreateFont("tahoma", 8f * SizeMultiplier, 255, 0, 255, 0, false, false, 255, 0, 0, 0, true);
  63. AlmostGoneTimeLeftFont = Hud.Render.CreateFont("tahoma", 9, 255, 255, 0, 0, false, false, 255, 0, 0, 0, true);
  64.  
  65. }
  66. public void PaintTopInGame(ClipState clipState)
  67. {
  68. if (clipState != ClipState.BeforeClip) return;
  69. if (!Hud.Game.IsInGame) return;
  70. if (!Hud.Game.Me.InGreaterRift) return;
  71. if (Hud.Game.Me.Powers.BuffIsActive(484426)) //风暴试练
  72. {
  73. SizeIconWidth = TextureBG.Width * Hud.Game.Me.PortraitUiElement.Rectangle.Width / 100 * SizeMultiplier;
  74. SizeIconHeight = TextureBG.Height * Hud.Game.Me.PortraitUiElement.Rectangle.Width / 100 * SizeMultiplier;
  75. var players = Hud.Game.Players;
  76. foreach (var player in players)
  77. {
  78. var buff = player.Powers.GetBuff(484426);
  79. if (buff != null)
  80. {
  81. var portraitRect = player.PortraitUiElement.Rectangle;
  82. float x, y;
  83. x = portraitRect.Right;
  84. y = portraitRect.Top + portraitRect.Height * 0.3f;
  85. Buff.Left = x;
  86. Buff.Top = y;
  87. Buff.Right = x + SizeIconWidth;
  88. Buff.Bottom = y + SizeIconHeight;
  89. TextureBG.Draw(x, y, SizeIconWidth, SizeIconHeight, Opacity);
  90. (player.HasValidActor ? Hud.Texture.BuffFrameTexture : Hud.Texture.DebuffFrameTexture).Draw(x, y, SizeIconWidth, SizeIconHeight, Opacity);
  91.  
  92. if (player.HasValidActor) t[player.Index] = buff.TimeLeftSeconds[1]; //赛季BUFF下个爆发的倒计时 layout = FontCounter.GetTextLayout(t.ToString( (t < 1)? "F1" : "F0") );
  93.  
  94. if (!player.HasValidActor)//距离过远的玩家获取模拟时间
  95. {
  96. if (reset[player.Index] == false)
  97. {
  98. t[player.Index] = buff.TimeLeftSeconds[1];
  99. }
  100. else
  101. {
  102. t[player.Index] = 90;
  103. }
  104. if (timers[player.Index] == 0)
  105. {
  106. timers[player.Index] = Hud.Game.CurrentRealTimeMilliseconds;//记录最后一个有效BUFF的时间
  107. }
  108. else
  109. {
  110. t[player.Index] -= (Hud.Game.CurrentRealTimeMilliseconds - timers[player.Index]) / 1000;//根据最后一次有效BUFF时间模拟计算远距离BUFF剩余时间
  111. }
  112.  
  113. if (t[player.Index] < 0)
  114. {
  115. //模拟计算BUFF剩余时间小于0时重置为90秒
  116. t[player.Index] = 90;
  117. reset[player.Index] = true;
  118. timers[player.Index] = 0;//重置记录有效距离BUFF时间
  119. }
  120. }
  121. else
  122. {
  123. reset[player.Index] = false;
  124. timers[player.Index] = 0;//重置记录有效距离BUFF时间
  125. }
  126.  
  127.  
  128.  
  129. if (t[player.Index] < 1.0f)//倒计时时间格式化
  130. {
  131. layout = FontCounter.GetTextLayout(String.Format("{0:N1}", t[player.Index]));
  132. }
  133. else
  134. {
  135. layout = FontCounter.GetTextLayout((t[player.Index] < 60) ? String.Format("{0:0}", t[player.Index]) : String.Format("{0:0}:{1:00}", (int)(t[player.Index] / 60), t[player.Index] % 60));
  136. }
  137. FontCounter.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width)) / 2.0f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height)) / 2.0f));
  138.  
  139. if (t[player.Index] < 10)//小于10秒时红框红字显示
  140. {
  141.  
  142. AlmostGoneBorderBrush?.DrawRectangle(Buff);
  143. AlmostGoneTimeLeftFont.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width)) / 2.0f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height)) / 2.0f));
  144. }
  145.  
  146. layout = FontStacks1.GetTextLayout(buff.IconCounts[8].ToString());
  147. FontStacks1.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width)) / 1.17f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height)) / 1.1f));
  148.  
  149. FontStacks0 = FontStacksG;
  150. for (int i = 2; i < 7; i++)
  151. {//爆发时的BUFF倒计时
  152. double t2 = 0;
  153. t2 = buff.TimeLeftSeconds[i];
  154. if (t2 > 0)
  155. {
  156. layout = FontTimeLeft.GetTextLayout(t2.ToString((t2 < 1) ? "F1" : "F0"));
  157. FontTimeLeft.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width)) / 7.0f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height)) / 1.1f));
  158. Hud.Texture.GetTexture(Textures[i]).Draw(x + 0.08f * SizeIconWidth, y + 0.08f * SizeIconHeight, SizeIconHeight * 0.28f, SizeIconHeight * 0.28f, 1.0f);
  159. Brushes[i].DrawRectangle(x + 0.08f * SizeIconWidth, y + 0.08f * SizeIconHeight, SizeIconHeight * 0.28f, SizeIconHeight * 0.28f);
  160. FontStacks0 = FontStacksY;
  161. break;
  162. }
  163. }
  164. layout = FontStacks0.GetTextLayout(buff.IconCounts[9].ToString());
  165. FontStacks0.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width)) / 1.17f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height)) / 12.0f));
  166. }
  167. }
  168. }
  169. }
  170. }
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement