Advertisement
HaKache

PortraitInfosPlugin

Aug 30th, 2019
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.97 KB | None | 0 0
  1. // PortraitInfosPlugin
  2. // Plugin version of XML portraits Template (DPS meter, EHP Bar, Tracker). Adds a hint for support players (zDPS).
  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;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using Turbo.Plugins.Default;
  10.  
  11. namespace Turbo.Plugins.Extended.Addons
  12. {
  13.     public class PortraitInfosPlugin : BasePlugin, IInGameTopPainter
  14.     {
  15.     public TopLabelDecorator PortraitStats1Decorator { get; set; }
  16.     public TopLabelDecorator PortraitStats2Decorator { get; set; }
  17.     public TopLabelDecorator PortraitStats3Decorator { get; set; }
  18.     public TopLabelDecorator SupportHintDecorator { get; set; }
  19.     public IFont TrackerFont { get; set; }
  20.     public TopLabelDecorator EhpBarDecorator { get; set; }
  21.     public TopLabelDecorator EhpBarFillDecorator { get; set; }
  22.  
  23.     public bool EnableDamageMeter { get; set; }
  24.     public bool EnableToughnessBar { get; set; }
  25.     public bool EnableTrackerHint { get; set; }
  26.     public bool EnableSupportHint { get; set; }
  27.  
  28.     public PortraitInfosPlugin()
  29.     {
  30.         Enabled = true;
  31.         Order = 40000;
  32.  
  33.         EnableDamageMeter = true;
  34.         EnableToughnessBar = true;
  35.         EnableTrackerHint = true;
  36.         EnableSupportHint = true;
  37.     }
  38.  
  39.     public override void Load(IController hud)
  40.     {
  41.         base.Load(hud);
  42.  
  43.         TrackerFont = Hud.Render.CreateFont("tahoma", 6, 255, 255, 200, 0, true, false, 192, 0, 0, 0, true);
  44.  
  45.             PortraitStats1Decorator = new TopLabelDecorator(Hud)
  46.             {
  47.                 TextFont = Hud.Render.CreateFont("tahoma", 6, 255, 0, 220, 255, true, false, 192, 0, 0, 0, true),
  48.                 TextFunc = () => ValueToString(Hud.Game.Me.Damage.CurrentDps, ValueFormat.LongNumber),
  49.                 HintFunc = () => "Current DPS",
  50.             };
  51.             PortraitStats2Decorator = new TopLabelDecorator(Hud)
  52.             {
  53.                 TextFont = Hud.Render.CreateFont("tahoma", 6, 255, 0, 220, 255, true, false, 192, 0, 0, 0, true),
  54.                 TextFunc = () => ValueToString(Hud.Game.Me.Damage.RunDps, ValueFormat.LongNumber),
  55.                 HintFunc = () => "Run DPS",
  56.             };
  57.             PortraitStats3Decorator = new TopLabelDecorator(Hud)
  58.             {
  59.                 TextFont = Hud.Render.CreateFont("tahoma", 6, 255, 255, 220, 0, true, false, 192, 0, 0, 0, true),
  60.                 TextFunc = () => ValueToString(Hud.Game.Me.Damage.TotalDamage, ValueFormat.LongNumber),
  61.                 HintFunc = () => "Total Damage",
  62.             };
  63.  
  64.             SupportHintDecorator = new TopLabelDecorator(Hud)
  65.             {
  66.                 TextFont = Hud.Render.CreateFont("tahoma", 8, 255, 255, 120, 0, true, false, 192, 0, 0, 0, true),
  67.                 TextFunc = () => "Z",
  68.             };
  69.  
  70.             EhpBarDecorator = new TopLabelDecorator(Hud)
  71.             {
  72.         BackgroundBrush = Hud.Render.CreateBrush(255, 75, 75, 75, 0),
  73.                 TextFont = Hud.Render.CreateFont("tahoma", 6, 255, 255, 220, 0, true, false, 192, 0, 0, 0, true),
  74.                 HintFunc = () => "Effective Toughness",
  75.             };
  76.             EhpBarFillDecorator = new TopLabelDecorator(Hud)
  77.             {
  78.         BackgroundBrush = Hud.Render.CreateBrush(255, 25, 130, 25, 0),
  79.                 TextFont = Hud.Render.CreateFont("tahoma", 6, 255, 255, 220, 0, true, false, 192, 0, 0, 0, true),
  80.             };
  81.         }
  82.  
  83.         public void PaintTopInGame(ClipState clipState)
  84.         {
  85.             if (Hud.Render.UiHidden) return;
  86.             if (clipState != ClipState.BeforeClip) return;
  87.             if (Hud.Game.Me.PortraitUiElement.Rectangle == null) return;
  88.             if ((Hud.Game.MapMode == MapMode.WaypointMap) || (Hud.Game.MapMode == MapMode.ActMap) || (Hud.Game.MapMode == MapMode.Map)) return;
  89.  
  90.     // Damage Meter on your personal portrait
  91.         if (EnableDamageMeter)
  92.         {
  93.             var uiRect = Hud.Game.Me.PortraitUiElement.Rectangle;
  94.  
  95.             PortraitStats1Decorator.Paint(uiRect.Left + uiRect.Width * 0.35f, uiRect.Top + uiRect.Height * 0.44f, uiRect.Width * 0.48f, uiRect.Height * 0.14f, HorizontalAlign.Right);
  96.             PortraitStats2Decorator.Paint(uiRect.Left + uiRect.Width * 0.35f, uiRect.Top + uiRect.Height * 0.525f, uiRect.Width * 0.48f, uiRect.Height * 0.14f, HorizontalAlign.Right);
  97.             PortraitStats3Decorator.Paint(uiRect.Left + uiRect.Width * 0.35f, uiRect.Top + uiRect.Height * 0.61f, uiRect.Width * 0.48f, uiRect.Height * 0.14f, HorizontalAlign.Right);
  98.         }
  99.  
  100.         var CalcEhp = Hud.Game.Players.OrderByDescending(x => x.Defense.EhpMax).First().Defense.EhpMax.ToString();
  101.         var BestEhp = float.Parse(CalcEhp);
  102.  
  103.               foreach (var player in Hud.Game.Players.OrderBy(p => p.PortraitIndex))
  104.               {
  105.  
  106.             var portRect = player.PortraitUiElement.Rectangle;
  107.         var EhpMax = player.Defense.EhpMax;
  108.         var EhpHeight = portRect.Height * 0.727f;
  109.  
  110.     // Player is a Support (zDPS)
  111.         if (EnableSupportHint && IsZDPS(player))
  112.         {
  113.             SupportHintDecorator.Paint(portRect.Left + portRect.Width * 0.12f, portRect.Top + portRect.Height * 0.58f, portRect.Width * 0.48f, portRect.Height * 0.14f, HorizontalAlign.Left);
  114.         }
  115.  
  116.  
  117.     // Players Actions & Position Tracker
  118.         if (EnableTrackerHint)
  119.         {
  120.         if (player.GetAttributeValue(Hud.Sno.Attributes.Power_Buff_0_Visual_Effect_None, 259848) == 1 && player.SnoArea == Hud.Game.Me.SnoArea && player.CoordinateKnown) {
  121.         var zone = " Identifying a legendary... ";
  122.         var layout = TrackerFont.GetTextLayout(zone);
  123.         TrackerFont.DrawText(layout, portRect.Right + portRect.Width * 0.02f, portRect.Top + portRect.Height * 0.712f);
  124.                     }
  125.  
  126.         if (player.GetAttributeValue(Hud.Sno.Attributes.Power_Buff_0_Visual_Effect_None, 293981) == 1 && player.SnoArea == Hud.Game.Me.SnoArea && player.CoordinateKnown) {
  127.         var zone = " Identifying legendaries... ";
  128.         var layout = TrackerFont.GetTextLayout(zone);
  129.         TrackerFont.DrawText(layout, portRect.Right + portRect.Width * 0.02f, portRect.Top + portRect.Height * 0.712f);
  130.                     }
  131.  
  132.         if (player.AnimationState == AcdAnimationState.CastingPortal && player.SnoArea == Hud.Game.Me.SnoArea && player.CoordinateKnown) {
  133.         var zone = " Teleporting... ";
  134.         var layout = TrackerFont.GetTextLayout(zone);
  135.         TrackerFont.DrawText(layout, portRect.Right + portRect.Width * 0.02f, portRect.Top + portRect.Height * 0.712f);
  136.                     }
  137.  
  138.         if (!player.IsMe && player.SnoArea != Hud.Game.Me.SnoArea) {
  139.         var zone = " [" + player.SnoArea.NameLocalized + "] ";
  140.         var layout = TrackerFont.GetTextLayout(zone);
  141.         TrackerFont.DrawText(layout, portRect.Right + portRect.Width * 0.02f, portRect.Top + portRect.Height * 0.712f);
  142.                     }
  143.        
  144.         }
  145.  
  146.     // Players EHP Bar
  147.         if (EnableToughnessBar)
  148.         {
  149.         if (Hud.Game.NumberOfPlayersInGame == 1) return;
  150.  
  151.         if (player.SnoArea == Hud.Game.Me.SnoArea)
  152.         {
  153.             EhpBarDecorator.Paint(portRect.Left - portRect.Width * 0.14f, portRect.Top + portRect.Height * 0.1f, portRect.Width * 0.05f, EhpHeight, HorizontalAlign.Left);
  154.  
  155.         if (EhpMax == BestEhp)
  156.         {
  157.         var Ehp = EhpMax;
  158.                 EhpBarFillDecorator.Paint(portRect.Left - portRect.Width * 0.14f, portRect.Top + portRect.Height * 0.1f, portRect.Width * 0.05f, EhpHeight, HorizontalAlign.Left);
  159.         }
  160.         else
  161.         {
  162.         var Ehp = (EhpMax / BestEhp);
  163.                 EhpBarFillDecorator.Paint(portRect.Left - portRect.Width * 0.14f, portRect.Top + portRect.Height * 0.1f + (EhpHeight * (1 - Ehp)), portRect.Width * 0.05f, EhpHeight * Ehp, HorizontalAlign.Left);
  164.         }
  165.         }
  166.         }
  167.  
  168. // End Loop Player
  169.         }
  170.         }
  171.  
  172.     // ZDPS Tracker - Thanks to Resu
  173.         private bool IsZDPS(IPlayer player)
  174.         {
  175.          int Points = 0;
  176.          
  177.          var IllusoryBoots = player.Powers.GetBuff(318761);
  178.          if (IllusoryBoots == null || !IllusoryBoots.Active) {} else {Points++;}
  179.          
  180.          var LeoricsCrown = player.Powers.GetBuff(442353);
  181.          if (LeoricsCrown == null || !LeoricsCrown.Active) {} else {Points++;}
  182.          
  183.          var EfficaciousToxin = player.Powers.GetBuff(403461);
  184.          if (EfficaciousToxin == null || !EfficaciousToxin.Active) {} else {Points++;}
  185.          
  186.          var OculusRing = player.Powers.GetBuff(402461);
  187.          if (OculusRing == null || !OculusRing.Active) {} else {Points++;}
  188.          
  189.          var ZodiacRing = player.Powers.GetBuff(402459);
  190.          if (ZodiacRing == null || !ZodiacRing.Active) {} else {Points++;}
  191.          
  192.          if (player.Offense.SheetDps < 500000f) Points++;
  193.          if (player.Offense.SheetDps > 1500000f) Points--;
  194.          
  195.          if (player.Defense.EhpMax > 80000000f) Points++;
  196.          
  197.          var ConventionRing = player.Powers.GetBuff(430674);
  198.          if (ConventionRing == null || !ConventionRing.Active) {} else {Points--;}
  199.          
  200.          var Stricken = player.Powers.GetBuff(428348);
  201.          if (Stricken == null || !Stricken.Active) {} else {Points--;}
  202.        
  203.         if (Points >= 4) { return true; } else { return false; }
  204.          
  205.         }
  206.  
  207.     }
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement