Advertisement
jarppaaja

ImportantItems rev 931

Feb 2nd, 2019
472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 14.11 KB | None | 0 0
  1. // ImportantItems.cs "$Revision: 931 $" "$Date: 2019-02-02 12:40:48 +0200 (la, 02 helmi 2019) $"
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Turbo.Plugins.Default;
  5.  
  6. namespace Turbo.Plugins.JarJar.DefaultUI
  7. {
  8.     public class ImportantItems : BasePlugin, ICustomizer, IInGameTopPainter
  9.     {
  10.         public string ShowEquippedItemsChar { get; set; } = BC;         // Override equipped items marker - set null to disable!
  11.         public string MultiMatchIndicator { get; set; } = CAPI;         // Indicator for multiple item matches, font is hard coded!
  12.         public bool CheckItemRank { get; set; } = true;                 // Check item rank.
  13.         public string HigherRankIndicator { get; set; } = RE;           // Indicator for items that have higher ranked items elsewhere.
  14.  
  15.         // These must be compile time constants for our item table.
  16.  
  17.         const string BC = "\u25CF";             // black circle
  18.         const string RE = "\u267A";             // recycling symbol
  19.         const string FO = "\uD83D\uDEE1";       // shield
  20.         const string CAPI = "\u24BE";           // circled latin capital letter i
  21.  
  22.         const string C1 = "\u2460";             // circled digit one
  23.         const string C2 = "\u2461";             // circled digit two
  24.         const string C3 = "\u2462";             // circled digit three
  25.         const string C4 = "\u2463";             // circled digit four
  26.         const string C5 = "\u2464";             // circled digit five
  27.  
  28.         const int DEFAULT = 0;                  // Default font index.
  29.         const int FOLLOWER = 1;                 // Follower shield index.
  30.         const int NOTICE = 2;                   // NoticeFont index.
  31.         const int EQUIPPED = 3;                 // Default font with shadow index.
  32.         const int MULTI = 4;                    // Multiple matches.
  33.         const int HIGHER = 5;                   // Multiple matches.
  34.  
  35.         IFont[] Fonts;                          // Actual fonts.
  36.  
  37.         public ImportantItems() { Enabled = true; }
  38.  
  39.         public void Customize()
  40.         {
  41.             // Setup original InventoryAndStashPlugin & Co.!
  42.             Hud.RunOnPlugin<Turbo.Plugins.Default.InventoryAndStashPlugin>(plugin =>
  43.             {
  44.                 plugin.LooksGoodDisplayEnabled = false;
  45.                 plugin.NotGoodDisplayEnabled = false;
  46.                 plugin.DefinitelyBadDisplayEnabled = false;
  47.                 plugin.CanCubedEnabled = false;
  48.             });
  49.             Hud.TogglePlugin<Turbo.Plugins.Default.HoveredItemInfoPlugin>(false);
  50.         }
  51.  
  52.         public override void Load(IController hud)
  53.         {
  54.             base.Load(hud);
  55.  
  56.             List<IFont> fonts = new List<IFont>();
  57.  
  58.             // Add fonts in font index order!
  59.             fonts.Add(Hud.Render.CreateFont("arial", 10, 255, 255, 0, 255, true, false, false));    // DEFAULT      Bright violet
  60.             fonts.Add(Hud.Render.CreateFont("arial", 7, 255, 51, 204, 166, false, false, true));    // FOLLOWER     Green-blue
  61.             fonts.Add(Hud.Render.CreateFont("arial", 10, 255, 255, 128, 0, true, false, true));     // NOTICE       Orange
  62.             fonts.Add(Hud.Render.CreateFont("arial", 9, 255, 255, 0, 255, true, false, false));     // EQUIPPED     Bright violet + shadow
  63.             fonts.Add(Hud.Render.CreateFont("arial", 10, 255, 255, 51, 153, true, false, false));   // MULTI        Bright reddish violet
  64.             fonts.Add(Hud.Render.CreateFont("arial", 10, 255, 255, 0, 102, true, false, true));     // HIGHER       Violet red
  65.  
  66.             // Grab fonts into an array because we need to access them by index for "Important" array.
  67.             Fonts = fonts.ToArray();
  68.             Fonts[EQUIPPED].SetShadowBrush(128, 63, 63, 63, true);      // Almost black
  69.         }
  70.  
  71.         private int stashPage, stashTab, stashTabAbs;
  72.         private float rv;
  73.  
  74.         public void PaintTopInGame(ClipState clipState)
  75.         {
  76.             if (clipState != ClipState.Inventory) return;
  77.  
  78.             stashTab = Hud.Inventory.SelectedStashTabIndex;
  79.             stashPage = Hud.Inventory.SelectedStashPageIndex;
  80.             stashTabAbs = stashTab + stashPage * Hud.Inventory.MaxStashTabCountPerPage;
  81.  
  82.             rv = 32.0f / 600.0f * Hud.Window.Size.Height;
  83.  
  84.             var items = Hud.Game.Items.Where(x => x.Location >= ItemLocation.Stash || (x.Location >= ItemLocation.Inventory && x.Location <= ItemLocation.Neck));
  85.             foreach (var item in items)
  86.             {
  87.                 if (item.Location == ItemLocation.Stash)
  88.                 {
  89.                     var tabIndex = item.InventoryY / 10;
  90.                     if (tabIndex != stashTabAbs) continue;
  91.                 }
  92.                 if ((item.InventoryX < 0) || (item.InventoryY < 0)) continue;
  93.  
  94.                 var rect = Hud.Inventory.GetItemRect(item);
  95.                 if (rect == System.Drawing.RectangleF.Empty) continue;
  96.  
  97.                 // New paint logic.
  98.                 if (item.Location == ItemLocation.Stash || item.Location == ItemLocation.Inventory)
  99.                 {
  100.                     if (item.Unidentified ||
  101.                         !item.IsLegendary ||
  102.                         item.SnoItem.Kind == ItemKind.gem ||
  103.                         item.SnoItem.Kind == ItemKind.uberstuff ||
  104.                         item.SnoItem.Kind == ItemKind.potion ||
  105.                         item.SnoItem.MainGroupCode == "gems_unique" ||
  106.                         item.SnoItem.MainGroupCode == "riftkeystone" ||
  107.                         item.SnoItem.MainGroupCode == "healthpotions" ||
  108.                         item.SnoItem.MainGroupCode == "consumable" ||
  109.                         item.SnoItem.MainGroupCode == "horadriccache")
  110.                     {
  111.                         continue;
  112.                     }
  113.                 }
  114.                 if ((item.SnoItem.NameEnglish == "Puzzle Ring" || item.SnoItem.NameEnglish == "Bovine Bardiche"))
  115.                 {
  116.                     ShowStar(rect, RE, Fonts[NOTICE], false);
  117.                     continue;
  118.                 }
  119.                 List<ImportantItem> important = Important.Where(x => x.Name == item.SnoItem.NameEnglish).ToList();
  120.                 if (important.Count > 0)
  121.                 {
  122.                     // Important item with our main stat (or wildcard).
  123.                     bool halfSize = item.Location == ItemLocation.Waist;
  124.                     if (item.Location == ItemLocation.Stash || item.Location == ItemLocation.Inventory || ShowEquippedItemsChar == null)
  125.                     {
  126.                         int higherRankedItems = CheckItemRank ? countHigherRankedItems(item) : 0;
  127.                         if (higherRankedItems > 0)
  128.                         {
  129.                             if (HigherRankIndicator != null)
  130.                             {
  131.                                 ShowStar(rect, HigherRankIndicator, Fonts[HIGHER], halfSize);
  132.                             }
  133.                         }
  134.                         else if (important.Count == 1)
  135.                         {
  136.                             ShowStar(rect, important[0], halfSize);
  137.                         }
  138.                         else
  139.                         {
  140.                             ShowStar(rect, MultiMatchIndicator, Fonts[MULTI], halfSize);
  141.                         }
  142.                     }
  143.                     else
  144.                     {
  145.                         ShowStar(rect, ShowEquippedItemsChar, Fonts[EQUIPPED], halfSize);
  146.                     }
  147.                 }
  148.                 else if (item.Location == ItemLocation.Inventory && item.SnoItem.CanKanaiCube && !Hud.Game.Me.IsCubed(item.SnoItem))
  149.                 {
  150.                     DrawItemCanCubed(rect, item);
  151.                 }
  152.             }
  153.         }
  154.  
  155.         int countHigherRankedItems(IItem item)
  156.         {
  157.             // Check only normal or ancient legendaries!
  158.             if ((item.Location == ItemLocation.Stash || item.Location == ItemLocation.Inventory) && item.AncientRank < 2)
  159.             {
  160.                 return Hud.Game.Items.Count(x => x.SnoItem.NameEnglish == item.SnoItem.NameEnglish && x.AncientRank > item.AncientRank && x.ItemUniqueId != item.ItemUniqueId);
  161.             }
  162.             return 0;
  163.         }
  164.  
  165.         void ShowStar(System.Drawing.RectangleF rect, ImportantItem important, bool halfSize)
  166.         {
  167.             ShowStar(rect, important.MarkerChar, Fonts[important.FontIndex], halfSize);
  168.         }
  169.  
  170.         void ShowStar(System.Drawing.RectangleF rect, string symbol, IFont font, bool halfSize)
  171.         {
  172.             // Top right corner.
  173.             var textLayout = font.GetTextLayout(symbol);
  174.             font.DrawText(textLayout, rect.Right - rv / 15.0f - textLayout.Metrics.Width, rect.Top - rv / (halfSize ? 8.75f : 17.5f));
  175.         }
  176.  
  177.         private void DrawItemCanCubed(System.Drawing.RectangleF rect, IItem item)
  178.         {
  179.             var cubeTexture = Hud.Texture.KanaiCubeTexture;
  180.             var h = cubeTexture.Height * 0.6f / 1200.0f * Hud.Window.Size.Height;
  181.             var x = rect.Right - h * 0.80f;
  182.             var y = rect.Top - h * 0.20f;
  183.             cubeTexture.Draw(x, y, h, h, 1);
  184.         }
  185.  
  186.         public class ImportantItem
  187.         {
  188.             public readonly string Name;
  189.             public readonly string MarkerChar;
  190.             public readonly int FontIndex;
  191.  
  192.             public ImportantItem(string name, string markerChar, int fontIndex)
  193.             {
  194.                 Name = name;
  195.                 MarkerChar = markerChar;
  196.                 FontIndex = fontIndex;
  197.             }
  198.         }
  199.  
  200.         static ImportantItem important(string name, string markerChar = BC, int fontIndex = 0)
  201.         {
  202.             return new ImportantItem(name, markerChar, fontIndex);
  203.         }
  204.  
  205.         public static ImportantItem[] Important = new ImportantItem[]
  206.         {
  207.             important("Ring of Royal Grandeur", BC, NOTICE),
  208.             important("Unity", BC, NOTICE),
  209.             // Barbarian HotA
  210.             important("Immortal King's Triumph", C1),
  211.             important("Immortal King's Eternal Reign", C1),
  212.             important("Immortal King's Irons", C1),
  213.             important("Immortal King's Tribal Binding", C1),
  214.             important("Immortal King's Stature", C1),
  215.             important("Immortal King's Stride", C1),
  216.             important("Fury of the Ancients", C1),
  217.             important("Bracers of the First Men", C1),
  218.             important("Magefist", C1),
  219.             important("The Traveler's Pledge", C1),
  220.             important("The Compass Rose", C1),
  221.             important("Convention of Elements", C1),
  222.             important("Little Rogue", C1),
  223.             important("The Slanderer", C1),
  224.             // Barbarian LeapQuake
  225.             important("Eyes of the Earth", C2),
  226.             important("Spires of the Earth", C2),
  227.             important("Pull of the Earth", C2),
  228.             important("Spirit of the Earth", C2),
  229.             important("Girdle of Giants", C2),
  230.             important("Weight of the Earth", C2),
  231.             important("Foundation of the Earth", C2),
  232.             important("Lut Socks", C2),
  233.             important("Ancient Parthan Defenders", C2),
  234.             important("Hellfire Amulet", C2),
  235.             important("Focus", C2),
  236.             important("Restraint", C2),
  237.             important("Blade of the Tribes", C2),
  238.             // Barbarian Whirlwind
  239.             important("Helm of the Wastes", C3),
  240.             important("Pauldrons of the Wastes", C3),
  241.             important("Cuirass of the Wastes", C3),
  242.             important("Ancient Parthan Defenders", C3),
  243.             important("Strongarm Bracers", C3),
  244.             important("Gauntlet of the Wastes", C3),
  245.             important("Pride of Cassius", C3),
  246.             important("Tasset of the Wastes", C3),
  247.             important("Swamp Land Waders", C3),
  248.             important("Sabaton of the Wastes", C3),
  249.             important("Hellfire Amulet", C3),
  250.             important("Mara's Kaleidoscope", C3),
  251.             important("Eye of Etlich", C3),
  252.             important("Obsidian Ring of the Zodiac", C3),
  253.             important("Convention of Elements", C3),
  254.             important("Bul-Kathos's Solemn Vow", C3),
  255.             important("Bul-Kathos's Warrior Blood", C3),
  256.             // Barbarian Raekor Furious Charge
  257.             important("Raekor's Will", C4),
  258.             important("Immortal King's Triumph", C4),
  259.             important("Raekor's Burden", C4),
  260.             important("Raekor's Heart", C4),
  261.             important("Immortal King's Eternal Reign", C4),
  262.             important("Ancient Parthan Defenders", C4),
  263.             important("Skular's Salvation", C4),
  264.             important("Bracers of Destruction", C4),
  265.             important("Raekor's Wraps", C4),
  266.             important("Immortal King's Irons", C4),
  267.             important("Immortal King's Tribal Binding", C4),
  268.             important("Raekor's Breeches", C4),
  269.             important("Immortal King's Stature", C4),
  270.             important("Raekor's Striders", C4),
  271.             important("Immortal King's Stride", C4),
  272.             important("Hellfire Amulet", C4),
  273.             important("Mara's Kaleidoscope", C4),
  274.             important("Eye of Etlich", C4),
  275.             important("Band of Might", C4),
  276.             important("Focus", C4),
  277.             important("Convention of Elements", C4),
  278.             important("Restraint", C4),
  279.             important("Immortal King's Boulder Breaker", C4),
  280.             // Follower - Templar
  281.             // See: https://www.icy-veins.com/d3/follower-skills-and-gearing-patch-2-6-1
  282.             important("Thunderfury, Blessed Blade of the Windseeker", FO, FOLLOWER),
  283.             important("Eun-jang-do", FO, FOLLOWER),
  284.             important("Freeze of Deflection", FO, FOLLOWER),
  285.             important("Defender of Westmarch", FO, FOLLOWER),
  286.             important("Lidless Wall", FO, FOLLOWER),
  287.             important("The Ess of Johan", FO, FOLLOWER),
  288.             important("Overwhelming Desire", FO, FOLLOWER),
  289.             important("Wyrdward", FO, FOLLOWER),
  290.             important("Oculus Ring", FO, FOLLOWER),
  291.             important("Justice Lantern", FO, FOLLOWER),
  292.             important("Enchanting Favor", FO, FOLLOWER),
  293.         };
  294.     }
  295. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement