Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
496
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 17.08 KB | None | 0 0
  1. // InventoryAndStashPlugin.cs "$Revision: 3697 $" "$Date: 2018-01-16 14:11:32 +0200 (ti, 16 tammi 2018) $"
  2. using System.Diagnostics;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using Turbo.Plugins.Default;
  7.  
  8. namespace Turbo.Plugins.JarJar.Stolen
  9. {
  10.     // Forked from: Turbo.Plugins.Default.InventoryAndStashPlugin.cs
  11.  
  12.     public class InventoryAndStashPlugin : BasePlugin, IKeyEventHandler, IInGameTopPainter
  13.     {
  14.         public bool ShowGreenStarEnabled { get; set; }
  15.         public bool ShowRedStarEnabled { get; set; }
  16.  
  17.         public bool HoradricCacheEnabled { get; set; }
  18.         public bool CanCubedEnabled { get; set; }
  19.         public bool AncientRankEnabled { get; set; }
  20.         public bool CaldesannRankEnabled { get; set; }
  21.         public bool SocketedLegendaryGemRankEnabled { get; set; }
  22.  
  23.         public string StarChar { get; set; }
  24.         public string RecycleChar { get; set; }
  25.         public IFont LooksGoodFont { get; set; }
  26.         public IFont LooksBadFont { get; set; }
  27.         public IFont RecycleFont { get; set; }
  28.         public IFont AncientRankFont { get; set; }
  29.         public IFont PrimalRankFont { get; set; }
  30.         public IFont SocketedLegendaryGemRankFont { get; set; }
  31.         public IFont HoradricCacheFont { get; set; }
  32.         public IFont QuantityFont { get; set; }
  33.  
  34.         public IBrush InventoryLockBorderBrush { get; set; }
  35.  
  36.         // Armory
  37.         public bool ArmoryBordersEnabled { get; set; }
  38.         public bool StashBorderEnabled { get; set; }
  39.         public bool InventoryhBorderEnabled { get; set; }
  40.         public bool EquippedhBorderEnabled { get; set; }
  41.         public bool KeyboardEnabled { get; set; }
  42.  
  43.         public IFont ArmorySetFont { get; set; }
  44.  
  45.         public IBrush StashBorderBrush { get; set; }
  46.         public IBrush InventoryBorderBrush { get; set; }
  47.         public IBrush EquippedBorderBrush { get; set; }
  48.         public IBrush GoodItemBrush { get; set; }
  49.  
  50.         private readonly Stopwatch _stopper = Stopwatch.StartNew();
  51.  
  52.         public InventoryAndStashPlugin()
  53.         {
  54.             // Must be explicitly enabled as this draws to same places as original InventoryAndStashPlugin!
  55.             Enabled = false;
  56.  
  57.             ShowGreenStarEnabled = true;
  58.             ShowRedStarEnabled = false;
  59.             AncientRankEnabled = true;
  60.             SocketedLegendaryGemRankEnabled = true;
  61.             CaldesannRankEnabled = true;
  62.             HoradricCacheEnabled = true;
  63.             CanCubedEnabled = false;
  64.  
  65.             ArmoryBordersEnabled = false;
  66.             StashBorderEnabled = true;
  67.             InventoryhBorderEnabled = true;
  68.             EquippedhBorderEnabled = true;
  69.             KeyboardEnabled = true;
  70.         }
  71.  
  72.         public override void Load(IController hud)
  73.         {
  74.             base.Load(hud);
  75.  
  76.             StarChar = "\u2605";        // black star
  77.             RecycleChar = "\u267A";     // recycling symbol for generic materials
  78.             LooksGoodFont = Hud.Render.CreateFont("arial", 9, 255, 0, 255, 0, false, false, true);  // Bright green
  79.             LooksBadFont = Hud.Render.CreateFont("arial", 9, 255, 204, 0, 0, false, false, true);   // Red
  80.             RecycleFont = Hud.Render.CreateFont("arial", 10, 255, 255, 128, 0, true, false, true);  // Orange
  81.  
  82.             HoradricCacheFont = Hud.Render.CreateFont("tahoma", 8, 255, 255, 255, 255, false, false, false);
  83.             HoradricCacheFont.SetShadowBrush(128, 0, 0, 0, true);
  84.             AncientRankFont = Hud.Render.CreateFont("arial", 7, 255, 0, 0, 0, true, false, 220, 227, 153, 25, true);
  85.             PrimalRankFont = Hud.Render.CreateFont("arial", 7, 255, 0, 0, 0, true, false, 180, 255, 64, 64, true);
  86.             SocketedLegendaryGemRankFont = Hud.Render.CreateFont("arial", 7, 255, 0, 0, 0, true, false, false);
  87.             SocketedLegendaryGemRankFont.SetShadowBrush(128, 240, 240, 64, true);
  88.             QuantityFont = Hud.Render.CreateFont("tahoma", 8, 255, 200, 200, 200, false, false, false);
  89.             QuantityFont.SetShadowBrush(128, 0, 0, 0, true);
  90.  
  91.             InventoryLockBorderBrush = Hud.Render.CreateBrush(100, 0, 150, 200, -1.6f);
  92.  
  93.             // Armory
  94.             ArmorySetFont = Hud.Render.CreateFont("arial", 7, 255, 192, 192, 192, true, false, 220, 32, 32, 32, true); // light grey on drak grey
  95.  
  96.             StashBorderBrush = Hud.Render.CreateBrush(100, 0, 128, 128, -1.6f);         // teal
  97.             InventoryBorderBrush = Hud.Render.CreateBrush(200, 255, 0, 0, -1.6f);       // red
  98.             EquippedBorderBrush = Hud.Render.CreateBrush(100, 238, 232, 170, -1.6f);    // pale golden rod
  99.             GoodItemBrush = Hud.Render.CreateBrush(150, 255, 255, 0, -1.6f, SharpDX.Direct2D1.DashStyle.Dash); // yellow
  100.         }
  101.  
  102.         bool _shiftPressed;
  103.  
  104.         public void OnKeyEvent(IKeyEvent keyEvent)
  105.         {
  106.             if (KeyboardEnabled) _shiftPressed = keyEvent.ShiftPressed;
  107.         }
  108.  
  109.         private int stashPage, stashTab, stashTabAbs;
  110.         private float rv;
  111.         private StringBuilder builder = new StringBuilder();
  112.  
  113.         public void PaintTopInGame(ClipState clipState)
  114.         {
  115.             if (clipState != ClipState.Inventory) return;
  116.  
  117.             stashTab = Hud.Inventory.SelectedStashTabIndex;
  118.             stashPage = Hud.Inventory.SelectedStashPageIndex;
  119.             stashTabAbs = stashTab + stashPage * Hud.Inventory.MaxStashTabCountPerPage;
  120.  
  121.             rv = 32.0f / 600.0f * Hud.Window.Size.Height;
  122.  
  123.             if ((Hud.Inventory.InventoryLockArea.Width > 0) && (Hud.Inventory.InventoryLockArea.Height > 0))
  124.             {
  125.                 var rect = Hud.Inventory.GetRectInInventory(Hud.Inventory.InventoryLockArea.X, Hud.Inventory.InventoryLockArea.Y, Hud.Inventory.InventoryLockArea.Width, Hud.Inventory.InventoryLockArea.Height);
  126.                 InventoryLockBorderBrush.DrawRectangle(rect.X, rect.Y, rect.Width, rect.Height);
  127.             }
  128.  
  129.             builder.Length = 0;
  130.             var items = Hud.Game.Items.Where(x => x.Location != ItemLocation.Merchant && x.Location != ItemLocation.Floor);
  131.             foreach (var item in items)
  132.             {
  133.                 if (item.Location == ItemLocation.Stash)
  134.                 {
  135.                     var tabIndex = item.InventoryY / 10;
  136.                     if (tabIndex != stashTabAbs) continue;
  137.                 }
  138.                 if ((item.InventoryX < 0) || (item.InventoryY < 0)) continue;
  139.  
  140.                 var rect = Hud.Inventory.GetItemRect(item);
  141.                 if (rect == System.Drawing.RectangleF.Empty) continue;
  142.  
  143.                 DrawItemSocketedLegendaryGemRank(item, rect);
  144.                 DrawItemAncientRank(item, rect);
  145.                 DrawItemHoradricCache(item, rect);
  146.                 DrawItemCanCubed(item, rect);
  147.  
  148.                 // New paint logic.
  149.                 if (item.Location == ItemLocation.Stash || item.Location == ItemLocation.Inventory)
  150.                 {
  151.                     if (!item.IsLegendary ||
  152.                         item.SnoItem.Kind == ItemKind.gem ||
  153.                         //item.SnoItem.Kind == ItemKind.craft ||
  154.                         item.SnoItem.Kind == ItemKind.uberstuff ||
  155.                         item.SnoItem.Kind == ItemKind.potion ||
  156.                         item.SnoItem.MainGroupCode == "riftkeystone" ||
  157.                         item.SnoItem.MainGroupCode == "gems_unique" ||
  158.                         item.SnoItem.MainGroupCode == "consumable" ||
  159.                         item.SnoItem.MainGroupCode == "horadriccache")
  160.                     {
  161.                         continue;
  162.                     }
  163.                 }
  164.                 if (ShowGreenStarEnabled || ShowRedStarEnabled)
  165.                 {
  166.                     if ((item.SnoItem.NameEnglish == "Puzzle Ring" || item.SnoItem.NameEnglish == "Bovine Bardiche") && RecycleFont != null)
  167.                     {
  168.                         ShowStar(rect, RecycleChar, RecycleFont, false);
  169.                         continue;
  170.                     }
  171.                     bool belt = item.Location == ItemLocation.Waist;
  172.                     if (ShowGreenStarEnabled)
  173.                     {
  174.                         if (item.KeepDecision == ItemKeepDecision.LooksGood) ShowStar(rect, StarChar, LooksGoodFont, belt);
  175.                     }
  176.                     if (ShowRedStarEnabled)
  177.                     {
  178.                         if (item.KeepDecision != ItemKeepDecision.LooksGood) ShowStar(rect, StarChar, LooksBadFont, belt);
  179.                     }
  180.                 }
  181.                 if (ArmoryBordersEnabled) checkArmorySets(item, rect);
  182.             }
  183.         }
  184.  
  185.         void ShowStar(System.Drawing.RectangleF rect, string symbol, IFont font, bool belt)
  186.         {
  187.             // Top right corner.
  188.             var textLayout = font.GetTextLayout(symbol);
  189.             font.DrawText(textLayout, rect.Right - rv / 15.0f - textLayout.Metrics.Width, rect.Top - rv / (belt ? 8.75f : 17.5f));
  190.         }
  191.  
  192.         private void DrawItemSocketedLegendaryGemRank(IItem item, System.Drawing.RectangleF rect)
  193.         {
  194.             if (!SocketedLegendaryGemRankEnabled) return;
  195.             if (item.ItemsInSocket == null) return;
  196.  
  197.             var legendaryGem = item.ItemsInSocket.FirstOrDefault(x => x.Quality == ItemQuality.Legendary && x.JewelRank > -1);
  198.             if (legendaryGem == null) return;
  199.            
  200.             var jewelRank = legendaryGem.JewelRank;
  201.             if (jewelRank > -1)
  202.             {
  203.                 var text = jewelRank.ToString("D", CultureInfo.InvariantCulture);
  204.                 var layout = SocketedLegendaryGemRankFont.GetTextLayout(text);
  205.                 SocketedLegendaryGemRankFont.DrawText(layout, rect.X, rect.Y);
  206.             }
  207.         }
  208.  
  209.         private void DrawItemAncientRank(IItem item, System.Drawing.RectangleF rect)
  210.         {
  211.             if (!AncientRankEnabled) return;
  212.             var ancientRank = item.AncientRank;
  213.             if (ancientRank >= 1)
  214.             {
  215.                 var caldesannRank = CaldesannRankEnabled ? item.CaldesannRank : 0;
  216.  
  217.                 var ancientRankText = ancientRank == 1 ? "A" : "P";
  218.                 var font = ancientRank == 1 ? AncientRankFont : PrimalRankFont;
  219.  
  220.                 var text = ancientRankText + (caldesannRank > 0 ? ("+" + caldesannRank.ToString("D", CultureInfo.InvariantCulture)) : "");
  221.                 var textLayout = font.GetTextLayout(text);
  222.                 font.DrawText(textLayout, rect.Right - rv / 15.0f - textLayout.Metrics.Width, rect.Bottom - rv / 35.0f - textLayout.Metrics.Height);
  223.             }
  224.         }
  225.  
  226.         private void DrawItemCanCubed(IItem item, System.Drawing.RectangleF rect)
  227.         {
  228.             if (!CanCubedEnabled) return;
  229.             if ((item.Location != ItemLocation.Inventory) && (item.Location != ItemLocation.Stash)) return;
  230.             var allowCube = item.SnoItem.CanKanaiCube && !Hud.Game.Me.IsCubed(item.SnoItem);
  231.             if (allowCube && !item.IsInventoryLocked)
  232.             {
  233.                 var cubeTexture = Hud.Texture.KanaiCubeTexture;
  234.                 var h = cubeTexture.Height * 0.6f / 1200.0f * Hud.Window.Size.Height;
  235.                 var rh = h;
  236.                 var mod = (_stopper.ElapsedMilliseconds) % 1000;
  237.                 var ratio = 0.8f + 1.2f / 1000.0f * (mod < 500 ? mod : 1000 - mod);
  238.                 rh *= ratio;
  239.  
  240.                 var x = rect.Right - h * 0.80f - ((rh - h) / 2);
  241.                 var y = rect.Top - h * 0.20f - ((rh - h) / 2);
  242.                 cubeTexture.Draw(x, y, rh, rh, 1);
  243.             }
  244.         }
  245.  
  246.         private void DrawItemHoradricCache(IItem item, System.Drawing.RectangleF rect)
  247.         {
  248.             if (!HoradricCacheEnabled) return;
  249.             if (item.SnoItem.MainGroupCode != "horadriccache") return;
  250.  
  251.             var text = "";
  252.             if (item.SnoItem.Code.Contains("A1")) text = "A1";
  253.             if (item.SnoItem.Code.Contains("A2")) text = "A2";
  254.             if (item.SnoItem.Code.Contains("A3")) text = "A3";
  255.             if (item.SnoItem.Code.Contains("A4")) text = "A4";
  256.             if (item.SnoItem.Code.Contains("A5")) text = "A5";
  257.             if (item.SnoItem.Code.Contains("Act1")) text = "A1";
  258.             if (item.SnoItem.Code.Contains("Act2")) text = "A2";
  259.             if (item.SnoItem.Code.Contains("Act3")) text = "A3";
  260.             if (item.SnoItem.Code.Contains("Act4")) text = "A4";
  261.             if (item.SnoItem.Code.Contains("Act5")) text = "A5";
  262.             if (item.SnoItem.Code.Contains("Hard")) text += ": H";
  263.             if (item.SnoItem.Code.Contains("Expert")) text += ": E";
  264.             if (item.SnoItem.Code.Contains("Master")) text += ": M";
  265.  
  266.             if (item.SnoItem.Code.Contains("T13")) text += ": T13";
  267.             else if (item.SnoItem.Code.Contains("T12")) text += ": T12";
  268.             else if (item.SnoItem.Code.Contains("T11")) text += ": T11";
  269.             else if (item.SnoItem.Code.Contains("T10")) text += ": T10";
  270.             else if (item.SnoItem.Code.Contains("T9")) text += ": T9";
  271.             else if (item.SnoItem.Code.Contains("T8")) text += ": T8";
  272.             else if (item.SnoItem.Code.Contains("T7")) text += ": T7";
  273.             else if (item.SnoItem.Code.Contains("T6")) text += ": T6";
  274.             else if (item.SnoItem.Code.Contains("T5")) text += ": T5";
  275.             else if (item.SnoItem.Code.Contains("T4")) text += ": T4";
  276.             else if (item.SnoItem.Code.Contains("T3")) text += ": T3";
  277.             else if (item.SnoItem.Code.Contains("T2")) text += ": T2";
  278.             else if (item.SnoItem.Code.Contains("T1")) text += ": T1";
  279.  
  280.             if (item.SnoItem.Code.Contains("Torment13")) text += ": T13";
  281.             else if (item.SnoItem.Code.Contains("Torment12")) text += ": T12";
  282.             else if (item.SnoItem.Code.Contains("Torment11")) text += ": T11";
  283.             else if (item.SnoItem.Code.Contains("Torment10")) text += ": T10";
  284.             else if (item.SnoItem.Code.Contains("Torment9")) text += ": T9";
  285.             else if (item.SnoItem.Code.Contains("Torment8")) text += ": T8";
  286.             else if (item.SnoItem.Code.Contains("Torment7")) text += ": T7";
  287.             else if (item.SnoItem.Code.Contains("Torment6")) text += ": T6";
  288.             else if (item.SnoItem.Code.Contains("Torment5")) text += ": T5";
  289.             else if (item.SnoItem.Code.Contains("Torment4")) text += ": T4";
  290.             else if (item.SnoItem.Code.Contains("Torment3")) text += ": T3";
  291.             else if (item.SnoItem.Code.Contains("Torment2")) text += ": T2";
  292.             else if (item.SnoItem.Code.Contains("Torment1")) text += ": T1";
  293.  
  294.             if (text != null)
  295.             {
  296.                 var textLayout = HoradricCacheFont.GetTextLayout(text);
  297.                 HoradricCacheFont.DrawText(textLayout, rect.Right - rv / 20.0f - textLayout.Metrics.Width, rect.Bottom - rv / 70.0f - textLayout.Metrics.Height);
  298.             }
  299.         }
  300.  
  301.         void checkArmorySets(IItem item, System.Drawing.RectangleF rect)
  302.         {
  303.             if (item.Location == ItemLocation.Stash)
  304.             {
  305.                 if (!StashBorderEnabled) return;
  306.             }
  307.             else if (item.Location == ItemLocation.Inventory)
  308.             {
  309.                 if (!InventoryhBorderEnabled) return;
  310.             }
  311.             else
  312.             {
  313.                 if (!EquippedhBorderEnabled) return;
  314.             }
  315.             builder.Length = 0;
  316.             for (int i = 0; i < Hud.Game.Me.ArmorySets.Length; ++i)
  317.             {
  318.                 var set = Hud.Game.Me.ArmorySets[i];
  319.                 if (set.ContainsItem(item))
  320.                 {
  321.                     if (_shiftPressed)
  322.                     {
  323.                         if (builder.Length > 1) builder.Append(',');
  324.                         else if (builder.Length == 0) builder.Append('#');
  325.                         builder.Append(i + 1);
  326.                     }
  327.                     else
  328.                     {
  329.                         builder.Append('x');
  330.                         break;
  331.                     }
  332.                 }
  333.             }
  334.             if (builder.Length == 0)
  335.             {
  336.                 return;
  337.             }
  338.             if (item.Location == ItemLocation.Stash)
  339.             {
  340.                 if (StashBorderEnabled) StashBorderBrush.DrawRectangle(rect.X, rect.Y, rect.Width, rect.Height);
  341.             }
  342.             else if (item.Location == ItemLocation.Inventory)
  343.             {
  344.                 if (InventoryhBorderEnabled) InventoryBorderBrush.DrawRectangle(rect.X, rect.Y, rect.Width, rect.Height);
  345.             }
  346.             else
  347.             {
  348.                 if (EquippedhBorderEnabled) EquippedBorderBrush.DrawRectangle(rect.X, rect.Y, rect.Width, rect.Height);
  349.             }
  350.             if (_shiftPressed)
  351.             {
  352.                 bool upper = item.Location == ItemLocation.Stash || item.Location == ItemLocation.Inventory;
  353.                 var font = ArmorySetFont;
  354.                 var text = builder.ToString();
  355.                 var textLayout = font.GetTextLayout(text);
  356.                 var x = rect.Right - textLayout.Metrics.Width - (upper ? rv / 15.0f : 0f);
  357.                 var y = upper ? rect.Top + rv / 35.0f : rect.Bottom - 2 * (rv / 35.0f);
  358.                 font.DrawText(textLayout, x, y);
  359.             }
  360.         }
  361.     }
  362. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement