Advertisement
Guest User

10 sec alarm RNN Season Theme

a guest
Jul 22nd, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.99 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. private long asd;
  32.  
  33. private IFont FontTimeLeft { get; set; }
  34. private IBrush BrushBorder { get; set; }
  35. private IBrush BrushMin { get; set; }
  36.  
  37. public bool PortraitMe { get; set; }
  38. public bool PortraitOthers { get; set; }
  39. public float OffsetX { get; set; }
  40. public float OffsetY { get; set; }
  41. public float OffsetXPortrait { get; set; }
  42. public float OffsetYPortrait { get; set; }
  43.  
  44. public float Opacity { get; set; }
  45. public float SizeMultiplier { get; set; }
  46.  
  47. public bool OnlyGR { get; set; }
  48. public bool OnlyMe { get; set; }
  49. public bool VisibleFar { get; set; }
  50.  
  51. public bool SoundEnabled { get; set; }
  52. public string FileSound { get; set; }
  53.  
  54. public TrialsOfTempestsIcon()
  55. {
  56. Enabled = true;
  57. }
  58.  
  59. public override void Load(IController hud)
  60. {
  61. base.Load(hud);
  62. Order = 30001;
  63.  
  64. OnlyGR = false;
  65. OnlyMe = false;
  66. 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
  67.  
  68. PortraitMe = true; // Show icon near portrait or next to our character (for Me)
  69. PortraitOthers = true; // Show icon near portrait or next to our character (for Others Players)
  70. OffsetX = +0.020f; // To modify the position of the icon. Reference point: character
  71. OffsetY = -0.020f;
  72. OffsetXPortrait = -0.009f; // To modify the position of the icon. Reference point: portrait
  73. OffsetYPortrait = +0.042f;
  74.  
  75. Opacity = 0.85f;
  76. SizeMultiplier = 0.75f;
  77.  
  78. SoundEnabled = false;
  79. FileSound = "notification_5.wav"; // File to be played. It must be in the Sounds\ folder
  80.  
  81. TextureBG = Hud.Texture.GetTexture(3144819863);
  82.  
  83. var tr = 1.0f;
  84. BrushBorder = Hud.Render.CreateBrush( 255, 255, 255, 255, tr);
  85. Brushes = new IBrush[7] // 0,1, 2-Fuego, 3-Frío, 4-Veneno, 5-Físico, 6-Rayos
  86. {
  87. BrushBorder,
  88. BrushBorder,
  89. Hud.Render.CreateBrush( 255, 255, 0, 0, tr),
  90. BrushBorder,
  91. Hud.Render.CreateBrush( 255, 0, 255, 0, tr),
  92. Hud.Render.CreateBrush( 255, 80, 80, 80, tr),
  93. Hud.Render.CreateBrush( 255, 0, 128, 255, tr),
  94. };
  95. BrushMin = Hud.Render.CreateBrush( 255, 0, 255, 0, 2);
  96. }
  97.  
  98. public void Customize()
  99. {
  100. FontStacks1 = Hud.Render.CreateFont("tahoma", 8f * SizeMultiplier, 255, 255, 255, 255, false, false, 255, 0, 0, 0, true);
  101. FontStacksY = Hud.Render.CreateFont("tahoma", 8f * SizeMultiplier, 255, 255, 255, 0, false, false, 255, 0, 0, 0, true);
  102. FontStacksG = Hud.Render.CreateFont("tahoma", 8f * SizeMultiplier, 255, 195, 195, 195, false, false, 255, 0, 0, 0, true);
  103. FontCounter = Hud.Render.CreateFont("tahoma", 9f * SizeMultiplier, 255, 255, 255, 255, false, false, 255, 0, 0, 0, true);
  104. FontCounter10 = Hud.Render.CreateFont("tahoma", 9f * SizeMultiplier, 255, 0, 255, 0, false, false, 255, 0, 0, 0, true);
  105. FontTimeLeft = Hud.Render.CreateFont("tahoma", 8f * SizeMultiplier, 255, 0, 255, 0, false, false, 255, 0, 0, 0, true);
  106.  
  107. SizeIconWidth = TextureBG.Width * Hud.Window.Size.Height/1200.0f * SizeMultiplier * 0.90f;
  108. SizeIconHeight = TextureBG.Height * Hud.Window.Size.Height/1200.0f * SizeMultiplier;
  109. }
  110.  
  111. public void OnNewArea(bool newGame, ISnoArea area)
  112. {
  113. if (newGame || (MyIndex != Hud.Game.Me.Index) )
  114. {
  115. MyIndex = Hud.Game.Me.Index;
  116. TotalPlayers = Hud.Game.NumberOfPlayersInGame;
  117. for (var i = 0; i < 4; i++) { valid[i] = false; tvalid[i] = 0; }
  118. }
  119. }
  120.  
  121. public void Play_Sound(string Sonido)
  122. {
  123. var playSonido = Hud.Sound.LoadSoundPlayer(Sonido);
  124. ThreadPool.QueueUserWorkItem(state =>
  125. {
  126. try { playSonido.PlaySync(); }
  127. catch (Exception) { }
  128. } );
  129. }
  130.  
  131. public void AfterCollect()
  132. {
  133. if (!Hud.Game.IsInGame) return;
  134. if (TotalPlayers != Hud.Game.NumberOfPlayersInGame)
  135. {
  136. TotalPlayers = Hud.Game.NumberOfPlayersInGame;
  137. for (var i = 0; i < 4; i++) { valid[i] = false; tvalid[i] = 0; }
  138. }
  139. }
  140.  
  141. public void PaintTopInGame(ClipState clipState)
  142. {
  143. if (clipState != ClipState.BeforeClip) return;
  144. if (!Hud.Game.IsInGame) return;
  145. if (OnlyGR && !Hud.Game.Me.InGreaterRift) return;
  146. if (Hud.Game.Me.Powers.BuffIsActive(484426)) // Jugando en temporada
  147. {
  148. var players = Hud.Game.Players.Where(p => (p.Powers.GetBuff(484426) != null) && (p.IsMe || (!OnlyMe && (p.HasValidActor || VisibleFar))) )
  149. .OrderBy(p => p.Powers.GetBuff(484426).TimeLeftSeconds[1]);
  150. bool Search = true;
  151. foreach(var player in players)
  152. {
  153. var buff = player.Powers.GetBuff(484426);
  154. float x, y;
  155. if ( player.IsMe?PortraitMe:PortraitOthers )
  156. {
  157. x = player.PortraitUiElement.Rectangle.X + Hud.Window.Size.Width * OffsetXPortrait;
  158. y = player.PortraitUiElement.Rectangle.Y + Hud.Window.Size.Height * OffsetYPortrait;
  159. }
  160. else
  161. {
  162. x = player.FloorCoordinate.ToScreenCoordinate().X + Hud.Window.Size.Width * OffsetX;
  163. y = player.FloorCoordinate.ToScreenCoordinate().Y + Hud.Window.Size.Height * OffsetY;
  164. }
  165.  
  166. TextureBG.Draw(x, y, SizeIconWidth, SizeIconHeight, Opacity);
  167. (player.HasValidActor?Hud.Texture.BuffFrameTexture:Hud.Texture.DebuffFrameTexture).Draw(x, y, SizeIconWidth, SizeIconHeight, Opacity);
  168.  
  169. double t = 0 ;
  170.  
  171. if (player.HasValidActor)
  172. {
  173. t = buff.TimeLeftSeconds[1]; //layout = FontCounter.GetTextLayout(t.ToString( (t < 1)? "F1" : "F0") );
  174. if (Search && (t < 10))
  175. {
  176. Search = false;
  177. if (Hud.Game.NumberOfPlayersInGame > 1) BrushMin.DrawRectangle(x + 1,y + 1,SizeIconWidth -2,SizeIconHeight -2);
  178. }
  179. if (valid[player.Index] == false)
  180. {
  181. valid[player.Index] = true;
  182. tvalid[player.Index] = Hud.Game.CurrentRealTimeMilliseconds - (long) (buff.TimeElapsedSeconds[1] * 1000d);
  183. }
  184.  
  185. layout = FontStacks1.GetTextLayout(buff.IconCounts[8].ToString());
  186. FontStacks1.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/1.17f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/1.1f) );
  187.  
  188. FontDefault = FontStacksG;
  189. for(int i = 2; i < 7; i++ )
  190. {
  191. var ti = buff.TimeLeftSeconds[i];
  192. if (ti > 0)
  193. {
  194. layout = FontTimeLeft.GetTextLayout(ti.ToString( (ti < 1)? "F1" : "F0") );
  195. FontTimeLeft.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/7.0f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/1.1f) );
  196. Hud.Texture.GetTexture(Textures[i]).Draw(x + 0.08f * SizeIconWidth, y + 0.08f * SizeIconHeight, SizeIconHeight * 0.28f, SizeIconHeight * 0.28f, 1.0f);
  197. Brushes[i].DrawRectangle(x + 0.08f * SizeIconWidth, y + 0.08f * SizeIconHeight, SizeIconHeight * 0.28f, SizeIconHeight * 0.28f);
  198. FontDefault = FontStacksY;
  199. if (buff.TimeElapsedSeconds[i] < 1)
  200. {
  201. tvalid[player.Index] = Hud.Game.CurrentRealTimeMilliseconds - (long) (buff.TimeElapsedSeconds[1] * 1000d);
  202. if (SoundEnabled && (Hud.Game.CurrentRealTimeMilliseconds > timers[player.Index])) // if ((Hud.Game.CurrentRealTimeMilliseconds - timers[player.Index]) > 2000)
  203. {
  204. timers[player.Index] = (long) ti * 1000 + Hud.Game.CurrentRealTimeMilliseconds; // timers[player.Index] = Hud.Game.CurrentRealTimeMilliseconds;
  205. Play_Sound(FileSound);
  206. }
  207. }
  208. break;
  209. }
  210. }
  211. layout = FontDefault.GetTextLayout(buff.IconCounts[9].ToString());
  212. FontDefault.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/1.17f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/12.0f) );
  213.  
  214. }
  215. else
  216. {
  217. if (valid[player.Index] == true) { valid[player.Index] = false; }
  218. if (tvalid[player.Index] == 0) continue;
  219. t = 90 - ( ((Hud.Game.CurrentRealTimeMilliseconds - tvalid[player.Index]) / 1000d) % 90 );
  220. }
  221.  
  222. FontDefault = (t < 10)? FontCounter10:FontCounter;
  223. if(SoundEnabled && t < 10 && asd + 5000 < Hud.Game.CurrentRealTimeMilliseconds){
  224. Play_Sound(FileSound);
  225. asd = Hud.Game.CurrentRealTimeMilliseconds;
  226. }
  227. if (t < 1.0f)
  228. {
  229. layout = FontDefault.GetTextLayout(String.Format("{0:N1}", t));
  230. }
  231. else
  232. {
  233. layout = FontDefault.GetTextLayout((t < 60)? String.Format("{0:0}", t ) : String.Format("{0:0}:{1:00}", (int) (t/60), t%60 )) ;
  234.  
  235. }
  236. FontDefault.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/2.0f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/2.0f) );
  237. }
  238. }
  239. }
  240. }
  241. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement