Advertisement
RNNCode

ENPylonMarker

Mar 24th, 2024 (edited)
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 13.50 KB | None | 0 0
  1. using Turbo.Plugins.Default;
  2. using System;
  3. using System.Text;
  4. using System.Linq;
  5. using System.Collections.Generic;
  6. using System.Text.RegularExpressions;
  7. using System.Threading;
  8.  
  9. namespace Turbo.Plugins.RNN
  10. {
  11.     public class ENPylonMarker : BasePlugin, ICustomizer, IAfterCollectHandler, IInGameTopPainter, IInGameWorldPainter
  12.     {
  13.         private WorldDecoratorCollection LineBandit { get; set; }
  14.         private WorldDecoratorCollection LineBanditUsed { get; set; }
  15.  
  16.         protected IUiElement LevelUIE;
  17.         protected IUiElement EnBarUIE;
  18.  
  19.         private Dictionary<ActorSnoEnum, PylonData> PylonData_Dic { get; set; }
  20.  
  21.         private bool fixLoad { get; set; } = true;
  22.         private float xPos { get; set; } = 0;
  23.         private float yPos { get; set; } = 0;
  24.         private float heightFont { get; set; } = 0f;
  25.         private float sizeTexture { get; set; } = 0f;
  26.         private SharpDX.DirectWrite.TextLayout layout { get; set; } = null;
  27.         private string TiempoTotalString { get; set; } = string.Empty;
  28.         private string InfoExtra { get; set; } = string.Empty;
  29.         private int OrderBuff { get; set; } = 0;
  30.         private bool BanditAppears { get; set; } = false;
  31.         private bool _InEN { get; set; } = false;
  32.         private bool InEN
  33.         {
  34.             get { return _InEN; }
  35.             set
  36.             {
  37.                 if (_InEN ^ value) { foreach(var p in PylonData_Dic) p.Value.Reset(); TiempoTotalString = string.Empty; InfoExtra = string.Empty; OrderBuff = 0; BanditAppears = false; }
  38.                 _InEN = value;
  39.             }
  40.         }
  41.  
  42.         public IFont DefaultFont { get; set; } = null;
  43.         public IFont FontUsed { get; set; }
  44.         public IFont FontLevel { get; set; }
  45.         public IFont FontYellow { get; set; }
  46.         public IFont FontGreen { get; set; }
  47.         public IFont LeftFont { get; set; }
  48.         public IBrush BorderOrangeBrush { get; set; }
  49.  
  50.         public float xPor { get; set; } = 0;
  51.         public float yPor { get; set; } = 0;
  52.         public float sizeFont { get; set; } = 8;
  53.         public float LineSpacing { get; set; }
  54.         public bool ShowNames { get; set; }
  55.         public bool NotifyBandit { get; set; }
  56.         public string NotifyBanditWav { get; set; }
  57.         public string NotifyBanditSpeak { get; set; }
  58.         public float LineToBanditWidth { get; set;}
  59.         public bool LineToBandit { get; set;}
  60.         public bool LineToBanditHideUsed { get; set;}
  61.  
  62.         public ENPylonMarker()
  63.         {
  64.             Enabled = true;
  65.         }
  66.  
  67.         public class PylonData
  68.         {
  69.             public string Name { get; set; }
  70.             public int PreOrder { get; set; }
  71.             public int OrderShow { get; set; } = 0;
  72.             public uint BuffSno { get; set; }
  73.             public ITexture Texture { get; set; }
  74.             public ActorSnoEnum ASE { get; set; }
  75.  
  76.             public string LeveLStr { get; set; } = "-";
  77.             public string TimeStr { get; set; } = "-";
  78.             public bool Used { get; set; } = false;
  79.             public string Player { get; set; } = string.Empty;
  80.  
  81.             public void Reset()
  82.             {
  83.                 this.LeveLStr = "-";
  84.                 this.TimeStr = "-";
  85.                 this.Used = false;
  86.                 this.Player = string.Empty;
  87.                 this.OrderShow = this.PreOrder;
  88.             }
  89.         }
  90.  
  91.        public override void Load(IController hud)
  92.         {
  93.             base.Load(hud);
  94.             Order = 90001;
  95.  
  96.             xPor = -0.01f;  // x = <Nightmare Bar Position> + Hud.Window.Size.Width * xPor
  97.             yPor = 0.033f;  // y = <Nightmare Bar Position> + Hud.Window.Size.Height * yPor;
  98.  
  99.             sizeFont = 8f;          // Text font size
  100.             LineSpacing = 1.05f;    // Line spacing in text . Allowed values: from 0.8f to 1.2f
  101.             ShowNames = true;       // Show the name of the Player who took the Pylon
  102.  
  103.             NotifyBandit = true;            // Notify when bandit appears  (sound and/or speak)
  104.             NotifyBanditWav = "notification_5.wav";     // Filename to play, must be in the .\sounds\ folder. Example: "notification_5.wav" (null or "" so that it does not notify)
  105.             NotifyBanditSpeak = ""; // Text to Speak. Example: "Bandit" (null or "" so that it does not notify)
  106.  
  107.             LineToBandit = true;            // Line to Shrine (yellow used, grey not used)
  108.             LineToBanditWidth = 2.0f;
  109.             LineToBanditHideUsed = false;   // Hide line to Shrine if used (grey)
  110.  
  111.             BorderOrangeBrush = Hud.Render.CreateBrush(250, 250, 100, 0, 1);
  112.  
  113.             LevelUIE = Hud.Render.RegisterUiElement("Root.NormalLayer.eventtext_bkgrnd.eventtext_region.stackpanel.sidequest_wrapper.quest_stack_side 486773.objective_stack.486773 1 1 wrapper.text", null, null);
  114.             EnBarUIE = Hud.Render.RegisterUiElement("Root.NormalLayer.eventtext_bkgrnd.eventtext_region.stackpanel.sidequest_wrapper.quest_stack_side 486773", null, null);
  115.  
  116.             PylonData_Dic = new Dictionary<ActorSnoEnum, PylonData>() // PreOrder is num 1...5
  117.             {
  118.                 { ActorSnoEnum._x1_lr_shrine_infinite_casting,  new PylonData(){ Name = "Chann",    PreOrder = 1, BuffSno = 486868, Texture = Hud.Texture.GetTexture(3254056115), ASE = ActorSnoEnum._p73_swarmrift_shrine_infinite_casting}    },
  119.                 { ActorSnoEnum._x1_lr_shrine_run_speed,         new PylonData(){ Name = "Speed",    PreOrder = 2, BuffSno = 487614, Texture = Hud.Texture.GetTexture(1927801803), ASE = ActorSnoEnum._p73_shrine_run_speed} },  // 487615 KnockBack , 487616 Waller
  120.                 { ActorSnoEnum._x1_lr_shrine_damage,            new PylonData(){ Name = "Power",    PreOrder = 3, BuffSno = 486865, Texture = Hud.Texture.GetTexture(2350065673), ASE = ActorSnoEnum._p73_swarmrift_shrine_damage}  },
  121.                 { ActorSnoEnum._x1_lr_shrine_electrified,       new PylonData(){ Name = "Conduit",  PreOrder = 4, BuffSno = 486873, Texture = Hud.Texture.GetTexture(1751750314), ASE = ActorSnoEnum._p73_swarmrift_shrine_electrified} },
  122.                 { ActorSnoEnum._shrine_global,                  new PylonData(){ Name = "Bandit",   PreOrder = 5, BuffSno =      0, Texture = Hud.Texture.GetTexture(218235,0),   ASE = ActorSnoEnum._p73_shrine_treasuregoblin}    },
  123.             };
  124.         }
  125.  
  126.         public void Customize()
  127.         {
  128.             FontUsed = Hud.Render.CreateFont("Consolas", sizeFont, 255, 170, 170, 170, false, false, 250, 0, 0, 0, true);
  129.             FontLevel = Hud.Render.CreateFont("Consolas", sizeFont, 255, 235, 145, 235, false, false, 160, 0, 0, 0, true);
  130.             FontYellow = Hud.Render.CreateFont("Consolas", sizeFont, 255, 250, 250, 50, false, false, 160, 0, 0, 0, true);
  131.             FontGreen = Hud.Render.CreateFont("Consolas", sizeFont, 255, 50, 250, 50, false, false, 160, 0, 0, 0, true);
  132.             LeftFont = Hud.Render.CreateFont("Consolas", sizeFont - ( (sizeFont > 7)? 1.0f : 0.5f ), 255, 255, 255, 255, false, false, 160, 0, 0, 0, true);
  133.  
  134.             if (LineSpacing > 1.2f) { LineSpacing = 1.2f; }
  135.             else if (LineSpacing < 0.8f) { LineSpacing = 0.8f; }
  136.  
  137.             LineBanditUsed = new WorldDecoratorCollection(
  138.                 new MapShapeDecorator(Hud)
  139.                 {
  140.                     Brush = Hud.Render.CreateBrush(255, 200, 200, 200, LineToBanditWidth, SharpDX.Direct2D1.DashStyle.DashDot),
  141.                     ShapePainter = new LineFromMeShapePainter(Hud)
  142.                 }
  143.             );
  144.  
  145.             LineBandit = new WorldDecoratorCollection(
  146.                 new MapShapeDecorator(Hud)
  147.                 {
  148.                     Brush = Hud.Render.CreateBrush(255, 255, 200, 50, LineToBanditWidth, SharpDX.Direct2D1.DashStyle.Dash),
  149.                     ShapePainter = new LineFromMeShapePainter(Hud)
  150.                 }
  151.             );
  152.         }
  153.  
  154.         public void Play_Sound(string Sonido)
  155.         {
  156.             var playSonido = Hud.Sound.LoadSoundPlayer(Sonido);
  157.             ThreadPool.QueueUserWorkItem(state =>
  158.             {
  159.                 try  { playSonido.PlaySync(); }
  160.                 catch (Exception)  {   }
  161.             }   );
  162.         }
  163.  
  164.         public void AfterCollect()
  165.         {
  166.             if (!Hud.Game.IsInGame) return;
  167.             var quest = Hud.Game.Quests.FirstOrDefault(q => q.SnoQuest.Sno == 486773 && q.State == QuestState.started);
  168.             if (quest != null)
  169.             {
  170.                 if (!InEN) InEN = true;
  171.  
  172.                 long t = (Hud.Game.CurrentGameTick - quest.CreatedOn)/60;   //InfoExtra = string.Format("[{0}/{1}/{2:0}m{3:00}s]", quest.QuestStepId, quest.State , t/60, t%60);
  173.                 if (quest.QuestStepId == 13)
  174.                 {
  175.                     TiempoTotalString = string.Format("{0}s", t - 10);
  176.                 }
  177.                 else if (quest.QuestStepId == 1)
  178.                 {
  179.                     TiempoTotalString = (t < 60)?string.Format("{0}s",t):string.Format("{0:0}m{1:00}s", t/60, t%60);
  180.                 }
  181.                 else if (quest.QuestStepId == 9)
  182.                 {
  183.                     if (TiempoTotalString == string.Empty) TiempoTotalString = "+" + ((t < 60)?string.Format("{0}s",t):string.Format("{0:0}m{1:00}s", t/60, t%60));
  184.                     if (InfoExtra == string.Empty && LevelUIE.Visible)
  185.                     {
  186.                         if (!string.IsNullOrEmpty(LevelUIE.ReadText(Encoding.UTF8, true)))
  187.                         {
  188.                             var textLevel = Regex.Replace(LevelUIE.ReadText(Encoding.UTF8, true), @"(.+:\s)?", "");
  189.                             if (Int32.TryParse(textLevel,out var levelGem)) InfoExtra = string.Format("[{0}, Gem {1}]", levelGem, levelGem>125?125:levelGem-1);
  190.                         }
  191.                     }
  192.                 }
  193.             }
  194.             else
  195.             {
  196.                 if (InEN) InEN = false;
  197.             }
  198.         }
  199.  
  200.         public void PaintTopInGame(ClipState clipState)
  201.         {
  202.             if ( clipState != ClipState.BeforeClip || !Hud.Game.IsInGame || Hud.Game.IsPaused || Hud.Game.Me.SnoArea.Sno != 486520) return;  // || Hud.Game.Me.SnoArea.Sno != 486520
  203.             if (InEN && EnBarUIE.Visible)
  204.             {
  205.                 heightFont = FontLevel.GetTextLayout("O").Metrics.Height; sizeTexture = heightFont * LineSpacing - 1;
  206.                 xPos = EnBarUIE.Rectangle.Left + Hud.Window.Size.Width * xPor; yPos = EnBarUIE.Rectangle.Bottom + Hud.Window.Size.Height * yPor;
  207.                 foreach (var m in Hud.Game.Markers)
  208.                 {
  209.                     var timeleft = 0d;  bool newUsed = false; PylonData data;
  210.                     if (m.IsShrine)
  211.                     {
  212.                         data = PylonData_Dic[ActorSnoEnum._shrine_global];
  213.                         if (!BanditAppears)
  214.                         {
  215.                             BanditAppears = true;
  216.                             if (NotifyBandit)
  217.                             {
  218.                                 if (!string.IsNullOrWhiteSpace(NotifyBanditWav) ) {  Play_Sound(NotifyBanditWav);  }
  219.                                 if (!string.IsNullOrWhiteSpace(NotifyBanditSpeak) ) {  Hud.Sound.Speak(NotifyBanditSpeak); }
  220.                             }
  221.                         }
  222.                         if (data.Used) DefaultFont = FontUsed;
  223.                         else
  224.                         {
  225.                             var bandit = Hud.Game.Actors.FirstOrDefault(a => a.SnoActor.Sno == data.ASE);
  226.                             if (bandit != null && bandit.GetAttributeValue(Hud.Sno.Attributes.Gizmo_Has_Been_Operated, 1048575) == 1)
  227.                             {                                               // los posibles valores son 2^20 = 1048576 , rango de valores: 0 .. 1048575 (maxvalue, equivalente a -1)
  228.                                 newUsed = true;
  229.                                 DefaultFont = FontUsed;
  230.                                 var pId = bandit.GetAttributeValueAsUInt(Hud.Sno.Attributes.Gizmo_Operator_ACDID, 1048575);
  231.                                 var pTaker = Hud.Game.Players.FirstOrDefault(p => p.AnnId == pId);
  232.                                 if (pTaker != null) { data.Player = pTaker.BattleTagAbovePortrait; }
  233.                             }
  234.                             else DefaultFont = FontLevel;
  235.                         }
  236.                     }
  237.                     else if (m.IsPylon && PylonData_Dic.TryGetValue(m.SnoActor.Sno,out data))
  238.                     {
  239.                         if (m.IsUsed)   // Pylon: Speed, Channeling, Power, Conduit
  240.                         {
  241.                             if (!data.Used) newUsed = true;
  242.                             if (data.Player == string.Empty)
  243.                             {
  244.                                 var actor = Hud.Game.Actors.FirstOrDefault(a => a.SnoActor.Sno == data.ASE);
  245.                                 if (actor != null)
  246.                                 {
  247.                                     var pId = actor.GetAttributeValueAsUInt(Hud.Sno.Attributes.Gizmo_Operator_ACDID, 1048575);
  248.                                     var pTaker = Hud.Game.Players.FirstOrDefault(p => p.AnnId == pId);
  249.                                     if (pTaker != null) { data.Player = pTaker.BattleTagAbovePortrait; }
  250.                                 }
  251.                             }
  252.                             var players = Hud.Game.Players.Where(p => p.HasValidActor && p.Powers.BuffIsActive(data.BuffSno,0));
  253.                             if (players.Any())
  254.                             {
  255.                                 if (Hud.Game.Me.Powers.BuffIsActive(data.BuffSno,0))
  256.                                 {
  257.                                     timeleft = Hud.Game.Me.Powers.GetBuff(data.BuffSno).TimeLeftSeconds[0];
  258.                                     DefaultFont = FontGreen;
  259.                                 }
  260.                                 else
  261.                                 {
  262.                                     timeleft = players.FirstOrDefault().Powers.GetBuff(data.BuffSno).TimeLeftSeconds[0];
  263.                                     DefaultFont = FontYellow;
  264.                                 }
  265.                             }
  266.                             else DefaultFont = FontUsed;
  267.                         }
  268.                         else DefaultFont = FontLevel;
  269.                     }
  270.                     else continue;
  271.                     if (newUsed)
  272.                     {
  273.                         data.Used = true;
  274.                         data.LeveLStr = (LevelUIE.Visible && Int32.TryParse(Regex.Replace(LevelUIE.ReadText(Encoding.UTF8, true), @"(.+:\s)?", ""),out var intLevel))?intLevel.ToString():"??";
  275.                         data.TimeStr = TiempoTotalString;
  276.                         if (++OrderBuff != data.OrderShow)
  277.                         {
  278.                             foreach(var data2 in PylonData_Dic)
  279.                             {
  280.                                 if (data2.Value.OrderShow == OrderBuff) { data2.Value.OrderShow = data.OrderShow; data.OrderShow = OrderBuff; break; }
  281.                             }
  282.                         }
  283.                     }
  284.  
  285.                     var y = yPos + data.OrderShow * (heightFont * LineSpacing);
  286.                     if (timeleft > 0)
  287.                     {
  288.                         layout = LeftFont.GetTextLayout( timeleft.ToString((timeleft < 1)?"F1":"F0") );
  289.                         LeftFont.DrawText(layout,xPos - layout.Metrics.Width - 3, y + (sizeTexture - layout.Metrics.Height)/2.0f);
  290.                     }
  291.  
  292.                     data.Texture.Draw(xPos, y + (heightFont - sizeTexture)/2.0f,  sizeTexture, sizeTexture);
  293.                     BorderOrangeBrush.DrawRectangle(xPos + 1, y + (heightFont - sizeTexture)/2.0f + 1, sizeTexture - 2, sizeTexture - 2);
  294.  
  295.                     if (ShowNames && data.Player != string.Empty) layout = DefaultFont.GetTextLayout(string.Format("{0,-8} Level:{1,-3} Time:{2} [{3}]", data.Name, data.LeveLStr, data.TimeStr, data.Player));
  296.                     else layout = DefaultFont.GetTextLayout(string.Format("{0,-8} Level:{1,-3} Time:{2}", data.Name, data.LeveLStr, data.TimeStr));
  297.  
  298.                     DefaultFont.DrawText(layout,xPos + heightFont * 1.5f,y);
  299.                 }
  300.                 FontLevel.DrawText(FontUsed.GetTextLayout(string.Format("Time Elapsed:{0} {1}", TiempoTotalString, InfoExtra)),xPos + heightFont * 2.0f, yPos);
  301.             }
  302.         }
  303.  
  304.         public void PaintWorld(WorldLayer layer)
  305.         {
  306.             if (!Hud.Game.IsInGame || layer != WorldLayer.Map || Hud.Game.Me.SnoArea.Sno != 486520) return;
  307.             if (InEN && LineToBandit)
  308.             {
  309.                 var bandit = Hud.Game.Markers.FirstOrDefault(m => m.IsShrine); // ActorSnoEnum._shrine_global
  310.                 if (bandit != null)
  311.                 {
  312.                     if (!PylonData_Dic[ActorSnoEnum._shrine_global].Used)       LineBandit.Paint(layer, null, bandit.FloorCoordinate, "");
  313.                     else if (!LineToBanditHideUsed)                             LineBanditUsed.Paint(layer, null, bandit.FloorCoordinate, "");
  314.                 }
  315.             }
  316.         }
  317.     }
  318. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement