RNNCode

PandemoniumIconBuff

Jun 17th, 2025 (edited)
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 11.78 KB | None | 0 0
  1. using System;
  2. using Turbo.Plugins.Default;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5. using System.Threading;
  6. using SharpDX.DirectInput;
  7.  
  8. namespace Turbo.Plugins.RNN
  9. {
  10.     public class PandemoniumIconBuff : BasePlugin, IInGameTopPainter, ICustomizer, INewAreaHandler, IKeyEventHandler
  11.     {
  12.         private IKeyEvent ToogleKeyEventOn { get; set; }  // Show/Hide.
  13.         private IKeyEvent ToggleKeyEventCircle { get; set; }
  14.         private MapShapeDecorator YardMapShapeDecorator;
  15.  
  16.         public bool TurnOffWhenNewGameStarts { get; set; }
  17.         private bool PI_On { get; set; } = true;
  18.  
  19.         private ITexture TextureBG { get; set; } = null;
  20.         private ITexture TextureRS { get; set; } = null;
  21.  
  22.         private IFont BuffOtherFont { get; set; }
  23.         private IFont BuffOtherFontMax { get; set; }
  24.         private IFont TimeleftFont { get; set; }
  25.         private IFont StackFont { get; set; }
  26.         private IFont StackFontOther { get; set; }
  27.         private IFont NextFont  { get; set; }
  28.         private IFont NextFontY  { get; set; }
  29.         private IFont NextFontN  { get; set; }
  30.         private IFont MyFont { get; set; } = null;
  31.         private IFont MonsterCounterFont  { get; set; }
  32.         private IFont YardFont  { get; set; }
  33.  
  34.         private int MyIndex { get; set; } = -1;
  35.         private bool Buffon { get; set; } = false;
  36.         private int NewTarget { get; set; } = 0;
  37.         private int Kills { get; set; } = 0;
  38.         private int YardsTarget { get; set; } = 0;
  39.  
  40.         private SortedDictionary<int,string> NextBuff { get; set; } = new SortedDictionary<int,string>
  41.         //private Dictionary<int,string> NextBuff { get; set; } = new Dictionary<int,string>
  42.         {
  43.              {15,"15"}, {30,"30"}{50,"50"}{100,"100"}, {150,"150"}, {200,"200"}{300,"300"},    {400,"400"},    {500,"500"},    {1000,"1000"} , {int.MaxValue,"∞"}
  44.         };
  45.  
  46.         public float Xpor  { get; set; }
  47.         public float Ypor  { get; set; }
  48.  
  49.         private float _SizeMultiplier  { get; set; }
  50.         public float SizeMultiplier
  51.         {
  52.             get { return _SizeMultiplier; }
  53.             set
  54.             {
  55.                 if (_SizeMultiplier != value)
  56.                 {
  57.                     _SizeMultiplier = value;
  58.  
  59.                     NextFont = Hud.Render.CreateFont("tahoma",  4.5f * _SizeMultiplier, 255, 225 , 170, 0, true, false, 160, 0, 0, 0, true);
  60.                     NextFontY = Hud.Render.CreateFont("tahoma", 4.5f * _SizeMultiplier, 255, 0 , 204, 102, true, false, 160, 0, 0, 0, true);
  61.                     NextFontN = Hud.Render.CreateFont("tahoma", 4.5f * _SizeMultiplier, 255, 0 , 150, 0, true, false, 160, 0, 0, 0, true);
  62.                     YardFont = Hud.Render.CreateFont("tahoma", 4.5f * _SizeMultiplier, 255, 200 , 200, 200, true, false, 160, 0, 0, 0, true);
  63.                     MonsterCounterFont = Hud.Render.CreateFont("tahoma", 4.5f * _SizeMultiplier, 255, 200 , 200, 200, true, false, 160, 0, 0, 0, true);
  64.  
  65.                     TimeleftFont = Hud.Render.CreateFont("tahoma", 6.2f * _SizeMultiplier, 255, 255, 255, 255, true, false, 255, 0, 0, 0, true);
  66.  
  67.                     StackFont = Hud.Render.CreateFont("tahoma", 8f * _SizeMultiplier, 255, 255, 220, 0, true, false, 160, 0, 0, 0, true);
  68.                     StackFontOther = Hud.Render.CreateFont("tahoma", 8f * _SizeMultiplier, 255, 255, 150, 0, true, false, 160, 0, 0, 0, true);
  69.  
  70.                     BuffOtherFont = Hud.Render.CreateFont("tahoma", 4f * _SizeMultiplier, 255, 255, 220, 0, true, false, 160, 0, 0, 0, true);
  71.                     BuffOtherFontMax = Hud.Render.CreateFont("tahoma", 4f * _SizeMultiplier, 255, 255, 150, 0, true, false, 160, 0, 0, 0, true);
  72.                 }
  73.             }
  74.         }
  75.  
  76.         public bool ShowIcon { get; set; }
  77.         public bool SoundLost { get; set; }
  78.         public bool SoundTarget { get; set; }
  79.         public string FileSoundLost { get; set; }
  80.         public string FileSoundTarget { get; set; }
  81.         public int MinKillsLost { get; set; }
  82.         public int MinTarget { get; set; }
  83.         public int YardsMinTarget { get; set; }
  84.         public int YardsMaxTarget { get; set; }
  85.         public bool ShowCircle { get; set; }
  86.         public bool ShowMonsterCounter { get; set; }
  87.         public bool ShowBuffOthers { get; set; }
  88.  
  89.         public PandemoniumIconBuff()
  90.         {
  91.             Enabled = true;
  92.         }
  93.  
  94.         public override void Load(IController hud)
  95.         {
  96.             base.Load(hud);
  97.             Order = 90002;
  98.  
  99.             Xpor = 0.44f;   // Valid values: from 0 to 1 . To set the x coordinate of the icon
  100.             Ypor = 0.45f;   // Valid values: from 0 to 1 . To set the y coordinate of the icon
  101.             SizeMultiplier = 1.2f; // Size multiplier for icons
  102.  
  103.             SoundLost = true;       //Notify with a sound when the buff is lost
  104.             SoundTarget = true; //Notify with a sound when a target (15,30,50,100,150,200,300,400,500,1000) was reached
  105.             FileSoundTarget = "PandemoniumTarget.wav";  // File to be played. It must be in the Sounds\ folder
  106.             FileSoundLost   = "PandemoniumLost.wav";    // File to be played. It must be in the Sounds\ folder
  107.             MinTarget = 100;        // The minimum target where you will begin to notify
  108.             MinKillsLost = 100;     // Minimum kills required to notify Buff was lost
  109.             ShowIcon = true;        // Show/Hide icon. Maybe someone just wants sound
  110.             YardsMinTarget = 40;    // Green text when the next target can be achieved by killing the monsters that are at this distance. Control key to switch between YardsMax and YardsMin
  111.             YardsMaxTarget = 120;   // Green text when the next target can be achieved by killing the monsters that are at this distance. Control key to switch between YardsMax and YardsMin
  112.             ShowCircle = true;      // Show circle on the Map, radio YardsMinTarget/YardsMaxTarget.  Control key to switch between YardsMin and YardsMax
  113.             ShowMonsterCounter = true;  // Show Monster Counter
  114.             ShowBuffOthers = true;      // Show the counter of kills of nearby players.
  115.             TurnOffWhenNewGameStarts = false;
  116.  
  117.             ToggleKeyEventCircle = Hud.Input.CreateKeyEvent(true, Key.LeftControl, true, false, false);
  118.             ToogleKeyEventOn     = Hud.Input.CreateKeyEvent(true, Key.F6, controlPressed: true, altPressed: false, shiftPressed: false);
  119.  
  120.             TextureBG = Hud.Texture.BuffFrameTexture;
  121.             TextureRS = Hud.Texture.GetItemTexture(Hud.Sno.SnoItems.P4_Unique_Spear_002);
  122.  
  123.             YardMapShapeDecorator = new MapShapeDecorator(Hud)
  124.             {
  125.                 Brush = Hud.Render.CreateBrush(150, 180, 147, 109, 1),
  126.                 ShapePainter = new CircleShapePainter(Hud),
  127.                 Radius = 40,
  128.             };
  129.         }
  130.  
  131.         public void Customize()
  132.         {
  133.             YardsTarget =  YardsMinTarget;
  134.             YardMapShapeDecorator.Radius = YardsTarget;
  135.             if (MinTarget < 15)  { MinTarget = 15; }
  136.         }
  137.  
  138.         public void OnKeyEvent(IKeyEvent keyEvent)
  139.         {
  140.             if (keyEvent.IsPressed)
  141.             {
  142.                 if (ToggleKeyEventCircle.Matches(keyEvent))
  143.                 {
  144.                     YardsTarget = (YardsTarget  != YardsMaxTarget) ? YardsMaxTarget : YardsMinTarget;
  145.                     YardMapShapeDecorator.Radius = YardsTarget;
  146.                 }
  147.                 else if (ToogleKeyEventOn.Matches(keyEvent))
  148.                 {
  149.                     PI_On = !PI_On;
  150.                     Buffon = false;
  151.                 }
  152.             }
  153.         }
  154.  
  155.         public void OnNewArea(bool newGame, ISnoArea area)
  156.         {
  157.             if (newGame || (MyIndex != Hud.Game.Me.Index) )
  158.             {
  159.                 MyIndex = Hud.Game.Me.Index;
  160.                 Buffon = false;
  161.                 if (TurnOffWhenNewGameStarts)   { PI_On = false; }
  162.             }
  163.         }
  164.  
  165.         public void Play_Sound(string Sonido)
  166.         {
  167.             var playSonido = Hud.Sound.LoadSoundPlayer(Sonido);
  168.             ThreadPool.QueueUserWorkItem(state =>
  169.             {
  170.                 try  { playSonido.PlaySync(); }
  171.                 catch (Exception)  {   }
  172.             }   );
  173.         }
  174.  
  175.         public void PaintTopInGame(ClipState clipState)
  176.         {
  177.             if (clipState != ClipState.BeforeClip) return;
  178.             if (!Hud.Game.IsInGame) return;
  179.             if (PI_On && Hud.Game.Me.Powers.BuffIsActive(483967))  // Jugando en temporada
  180.             {
  181.                 var players = Hud.Game.Players.Where(p => p.HasValidActor && (p.Powers.GetBuff(483967) != null) && (p.Powers.GetBuff(483967).IconCounts[1] > 0));
  182.                 if (players.Any())
  183.                 {
  184.                     var playerc = players.OrderByDescending(o => o.Powers.GetBuff(483967).IconCounts[1]).FirstOrDefault();
  185.                     int c = playerc.Powers.GetBuff(483967).IconCounts[1];
  186.                     int cme = Hud.Game.Me.Powers.GetBuff(483967).IconCounts[1];
  187.                     if (!Buffon) { Buffon = true; NewTarget = 0; }
  188.                     foreach(var d in NextBuff)
  189.                     {
  190.                         if (d.Key > c)
  191.                         {
  192.                             if (d.Key != NewTarget)
  193.                             {
  194.                                 if (SoundTarget)
  195.                                 {
  196.                                     if (c >= MinTarget)
  197.                                     {
  198.                                         if ( (NewTarget > 0) && (d.Key > NewTarget) && (cme == c) )
  199.                                                 Play_Sound(FileSoundTarget);
  200.                                     }
  201.                                 }
  202.                                 NewTarget = d.Key;
  203.                             }
  204.                             break;
  205.                         }
  206.                     }
  207.                     if (Kills != c) { Kills = c; }
  208.                     if (ShowIcon)
  209.                     {
  210.                         var x = Hud.Window.Size.Width * Xpor;   var y = Hud.Window.Size.Height * Ypor;
  211.                         var SizeIconWidth = TextureBG.Width  * 0.61f * SizeMultiplier;  var SizeIconHeight = TextureBG.Height * 0.68f * SizeMultiplier;
  212.                         Hud.Texture.Button2TextureOrange.Draw(x, y, SizeIconWidth, SizeIconHeight, 0.7f);
  213.                         Hud.Texture.BackgroundTextureYellow.Draw(x, y, SizeIconWidth, SizeIconHeight, 1f);
  214.                         TextureRS.Draw(x, y, SizeIconWidth, SizeIconHeight, 1f);
  215.                         if (cme == 0) { Hud.Texture.DebuffFrameTexture.Draw(x, y, SizeIconWidth, SizeIconHeight, 1f); }
  216.                         else { TextureBG.Draw(x, y, SizeIconWidth, SizeIconHeight, 1f); }
  217.  
  218.                         double t = playerc.Powers.GetBuff(483967).TimeLeftSeconds[1];
  219.                         var layout = TimeleftFont.GetTextLayout(t.ToString( (t < 1)? "F1" : "F0") );
  220.                         TimeleftFont.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/2.0f), y + ((SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height))/2.58f));
  221.                         MyFont = (c > cme)? StackFontOther : StackFont ;
  222.                         layout = MyFont.GetTextLayout(c.ToString());
  223.                         MyFont.DrawText(layout, x + (SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width)) - SizeIconWidth/15, y + (SizeIconHeight - (float)Math.Ceiling(layout.Metrics.Height)) - SizeIconHeight/30 );
  224.                         var monsters = Hud.Game.AliveMonsters.Where(m => m.FloorCoordinate.XYDistanceTo(Hud.Game.Me.FloorCoordinate) <= YardsTarget);
  225.                         var mc = monsters.Count();
  226.                         if (NewTarget != 0)
  227.                         {
  228.                             MyFont = ((c + mc) < NewTarget)? NextFont : (((c + monsters.Where(m => m.Rarity == ActorRarity.Normal).Count()) < NewTarget)? NextFontN : NextFontY) ;
  229.                             MyFont.DrawText(NextFont.GetTextLayout(NextBuff[NewTarget]), x + SizeIconWidth/12, y + SizeIconHeight/18 );
  230.                         }
  231.  
  232.                         if (ShowMonsterCounter)
  233.                         {
  234.                             layout = MonsterCounterFont.GetTextLayout(mc.ToString());
  235.                             MonsterCounterFont.DrawText(layout, x + SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width) - SizeIconWidth/12, y + SizeIconHeight/18);
  236.                         }
  237.                         else
  238.                         {
  239.                             layout = YardFont.GetTextLayout((YardsTarget == YardsMaxTarget)? "+":"-");
  240.                             YardFont.DrawText(layout, x + SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width) - SizeIconWidth/12, y + SizeIconHeight/18);
  241.                         }
  242.                         if (ShowBuffOthers && Hud.Game.NumberOfPlayersInGame > 1)
  243.                         {
  244.                             if (Hud.Game.IsInTown) return;
  245.                             x += SizeIconWidth + 1;
  246.                             Hud.Texture.Button2TextureOrange.Draw(x, y, SizeIconWidth, SizeIconHeight, 0.4f);
  247.                             Hud.Texture.BackgroundTextureYellow.Draw(x, y, SizeIconWidth, SizeIconHeight, 0.5f);
  248.                             foreach (var pl in Hud.Game.Players)
  249.                             {
  250.                                 MyFont = (!pl.IsMe && pl.Powers.GetBuff(483967)?.IconCounts[1] > cme)? BuffOtherFontMax : BuffOtherFont ;
  251.                                 layout = MyFont.GetTextLayout(!pl.HasValidActor ? "?" : (pl.Powers.GetBuff(483967) == null)? "-": pl.Powers.GetBuff(483967).IconCounts[1].ToString());
  252.                                 MyFont.DrawText(layout, x + ((SizeIconWidth - (float)Math.Ceiling(layout.Metrics.Width))/2.0f), y + (int)(SizeIconHeight/10) + (layout.Metrics.Height * 0.93f * pl.PortraitIndex));
  253.                             }
  254.                             Hud.Texture.DebuffFrameTexture.Draw(x, y, SizeIconWidth, SizeIconHeight, 0.5f);
  255.                         }
  256.                     }
  257.                     if (ShowCircle) { YardMapShapeDecorator.Paint(null, Hud.Game.Me.FloorCoordinate, null); }
  258.                 }
  259.                 else
  260.                 {
  261.                     if (Buffon)
  262.                     {
  263.                         Buffon = false;
  264.                         if (SoundLost)
  265.                         {
  266.                             if ((Kills >= MinKillsLost) && !Hud.Game.IsInTown)
  267.                             {
  268.                                 Play_Sound(FileSoundLost);
  269.                             }
  270.                         }
  271.                     }
  272.                 }
  273.             }
  274.         }
  275.     }
  276. }
Advertisement
Add Comment
Please, Sign In to add comment