Advertisement
jarppaaja

CheckMissingItems

Jun 15th, 2019
631
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 10.13 KB | None | 0 0
  1. // CheckMissingItems.cs "$Revision: 2578 $" "$Date: 2019-09-05 19:16:59 +0300 (to, 05 syys 2019) $"
  2. // https://www.ownedcore.com/forums/diablo-3/turbohud/turbohud-community-plugins/791893-intl-jarjar-checkmissingitems.html
  3. // https://pastebin.com/G66Ar9Xe
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using Turbo.Plugins.Default;
  7.  
  8. namespace Turbo.Plugins.JarJar.DefaultUI
  9. {
  10.     public class CheckMissingItems : BasePlugin, IInGameTopPainter
  11.     {
  12.         public string Title { get; set; } = "\uD83D\uDC80 Item Check \uD83D\uDC80";     // 💀 skull
  13.         public string Bullet { get; set; } = "\u25CF";                                  // ● black circle
  14.         public string Note { get; set; } = "\u24BE";                                    // Ⓘ circled latin capital letter i
  15.  
  16.         public string GemsWarningZero { get; set; } = "{0} You do not have any active gems equipped";
  17.         public string GemsWarning { get; set; } = "{0} You have only {1} active gem(s) equipped";
  18.         public string BrokenCrownWarning { get; set; } = "{0} Broken Crown is equipped";
  19.         public string FollowerWarning { get; set; } = "{0} Check follower items";
  20.  
  21.         public bool DoLegacyOfDreamsCheck { get; set; } = true;
  22.         public string LegacyOfDreamsOK { get; set; } = "{0} Legacy Of Dreams is active";
  23.         public string LegacyOfDreamsWarning { get; set; } = "{0} Legacy Of Dreams is NOT ACTIVE";
  24.  
  25.         public float OffsetX { get; set; } = 0.20f;     // Percent-X pos
  26.         public float OffsetY { get; set; } = 0.01f;     // Percent-Y pos
  27.  
  28.         public TopLabelWithTitleDecorator LabelDecorator { get; set; }
  29.  
  30.         public CheckMissingItems() { Enabled = true; }
  31.  
  32.         public override void Load(IController hud)
  33.         {
  34.             base.Load(hud);
  35.  
  36.             LabelDecorator = new TopLabelWithTitleDecorator(Hud)
  37.             {
  38.                 BorderBrush = Hud.Render.CreateBrush(255, 230, 30, 30, -1),
  39.                 BackgroundBrush = Hud.Render.CreateBrush(190, 0, 0, 0, 0),
  40.                 TextFont = Hud.Render.CreateFont("tahoma", 8, 255, 230, 30, 30, false, false, false),
  41.                 TitleFont = Hud.Render.CreateFont("tahoma", 10, 255, 255, 0, 0, true, false, false),
  42.             };
  43.         }
  44.  
  45.         public void PaintTopInGame(ClipState clipState)
  46.         {
  47.             var player = Hud.Game.Me;
  48.             if (player.IsDead || !player.HasValidActor)
  49.                 return;
  50.             if (player.CurrentLevelParagon == 0)
  51.                 return;     // Ignore player without paragon points.
  52.             if (player.CubedItems.Count() == 0)
  53.                 return;     // Ignore player without cubed items.
  54.  
  55.             if (Hud.Render.UiHidden)
  56.                 return;
  57.             if (clipState != ClipState.BeforeClip)
  58.                 return;
  59.             if ((Hud.Game.MapMode == MapMode.WaypointMap) || (Hud.Game.MapMode == MapMode.ActMap) || (Hud.Game.MapMode == MapMode.Map))
  60.                 return;
  61.             if (Hud.Inventory.HoveredItem != null)
  62.                 return;
  63.  
  64.             var textLines = new List<string>();
  65.  
  66.             // Check active gems.
  67.             var activeGems = ActiveGemPrimaryBuffs(player).Count();
  68.             if (activeGems < 3)
  69.             {
  70.                 var socketCount = getJewelryWithSockets().Count();
  71.                 if (socketCount > activeGems)
  72.                 {
  73.                     textLines.Add(string.Format(activeGems == 0 ? GemsWarningZero : GemsWarning, Bullet, activeGems));
  74.                     if (DoLegacyOfDreamsCheck && Hud.Game.NumberOfPlayersInGame == 1)
  75.                     {
  76.                         doLegacyOfDreamsCheck(player, textLines);
  77.                     }
  78.                 }
  79.             }
  80.             if (Hud.Game.NumberOfPlayersInGame == 1)
  81.             {
  82.                 // Broken Crown.
  83.                 foreach (var item in Hud.Game.Items.Where(x => x.Location == ItemLocation.Head))
  84.                 {
  85.                     if (item.SnoItem.NameEnglish == "Broken Crown")
  86.                     {
  87.                         textLines.Add(string.Format(BrokenCrownWarning, Bullet));
  88.                     }
  89.                 }
  90.                 // Follower shield and weapon.
  91.                 var followerItems = Hud.Game.Items.Count(x => x.Location == ItemLocation.Unknown1 || x.Location == ItemLocation.Unknown2);
  92.                 if (followerItems == 0)
  93.                 {
  94.                     textLines.Add(string.Format(FollowerWarning, Bullet));
  95.                 }
  96.             }
  97.             if (textLines.Count > 0)
  98.             {
  99.                 paint(textLines);
  100.             }
  101.         }
  102.  
  103.         private void doLegacyOfDreamsCheck(IPlayer player, List<string> textLines)
  104.         {
  105.             var ok = 0;
  106.             var warning = 1;
  107.             var result = isLegacyOfDreamsEquipped(player, ok, warning);
  108.             if (result == ok)
  109.             {
  110.                 textLines.Add(string.Format(LegacyOfDreamsOK, Note));
  111.             }
  112.             else if (result == warning)
  113.             {
  114.                 textLines.Add(string.Format(LegacyOfDreamsWarning, Bullet));
  115.             }
  116.         }
  117.  
  118.         private int isLegacyOfDreamsEquipped(IPlayer player, int ok, int warning)
  119.         {
  120.             var found = -1;
  121.             var equipped = -1;
  122.             var buff = player.Powers.UsedLegendaryGems.LegacyOfDreamsPrimary;
  123.             if (buff == null)
  124.             {
  125.                 if (isLegacyOfDreamsInSocket())
  126.                 {
  127.                     return warning;     // No buff - and is equipped.
  128.                 }
  129.                 countLegacyOfDreams(out found, out equipped);
  130.                 if (equipped > 0)
  131.                 {
  132.                     return warning;     // No buff - and equipped.
  133.                 }
  134.                 return -1;              // No buff - not equipped - ignored!
  135.             }
  136.             if (buff.Active)
  137.             {
  138.                 return ok;          // Buff is active - must be equipped!
  139.             }
  140.             if (isLegacyOfDreamsInSocket())
  141.             {
  142.                 return warning;     // Buff is passive - and equipped.
  143.             }
  144.             countLegacyOfDreams(out found, out equipped);
  145.             if (equipped > 0)
  146.             {
  147.                 return warning;     // Buff is passive - and equipped.
  148.             }
  149.             return -2;              // Buff is passive - not equipped - ignored!
  150.         }
  151.  
  152.         private bool isLegacyOfDreamsInSocket()
  153.         {
  154.             // Check if "Legacy of Dreams" gem is equipped in any jewelry socket - but not 100% reliable!
  155.             foreach (var item in getJewelryWithSockets())
  156.             {
  157.                 if (item.ItemsInSocket != null && item.ItemsInSocket.Length == 1 && item.ItemsInSocket[0].SnoItem.NameEnglish == "Legacy of Dreams")
  158.                 {
  159.                     return true;
  160.                 }
  161.             }
  162.             // Not found but this does not mean nothing as it can be equipped or not (due to a bug in THUD reading items in socket)!
  163.             return false;
  164.         }
  165.  
  166.         private void countLegacyOfDreams(out int found, out int equipped)
  167.         {
  168.             found = 0;
  169.             equipped = 0;
  170.             foreach (var item in Hud.Game.Items.Where(x => x.SnoItem.NameEnglish == "Legacy of Dreams"))
  171.             {
  172.                 if (item.Location == ItemLocation.InSocket)
  173.                 {
  174.                     equipped += 1;
  175.                 }
  176.                 else
  177.                 {
  178.                     found += 1;
  179.                 }
  180.             }
  181.         }
  182.  
  183.         private IEnumerable<IItem> getJewelryWithSockets()
  184.         {
  185.             return Hud.Game.Items.Where(x => x.Location >= ItemLocation.LeftRing && x.Location <= ItemLocation.Neck && x.SocketCount > 0);
  186.         }
  187.  
  188.         private void paint(List<string> lines)
  189.         {
  190.             var w = 0f;
  191.             var margin = 0f;
  192.             foreach (var line in lines)
  193.             {
  194.                 var layout = LabelDecorator.TextFont.GetTextLayout(line);
  195.                 if (w < layout.Metrics.Width)
  196.                 {
  197.                     w = layout.Metrics.Width;
  198.                 }
  199.                 if (margin == 0f)
  200.                 {
  201.                     margin = layout.Metrics.Height * 2f;
  202.                 }
  203.             }
  204.             var text = string.Join("\r\n", lines);
  205.             var h = LabelDecorator.TitleFont.GetTextLayout(Title).Metrics.Height + LabelDecorator.TextFont.GetTextLayout(text).Metrics.Height;
  206.             var x = Hud.Window.Size.Width * OffsetX;
  207.             var y = Hud.Window.Size.Height * OffsetY;
  208.             LabelDecorator.Paint(x, y, w + margin, h + margin, text, Title);
  209.         }
  210.  
  211.         private static IEnumerable<IBuff> ActiveGemPrimaryBuffs(IPlayer player)
  212.         {
  213.             var gems = player.Powers.UsedLegendaryGems;
  214.             var buffs = new IBuff[]
  215.             {
  216.                 gems.BaneOfThePowerfulPrimary,
  217.                 gems.BaneOfTheStrickenPrimary,
  218.                 gems.BaneOfTheTrappedPrimary,
  219.                 gems.BoonOfTheHoarderPrimary,
  220.                 gems.BoyarskysChipPrimary,
  221.                 gems.EnforcerPrimary,
  222.                 gems.EsotericAlterationPrimary,
  223.                 //gems.GemOfEasePrimary,            // Ignore in this context.
  224.                 gems.GemOfEfficaciousToxinPrimary,
  225.                 gems.GogokOfSwiftnessPrimary,
  226.                 gems.IceblinkPrimary,
  227.                 gems.InvigoratingGemstonePrimary,
  228.                 gems.LegacyOfDreamsPrimary,
  229.                 gems.MoltenWildebeestsGizzardPrimary,
  230.                 gems.MoratoriumPrimary,
  231.                 gems.MirinaeTeardropOfTheStarweaverPrimary,
  232.                 gems.MutilationGuardPrimary,
  233.                 gems.PainEnhancerPrimary,
  234.                 //gems.RedSoulShardPrimary,         // Ignore in this context.
  235.                 gems.SimplicitysStrengthPrimary,
  236.                 gems.TaegukPrimary,
  237.                 gems.WreathOfLightningPrimary,
  238.                 gems.ZeisStoneOfVengeancePrimary,
  239.             };
  240.             foreach (var buff in buffs)
  241.             {
  242.                 if (buff != null && buff.Active)
  243.                     yield return buff;
  244.             }
  245.         }
  246.     }
  247. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement