RNNCode

MyBuffs

Mar 17th, 2020 (edited)
540
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 14.23 KB | None | 0 0
  1. // https://www.ownedcore.com/forums/diablo-3/turbohud/turbohud-community-plugins/800417-v9-0-eng-rnn-mybuffs.html  (Forum Post)
  2. // Thanks to JarJarD3 for his many contributions to this plugin.
  3.  
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using SharpDX.DirectInput;
  7. using Turbo.Plugins.Default;
  8.  
  9. namespace Turbo.Plugins.RNN
  10. {
  11.     public class MyBuffs : BasePlugin, IInGameTopPainter, IKeyEventHandler, INewAreaHandler
  12.     {
  13.         protected IUiElement SeasonalLeaf;
  14.         public IFont FuenteW { get; set; }
  15.         public IFont FuenteY { get; set; }
  16.         public IFont FuenteG { get; set; }
  17.         public IFont FuenteB { get; set; }
  18.         private IFont font { get; set; }
  19.         public int info { get; set; } = 1;
  20.  
  21.         public float XCoord { get; set; } = 220f;
  22.         public float YCoord { get; set; } = 25f;
  23.         public float LineHeightPC { get; set; } = 0.85f; // Line height modifier.
  24.  
  25.         public bool ShowAllTextures { get; set; } = false;
  26.         public bool Debug_On { get; set; }
  27.         public IKeyEvent ToggleKeyEvent1 { get; set; }  // Show/Hide.
  28.         public IKeyEvent ToggleKeyEvent2 { get; set; }  // Display info mode.
  29.         public IKeyEvent ToggleKeyEvent3 { get; set; }  // Reposition to mouse cursor.
  30.  
  31.         public bool ShowBuffsExcluded  { get; set; }
  32.  
  33.         public Dictionary<uint, int> FixIndexSkills { get; set; }
  34.  
  35.         public uint[] ExcludedSnos { get; set; } = new uint[]
  36.         {
  37.             220304,     // ActorInTownBuff
  38.             439438,     // ActorInvulBuff
  39.             212032,     // ActorLoadingBuff
  40.             134334,     // Banter_Cooldown
  41.             30145,      // BareHandedPassive
  42.             225599,     // CannotDieDuringBuff
  43.             134225,     // Callout_Cooldown
  44.             30176,      // Cooldown
  45.             428398,     // Cosmetic_SpectralHound_Buff
  46.             193438,     // DualWieldBuff
  47.             257687,     // Enchantress_MissileWard
  48.             286747,     // g_paragonBuff
  49.             30283,      // ImmuneToFearDuringBuff
  50.             30284,      // ImmuneToRootDuringBuff
  51.             30285,      // ImmuneToSnareDuringBuff
  52.             30286,      // ImmuneToStunDuringBuff
  53.             30290,      // InvulnerableDuringBuff
  54.             349060,     // TeleportToWaypoint
  55.             371141,     // TeleportToWaypoint_Cast
  56.             79486,      // UninterruptibleDuringBuff
  57.             30582,      // UntargetableDuringBuff
  58.             30584,      // UseHealthGlyph
  59.             132910,     // WarpInMagical
  60.             223604,     // WorldCreatingBuff
  61.         };
  62.  
  63.         public uint[] AltarSnos { get; set; } = new uint[]
  64.         {
  65.             488004,     // Madre
  66.             488036,
  67.             488037,
  68.             488038,
  69.             488006,
  70.             488011,
  71.             488012,
  72.             488013,
  73.             488014,
  74.             488015,
  75.             488016,
  76.             488017,
  77.             488018,
  78.             488019,
  79.             488020,
  80.             488021,
  81.             488022,
  82.             488023,
  83.             488024,
  84.             488025,
  85.             488026,
  86.             488027,
  87.             488028,
  88.             488029,
  89.             488030,
  90.             488031,
  91.             488032,
  92.             488033,
  93.             488034,
  94.             488035,
  95.  
  96.         };
  97.  
  98.         public MyBuffs()
  99.         {
  100.             Enabled = true;
  101.         }
  102.  
  103.         public override void Load(IController hud)
  104.         {
  105.             base.Load(hud);
  106.             Order = 100001;
  107.  
  108.             ShowBuffsExcluded = false;
  109.  
  110.             ToggleKeyEvent1 = Hud.Input.CreateKeyEvent(true, Key.F7, controlPressed: false, altPressed: false, shiftPressed: true);
  111.             ToggleKeyEvent2 = Hud.Input.CreateKeyEvent(true, Key.F7, controlPressed: true, altPressed: false, shiftPressed: false);
  112.             ToggleKeyEvent3 = Hud.Input.CreateKeyEvent(true, Key.F7, controlPressed: false, altPressed: true, shiftPressed: false);
  113.             Debug_On = false;
  114.  
  115.             FuenteW = Hud.Render.CreateFont("consolas", 8f, 255, 200, 200, 200, false, false, 220, 32, 32, 32, false);
  116.             FuenteY = Hud.Render.CreateFont("consolas", 9f, 255, 255, 255, 0, false, false, 220, 32, 32, 32, false);
  117.             FuenteG = Hud.Render.CreateFont("consolas", 9f, 255, 0, 255, 0, false, false, 220, 32, 32, 32, false);
  118.             FuenteB = Hud.Render.CreateFont("consolas", 9f, 255, 0, 128, 255, false, false, 220, 32, 32, 32, false); //FuenteB = Hud.Render.CreateFont("consolas", 9f, 255, 0, 128, 255, true, false, 220, 32, 32, 32, true);
  119.  
  120.             FixIndexSkills = new Dictionary<uint, int>  // Skill Default Index (info = 4).
  121.             {                                           //Por defecto se muestran los tiempos que correspondan al indice con mayor Timeleft , aquí se puede fijar un indice concreto para la habilidad
  122.                 {79528, 0}                      // Skill Ignore Pain, use index 0 always
  123.             };
  124.             SeasonalLeaf = Hud.Render.RegisterUiElement("Root.NormalLayer.minimap_dialog_backgroundScreen.minimap_dialog_pve.BoostWrapper.BoostsDifficultyStackPanel.BoostsStackWrapper.BoostsStackPanel.Seasonal", null, null);
  125.         }
  126.  
  127.         public void OnNewArea(bool newGame, ISnoArea area)
  128.         {
  129.             if (newGame)
  130.             {
  131.                 Debug_On = false;
  132.                 if (info == 4 && !SeasonalLeaf.Visible) info = 1;
  133.             }
  134.         }
  135.  
  136.         public void OnKeyEvent(IKeyEvent keyEvent)
  137.         {
  138.             if (keyEvent.IsPressed)
  139.             {
  140.                 if (ToggleKeyEvent1.Matches(keyEvent))
  141.                 {
  142.                     Debug_On = !Debug_On;
  143.                 }
  144.                 else if (ToggleKeyEvent2.Matches(keyEvent))
  145.                 {
  146.                     if (Debug_On)
  147.                     {
  148.                         if (++info > 6)
  149.                         {
  150.                             info = 1;
  151.                         }
  152.                         else if (info == 4)
  153.                         {
  154.                             //if (!Hud.Game.Me.Hero.Seasonal) info = ShowBuffsExcluded?5:6;
  155.                             if (!SeasonalLeaf.Visible)  info = ShowBuffsExcluded?5:6;
  156.                         }
  157.                         else if (info == 5)
  158.                         {
  159.                             if (!ShowBuffsExcluded) info = 6;
  160.                         }
  161.                     }
  162.                 }
  163.                 else if (ToggleKeyEvent3.Matches(keyEvent))
  164.                 {
  165.                     if (Debug_On)
  166.                     {
  167.                         var mouse = Hud.Window.CreateScreenCoordinate(Hud.Window.CursorX, Hud.Window.CursorY);
  168.                         XCoord = mouse.X;
  169.                         YCoord = mouse.Y;
  170.                     }
  171.                 }
  172.             }
  173.         }
  174.  
  175.         public void PaintTopInGame(ClipState clipState)
  176.         {
  177.             if (Hud.Render.UiHidden)
  178.                 return;
  179.             if (clipState != ClipState.BeforeClip)
  180.                 return;
  181.             if (!Hud.Game.IsInGame || !Debug_On)
  182.                 return;
  183.  
  184.             var texto = string.Empty;
  185.             //var texto2 = "(Shift+F7 = Show/Hide , Ctrl+F7 = BUFFs All/Actives/Timeleft" + (Hud.Game.Me.Hero.Seasonal?"/Altar":"") + (ShowBuffsExcluded? "/Excluded":"") + " and SKILLs)";
  186.             var texto2 = "(Shift+F7 = Show/Hide , Ctrl+F7 = BUFFs All/Actives/Timeleft" + (SeasonalLeaf.Visible?"/Altar":"") + (ShowBuffsExcluded? "/Excluded":"") + " and SKILLs)";
  187.             var indice = 1;
  188.             var xPos = XCoord;
  189.             var yPos = YCoord;
  190.             if (info < 6)
  191.             {
  192.                 List<IBuff> powers = new List<IBuff>();
  193.                 if (info == 4)  powers = Hud.Game.Me.Powers.AllBuffs.Where(x => AltarSnos.Contains(x.SnoPower.Sno)).ToList();
  194.                 else if (info == 5) powers = Hud.Game.Me.Powers.AllBuffs.Where(x => ExcludedSnos.Contains(x.SnoPower.Sno)).ToList();
  195.                 else powers = Hud.Game.Me.Powers.AllBuffs.Where(x => (x.Active || info == 1) && !ExcludedSnos.Contains(x.SnoPower.Sno) && !AltarSnos.Contains(x.SnoPower.Sno)).ToList();
  196.                 powers.Sort((a, b) => a.SnoPower.Code.CompareTo(b.SnoPower.Code));
  197.                 texto = "BUFFs "
  198.                 + ((info == 1)?" <All> "
  199.                     : (info == 2)?" <Actives> "
  200.                         : (info == 3)?" <TimeLeft> "
  201.                             : (info == 4)?" <Altar> "
  202.                             : " <Excluded> ")
  203.                 + texto2;
  204.                 var layout = FuenteW.GetTextLayout(texto);
  205.                 FuenteW.DrawText(layout, xPos, yPos);
  206.                 yPos += layout.Metrics.Height * LineHeightPC;
  207.                 texto = "xx)     Sno   Active                   Code                         (Namelocalized)             [index]Timeleft/Duration{#Stacks}:TextureId ";
  208.                 FuenteW.DrawText(FuenteW.GetTextLayout(texto), xPos, yPos);
  209.                 yPos += layout.Metrics.Height * LineHeightPC;
  210.                 foreach (var power in powers)
  211.                 {
  212.                     //if (power.SnoPower.Sno > 273941 && power.SnoPower.Sno != 462239 && power.SnoPower.Sno != 467463 && power.SnoPower.Sno !=  476587) continue;
  213.                     texto = string.Format("{0:00}) {1,7}  {2,-6} {3,-37}  {4,-27}",
  214.                         indice,
  215.                         power.SnoPower.Sno,
  216.                         power.Active,
  217.                         power.SnoPower.Code,
  218.                         (power.SnoPower.NameLocalized != null)? "(" + power.SnoPower.NameLocalized + ")":""
  219.                         );
  220.                     var t = string.Empty;
  221.                     var j = power.TimeLeftSeconds.Count();
  222.                     var color = false;
  223.                     for (var i = 0; i < j; i++)
  224.                     {
  225.                         if (power.TimeLeftSeconds[i] > 0)
  226.                         {
  227.                             t = string.Format("{0}[{1}]{2:F1}/{3:F1}{4}{5}  ",
  228.                                     t,
  229.                                     i,
  230.                                     power.TimeLeftSeconds[i],
  231.                                     power.TimeLeftSeconds[i] + power.TimeElapsedSeconds[i],
  232.                                     "{#" + power.IconCounts[i] + "}",
  233.                                     power.SnoPower.Icons[i].TextureId != 0 ? (":" + power.SnoPower.Icons[i].TextureId.ToString()):""
  234.                                 );
  235.                             color = true;
  236.                         }
  237.                         else if ( (power.IconCounts[i] > 0)  || (ShowAllTextures && (power.SnoPower.Icons[i].TextureId != 0))  )
  238.                         {
  239.                             t = string.Format("{0}[{1}]{2}{3}  ",
  240.                                     t,
  241.                                     i,
  242.                                     "{#" + power.IconCounts[i] + "}",
  243.                                     power.SnoPower.Icons[i].TextureId != 0 ? (":" + power.SnoPower.Icons[i].TextureId.ToString()) : ""
  244.                                 );
  245.                         }
  246.                     }
  247.                     font = null;
  248.                     if (color)  { font = FuenteG; }
  249.                     else
  250.                     {
  251.                         if (info == 3) continue;
  252.                         font = FuenteY;
  253.                     }
  254.                     texto = texto + t;
  255.                     layout = font.GetTextLayout(texto);
  256.                     font.DrawText(layout, xPos, yPos);
  257.                     yPos += layout.Metrics.Height * LineHeightPC;
  258.                     indice++;
  259.                 }
  260.             }
  261.             else if (info == 6)
  262.             {
  263.                 texto = "SKILLs " + texto2;
  264.                 var layout = FuenteW.GetTextLayout(texto);
  265.                 FuenteW.DrawText(layout, xPos, yPos);
  266.                 yPos += layout.Metrics.Height * LineHeightPC;
  267.                 texto = "[Key] CurrentSno BuffActive InCoolDown                Code  (NameLocalized)                          Rune  (NameLocalized)         TextureId    [Index] Timeleft (higher)";
  268.                 FuenteW.DrawText(FuenteW.GetTextLayout(texto), xPos, yPos);
  269.                 yPos += layout.Metrics.Height * LineHeightPC;
  270.                 foreach (var skill in Hud.Game.Me.Powers.CurrentSkills)
  271.                 {
  272.                     texto = string.Empty;
  273.                     double TimeLeftSec = 0;
  274.                     if (skill.BuffIsActive)
  275.                     {
  276.                         if (FixIndexSkills.TryGetValue(skill.CurrentSnoPower.Sno, out var index))
  277.                         {
  278.                             TimeLeftSec = skill.Buff.TimeLeftSeconds[index];
  279.                         }
  280.                         else
  281.                         {
  282.                             for (var i = 0; i < skill.Buff.TimeLeftSeconds.Length; i++)
  283.                             {
  284.                                 if (skill.Buff.TimeLeftSeconds[i] > TimeLeftSec)
  285.                                 {
  286.                                     TimeLeftSec = skill.Buff.TimeLeftSeconds[i];
  287.                                     index = i;
  288.                                 }
  289.                             }
  290.                         }
  291.  
  292.                         if (TimeLeftSec >= 0)
  293.                         {
  294.                             if (TimeLeftSec < 1.0f)
  295.                             {
  296.                                 texto = string.Format("{0:N1}", TimeLeftSec);
  297.                             }
  298.                             else
  299.                             {
  300.                                 TimeLeftSec = (int)(TimeLeftSec + 0.80);  // Redondeará a X si es menor  a X.20
  301.                                 texto = (TimeLeftSec < 60) ? string.Format("{0:0}", TimeLeftSec) : string.Format("{0:0}:{1:00}", (int)(TimeLeftSec / 60), TimeLeftSec % 60);
  302.                             }
  303.                         }
  304.                         texto = " [" + index + "] " + texto;
  305.                     }
  306.                     texto = string.Format("  {0,-2} {1,8}    {7,-6}    {2,-6}   {3,-29} {4,-22} {5,3} {6,-22} {8,10}  {9}",
  307.                         skill.Key.ToString().Replace("Skill", "").Substring(0, 1),
  308.                         skill.CurrentSnoPower.Sno,
  309.                         skill.IsOnCooldown,
  310.                         skill.CurrentSnoPower.Code,
  311.                         "(" + skill.CurrentSnoPower.NameLocalized + ")",
  312.                         skill.Rune,
  313.                         "(" + skill.RuneNameLocalized + ")",
  314.                         skill.BuffIsActive,
  315.                         skill.CurrentSnoPower.NormalIconTextureId,
  316.                         texto);
  317.                     layout = FuenteB.GetTextLayout(texto);
  318.                     FuenteB.DrawText(layout, xPos, yPos);
  319.                     yPos += layout.Metrics.Height * LineHeightPC;
  320.                     indice++;
  321.                 }
  322.  
  323.                 texto = "Passive    Sno              Code  (NameLocalized)                                                      TextureId";
  324.                 layout = FuenteW.GetTextLayout(texto);
  325.                 yPos += layout.Metrics.Height * LineHeightPC;
  326.                 FuenteW.DrawText(layout, xPos, yPos);
  327.                 yPos += layout.Metrics.Height * LineHeightPC;
  328.                 indice = 1;
  329.                 foreach (var power in Hud.Game.Me.Powers.UsedPassives)
  330.                 {
  331.                     texto = string.Format("{0,3}   {1,8}   {2,-40}  {3,-30}  {4,10}",
  332.                         indice,
  333.                         power.Sno,
  334.                         power.Code,
  335.                         (power.NameLocalized != null)? "(" + power.NameLocalized + ")":"",
  336.                         power.NormalIconTextureId
  337.                         );
  338.                     layout = FuenteB.GetTextLayout(texto);
  339.                     FuenteB.DrawText(layout, xPos, yPos);
  340.                     yPos += layout.Metrics.Height * LineHeightPC;
  341.                     indice++;
  342.                     if (indice > 5) break;
  343.                 }
  344.             }
  345.         }
  346.     }
  347. }
Advertisement
Add Comment
Please, Sign In to add comment