Advertisement
HaKache

PlayerInfosPlugin

Aug 30th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 11.63 KB | None | 0 0
  1. // Custom PlayerInfosPlugin (Original by GLQ & Refactoring by Jack)
  2. // C# version of XML Player Infos Table.
  3. // Go to config/ui_default/ui_default_main.xml and disable the portraits template : <portraits enabled="0">
  4.  
  5. using System.Globalization;
  6. using System.Linq;
  7. using Turbo.Plugins.Default;
  8. using Turbo.Plugins.Extended.Resources;
  9.  
  10. namespace Turbo.Plugins.Extended.Addons
  11. {
  12.  
  13.     public class PlayerInfosPlugin : BasePlugin, INewAreaHandler, IInGameTopPainter
  14.     {
  15.         public TopTable Table { get; set; }
  16.  
  17.         private int lastPlayerCount = -1;
  18.         private int hoveredPlayerIndex = -1;
  19.  
  20.         public PlayerInfosPlugin()
  21.         {
  22.             Enabled = true;
  23.             Order = int.MaxValue;
  24.         }
  25.  
  26.         public override void Load(IController hud)
  27.         {
  28.             base.Load(hud);
  29.  
  30.             Table = new TopTable(Hud)
  31.             {
  32.                 RatioPositionX = 0.5f,
  33.                 RatioPositionY = 0.03f,
  34.                 HorizontalCenter = true,
  35.                 VerticalCenter = false,
  36.                 PositionFromRight = false,
  37.                 PositionFromBottom = false,
  38.                 ShowHeaderLeft = false,
  39.                 ShowHeaderTop = true,
  40.                 ShowHeaderRight = false,
  41.                 ShowHeaderBottom = false,
  42.                 DefaultCellDecorator = new TopTableCellDecorator(Hud)
  43.                 {
  44.                     BackgroundBrush = Hud.Render.CreateBrush(128, 0, 0, 0, 0),
  45.                     BorderBrush = Hud.Render.CreateBrush(255, 70, 56, 42, 1.5f),
  46.                     TextFont = Hud.Render.CreateFont("tahoma", 7, 255, 255, 255, 255, false, false, false),
  47.                 },
  48.                 DefaultHighlightDecorator = new TopTableCellDecorator(Hud)
  49.                 {
  50.                     BackgroundBrush = Hud.Render.CreateBrush(128, 0, 0, 242, 0),
  51.                     BorderBrush = Hud.Render.CreateBrush(255, 70, 56, 42, 1.5f),
  52.                     TextFont = Hud.Render.CreateFont("tahoma", 7, 255, 255, 255, 255, false, false, false),
  53.                 },
  54.                 DefaultHeaderDecorator = new TopTableCellDecorator(Hud)
  55.                 {
  56.                     BackgroundBrush = Hud.Render.CreateBrush(128, 0, 0, 0, 0),
  57.                     BorderBrush = Hud.Render.CreateBrush(255, 70, 56, 42, 1.5f),
  58.                     TextFont = Hud.Render.CreateFont("tahoma", 7, 255, 255, 255, 255, false, false, true),
  59.                 }
  60.             };
  61.             DefineColumns();
  62.         }
  63.  
  64.         public void OnNewArea(bool newGame, ISnoArea area)
  65.         {
  66.             if (!newGame) return;
  67.  
  68.             lastPlayerCount = -1;
  69.         }
  70.  
  71.         private void DefineTable()
  72.         {
  73.             Table.Reset(true); // keep columns
  74.  
  75.             foreach (var player in Hud.Game.Players.OrderBy(p => p.PortraitIndex))
  76.             {
  77.                 if (player == null) continue;
  78.  
  79.                 Table.AddLine(
  80.                     new TopTableHeader(Hud, (pos, curPos) => "")
  81.                     {
  82.                         RatioWidth = 120 / 1080f,
  83.                         RatioHeight = 28 / 1080f,
  84.                         HighlightFunc = (pos, curPos) => hoveredPlayerIndex == pos,
  85.                         HighlightDecorator = new TopTableCellDecorator(Hud)
  86.                         {
  87.                             BackgroundBrush = Hud.Render.CreateBrush(96, 255, 255, 128, 0),
  88.                             BorderBrush = Hud.Render.CreateBrush(255, 70, 56, 42, 1.5f),
  89.                             TextFont = Hud.Render.CreateFont("tahoma", 7, 255, 0, 0, 0, true, false, false),
  90.                         },
  91.                         CellHighlightDecorator = new TopTableCellDecorator(Hud)
  92.                         {
  93.                             BackgroundBrush = Hud.Render.CreateBrush(96, 255, 0, 255, 0),
  94.                             BorderBrush = Hud.Render.CreateBrush(255, 70, 56, 42, 1.5f),
  95.                             TextFont = Hud.Render.CreateFont("tahoma", 7, 255, 255, 255, 255, true, false, true),
  96.                         },
  97.                     },
  98.                     new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  99.                     new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  100.                     new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  101.                     new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  102.                     new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  103.                     new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  104.                     new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  105.                     new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  106.                     new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  107.                     new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  108.                     new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  109.                     new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c))
  110.                     );
  111.             }
  112.         }
  113.  
  114.         private string GetCellText(int line, int column)
  115.         {
  116.             var player = Hud.Game.Players.FirstOrDefault(p => p.PortraitIndex == line);
  117.             if (player == null) return string.Empty;
  118.  
  119.  
  120.             switch (column)
  121.             {
  122.                 case 0:
  123.             return player.BattleTagAbovePortrait + IsZDPS(player);
  124.                 case 1:
  125.                     return ValueToString((long)player.Defense.EhpCur, ValueFormat.LongNumber);
  126.                 case 2:
  127.                     return ValueToString((long)player.Offense.SheetDps, ValueFormat.LongNumber) + " (" + ValueToString((long)((player.Offense.HighestElementalDamageBonus + 1) * (player.Offense.SheetDps)), ValueFormat.LongNumber) + ")";
  128.                 case 3:
  129.             return ValueToString((long)((player.Offense.BonusToElites + 1) * ((player.Offense.HighestElementalDamageBonus + 1) * (player.Offense.SheetDps))), ValueFormat.LongNumber);
  130.                 case 4:
  131.                     return player.Stats.MainStat.ToString();
  132.                 case 5:
  133.                     return player.Offense.AttackSpeed.ToString("F2", CultureInfo.InvariantCulture) + "/s";
  134.                 case 6:
  135.                     return player.Offense.CriticalHitChance.ToString("F2", CultureInfo.InvariantCulture) + "%";
  136.                 case 7:
  137.                     return player.Offense.CritDamage.ToString("F0", CultureInfo.InvariantCulture) + "%";
  138.                 case 8:
  139.                     return (player.Stats.CooldownReduction * 100).ToString("F1", CultureInfo.InvariantCulture) + "%";
  140.                 case 9:
  141.                     return (player.Stats.ResourceCostReduction * 100).ToString("F1", CultureInfo.InvariantCulture) + "%";
  142.                 case 10:
  143.                     return player.Offense.AreaDamageBonus.ToString() + "%";
  144.                 case 11:
  145.                     return player.HighestSoloRiftLevel.ToString();
  146.                 default:
  147.                     return string.Empty;
  148.             }
  149.         }
  150.  
  151.         private void DefineColumns()
  152.         {
  153.             Table.DefineColumns(
  154.                 new TopTableHeader(Hud, (pos, curPos) => "Player")
  155.                 {
  156.                     RatioHeight = 28 / 1080f,
  157.                     RatioWidth = 120 / 1080f,
  158.                 },
  159.                 new TopTableHeader(Hud, (pos, curPos) => "EHP")
  160.                 {
  161.                     RatioWidth = 0.065f,
  162.                 },
  163.                 new TopTableHeader(Hud, (pos, curPos) => "DPS (Elem)")
  164.                 {
  165.                     RatioWidth = 0.09f,
  166.                 },
  167.                 new TopTableHeader(Hud, (pos, curPos) => "Elite DPS")
  168.                 {
  169.                     RatioWidth = 0.07f,
  170.                 },
  171.                 new TopTableHeader(Hud, (pos, curPos) => "Main Stat")
  172.                 {
  173.                     RatioWidth = 0.07f,
  174.                 },
  175.                 new TopTableHeader(Hud, (pos, curPos) => "AS")
  176.                 {
  177.                     RatioWidth = 0.05f,
  178.                 },
  179.                 new TopTableHeader(Hud, (pos, curPos) => "CHC")
  180.                 {
  181.                     RatioWidth = 0.06f,
  182.                 },
  183.                 new TopTableHeader(Hud, (pos, curPos) => "CHD")
  184.                 {
  185.                     RatioWidth = 0.06f,
  186.                 },
  187.                 new TopTableHeader(Hud, (pos, curPos) => "CDR")
  188.                 {
  189.                     RatioWidth = 0.05f,
  190.                 },
  191.                 new TopTableHeader(Hud, (pos, curPos) => "RCR")
  192.                 {
  193.                     RatioWidth = 0.05f,
  194.                 },
  195.                 new TopTableHeader(Hud, (pos, curPos) => "AD")
  196.                 {
  197.                     RatioWidth = 0.05f,
  198.                 },
  199.                 new TopTableHeader(Hud, (pos, curPos) => "Solo GR")
  200.                 {
  201.                     RatioWidth = 0.06f,
  202.                 }
  203.             );
  204.         }
  205.  
  206.         public void PaintTopInGame(ClipState clipState)
  207.         {
  208.             if (clipState != ClipState.BeforeClip) return;
  209.             if (Hud.Inventory.StashMainUiElement.Visible) return;
  210.             var myPortrait = Hud.Game.Me.PortraitUiElement.Rectangle;
  211.             if (Hud.Window.CursorX > myPortrait.Right)
  212.             {
  213.                 lastPlayerCount = -1;
  214.                 return; // cursor is too much to the right, no need to go further
  215.             }
  216.  
  217.             if (lastPlayerCount != Hud.Game.Players.Count())
  218.             {
  219.                 lastPlayerCount = Hud.Game.Players.Count();
  220.                 DefineTable();
  221.                 return; // no need to lose more time within this frame
  222.             }
  223.  
  224.             var displayTable = false;
  225.             foreach (var player in Hud.Game.Players.OrderBy(p => p.PortraitIndex))
  226.             {
  227.                 if (player == null) continue;
  228.                 var portrait = player.PortraitUiElement.Rectangle;
  229.                 if (!Hud.Window.CursorInsideRect(portrait.X, portrait.Y, portrait.Width, portrait.Height)) continue;
  230.  
  231.                 hoveredPlayerIndex = (Hud.Game.NumberOfPlayersInGame > 1) ? player.PortraitIndex : -1;
  232.                 displayTable = true;
  233.             }
  234.  
  235.             if (displayTable && Table != null)
  236.                 Table.Paint();
  237.         }
  238.  
  239.         private string IsZDPS(IPlayer player) // Thanks to Resu
  240.         {
  241.          int Points = 0;
  242.          
  243.          var IllusoryBoots = player.Powers.GetBuff(318761);
  244.          if (IllusoryBoots == null || !IllusoryBoots.Active) {} else {Points++;}
  245.          
  246.          var LeoricsCrown = player.Powers.GetBuff(442353);
  247.          if (LeoricsCrown == null || !LeoricsCrown.Active) {} else {Points++;}
  248.          
  249.          var EfficaciousToxin = player.Powers.GetBuff(403461);
  250.          if (EfficaciousToxin == null || !EfficaciousToxin.Active) {} else {Points++;}
  251.          
  252.          var OculusRing = player.Powers.GetBuff(402461);
  253.          if (OculusRing == null || !OculusRing.Active) {} else {Points++;}
  254.          
  255.          var ZodiacRing = player.Powers.GetBuff(402459);
  256.          if (ZodiacRing == null || !ZodiacRing.Active) {} else {Points++;}
  257.          
  258.          if (player.Offense.SheetDps < 500000f) Points++;
  259.          if (player.Offense.SheetDps > 1500000f) Points--;
  260.          
  261.          if (player.Defense.EhpMax > 80000000f) Points++;
  262.          
  263.          var ConventionRing = player.Powers.GetBuff(430674);
  264.          if (ConventionRing == null || !ConventionRing.Active) {} else {Points--;}
  265.          
  266.          var Stricken = player.Powers.GetBuff(428348);
  267.          if (Stricken == null || !Stricken.Active) {} else {Points--;}
  268.          
  269.        
  270.         if (Points >= 4) { return " (Z)"; } else { return ""; }
  271.          
  272.         }
  273.  
  274. // End
  275.     }
  276. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement