Advertisement
s4000

DAV_MaterialCountPlugin

Feb 29th, 2020 (edited)
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.49 KB | None | 0 0
  1. using System;
  2. using Turbo.Plugins.Default;
  3.  
  4. namespace Turbo.Plugins.DAV
  5. {
  6.     public class DAV_MaterialCountPlugin : BasePlugin, IInGameTopPainter, ICustomizer {
  7.         public IFont Font_Norm { get; set; }
  8.         public IFont Font_Min { get; set; }
  9.         public IFont Font_Max { get; set; }
  10.  
  11.         private ISnoItem[] _bMaterials, _bountyMats, _InfMachine, _DemonOrgan;
  12.         private ITexture image_BG { get; set; }
  13.         private IUiElement uiInv { get; set; }
  14.         private IFont usedFont { get; set; }
  15.  
  16.         public DAV_MaterialCountPlugin() {
  17.             Enabled = true;
  18.         }
  19.  
  20.         public override void Load(IController hud) {
  21.             base.Load(hud);
  22.  
  23.             Font_Norm = Hud.Render.CreateFont("Arial", 8, 255, 255, 255, 255, false, false, false);
  24.             Font_Min = Hud.Render.CreateFont("Arial", 8, 255, 255, 51, 51, false, false, false);
  25.             Font_Max = Hud.Render.CreateFont("Arial", 8, 255, 51, 255, 51, false, false, false);
  26.  
  27.             image_BG = Hud.Texture.GetTexture("inventory_materials");
  28.             _bMaterials = new ISnoItem[] {
  29.                 Hud.Sno.SnoItems.Crafting_AssortedParts_01, // 3931359676 - Reusable Parts
  30.                 Hud.Sno.SnoItems.Crafting_Magic_01, // 2709165134 - Arcane Dust
  31.                 Hud.Sno.SnoItems.Crafting_Rare_01, // 3689019703 - Veiled Crystal
  32.                 Hud.Sno.SnoItems.Crafting_Looted_Reagent_01, // 2087837753 - Death's Breath
  33.                 Hud.Sno.SnoItems.Crafting_Legendary_01, // 2073430088 - Forgotten Soul
  34.             };
  35.             _bountyMats = new ISnoItem[] {
  36.                 Hud.Sno.SnoItems.p2_ActBountyReagent_01, // 1948629088 - Khanduran Rune
  37.                 Hud.Sno.SnoItems.p2_ActBountyReagent_02, // 1948629089 - Caldeum Nightshade
  38.                 Hud.Sno.SnoItems.p2_ActBountyReagent_03, // 1948629090 - Arreat War Tapestry
  39.                 Hud.Sno.SnoItems.p2_ActBountyReagent_04, // 1948629091 - Corrupted Angel Flesh
  40.                 Hud.Sno.SnoItems.p2_ActBountyReagent_05, // 1948629092 - Westmarch Holy Water
  41.             };
  42.             _InfMachine = new ISnoItem[] {
  43.                 Hud.Sno.SnoItems.InfernalMachine_SkeletonKing_x1, // 1054965529 - Infernal Machine of Regret
  44.                 Hud.Sno.SnoItems.InfernalMachine_Ghom_x1, // 2788723894 - Infernal Machine of Putridness
  45.                 Hud.Sno.SnoItems.InfernalMachine_SiegeBreaker_x1, // 2622355732 - Infernal Machine of Terror
  46.                 Hud.Sno.SnoItems.InfernalMachine_Diablo_x1, // 1458185494 - Infernal Machine of Fright
  47.                 Hud.Sno.SnoItems.GreaterLootRunKey, // 2835237830 - Greater Rift Keystone
  48.             };
  49.             _DemonOrgan = new ISnoItem[] {
  50.                 Hud.Sno.SnoItems.DemonOrgan_SkeletonKing_x1, // 1102953247 - Leoric's Regret
  51.                 Hud.Sno.SnoItems.DemonOrgan_Ghom_x1,// 2029265596 - Vial of Putridness
  52.                 Hud.Sno.SnoItems.DemonOrgan_SiegeBreaker_x1, // 2670343450 - Idol of Terror
  53.                 Hud.Sno.SnoItems.DemonOrgan_Diablo_x1, // 3336787100 - Heart of Fright
  54.                 Hud.Sno.SnoItems.Unique_Ring_004_x1, // 3106130529 - Puzzle Ring
  55.             };
  56.         }
  57.  
  58.         public void PaintTopInGame(ClipState clipState) {
  59.             if (clipState != ClipState.Inventory) return;
  60.             if (Hud.Game.Me.CurrentLevelNormalCap != 70) return;
  61.  
  62.             uiInv = Hud.Inventory.InventoryMainUiElement;
  63.             if (!uiInv.Visible) return;
  64.  
  65.             var y = uiInv.Rectangle.Top + uiInv.Rectangle.Height * 0.825f;
  66.             y += DrawItemBar(_bMaterials, y);
  67.             y += DrawItemBar(_bountyMats, y, true, 5);
  68.             y += DrawItemBar(_DemonOrgan, y, true, 4);
  69.             y += DrawItemBar(_InfMachine, y, true, 4);
  70.         }
  71.  
  72.         private float DrawItemBar(ISnoItem[] itemsToDisplay, float barY, bool showMin = false, int maxArray = 1) {
  73.             var rect = new SharpDX.RectangleF(uiInv.Rectangle.Left - 1, barY, uiInv.Rectangle.Width + 2, image_BG.Height * uiInv.Rectangle.Width / image_BG.Width);
  74.             image_BG.Draw(rect.X, rect.Y, rect.Width, rect.Height);
  75.  
  76.             var itemCountList = new long[itemsToDisplay.Length];
  77.             var minValue = long.MaxValue;
  78.             var maxValue = (long) 0;
  79.             for (var j = 0; j < itemsToDisplay.Length; j++) {
  80.                 itemCountList[j] = GetItemCount(itemsToDisplay[j]);
  81.                 if (minValue > itemCountList[j] && j < maxArray)
  82.                     minValue = itemCountList[j];
  83.                 if (maxValue < itemCountList[j] && j < maxArray)
  84.                     maxValue = itemCountList[j];
  85.             }
  86.  
  87.             var w = rect.Width / (itemsToDisplay.Length + 1);
  88.             var h = rect.Height * 0.85f;
  89.             var y = rect.Top + ((rect.Height - h) / 2);
  90.             for (var i = 0; i < itemsToDisplay.Length; i++) {
  91.                 var texture = Hud.Texture.GetItemTexture(itemsToDisplay[i]);
  92.                 if (texture != null) {
  93.                     var x = (w / 2) + rect.Left + (i * w);
  94.                     texture.Draw(x + w - h, y, h, h, 1);
  95.  
  96.                     if (showMin) {
  97.                         if (itemCountList[i] == minValue)
  98.                             usedFont = Font_Min;
  99.                         else if (itemCountList[i] == maxValue)
  100.                             usedFont = Font_Max;
  101.                         else
  102.                             usedFont = Font_Norm;
  103.                     }
  104.                     else usedFont = Font_Norm;
  105.  
  106.                     var layout = usedFont.GetTextLayout(ValueToString(itemCountList[i], ValueFormat.NormalNumberNoDecimal));
  107.                     usedFont.DrawText(layout, x + w - (h * 1.2f) - layout.Metrics.Width, y + ((h - layout.Metrics.Height) / 2));
  108.  
  109.                     if (Hud.Window.CursorInsideRect(x + w - (h * 1.2f) - layout.Metrics.Width, y, (h * 1.2f) + layout.Metrics.Width, h))
  110.                         Hud.Render.SetHint(itemsToDisplay[i].NameLocalized);
  111.                 }
  112.             }
  113.  
  114.             return rect.Height;
  115.         }
  116.  
  117.         private long GetItemCount(ISnoItem snoItem) {
  118.             switch (snoItem.Sno) {
  119.                 case 3931359676: return Hud.Game.Me.Materials.ReusableParts;
  120.                 case 2709165134: return Hud.Game.Me.Materials.ArcaneDust;
  121.                 case 3689019703: return Hud.Game.Me.Materials.VeiledCrystal;
  122.                 case 2087837753: return Hud.Game.Me.Materials.DeathsBreath;
  123.                 case 2073430088: return Hud.Game.Me.Materials.ForgottenSoul;
  124.                 case 1948629088: return Hud.Game.Me.Materials.KhanduranRune;
  125.                 case 1948629089: return Hud.Game.Me.Materials.CaldeumNightShade;
  126.                 case 1948629090: return Hud.Game.Me.Materials.ArreatWarTapestry;
  127.                 case 1948629091: return Hud.Game.Me.Materials.CorruptedAngelFlesh;
  128.                 case 1948629092: return Hud.Game.Me.Materials.WestmarchHolyWater;
  129.                 case 1102953247: return Hud.Game.Me.Materials.LeoricsRegret;
  130.                 case 2029265596: return Hud.Game.Me.Materials.VialOfPutridness;
  131.                 case 2670343450: return Hud.Game.Me.Materials.IdolOfTerror;
  132.                 case 3336787100: return Hud.Game.Me.Materials.HeartOfFright;
  133.                 case 2835237830: return Hud.Game.Me.Materials.GreaterRiftKeystone;
  134.             }
  135.  
  136.             var count = 0;
  137.             foreach (var item in Hud.Inventory.ItemsInStash) {
  138.                 if (item.SnoItem == snoItem)
  139.                     count += (int) (item.Quantity > 0 ? item.Quantity : 1);
  140.             }
  141.  
  142.             foreach (var item in Hud.Inventory.ItemsInInventory) {
  143.                 if (item.SnoItem == snoItem)
  144.                     count += (int) (item.Quantity > 0 ? item.Quantity : 1);
  145.             }
  146.  
  147.             return count;
  148.         }
  149.  
  150.         public void Customize() {
  151.             Hud.TogglePlugin<InventoryMaterialCountPlugin>(false);
  152.         }
  153.     }
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement