RNNCode

PandemoniumIconBuff

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