Advertisement
Guest User

Trials

a guest
Sep 16th, 2020
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.92 KB | None | 0 0
  1. using Turbo.Plugins.Default;
  2. using System;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5. using System.Threading;
  6.  
  7. namespace Turbo.Plugins.RNN
  8. {
  9. public class TrialsOfTempestsIcon : BasePlugin, IInGameTopPainter, ICustomizer, INewAreaHandler, IAfterCollectHandler
  10. {
  11. private uint[] Textures { get; set; } = new uint[7] { 3405442230, 2639019912, 4122635698, 1541236666, 3513867492, 928374825, 569405584}; // 0,1, 2-Fuego, 3-Frío, 4-Veneno, 5-Físico, 6-Rayos
  12. private IBrush[] Brushes { get; set; }
  13. private ITexture TextureBG { get; set; }
  14. private long[] timers { get; set; } = new long[] {0,0,0,0};
  15. private float SizeIconWidth { get; set; }
  16. private float SizeIconHeight { get; set; }
  17.  
  18. private bool[] valid { get; set; } = new bool[] {false,false,false,false};
  19. private long[] tvalid { get; set; } = new long[] {0,0,0,0};
  20. private int MyIndex { get; set; } = -1;
  21. private int TotalPlayers { get; set; } = 0;
  22.  
  23. private SharpDX.DirectWrite.TextLayout layout { get; set; } = null;
  24. private IFont FontDefault { get; set; }
  25. private IFont FontStacks1 { get; set; }
  26. private IFont FontStacksY { get; set; }
  27. private IFont FontStacksG { get; set; }
  28. private IFont FontCounter { get; set; }
  29. private IFont FontCounter10 { get; set; }
  30.  
  31.  
  32. private IFont FontTimeLeft { get; set; }
  33. private IBrush BrushBorder { get; set; }
  34. private IBrush BrushMin { get; set; }
  35.  
  36. public bool PortraitMe { get; set; }
  37. public bool PortraitOthers { get; set; }
  38. public float OffsetX { get; set; }
  39. public float OffsetY { get; set; }
  40. public float OffsetXPortrait { get; set; }
  41. public float OffsetYPortrait { get; set; }
  42.  
  43. public float Opacity { get; set; }
  44. public float SizeMultiplier { get; set; }
  45.  
  46. public bool OnlyGR { get; set; }
  47. public bool OnlyMe { get; set; }
  48. public bool VisibleFar { get; set; }
  49.  
  50. public bool SoundEnabledProc { get; set; }
  51. public bool SoundEnabledLast10 { get; set; }
  52. public string FileSoundProc { get; set; }
  53. public string FileSoundLast10 { get; set; }
  54.  
  55. private int TicksLast10 { get; set; } = 0;
  56.  
  57. public TrialsOfTempestsIcon()
  58. {
  59. Enabled = true;
  60. }
  61.  
  62. public override void Load(IController hud)
  63. {
  64. base.Load(hud);
  65. Order = 30001;
  66.  
  67. OnlyGR = false;
  68. OnlyMe = false;
  69. VisibleFar = true; // Keep showing the icon of the players who are far away: the data will freeze, at this distance the values ​​are not updated
  70.  
  71. PortraitMe = true; // Show icon near portrait or next to our character (for Me)
  72. PortraitOthers = true; // Show icon near portrait or next to our character (for Others Players)
  73. OffsetX = +0.020f; // To modify the position of the icon. Reference point: character
  74. OffsetY = -0.020f;
  75. OffsetXPortrait = -0.009f; // To modify the position of the icon. Reference point: portrait
  76. OffsetYPortrait = +0.042f;
  77.  
  78. Opacity = 0.85f;
  79. SizeMultiplier = 0.75f;
  80.  
  81. SoundEnabledProc = false;
  82. SoundEnabledLast10 = false;
  83. FileSoundProc = "notification_5.wav"; // File to be played when a player proc . It must be in the Sounds\ folder
  84. FileSoundLast10 = "notification_6.wav"; // File to be played 10 seconds before an effect occurs. It must be in the Sounds\ folder
  85.  
  86. TextureBG = Hud.Texture.GetTexture(3144819863);
  87.  
  88. var tr = 1.0f;
  89. BrushBorder = Hud.Render.CreateBrush( 255, 255, 255, 255, tr);
  90. Brushes = new IBrush[7] // 0,1, 2-Fuego, 3-Frío, 4-Veneno, 5-Físico, 6-Rayos
  91. {
  92. BrushBorder,
  93. BrushBorder,
  94. Hud.Render.CreateBrush( 255, 255, 0, 0, tr),
  95. BrushBorder,
  96. Hud.Render.CreateBrush( 255, 0, 255, 0, tr),
  97. Hud.Render.CreateBrush( 255, 80, 80, 80, tr),
  98. Hud.Render.CreateBrush( 255, 0, 128, 255, tr),
  99. };
  100. BrushMin = Hud.Render.CreateBrush( 255, 0, 255, 0, 2);
  101. }
  102.  
  103. public void Customize()
  104. {
  105. FontStacks1 = Hud.Render.CreateFont("tahoma", 8f * SizeMultiplier, 255, 255, 255, 255, false, false, 255, 0, 0, 0, true);
  106. FontStacksY = Hud.Render.CreateFont("tahoma", 8f * SizeMultiplier, 255, 255, 255, 0, false, false, 255, 0, 0, 0, true);
  107. FontStacksG = Hud.Render.CreateFont("tahoma", 8f * SizeMultiplier, 255, 195, 195, 195, false, false, 255, 0, 0, 0, true);
  108. FontCounter = Hud.Render.CreateFont("tahoma", 9f * SizeMultiplier, 255, 255, 255, 255, false, false, 255, 0, 0, 0, true);
  109. FontCounter10 = Hud.Render.CreateFont("tahoma", 9f * SizeMultiplier, 255, 0, 255, 0, false, false, 255, 0, 0, 0, true);
  110. FontTimeLeft = Hud.Render.CreateFont("tahoma", 8f * SizeMultiplier, 255, 0, 255, 0, false, false, 255, 0, 0, 0, true);
  111.  
  112. SizeIconWidth = TextureBG.Width * Hud.Window.Size.Height/1200.0f * SizeMultiplier * 0.90f;
  113. SizeIconHeight = TextureBG.Height * Hud.Window.Size.Height/1200.0f * SizeMultiplier;
  114. }
  115.  
  116. public void OnNewArea(bool newGame, ISnoArea area)
  117. {
  118. if (newGame || (MyIndex != Hud.Game.Me.Index) )
  119. {
  120. MyIndex = Hud.Game.Me.Index;
  121. TotalPlayers = Hud.Game.NumberOfPlayersInGame;
  122. for (var i = 0; i < 4; i++) { valid[i] = false; tvalid[i] = 0; }
  123. TicksLast10 = Hud.Game.CurrentGameTick;
  124. }
  125. }
  126.  
  127. public void Play_Sound(string Sonido)
  128. {
  129. var playSonido = Hud.Sound.LoadSoundPlayer(Sonido);
  130. ThreadPool.QueueUserWorkItem(state =>
  131. {
  132. try { playSonido.PlaySync(); }
  133. catch (Exception) { }
  134. } );
  135. }
  136.  
  137. public void AfterCollect()
  138. {
  139. if (!Hud.Game.IsInGame) return;
  140. if (TotalPlayers != Hud.Game.NumberOfPlayersInGame)
  141. {
  142. TotalPlayers = Hud.Game.NumberOfPlayersInGame;
  143. for (var i = 0; i < 4; i++) { valid[i] = false; tvalid[i] = 0; }
  144. }
  145. }
  146.  
  147. public void PaintTopInGame(ClipState clipState)
  148. {
  149. if (clipState != ClipState.BeforeClip) return;
  150. if (!Hud.Game.IsInGame) return;
  151. if (OnlyGR && !Hud.Game.Me.InGreaterRift) return;
  152. if (Hud.Game.Me.Powers.BuffIsActive(484426)) // Jugando en temporada
  153. {
  154. var players = Hud.Game.Players.Where(p => (p.Powers.GetBuff(484426) != null) && (p.IsMe || (!OnlyMe && (p.HasValidActor || VisibleFar))) )
  155. .OrderBy(p => tvalid[p.Index]);
  156. bool Search = true;
  157. foreach(var player in players)
  158. {
  159. var buff = player.Powers.GetBuff(484426);
  160. float x, y;
  161. if ( player.IsMe?PortraitMe:PortraitOthers )
  162. {
  163. x = player.PortraitUiElement.Rectangle.X + Hud.Window.Size.Width * OffsetXPortrait;
  164. y = player.PortraitUiElement.Rectangle.Y + Hud.Window.Size.Height * OffsetYPortrait;
  165. }
  166. else
  167. {
  168. x = player.FloorCoordinate.ToScreenCoordinate().X + Hud.Window.Size.Width * OffsetX;
  169. y = player.FloorCoordinate.ToScreenCoordinate().Y + Hud.Window.Size.Height * OffsetY;
  170. }
  171.  
  172. TextureBG.Draw(x, y, SizeIconWidth, SizeIconHeight, Opacity);
  173. (player.HasValidActor?Hud.Texture.BuffFrameTexture:Hud.Texture.DebuffFrameTexture).Draw(x, y, SizeIconWidth, SizeIconHeight, Opacity);
  174.  
  175. double t = 0 ;
  176.  
  177. if (player.HasValidActor)
  178. {
  179. t = buff.TimeLeftSeconds[1];
  180. if (valid[player.Index] == false)
  181. {
  182. valid[player.Index] = true;
  183. tvalid[player.Index] = Hud.Game.CurrentRealTimeMilliseconds - (long) (buff.TimeElapsedSeconds[1] * 1000d);
  184. }
  185.  
  186. layout = FontStacks1.GetTextLayout(buff.IconCounts[8].ToString());
  187. FontStacks1.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/1.17f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/1.1f) );
  188.  
  189. FontDefault = FontStacksG;
  190. for(int i = 2; i < 7; i++ )
  191. {
  192. var ti = buff.TimeLeftSeconds[i];
  193. if (ti > 0)
  194. {
  195. layout = FontTimeLeft.GetTextLayout(ti.ToString( (ti < 1)? "F1" : "F0") );
  196. FontTimeLeft.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/7.0f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/1.1f) );
  197. Hud.Texture.GetTexture(Textures[i]).Draw(x + 0.08f * SizeIconWidth, y + 0.08f * SizeIconHeight, SizeIconHeight * 0.28f, SizeIconHeight * 0.28f, 1.0f);
  198. Brushes[i].DrawRectangle(x + 0.08f * SizeIconWidth, y + 0.08f * SizeIconHeight, SizeIconHeight * 0.28f, SizeIconHeight * 0.28f);
  199. FontDefault = FontStacksY;
  200. if ((buff.TimeElapsedSeconds[i] < 1) && (Hud.Game.CurrentRealTimeMilliseconds > timers[player.Index]))
  201. {
  202. tvalid[player.Index] = Hud.Game.CurrentRealTimeMilliseconds - (long) (buff.TimeElapsedSeconds[1] * 1000d);
  203. timers[player.Index] = (long) ti * 1000 + Hud.Game.CurrentRealTimeMilliseconds;
  204. if (SoundEnabledProc && Hud.Game.Me.InGreaterRiftRank > 0)
  205. {
  206. Play_Sound(FileSoundProc);
  207. }
  208. }
  209. break;
  210. }
  211. }
  212. layout = FontDefault.GetTextLayout(buff.IconCounts[9].ToString());
  213. FontDefault.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/1.17f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/12.0f) );
  214.  
  215. }
  216. else
  217. {
  218. if (valid[player.Index] == true) { valid[player.Index] = false; }
  219. if (tvalid[player.Index] == 0) continue;
  220. //t = 90 - ( ((Hud.Game.CurrentRealTimeMilliseconds - tvalid[player.Index]) / 1000d) % 90 ); // Replaced to avoid possible problem with OrderBy(p => tvalid[p.Index])
  221. if ((Hud.Game.CurrentRealTimeMilliseconds - tvalid[player.Index]) > 90000)
  222. tvalid[player.Index] = tvalid[player.Index] + 90000 * (int) ((Hud.Game.CurrentRealTimeMilliseconds - tvalid[player.Index]) /90000);
  223. t = 90 - ((Hud.Game.CurrentRealTimeMilliseconds - tvalid[player.Index]) / 1000d);
  224. }
  225.  
  226. if (t < 10)
  227. {
  228. FontDefault = FontCounter10;
  229. if (Search && player.HasValidActor) // use "if (Search)" to consider the far players for the green frame and the sound (last 10s)
  230. {
  231. Search = false;
  232. if (Hud.Game.NumberOfPlayersInGame > 1) BrushMin.DrawRectangle(x + 1,y + 1,SizeIconWidth -2,SizeIconHeight -2);
  233. if (SoundEnabledLast10 && t > 9 && TicksLast10 < Hud.Game.CurrentGameTick && Hud.Game.Me.InGreaterRiftRank > 0) // 1s=60 ticks. Highly recommended add check t>(1...9)
  234. {
  235. Play_Sound(FileSoundLast10);
  236. TicksLast10 = Hud.Game.CurrentGameTick + (int)(t * 60d); //
  237. }
  238. }
  239. }
  240. else { FontDefault = FontCounter; }
  241.  
  242. if (t < 1.0f) //layout = FontCounter.GetTextLayout(t.ToString( (t < 1)? "F1" : "F0") );
  243. {
  244. layout = FontDefault.GetTextLayout(String.Format("{0:N1}", t));
  245. }
  246. else
  247. {
  248. layout = FontDefault.GetTextLayout((t < 60)? String.Format("{0:0}", t ) : String.Format("{0:0}:{1:00}", (int) (t/60), t%60 )) ;
  249. }
  250. FontDefault.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/2.0f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/2.0f) );
  251. }
  252. }
  253. }
  254. }
  255. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement