s4000

DAV_EliteInfoPlugin

Aug 31st, 2019 (edited)
5,375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 14.86 KB | None | 0 0
  1. // combined of elite bar, elite circle, health bar on elite, elite line, Zei Circle for Boss
  2. using System;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5. using System.Globalization;
  6. using Turbo.Plugins.Default;
  7.  
  8. namespace Turbo.Plugins.DavMonster
  9. {
  10.     public class DAV_EliteInfoPlugin : BasePlugin, IInGameWorldPainter, ICustomizer {
  11.         public float XPos { get; set; }
  12.         public float YPos { get; set; }
  13.         public float offsetZ { get; set; } = 0f;
  14.         public bool showDebuff_CC { get; set; } = true;
  15.         public bool showCurse { get; set; } = true;
  16.         public WorldDecoratorCollection ZeiDecorator { get; set; }
  17.         public DAV_EliteInfo Elite_Boss { get; set; }
  18.         public DAV_EliteInfo Elite_Null { get; set; }
  19.         public DAV_EliteInfo Elite_Rare { get; set; }
  20.         public DAV_EliteInfo Elite_Judd { get; set; }
  21.         public Dictionary<int, DAV_EliteInfo> Elite_Blue { get; set; } = new Dictionary<int, DAV_EliteInfo>();
  22.         public Dictionary<string, IFont> Affix_Font { get; set; } = new Dictionary<string, IFont>();
  23.         public Dictionary<MonsterAffix, Tuple<int, string, string>> DisplayAffix { get; set; } = new Dictionary<MonsterAffix, Tuple<int, string, string>>();
  24.  
  25.         public DAV_EliteInfoPlugin() {
  26.             Enabled = true;
  27.             Order = 2005;
  28.         }
  29.  
  30.         public override void Load(IController hud) {
  31.             base.Load(hud);
  32.  
  33.             XPos = 1920 * 0.2f; // Hud.Window.Size.Width
  34.             YPos = 1080 * 0.005f; // Hud.Window.Size.Height
  35.  
  36.             //Colorization
  37.             Elite_Boss = new DAV_EliteInfo(Hud, 153, 51, 255);
  38.             Elite_Null = new DAV_EliteInfo(Hud, 178, 102, 255);
  39.             Elite_Rare = new DAV_EliteInfo(Hud, 255, 153, 51);
  40.             Elite_Judd = new DAV_EliteInfo(Hud, 255, 51, 51);
  41.             Elite_Blue.Add(1, new DAV_EliteInfo(Hud, 51, 153, 255));
  42.             Elite_Blue.Add(2, new DAV_EliteInfo(Hud, 0, 204, 0));
  43.             Elite_Blue.Add(3, new DAV_EliteInfo(Hud, 154, 205, 50));
  44.             Elite_Blue.Add(4, new DAV_EliteInfo(Hud, 255, 153, 204));
  45.             Elite_Blue.Add(5, new DAV_EliteInfo(Hud, 96, 96, 96));
  46.  
  47.             ZeiDecorator = new WorldDecoratorCollection(
  48.                 new GroundCircleDecorator(Hud) {
  49.                     Brush = Hud.Render.CreateBrush(255,192,96,0, 1),
  50.                     Radius = 50f
  51.                 }
  52.             );
  53.  
  54.             Affix_Font.Add("Normal", Hud.Render.CreateFont("arial", 6, 255, 240, 240, 240, false, false, true));
  55.             Affix_Font.Add("Lightning", Hud.Render.CreateFont("arial", 6, 255, 240, 240, 0, false, false, true));
  56.             Affix_Font.Add("Fire", Hud.Render.CreateFont("arial", 6, 255, 255, 70, 0, false, false, true));
  57.             Affix_Font.Add("Arcane", Hud.Render.CreateFont("arial", 6, 255, 140, 45, 225, false, false, true));
  58.             Affix_Font.Add("Cold", Hud.Render.CreateFont("arial", 6, 255, 0, 190, 255, false, false, true));
  59.             Affix_Font.Add("Poison", Hud.Render.CreateFont("arial", 6, 255, 128, 255, 0, false, false, true));
  60.             Affix_Font.Add("Danger", Hud.Render.CreateFont("arial", 6, 255, 255, 128, 0, false, false, true));
  61.  
  62.             DisplayAffix.Add(MonsterAffix.Wormhole, new Tuple<int, string, string>(1, "蟲洞", "Danger"));
  63.             DisplayAffix.Add(MonsterAffix.Juggernaut, new Tuple<int, string, string>(2, "強韌", "Danger"));
  64.             DisplayAffix.Add(MonsterAffix.Waller, new Tuple<int, string, string>(3, "築牆", "Danger"));
  65.             DisplayAffix.Add(MonsterAffix.Teleporter, new Tuple<int, string, string>(4, "傳送", "Danger"));
  66.             DisplayAffix.Add(MonsterAffix.Shielding, new Tuple<int, string, string>(5, "護盾", "Danger"));
  67.             DisplayAffix.Add(MonsterAffix.Illusionist, new Tuple<int, string, string>(6, "幻像", "Danger"));
  68.             DisplayAffix.Add(MonsterAffix.Electrified, new Tuple<int, string, string>(7, "帶電", "Lightning"));
  69.             DisplayAffix.Add(MonsterAffix.Orbiter, new Tuple<int, string, string>(8, "電球", "Lightning"));
  70.             DisplayAffix.Add(MonsterAffix.Thunderstorm, new Tuple<int, string, string>(9, "雷霆風暴", "Lightning"));
  71.             DisplayAffix.Add(MonsterAffix.FireChains, new Tuple<int, string, string>(10, "火鏈", "Fire"));
  72.             DisplayAffix.Add(MonsterAffix.Desecrator, new Tuple<int, string, string>(11, "褻瀆", "Fire"));
  73.             DisplayAffix.Add(MonsterAffix.Molten, new Tuple<int, string, string>(12, "熔火", "Fire"));
  74.             DisplayAffix.Add(MonsterAffix.Mortar, new Tuple<int, string, string>(13, "炮轟", "Fire"));
  75.             DisplayAffix.Add(MonsterAffix.FrozenPulse, new Tuple<int, string, string>(14, "冰凍衝擊", "Cold"));
  76.             DisplayAffix.Add(MonsterAffix.Frozen, new Tuple<int, string, string>(15, "凍結", "Cold"));
  77.             DisplayAffix.Add(MonsterAffix.Arcane, new Tuple<int, string, string>(16, "秘法", "Arcane"));
  78.             DisplayAffix.Add(MonsterAffix.Jailer, new Tuple<int, string, string>(17, "囚禁", "Arcane"));
  79.             DisplayAffix.Add(MonsterAffix.Plagued, new Tuple<int, string, string>(18, "瘟疫", "Poison"));
  80.             DisplayAffix.Add(MonsterAffix.Poison, new Tuple<int, string, string>(19, "毒素加持", "Poison"));
  81.             DisplayAffix.Add(MonsterAffix.Horde, new Tuple<int, string, string>(20, "族群", "Normal"));
  82.             DisplayAffix.Add(MonsterAffix.MissileDampening, new Tuple<int, string, string>(21, "投射抑制", "Normal"));
  83.             DisplayAffix.Add(MonsterAffix.ExtraHealth, new Tuple<int, string, string>(22, "強命", "Normal"));
  84.             DisplayAffix.Add(MonsterAffix.Fast, new Tuple<int, string, string>(23, "快速", "Normal"));
  85.             DisplayAffix.Add(MonsterAffix.Vampiric, new Tuple<int, string, string>(24, "吸血", "Normal"));
  86.             DisplayAffix.Add(MonsterAffix.Knockback, new Tuple<int, string, string>(25, "擊退", "Normal"));
  87.             DisplayAffix.Add(MonsterAffix.Nightmarish, new Tuple<int, string, string>(26, "夢魘", "Normal"));
  88.             DisplayAffix.Add(MonsterAffix.Vortex, new Tuple<int, string, string>(27, "漩渦", "Normal"));
  89.             DisplayAffix.Add(MonsterAffix.Avenger, new Tuple<int, string, string>(28, "復仇者", "Normal"));
  90.             DisplayAffix.Add(MonsterAffix.Reflect, new Tuple<int, string, string>(29, "傷害反彈", "Normal"));
  91.             DisplayAffix.Add(MonsterAffix.HealthLink, new Tuple<int, string, string>(30, "生命鏈接", "Normal"));
  92.             DisplayAffix.Add(MonsterAffix.Enervating, new Tuple<int, string, string>(999, "Enervating", "Normal"));
  93.             DisplayAffix.Add(MonsterAffix.Necrotic, new Tuple<int, string, string>(999, "Necrotic", "Normal"));
  94.         }
  95.  
  96.         public void PaintWorld(WorldLayer layer) {
  97.             var packs = Hud.Game.MonsterPacks.Where(x => x.MonstersAlive.Any()).OrderBy(m => m.IsFullChampionPack);
  98.             var bosses = Hud.Game.AliveMonsters.Where(m => (m.Rarity == ActorRarity.Boss || m.Rarity == ActorRarity.Unique) && m.SummonerAcdDynamicId == 0);
  99.             var nullpacks = Hud.Game.AliveMonsters.Where(m => (m.Rarity == ActorRarity.Champion || m.Rarity == ActorRarity.Rare) && m.SummonerAcdDynamicId == 0 && m.Pack == null);
  100.  
  101.             float yref = YPos;
  102.             foreach(IMonster m in bosses) {
  103.                 Elite_Boss.DrawInfo(layer, m, XPos, ref yref, offsetZ, showDebuff_CC, showCurse);
  104.                 yref += 0.2f;
  105.                 if (Hud.Game.Me.Powers.BuffIsActive(403468, 0))
  106.                     ZeiDecorator.Paint(layer, m, m.FloorCoordinate, null);
  107.             }
  108.  
  109.             foreach(IMonster nullpack in nullpacks) {
  110.                 if (nullpack.Rarity == ActorRarity.Rare)
  111.                     Elite_Rare.DrawInfo(layer, nullpack, XPos, ref yref, offsetZ, showDebuff_CC, showCurse);
  112.                 else Elite_Null.DrawInfo(layer, nullpack, XPos, ref yref, offsetZ, showDebuff_CC, showCurse);
  113.                 yref += 0.4f;
  114.             }
  115.  
  116.             var blueNum = 1;
  117.             foreach(IMonsterPack MonPack in packs){
  118.                 var monsters = MonPack.MonstersAlive.Where(m => m.Rarity != ActorRarity.RareMinion && m.SummonerAcdDynamicId == 0).OrderBy(p => p.CurHealth);
  119.                 if (monsters.Count() == 0) continue;
  120.  
  121.                 // Elite Affix
  122.                 var aff_x = XPos;
  123.                 float aff_h = 0f;
  124.                 var PackAffix = MonPack.AffixSnoList.ToList();
  125.                 PackAffix.Sort((a, b) => (DisplayAffix[a.Affix].Item1).CompareTo(DisplayAffix[b.Affix].Item1));
  126.  
  127.                 foreach(var affix in PackAffix) {
  128.                     var affixInfo = DisplayAffix[affix.Affix];
  129.                     var AffixFont = Affix_Font[affixInfo.Item3];
  130.                     var custname = AffixFont.GetTextLayout(affixInfo.Item2);
  131.                     AffixFont.DrawText(custname, aff_x, yref);
  132.                     aff_x += (float) custname.Metrics.Width + 5;
  133.                     aff_h = (float) custname.Metrics.Height;
  134.                 }
  135.                 yref += aff_h;
  136.  
  137.                 DAV_EliteInfo ColorInfo = null;
  138.                 if (MonPack.IsFullChampionPack) {
  139.                     ColorInfo = Elite_Blue[blueNum];
  140.  
  141.                     if (blueNum < Elite_Blue.Count)
  142.                         blueNum++;
  143.                 }
  144.                 else if (MonPack.AffixSnoList.Any(a => a.Affix == MonsterAffix.Juggernaut))
  145.                     ColorInfo = Elite_Judd;
  146.                 else
  147.                     ColorInfo = Elite_Rare;
  148.  
  149.                 foreach(var monster in monsters)
  150.                     ColorInfo.DrawInfo(layer, monster, XPos, ref yref, offsetZ, showDebuff_CC, showCurse);
  151.  
  152.                 yref += 0.2f;
  153.             }
  154.         }
  155.  
  156.         public void Customize() {
  157.             Hud.RunOnPlugin<StandardMonsterPlugin>(plugin => {
  158.                 plugin.EliteChampionDecorator.Enabled = false;
  159.                 plugin.EliteLeaderDecorator.Enabled = false;
  160.                 plugin.EliteMinionDecorator.Enabled = false;
  161.                 plugin.EliteUniqueDecorator.Enabled = false;
  162.                 plugin.KeywardenDecorator.Enabled = false;
  163.             });
  164.         }
  165.     }
  166.  
  167.     public class DAV_EliteInfo {
  168.         public bool Enabled { get; set; }
  169.         public IController Hud { get; set; }
  170.  
  171.         public float barH { get; set; }
  172.         public float barW { get; set; }
  173.         public float barHmon { get; set; }
  174.         public float barWmon { get; set; }
  175.         public float distance { get; set; }
  176.         public IBrush Brush_BG { get; set; }
  177.         public IBrush Brush_Border { get; set; }
  178.         public IBrush Brush_Health { get; set; }
  179.         public IBrush Brush_Line { get; set; }
  180.         public IBrush Brush_Invulnerable { get; set; }
  181.         public IFont Font_White { get; set; }
  182.         public IFont Font_Mon { get; set; }
  183.         public WorldDecoratorCollection EliteDecorator { get; set; }
  184.  
  185.         public DAV_EliteInfo(IController hud, int r, int g, int b, float Monsize = 3f, float dist = 45f) {
  186.             Enabled = true;
  187.             Hud = hud;
  188.  
  189.             barH = 1080 * 0.012f; // Hud.Window.Size.Height
  190.             barW = 1920 * 0.110f; // Hud.Window.Size.Width
  191.             barHmon = barH * 1.6f; // 1.4f
  192.             barWmon = barW * 0.35f;
  193.             distance = dist;
  194.             Font_White = Hud.Render.CreateFont("tahoma", 6, 255, 255, 255, 255, false, false, false); //255, 255, 255, 255, true);
  195.             Font_Mon = Hud.Render.CreateFont("tahoma", 8f, 200, 255, 255, 255, false, false, true);
  196.             Brush_BG = Hud.Render.CreateBrush(255, 125, 120, 120, 0);
  197.             Brush_Border = Hud.Render.CreateBrush(255, 255, 255, 255, -1);
  198.             Brush_Health = Hud.Render.CreateBrush(255, r, g, b, 0);
  199.             Brush_Line = Hud.Render.CreateBrush(153, r, g, b, -1);
  200.             Brush_Invulnerable = Hud.Render.CreateBrush(255, 255, 0, 0, 3);
  201.  
  202.             EliteDecorator = new WorldDecoratorCollection(
  203.                 new MapShapeDecorator(Hud) {
  204.                     Brush = Hud.Render.CreateBrush(180, r, g, b, 0),
  205.                     Radius = 8,
  206.                     ShapePainter = new CircleShapePainter(Hud)
  207.                 },
  208.                 new GroundCircleDecorator(Hud) {
  209.                     Brush = Hud.Render.CreateBrush(255, r, g, b, 6),
  210.                     Radius = Monsize
  211.                 },
  212.                 new GroundCircleDecorator(Hud) {
  213.                     Brush = Hud.Render.CreateBrush(255, 255, 255, 255, 1.5f),
  214.                     Radius = Monsize
  215.                 }
  216.             );
  217.         }
  218.  
  219.         private string Debuff(IMonster m, bool showDebuff) {
  220.             if (!showDebuff) return "";
  221.            
  222.             string textDebuff = null;
  223.             if (m.Locust) textDebuff += "Locust";
  224.             if (m.Haunted) textDebuff += (textDebuff == null ? "Haunt" : ", Haunt");
  225.             if (m.Palmed) textDebuff += (textDebuff == null ? "Palm" : ", Palm");
  226.             if (m.MarkedForDeath) textDebuff += (textDebuff == null ? "Mark" : ", Mark");
  227.             if (m.Strongarmed) textDebuff += (textDebuff == null ? "Strongarm" : ", Strongarm");
  228.            
  229.             string textCC = null;
  230.             if (m.Frozen) textCC += "Frozen";
  231.             if (m.Chilled) textCC += (textCC == null ? "Chill" : ", Chill");
  232.             if (m.Slow) textCC += (textCC == null ? "Slow" : ", Slow");
  233.             if (m.Stunned) textCC += (textCC == null ? "Stun" : ", Stun");
  234.             if (m.Invulnerable) textCC += (textCC == null ? "Invulnerable" : ", Invulnerable");
  235.             if (m.Blind) textCC += (textCC == null ? "Blind" : ", Blind");
  236.            
  237.             var output = "\t" + textDebuff + (textDebuff != null && textCC != null ? " | " : "") + textCC;
  238.             return output;
  239.         }
  240.        
  241.         private string Curse(IMonster m) {
  242.             string Curses = "";
  243.             if (m.GetAttributeValue(Hud.Sno.Attributes.Power_Buff_2_Visual_Effect_None, 471845) == 1) //471845 1 power: Frailty
  244.                 Curses += "F";
  245.             if (m.GetAttributeValue(Hud.Sno.Attributes.Power_Buff_2_Visual_Effect_None, 471869) == 1)  //471869 1 power: Leech
  246.                 Curses += (Curses == "" ? "L" : " L");
  247.             if (m.GetAttributeValue(Hud.Sno.Attributes.Power_Buff_2_Visual_Effect_None, 471738) == 1) //471738 1 power: Decrepify
  248.                 Curses += (Curses == "" ? "D" : " D");
  249.            
  250.             return Curses;
  251.         }
  252.        
  253.         public void DrawInfo(WorldLayer layer, IMonster monster, float Pos_X, ref float Pos_Y, float offset, bool showDebuff, bool showCurse){
  254.             EliteDecorator.Paint(layer, monster, monster.FloorCoordinate, monster.SnoMonster.NameLocalized);
  255.  
  256.             if (monster.CentralXyDistanceToMe >= distance)
  257.                 Brush_Line.DrawLineWorld(monster.FloorCoordinate, Hud.Game.Me.FloorCoordinate);
  258.  
  259.             var CurPercent = monster.CurHealth / monster.MaxHealth;
  260.             if (CurPercent < 0 || CurPercent > 1)
  261.                 CurPercent = 1;
  262.  
  263.             //Draw Rectangles
  264.             Brush_BG.DrawRectangle(Pos_X, Pos_Y, barW, barH);
  265.             Brush_Health.DrawRectangle(Pos_X, Pos_Y, (float) CurPercent * barW, barH);
  266.         //  Brush_Border.DrawRectangle(Pos_X, Pos_Y, barW, barH); // white border for bar on screen
  267.  
  268.             var name = Font_White.GetTextLayout(monster.SnoMonster.NameLocalized);
  269.             Font_White.DrawText(name, Pos_X + 3, Pos_Y + (barH - (float)name.Metrics.Height)/2);
  270.  
  271.             var HPtext = (CurPercent * 100).ToString("0.0") + "%";
  272.             var textLayout = Font_White.GetTextLayout(HPtext + Debuff(monster, showDebuff));
  273.             Font_White.DrawText(textLayout, Pos_X + barW + 4 , Pos_Y + (barH - (float)textLayout.Metrics.Height)/2);
  274.            
  275.             if (showCurse) {
  276.                 var curseInfo = Curse(monster);
  277.                 textLayout = Font_White.GetTextLayout(curseInfo);
  278.                 Font_White.DrawText(textLayout, Pos_X + barW - textLayout.Metrics.Width - 6, Pos_Y + (barH - (float)textLayout.Metrics.Height)/2);
  279.             }
  280.  
  281.             if (monster.IsOnScreen){
  282.                 var Mon_X = monster.FloorCoordinate.ToScreenCoordinate().X - barWmon / 2;
  283.                 var Mon_Y = monster.FloorCoordinate.ToScreenCoordinate().Y + barHmon + offset;
  284.                 // var Mon_X = monster.FloorCoordinate.ToScreenCoordinate(true, true).X - barWmon / 2;
  285.                 // var Mon_Y = monster.FloorCoordinate.ToScreenCoordinate(true, true).Y + barHmon + offset;
  286.                 // var Mon_X = monster.ScreenCoordinate.X - barWmon / 2;
  287.                 // var Mon_Y = monster.ScreenCoordinate.Y + barHmon + offset;
  288.  
  289.                 Brush_BG.DrawRectangle(Mon_X, Mon_Y, barWmon, barHmon);
  290.                 Brush_Health.DrawRectangle(Mon_X, Mon_Y, (float) CurPercent * barWmon, barHmon);
  291.                 if (monster.Invulnerable) Brush_Invulnerable.DrawRectangle(Mon_X, Mon_Y, barWmon, barHmon);
  292.                 else Brush_Border.DrawRectangle(Mon_X, Mon_Y, barWmon, barHmon);
  293.  
  294.                 var textLayout2 = Font_Mon.GetTextLayout(HPtext);
  295.                 Font_Mon.DrawText(HPtext, Mon_X + (barWmon - textLayout2.Metrics.Width)/2 , Mon_Y + (barHmon - textLayout2.Metrics.Height)/2);
  296.             }
  297.             else {
  298.                 var missing = Font_White.GetTextLayout("X");
  299.                 Font_White.DrawText(missing, Pos_X - 17, Pos_Y + (barH - missing.Metrics.Height)/2);
  300.             }
  301.  
  302.             Pos_Y += barH * 1.1f; // * 1.3f;
  303.         }
  304.     }
  305. }
Advertisement
Add Comment
Please, Sign In to add comment