RNNCode

Chilanik

Dec 30th, 2019 (edited)
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.56 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 Chilanik : 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.  
  15.         private SharpDX.DirectWrite.TextLayout layout { get; set; }
  16.  
  17.         private ITexture BGTexture { get; set; } = null;
  18.         private ITexture FGTexture { get; set; } = null;
  19.  
  20.         private IFont WhiteFont { get; set; }
  21.         private IFont CooldownFont { get; set; }
  22.         private IFont StacksFont { get; set; }
  23.  
  24.         private float x  { get; set; } = 0f;
  25.         private float y  { get; set; } = 0f;
  26.  
  27.         private float SizeIconWidth  { get; set; }
  28.         private float SizeIconHeight  { get; set; }
  29.  
  30.         public uint powersno { get; set; } = 0;
  31.         public int powerindex { get; set; } = 0;
  32.         public uint textureid { get; set; } = 0;        // Texture id for skills
  33.  
  34.         public ISnoItem snoItem { get; set; } = null;   // ISnoItem for Item Texture. Read interfaces\controllers\sno\ISnoItemList.cs
  35.         public uint powersno4cd { get; set; } = 0;      // powersno alternative for cooldown (from skill)
  36.  
  37.         public uint DurationBuffLost { get; set; } = 10;
  38.  
  39.         public bool ShowStacks { get; set; }
  40.         public bool ShowIcon { get; set; }
  41.         public bool SoundEnabled { get; set; }
  42.         public string FileSound { get; set; }
  43.         public bool BeepOption { get; set; }
  44.         public int BeepFrecuency { get; set; }
  45.         public int BeepDuration { get; set; }
  46.         public float EarlyAlert { get; set; }
  47.  
  48.         public float Xpor  { get; set; }
  49.         public float Ypor  { get; set; }
  50.         public float IconSize  { get; set; } = 28f;
  51.  
  52.         public float SizeMultiplier  { get; set; } = 1.0f;
  53.  
  54.         public  Chilanik()
  55.         {
  56.             Enabled = true;
  57.         }
  58.  
  59.         public override void Load(IController hud)
  60.         {
  61.             base.Load(hud);
  62.             Order = 30001;
  63.  
  64.             ShowIcon = true;
  65.             ShowStacks = false;
  66.             SoundEnabled = true;
  67.             FileSound = "notification_8.wav";  // File to be played. It must be in the Sounds\ folder
  68.             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
  69.             BeepOption = true;
  70.             BeepFrecuency = 1000;
  71.             BeepDuration = 50;
  72.  
  73.             Xpor = 0.557f;   // Valid values: from 0 to 1 . To set the x coordinate of the icon  // 0.461f mirror // 0.541f just beside
  74.             Ypor = 0.452f;  // Valid values: from 0 to 1 . To set the y coordinate of the icon
  75.             SizeMultiplier = 0.50f;
  76.  
  77.             powersno = 318821;
  78.             powerindex = 1;
  79.             textureid = 0;
  80.             snoItem = Hud.Sno.SnoItems.Unique_BarbBelt_101_x1;  // if it has a value other than null, textureid will be ignored, and the texture of this item will be drawn. // Chilanik
  81.             powersno4cd = 375483;   // powersno alternative for cooldown (from skill). If == 0, it will take the same value as powersno. // Warcry, for Chilanik
  82.         }
  83.  
  84.         public void Customize()
  85.         {
  86.             if ((EarlyAlert < 0) || (EarlyAlert > 4))   { EarlyAlert = 0; }
  87.             EarlyAlert = EarlyAlert + 0.2f; // para compensar el retraso en la reproduccion.
  88.  
  89.             WhiteFont = Hud.Render.CreateFont("tahoma", 17f * SizeMultiplier, 255, 255, 255, 255, true, false, 255, 0, 0, 0, true);
  90.             CooldownFont = Hud.Render.CreateFont("tahoma", 10f * SizeMultiplier, 220, 255, 255, 0, true, false, 255, 0, 0, 0, true);
  91.             StacksFont = Hud.Render.CreateFont("tahoma", 9f * SizeMultiplier, 220, 255, 255, 255, true, false, 255, 0, 0, 0, true);
  92.  
  93.             if (snoItem != null)
  94.             {
  95.                 BGTexture = Hud.Texture.InventoryLegendaryBackgroundSmall;
  96.                 FGTexture = Hud.Texture.GetItemTexture(snoItem);
  97.             }
  98.             else
  99.             {
  100.                 FGTexture = (textureid > 0)? Hud.Texture.GetTexture(textureid): Hud.Texture.InventoryLegendaryBackgroundSmall ;
  101.             }
  102.             if (powersno4cd == 0) { powersno4cd = powersno; }
  103.         }
  104.  
  105.         public void OnNewArea(bool newGame, ISnoArea area)
  106.         {
  107.             if ((newGame) || (Indice != Hud.Game.Me.Index))
  108.             {
  109.                 Indice = Hud.Game.Me.Index;
  110.                 Alerted = true;
  111.                 FinishTick = Hud.Game.CurrentGameTick - (int) DurationBuffLost * 65;
  112.             }
  113.         }
  114.  
  115.         public void Play_Sound(string Sonido)
  116.         {
  117.             var playSonido = Hud.Sound.LoadSoundPlayer(Sonido);
  118.             ThreadPool.QueueUserWorkItem(state =>
  119.             {
  120.                 try  { playSonido.PlaySync(); }
  121.                 catch (Exception)  {   }
  122.             }   );
  123.         }
  124.  
  125.         public void AfterCollect()
  126.         {
  127.             if (!Hud.Game.IsInGame) return;
  128.             if (Hud.Game.Me.Powers.GetBuff(powersno) == null) return;
  129.             double left = Hud.Game.Me.Powers.GetBuff(powersno).TimeLeftSeconds[powerindex];
  130.             if (left == 0)
  131.             {
  132.                 if (Hud.Game.Me.Powers.GetBuff(powersno).IconCounts[powerindex] > 0)    { return; }
  133.             }
  134.             else
  135.             {
  136.                 FinishTick = (int) (Hud.Game.CurrentGameTick + (left * 60));
  137.             }
  138.             if (SoundEnabled)
  139.             {
  140.                 if (left <= EarlyAlert)
  141.                 {
  142.                     if (!Alerted)
  143.                     {
  144.                         Alerted = true;
  145.                         if (!Hud.Game.IsInTown && !Hud.Game.Me.Powers.BuffIsActive(224639))
  146.                         {
  147.                             if (BeepOption) Console.Beep(BeepFrecuency, BeepDuration);
  148.                             else Play_Sound(FileSound);
  149.                         }
  150.                     }
  151.                 }
  152.                 else
  153.                 {
  154.                     if (Alerted)  { Alerted = false; }
  155.                 }
  156.             }
  157.         }
  158.  
  159.         public void PaintTopInGame(ClipState clipState)
  160.         {
  161.             if (clipState != ClipState.BeforeClip) return;
  162.             if (!Hud.Game.IsInGame || Hud.Game.IsInTown) return;
  163.             if (ShowIcon)
  164.             {
  165.                 if (Hud.Game.Me.Powers.GetBuff(powersno) == null) return;
  166.                 if (Hud.Game.Me.Powers.BuffIsActive(224639)) return;
  167.                 double left = Hud.Game.Me.Powers.GetBuff(powersno).TimeLeftSeconds[powerindex];
  168.  
  169.                 x = Hud.Window.Size.Width * Xpor;   y = Hud.Window.Size.Height * Ypor;
  170.                 SizeIconWidth = Hud.Texture.InventoryLegendaryBackgroundSmall.Width * SizeMultiplier;   SizeIconHeight = Hud.Texture.InventoryLegendaryBackgroundSmall.Height * SizeMultiplier;
  171.                 if (left == 0)
  172.                 {
  173.                     double elapsed = (Hud.Game.CurrentGameTick - FinishTick) / 60;
  174.                     if (elapsed > DurationBuffLost) return;
  175.                     if (BGTexture != null) BGTexture.Draw(x, y, SizeIconWidth, SizeIconHeight, 1f);
  176.                     if (FGTexture != null) FGTexture.Draw(x, y, SizeIconWidth, SizeIconHeight, 1f);
  177.                     Hud.Texture.DebuffFrameTexture.Draw(x, y, SizeIconWidth, SizeIconHeight, 0.8f);
  178.                     layout = WhiteFont.GetTextLayout( ((elapsed < 1)? "":"-") + elapsed.ToString("F0") );
  179.                 }
  180.                 else
  181.                 {
  182.                     if (BGTexture != null) BGTexture.Draw(x, y, SizeIconWidth, SizeIconHeight, 1f);
  183.                     if (FGTexture != null) FGTexture.Draw(x, y, SizeIconWidth, SizeIconHeight, 1f);
  184.                     Hud.Texture.BuffFrameTexture.Draw(x, y, SizeIconWidth, SizeIconHeight, 1f);
  185.                     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
  186.                 }
  187.                 WhiteFont.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/2.0f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/1.75f));
  188.                 if (ShowStacks)
  189.                 {
  190.                     layout = StacksFont.GetTextLayout(Hud.Game.Me.Powers.GetBuff(powersno).IconCounts[powerindex].ToString());
  191.                     StacksFont.DrawText(layout, x + (SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width)) - 2, y + 1);
  192.                 }
  193.                 var skill = Hud.Game.Me.Powers.UsedSkills.FirstOrDefault(s => s.SnoPower.Sno == powersno4cd);
  194.                 if (skill != null)
  195.                 {
  196.                     if (skill.IsOnCooldown)
  197.                     {
  198.                         var c = (skill.CooldownFinishTick - Hud.Game.CurrentGameTick) / 60f;
  199.                         CooldownFont.DrawText(CooldownFont.GetTextLayout(c.ToString( (c < 1)? "F1" : "F0")), x + 2, y + 1 );
  200.                     }
  201.                     else
  202.                     {
  203.                         CooldownFont.DrawText(CooldownFont.GetTextLayout("🞴"), x + 2, y );
  204.                     }
  205.                 }
  206.             }
  207.         }
  208.     }
  209. }
Advertisement
Add Comment
Please, Sign In to add comment