RNNCode

BandOfMight

Dec 23rd, 2019 (edited)
1,145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.47 KB | None | 0 0
  1. using System;
  2. using Turbo.Plugins.Default;
  3. using System.Linq;
  4. using System.Threading;
  5.  
  6. namespace Turbo.Plugins.RNN
  7. {
  8.     public class BandOfMight : BasePlugin, INewAreaHandler, IInGameTopPainter, ICustomizer, IAfterCollectHandler
  9.     {
  10.         private int Indice { get; set; } = -1;
  11.  
  12.         private bool Alerted { get; set; }
  13.         private int FinishTick  { get; set; } = 0;
  14.         private int AlertedTick  { get; set; } = 0;
  15.  
  16.         private ITexture BMTexture { get; set; } = null;
  17.         private IFont WhiteFont { get; set; }
  18.  
  19.         private float x  { get; set; } = 0f;
  20.         private float y  { get; set; } = 0f;
  21.  
  22.         private float SizeIconWidth  { get; set; }
  23.         private float SizeIconHeight  { get; set; }
  24.  
  25.         private uint powersno { get; set; } = 447060;
  26.         private int powerindex { get; set; } = 1;
  27.         private uint textureid { get; set; } = 3995670063;
  28.  
  29.         public uint DurationBuffLost { get; set; } = 5;
  30.  
  31.         public bool ShowIcon { get; set; }
  32.         public bool SoundEnabled { get; set; }
  33.         public string FileSound { get; set; }
  34.         public bool BeepOption { get; set; }
  35.         public int BeepFrecuency { get; set; }
  36.         public int BeepDuration { get; set; }
  37.         public float EarlyAlert { get; set; }
  38.  
  39.         public float Xpor  { get; set; }
  40.         public float Ypor  { get; set; }
  41.         public float IconSize  { get; set; } = 28f;
  42.  
  43.         public float SizeMultiplier  { get; set; } = 1.0f;
  44.  
  45.         public  BandOfMight()
  46.         {
  47.             Enabled = true;
  48.         }
  49.  
  50.         public override void Load(IController hud)
  51.         {
  52.             base.Load(hud);
  53.             Order = 30001;
  54.  
  55.             ShowIcon = true;
  56.             SoundEnabled = true;
  57.             FileSound = "notification_8.wav";  // File to be played. It must be in the Sounds\ folder
  58.             EarlyAlert = 1f;    // You can choose to be notified in advance. Valid values: from 0 to 4. If it is zero it will notify us just when the bonus ends
  59.             BeepOption = false;
  60.             BeepFrecuency = 1000;
  61.             BeepDuration = 50;
  62.  
  63.             Xpor = 0.525f;   // Valid values: from 0 to 1 . To set the x coordinate of the icon
  64.             Ypor = 0.452f;  // Valid values: from 0 to 1 . To set the y coordinate of the icon
  65.             SizeMultiplier = 0.45f;
  66.  
  67.             BMTexture = Hud.Texture.GetTexture(textureid);
  68.         }
  69.  
  70.         public void Customize()
  71.         {
  72.             if ((EarlyAlert < 0) || (EarlyAlert > 4))   { EarlyAlert = 0; }
  73.             EarlyAlert = EarlyAlert + 0.2f; // para compensar el retraso en la reproduccion.
  74.  
  75.             WhiteFont = Hud.Render.CreateFont("tahoma", 18f * SizeMultiplier, 255, 255, 255, 255, true, false, 255, 0, 0, 0, true);
  76.         }
  77.  
  78.         public void OnNewArea(bool newGame, ISnoArea area)
  79.         {
  80.             if ((newGame) || (Indice != Hud.Game.Me.Index))
  81.             {
  82.                 Indice = Hud.Game.Me.Index;
  83.                 Alerted = true;
  84.                 FinishTick = Hud.Game.CurrentGameTick - (int) DurationBuffLost * 65;
  85.                 AlertedTick = 0;
  86.             }
  87.         }
  88.  
  89.         public void Play_Sound(string Sonido)
  90.         {
  91.             var playSonido = Hud.Sound.LoadSoundPlayer(Sonido);
  92.             ThreadPool.QueueUserWorkItem(state =>
  93.             {
  94.                 try  { playSonido.PlaySync(); }
  95.                 catch (Exception)  {   }
  96.             }   );
  97.         }
  98.  
  99.         public void AfterCollect()
  100.         {
  101.             if (!Hud.Game.IsInGame) return;
  102.             if (Hud.Game.Me.Powers.BuffIsActive(powersno))
  103.             {
  104.                 double left = Hud.Game.Me.Powers.GetBuff(powersno).TimeLeftSeconds[powerindex];
  105.                 if (left == 0)
  106.                 {
  107.                     if (Hud.Game.Me.Powers.GetBuff(powersno).IconCounts[powerindex] >  0)   { return; }
  108.                 }
  109.                 else
  110.                 {
  111.                     FinishTick = (int) (Hud.Game.CurrentGameTick + (left * 60));
  112.                 }
  113.                 if (SoundEnabled)
  114.                 {
  115.                     if (left <= EarlyAlert)
  116.                     {
  117.                         if (!Alerted)
  118.                         {
  119.                             Alerted = true; AlertedTick = Hud.Game.CurrentGameTick;
  120.                             if (!Hud.Game.IsInTown && !Hud.Game.Me.Powers.BuffIsActive(224639))
  121.                             {
  122.                                 if (BeepOption) Console.Beep(BeepFrecuency, BeepDuration);
  123.                                 else Play_Sound(FileSound);
  124.                             }
  125.                         }
  126.                     }
  127.                     else
  128.                     {
  129.                         if (Alerted && ((Hud.Game.CurrentGameTick - AlertedTick) > 120) )  { Alerted = false; }
  130.                     }
  131.                 }
  132.             }
  133.         }
  134.  
  135.         public void PaintTopInGame(ClipState clipState)
  136.         {
  137.             if (clipState != ClipState.BeforeClip) return;
  138.             if (!Hud.Game.IsInGame || Hud.Game.IsInTown) return;
  139.             if (Hud.Game.Me.Powers.BuffIsActive(powersno) && ShowIcon)
  140.             {
  141.                 if (Hud.Game.Me.Powers.BuffIsActive(224639)) return;
  142.                 double left = Hud.Game.Me.Powers.GetBuff(powersno).TimeLeftSeconds[powerindex];
  143.                 x = Hud.Window.Size.Width * Xpor; y = Hud.Window.Size.Height * Ypor;
  144.                 SizeIconWidth = BMTexture.Width * SizeMultiplier;   SizeIconHeight = BMTexture.Height * SizeMultiplier;
  145.                 if (left == 0)
  146.                 {
  147.                     double elapsed = (Hud.Game.CurrentGameTick - FinishTick) / 60;
  148.                     if (elapsed > DurationBuffLost) return;
  149.                     BMTexture.Draw(x, y, SizeIconWidth, SizeIconHeight, 1f);
  150.                     Hud.Texture.DebuffFrameTexture.Draw(x, y, SizeIconWidth, SizeIconHeight, 0.8f);
  151.                     var layout = WhiteFont.GetTextLayout( ((elapsed < 1)? "":"-") + elapsed.ToString("F0") );
  152.                     WhiteFont.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/2.0f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/2.0f));
  153.                 }
  154.                 else
  155.                 {
  156.                     BMTexture.Draw(x, y, SizeIconWidth, SizeIconHeight, 1f);
  157.                     Hud.Texture.BuffFrameTexture.Draw(x, y, SizeIconWidth, SizeIconHeight, 1f);
  158.                     var layout = WhiteFont.GetTextLayout( ( left < 1)? String.Format("{0:N1}",left) : String.Format("{0:0}",(int) (left + 0.80)) ); // Redondeará a X si es menor  a X.20
  159.                     WhiteFont.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/2.0f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/2.0f));
  160.                 }
  161.             }
  162.         }
  163.     }
  164. }
Advertisement
Add Comment
Please, Sign In to add comment