RNNCode

GRPylonMarker

May 8th, 2025 (edited)
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 11.30 KB | None | 0 0
  1. // Based on GLQ_GreaterRiftPylonMarkerPlugin.cs  ( https://pastebin.com/iQeBWcTs )
  2. using Turbo.Plugins.Default;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System;
  6.  
  7. namespace Turbo.Plugins.RNN
  8. {
  9.     public class GRPylonMarker : BasePlugin, IInGameTopPainter, INewAreaHandler, IAfterCollectHandler, ICustomizer 
  10.     {
  11.         public Dictionary<ActorSnoEnum, PylonData> PylonsFound { get; set; } = new Dictionary<ActorSnoEnum, PylonData>();
  12.         public Dictionary<uint, Tuple<string,ActorSnoEnum,ITexture>> BuffNA { get; set; }
  13.         public Dictionary<uint, string> Lnn { get; set; }
  14.         public int MyIndex { get; set; } = -1;
  15.         public IFont FontUsed { get; set; }
  16.         public IFont FontLevel { get; set; }
  17.         public IFont LeftFont { get; set; }
  18.         public IFont LeftFontOther { get; set; }
  19.         public IFont FontOther { get; set; }
  20.         public IBrush BrushLine { get; set; }
  21.         public bool InRift { get; set; }
  22.         public bool MapGR { get; set; }
  23.         public bool Horizontal { get; set;}
  24.         public float sizeFont { get; set; }
  25.         public float widthLine { get; set; }
  26.         public IBrush BorderBrush { get; set; }
  27.         public IBrush BorderGreenBrush { get; set; }
  28.         public bool ShowIcon { get; set; }
  29.         public float SPname { get; set; } = 0f;
  30.         public float LineSpacing { get; set; }
  31.         public bool PreSetSPname { get; set; }     
  32.        
  33.         public GRPylonMarker()
  34.         {
  35.             Enabled = true;
  36.         }      
  37.         public override void Load(IController hud)
  38.         {
  39.             base.Load(hud);
  40.             Order = 30001;
  41.            
  42.             Horizontal = true;
  43.             ShowIcon = true;
  44.             sizeFont = 8f;
  45.             widthLine = 2f;
  46.             LineSpacing = 1f;
  47.            
  48.             PreSetSPname = false;
  49.            
  50.             BorderBrush = Hud.Render.CreateBrush(250, 250, 100, 0, 1);
  51.             BorderGreenBrush = Hud.Render.CreateBrush(250, 0, 220, 0, -1);
  52.             BuffNA = new Dictionary<uint, Tuple<string,ActorSnoEnum,ITexture>>   // < buffsno, <nombre,actosno,ITexture> >
  53.             {
  54.                 { 262935,   new Tuple<string,ActorSnoEnum,ITexture>( "Power",   ActorSnoEnum._x1_lr_shrine_damage, Hud.Texture.GetTexture(2350065673) )                 },
  55.                 { 403404,   new Tuple<string,ActorSnoEnum,ITexture>( "Conduit", ActorSnoEnum._x1_lr_shrine_electrified, Hud.Texture.GetTexture(1751750314) )    },
  56.                 { 266258,   new Tuple<string,ActorSnoEnum,ITexture>( "Chann",   ActorSnoEnum._x1_lr_shrine_infinite_casting, Hud.Texture.GetTexture(3254056115) )       },
  57.                 { 266254,   new Tuple<string,ActorSnoEnum,ITexture>( "Shield",  ActorSnoEnum._x1_lr_shrine_invulnerable, Hud.Texture.GetTexture(455040081) )            },
  58.                 { 266271,   new Tuple<string,ActorSnoEnum,ITexture>( "Speed",   ActorSnoEnum._x1_lr_shrine_run_speed, Hud.Texture.GetTexture(1927801803) )              }
  59.             };
  60.             Lnn = new Dictionary<uint,string>   // < SnoArea.Sno, Level string>
  61.             {
  62.                 {288482, "Level 01"},   {288684, "Level 02"},   {288686, "Level 03"},   {288797, "Level 04"},   {288799, "Level 05"},
  63.                 {288801, "Level 06"},   {288803, "Level 07"},   {288809, "Level 08"},   {288812, "Level 09"},   {288813, "Level 10"},
  64.                 {0, "Level xx"}  // está añadido por precaución, por si en el futuro añaden más niveles
  65.             }; 
  66.         }  
  67.                
  68.         public class PylonData
  69.         {
  70.             public string Name { get; set; }
  71.             public uint AreaSno { get; set; }
  72.             public double Percent { get; set; }
  73.             public uint BuffSno { get; set; }
  74.             public bool Used { get; set; }
  75.             public PylonData( string name, uint area , double percent , uint buff , bool used)
  76.             {
  77.                 this.Name = name;
  78.                 this.AreaSno = area;
  79.                 this.Percent = percent;
  80.                 this.BuffSno = buff;
  81.                 this.Used = used;                      
  82.             }
  83.         }
  84.        
  85.         public void Customize()
  86.         {
  87.             FontUsed = Hud.Render.CreateFont("tahoma", sizeFont, 255, 170, 170, 170, false, false, 250, 0, 0, 0, true);
  88.             FontLevel = Hud.Render.CreateFont("tahoma", sizeFont, 255, 235, 145, 235, false, false, 160, 0, 0, 0, true);
  89.             FontOther = Hud.Render.CreateFont("tahoma", sizeFont, 255, 250, 50, 50, false, false, 160, 0, 0, 0, true);
  90.             LeftFont = Hud.Render.CreateFont("tahoma", sizeFont - ( (sizeFont > 7)? 1.5f : 1f ), 255, 255, 255, 255, false, false, 160, 0, 0, 0, true);
  91.             LeftFontOther = Hud.Render.CreateFont("tahoma", sizeFont - ( (sizeFont > 7)? 1.5f : 1f ), 255, 102, 178, 255, false, false, 160, 0, 0, 0, true);
  92.             BrushLine = Hud.Render.CreateBrush(255, 125, 175, 240, widthLine); 
  93.             if (PreSetSPname)
  94.             {
  95.                 SPname = 0f;
  96.                 foreach(var e in BuffNA)
  97.                 {
  98.                     var spname = FontLevel.GetTextLayout(e.Value.Item1).Metrics.Width;
  99.                     if  (SPname < spname) { SPname = spname; }
  100.                 }
  101.                 //Hud.Sound.Speak(PreSetSPname + ", es ," + SPname);
  102.             }
  103.            
  104.             if (LineSpacing > 1.2f) { LineSpacing = 1.2f; }
  105.             else if (LineSpacing < 0.8f) { LineSpacing = 0.8f; }
  106.         }
  107.        
  108.         public void PylonsFoundAdd(uint buff , bool used)
  109.         {          
  110.             PylonsFound.Add(BuffNA[buff].Item2, new PylonData(BuffNA[buff].Item1,Hud.Game.Me.SnoArea.Sno,Hud.Game.RiftPercentage,buff,used));                      
  111.             if (!PreSetSPname)
  112.             {
  113.                 var spname = FontLevel.GetTextLayout(BuffNA[buff].Item1).Metrics.Width;
  114.                 if  (SPname < spname) { SPname = spname; }         
  115.             }
  116.         }  
  117.        
  118.         public void OnNewArea(bool newGame, ISnoArea area)
  119.         {  
  120.             if (newGame || (MyIndex != Hud.Game.Me.Index) )   // Fix partialment the newGame limitation
  121.             {
  122.                 MyIndex = Hud.Game.Me.Index;
  123.                 InRift = false; MapGR = false;
  124.             }
  125.             if ((area.HostAreaSno == 288482) || (area.Sno == 288482))
  126.             {  
  127.                 if (Hud.Game.Me.InGreaterRift) { MapGR = true; }       
  128.                 if (!InRift)        //Start New Rift (Nephalem o GR)
  129.                 {
  130.                     InRift = true;                 
  131.                     if (Hud.Game.Me.InGreaterRift)
  132.                     {
  133.                         if (!PreSetSPname) { SPname = 0; }
  134.                         PylonsFound.Clear();
  135.                     }                  
  136.                 }
  137.             }
  138.             else { MapGR = false; }
  139.         }  
  140.        
  141.         public void AfterCollect()  
  142.         {
  143.             if (!Hud.Game.IsInGame) return;
  144.             if (InRift && (Hud.Game.Quests.FirstOrDefault(q => (q.SnoQuest.Sno == 337492) && (q.State == QuestState.started || q.State == QuestState.completed )) == null)) { InRift = false; }
  145.         }  
  146.    
  147.         public void ShowIconBuff(uint buff,float x, float y,float s)
  148.         {
  149.             BuffNA[buff].Item3.Draw(x , y, s, s); // texture draw
  150.             IPlayer player = null; IFont pFont = null;
  151.             if (Hud.Game.Me.Powers.BuffIsActive(buff, 0))
  152.             {  
  153.                 player = Hud.Game.Me;
  154.                 pFont = LeftFont;
  155.             }
  156.             else
  157.             {
  158.                 var players = Hud.Game.Players.Where(p => !p.IsMe && p.HasValidActor && p.Powers.BuffIsActive(buff, 0));
  159.                 if (players.Any())
  160.                 {
  161.                     player = players.OrderByDescending(p => p.Powers.GetBuff(buff).TimeLeftSeconds[0]).FirstOrDefault();
  162.                     pFont = LeftFontOther;
  163.                 }              
  164.             }
  165.             if (player != null) // check buff
  166.             {
  167.                 var left = player.Powers.GetBuff(buff).TimeLeftSeconds[0];
  168.                 var layout = pFont.GetTextLayout(left.ToString( (left < 1)? "F1" : "F0") );
  169.                 pFont.DrawText(layout, x - layout.Metrics.Width - 3 , y + ((s - layout.Metrics.Height) / 2)); // counter                           
  170.                 BorderGreenBrush.DrawRectangle(x + 1, y + 1, s - 2, s - 2); // border green
  171.             }
  172.             else
  173.             {
  174.                 BorderBrush.DrawRectangle(x + 1, y + 1, s - 2, s - 2); // border orange
  175.             }
  176.         }
  177.        
  178.         public void PaintTopInGame(ClipState clipState)
  179.         {
  180.             if ( (clipState != ClipState.BeforeClip) || !Hud.Game.IsInGame || !MapGR ) return;   // Hud.Game.SpecialArea está enlazado a la visibilidad de la barra de progreso...  ¿por qué?   
  181.            
  182.             foreach (var m in Hud.Game.Markers)  // pilones que vemos
  183.             {
  184.                 if  (PylonsFound.ContainsKey(m.SnoActor.Sno))
  185.                 {
  186.                     if ( m.IsUsed && !PylonsFound[m.SnoActor.Sno].Used )    { PylonsFound[m.SnoActor.Sno].Used = true; }
  187.                     if ( Hud.Game.Me.SnoArea.Sno != PylonsFound[m.SnoActor.Sno].AreaSno )   // to fix slow update of snoarea for pylon near the door
  188.                     {
  189.                         PylonsFound[m.SnoActor.Sno].AreaSno = Hud.Game.Me.SnoArea.Sno;
  190.                     }  
  191.                 }
  192.                 else
  193.                 {
  194.                     switch (m.SnoActor.Sno)  
  195.                     {
  196.                         case ActorSnoEnum._x1_lr_shrine_damage:                 PylonsFoundAdd(262935,m.IsUsed); break;     //330695 Power
  197.                         case ActorSnoEnum._x1_lr_shrine_electrified:            PylonsFoundAdd(403404,m.IsUsed); break;     //398654 Conduit
  198.                         case ActorSnoEnum._x1_lr_shrine_infinite_casting:       PylonsFoundAdd(266258,m.IsUsed); break;     //330697 Channeling
  199.                         case ActorSnoEnum._x1_lr_shrine_invulnerable:           PylonsFoundAdd(266254,m.IsUsed); break;     //330698 Shield
  200.                         case ActorSnoEnum._x1_lr_shrine_run_speed:              PylonsFoundAdd(266271,m.IsUsed); break;     //330699 Speed                             
  201.                     }
  202.                 }                                          
  203.             }
  204.            
  205.             foreach (uint buff in BuffNA.Keys)  // bufos que recibimos , para marcar pilones usados y también para detectar pilones nuevos no vistos
  206.             {
  207.                 if ( Hud.Game.Players.Any(p => p.HasValidActor && p.Powers.BuffIsActive(buff,0)) )  // Miro el buff de todos los jugadores , no sólo el mío (Hud.Game.Me.Powers.BuffIsActive(buff, 0))
  208.                 {
  209.                     var sno = BuffNA[buff].Item2;
  210.                     if (PylonsFound.ContainsKey(sno))
  211.                     {
  212.                         if (!PylonsFound[sno].Used) PylonsFound[sno].Used = true;
  213.                     }
  214.                     else { PylonsFoundAdd(buff, true); }
  215.                 }
  216.             }
  217.                    
  218.             if (Hud.Render.GreaterRiftBarUiElement.Visible) // Se mostrará información sólo si la barra de progreso está visible, pero recolectaremos datos siempre
  219.             {
  220.                 var uiRect = Hud.Render.GreaterRiftBarUiElement.Rectangle;
  221.                 double lastPercent = 0; int num = 0; float bPos = 0; var Ypos = uiRect.Bottom + Hud.Window.Size.Height / 30; string texto = string.Empty; SharpDX.DirectWrite.TextLayout layout = null;
  222.                 foreach (var sno in PylonsFound.Keys)  
  223.                 {
  224.                     PylonData p = PylonsFound[sno];                
  225.                     IFont font = p.Used ? FontUsed : ( (p.AreaSno == Hud.Game.Me.SnoArea.Sno)? FontLevel : FontOther ) ;
  226.                     if (Horizontal) // modo Horizontal
  227.                     {
  228.                         bPos = uiRect.Left + uiRect.Width / 100 * (float) p.Percent;
  229.                         BrushLine.DrawLine(bPos, uiRect.Bottom, bPos, uiRect.Bottom + uiRect.Height * 0.3f , 0);    // Line Blue                       
  230.                         layout = font.GetTextLayout(p.Name);
  231.                         var h = layout.Metrics.Height; var x = uiRect.Left; var y = Ypos + num * (h * LineSpacing);
  232.                         if (ShowIcon)
  233.                         {  
  234.                             ShowIconBuff(p.BuffSno,x, y + (h * (1 - LineSpacing) + 1) / 2, h * LineSpacing - 1 );
  235.                             x += h * 1.4f;
  236.                         }                                              
  237.                         font.DrawText(layout, x, y);
  238.                         x = x + SPname;                            
  239.                         texto = string.Format("   {0}   {1:F1}%", Lnn[Lnn.ContainsKey(p.AreaSno) ? p.AreaSno : 0], p.Percent);
  240.                         if (num > 0) texto = string.Format("{0}  [+{1:F1}%]", texto, p.Percent - lastPercent) ;                                                
  241.                         font.DrawText(font.GetTextLayout(texto), x, y);                    
  242.                     }
  243.                     else // modo Vertical
  244.                     {
  245.                         bPos = (float) (uiRect.Left + (uiRect.Width * p.Percent  / 100));                  
  246.                         texto = (num > 0)? string.Format("[+{0:F0}%]",p.Percent - lastPercent) : "" ;
  247.                         texto = string.Format("{0:F1}%\n{1}\n{2}\n{3}",p.Percent, p.Name, Lnn[Lnn.ContainsKey(p.AreaSno) ? p.AreaSno : 0],texto);
  248.                         layout = font.GetTextLayout(texto);
  249.                         BrushLine.DrawLine(bPos, uiRect.Bottom, bPos, Ypos + layout.Metrics.Height / 2, 0);
  250.                         font.DrawText(layout, bPos - layout.Metrics.Width, Ypos);
  251.                     }
  252.                     lastPercent = p.Percent; num += 1;
  253.                 }
  254.                 if ( (num != 4) && (Hud.Game.RiftPercentage < 100)) // progreso que llevamos desde el último pilón
  255.                 {
  256.                     layout = FontLevel.GetTextLayout(string.Format("(+{0:F1}%)", Hud.Game.RiftPercentage - lastPercent));
  257.                     FontLevel.DrawText(layout, uiRect.Left + uiRect.Width / 2 - layout.Metrics.Width / 2, uiRect.Bottom + uiRect.Height * 0.25f);
  258.                 }                          
  259.             }  
  260.         }      
  261.     }  
  262. }
Advertisement
Add Comment
Please, Sign In to add comment