Advertisement
s4000

DAV_MainStatPlugin

May 29th, 2020 (edited)
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.53 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using Turbo.Plugins.Default;
  5.  
  6. namespace Turbo.Plugins.DAV
  7. {
  8.     public class DAV_MainStatPlugin : BasePlugin, IInGameTopPainter {
  9.         public bool showPotion { get; set; } = false;
  10.         public IFont PotionFont { get; set; }
  11.         public string perfectMsg { get; set; }
  12.  
  13.         public bool showElementalType { get; set; } = true;
  14.         public float sizeDivider_Elelment { get; set; }
  15.         public float sizeDivider_MainStat { get; set; }
  16.         public IBrush Brush_Ele { get; set; }
  17.  
  18.         private int stashTabAbs { get; set; }
  19.         private ITexture Icon_Str { get; set; }
  20.         private ITexture Icon_Dex { get; set; }
  21.         private ITexture Icon_Int { get; set; }
  22.         private ITexture Icon_Vit { get; set; }
  23.         private ITexture Icon_Oth { get; set; }
  24.  
  25.         public DAV_MainStatPlugin() {
  26.             Enabled = true;
  27.             Order = 5000;
  28.         }
  29.  
  30.         public override void Load(IController hud) {
  31.             base.Load(hud);
  32.  
  33.             perfectMsg = "Max";
  34.             PotionFont = Hud.Render.CreateFont("Arial", 7, 255, 255, 255, 255, true, false, true);
  35.  
  36.             sizeDivider_Elelment = 2;
  37.             sizeDivider_MainStat = 2.5f;
  38.             Brush_Ele = Hud.Render.CreateBrush(204, 255, 255, 255, 1f);
  39.  
  40.             Icon_Str = Hud.Texture.GetTexture(1489414124);
  41.             Icon_Dex = Hud.Texture.GetTexture(1889981188);
  42.             Icon_Int = Hud.Texture.GetTexture(633576440);
  43.             Icon_Vit = Hud.Texture.GetTexture(1021260537);
  44.             Icon_Oth = Hud.Texture.GetTexture(1797554470);
  45.         }
  46.  
  47.         public void PaintTopInGame(ClipState clipState) {
  48.             if (clipState != ClipState.Inventory) return;
  49.  
  50.             if (showPotion) {
  51.                 var EquippedPotion = Hud.Game.Items.FirstOrDefault(x => x.Location == ItemLocation.MerchantAvaibleItemsForPurchase);
  52.                 if (EquippedPotion != null)
  53.                     DrawPotionPerfection(EquippedPotion, Hud.Render.GetPlayerSkillUiElement(ActionKey.Heal).Rectangle);
  54.             }
  55.  
  56.             // stashTabAbs = Hud.Inventory.SelectedStashTabIndex + Hud.Inventory.SelectedStashPageIndex * Hud.Inventory.MaxStashTabCountPerPage;
  57.             // var items = Hud.Game.Items.Where(x => x.Location != ItemLocation.Merchant && x.Location != ItemLocation.Floor);
  58.             foreach (var item in ItemsVisible()) {
  59.                 // if (item.Location == ItemLocation.Stash && item.InventoryY / 10 != stashTabAbs) continue;
  60.                 // if (item.InventoryX < 0 || item.InventoryY < 0) continue;
  61.                 if (item.Unidentified || !item.IsLegendary) continue;
  62.                 if (item.SnoItem.HasGroupCode("gems")) continue;
  63.  
  64.                 var rect = Hud.Inventory.GetItemRect(item);
  65.                 if (rect == System.Drawing.RectangleF.Empty) continue;
  66.  
  67.                 if (item.SnoItem.Kind == ItemKind.potion || item.SnoItem.MainGroupCode == "healthpotions") {
  68.                     if (showPotion)
  69.                         DrawPotionPerfection(item, rect);
  70.                     continue;
  71.                 }
  72.  
  73.                 DrawItemMainStat(item, rect);
  74.             }
  75.        }
  76.        
  77.        private IEnumerable<IItem> ItemsVisible() {
  78.             var visStash = Hud.Inventory.StashMainUiElement.Visible;
  79.             var visInventory = Hud.Inventory.InventoryMainUiElement.Visible;
  80.             var visFollower = Hud.Inventory.FollowerMainUiElement.Visible;
  81.             var stashTabAbs = Hud.Inventory.SelectedStashTabIndex + Hud.Inventory.SelectedStashPageIndex * Hud.Inventory.MaxStashTabCountPerPage;
  82.  
  83.             return Hud.Game.Items.Where(x => IsItemVisible(x, visStash, visInventory, visFollower, stashTabAbs));
  84.         }
  85.  
  86.         private bool IsItemVisible(IItem item, bool showStash, bool showInventory, bool showFollower, int stashTabAbs) {
  87.             if (item.InventoryX < 0 || item.InventoryY < 0) return false; // Default Plugin Requirement
  88.  
  89.             if (item.Location == ItemLocation.Stash)
  90.                 return showStash && item.InventoryY / 10 == stashTabAbs;
  91.             else if (item.Location >= ItemLocation.Inventory && item.Location <= ItemLocation.Neck)
  92.                 return showInventory;
  93.             else if (item.Location >= ItemLocation.PetRightHand && item.Location <= ItemLocation.PetBracers)
  94.                 return showFollower;
  95.  
  96.             return false;
  97.         }
  98.  
  99.         private void DrawItemMainStat(IItem item, System.Drawing.RectangleF rect) {
  100.             if (item == null || item.Perfections == null || rect == null) return;
  101.             if (item.AncientRank < 0) return;
  102.  
  103.             var allClass = true;
  104.             var iconSize = Math.Min(rect.Width / sizeDivider_MainStat, rect.Height / 2f);
  105.             foreach (var perfection in item.Perfections) {
  106.                 if (perfection.Attribute == Hud.Sno.Attributes.Strength_Item) {
  107.                     Icon_Str.Draw(rect.X, rect.Bottom - iconSize, iconSize, iconSize);
  108.                     allClass = false;
  109.                 }
  110.                 else if (perfection.Attribute == Hud.Sno.Attributes.Dexterity_Item) {
  111.                     Icon_Dex.Draw(rect.X, rect.Bottom - iconSize, iconSize, iconSize);
  112.                     allClass = false;
  113.                 }
  114.                 else if (perfection.Attribute == Hud.Sno.Attributes.Intelligence_Item) {
  115.                     Icon_Int.Draw(rect.X, rect.Bottom - iconSize, iconSize, iconSize);
  116.                     allClass = false;
  117.                 }
  118.  
  119.                 if (showElementalType && perfection.Attribute == Hud.Sno.Attributes.Damage_Dealt_Percent_Bonus) {
  120.                     var iconSize2 = Math.Min(rect.Width / sizeDivider_Elelment, rect.Height / 2f);
  121.                     var index = (int) perfection.Modifier;
  122.                     if (index >= 0 && index < 7) {
  123.                         Hud.Texture.DrawElement(rect.Right - iconSize2, rect.Top, iconSize2, iconSize2, index);
  124.                         Brush_Ele?.DrawRectangle(rect.Right - iconSize2, rect.Top, iconSize2, iconSize2);
  125.                     }
  126.                 }
  127.             }
  128.  
  129.             if (allClass)
  130.                 Icon_Oth.Draw(rect.X, rect.Bottom - iconSize, iconSize, iconSize);
  131.  
  132.             if (item.CaldesannRank == 0) return;
  133.             foreach (var perfection in item.StatList) {
  134.                 if (perfection.Attribute == Hud.Sno.Attributes.Cube_Enchanted_Strength_Item) {
  135.                     Icon_Str.Draw(rect.X, rect.Bottom - 2 * iconSize, iconSize, iconSize);
  136.                     return;
  137.                 }
  138.                 else if (perfection.Attribute == Hud.Sno.Attributes.Cube_Enchanted_Dexterity_Item) {
  139.                     Icon_Dex.Draw(rect.X, rect.Bottom - 2 * iconSize, iconSize, iconSize);
  140.                     return;
  141.                 }
  142.                 else if (perfection.Attribute == Hud.Sno.Attributes.Cube_Enchanted_Intelligence_Item) {
  143.                     Icon_Int.Draw(rect.X, rect.Bottom - 2 * iconSize, iconSize, iconSize);
  144.                     return;
  145.                 }
  146.                 else if (perfection.Attribute == Hud.Sno.Attributes.Cube_Enchanted_Vitality_Item) {
  147.                     Icon_Vit.Draw(rect.X, rect.Bottom - 2 * iconSize, iconSize, iconSize);
  148.                     return;
  149.                 }
  150.             }
  151.         }
  152.  
  153.         private void DrawPotionPerfection(IItem item, System.Drawing.RectangleF rect) {
  154.             if (rect == null) return;
  155.  
  156.             foreach (var perfection in item.Perfections) {
  157.                 if (perfection.Max == perfection.Min) continue;
  158.                 var Percentage = (perfection.Cur - perfection.Min) / (perfection.Max - perfection.Min);
  159.                 var layout = PotionFont.GetTextLayout(Percentage >= 1d ? perfectMsg : Percentage.ToString("0.#%"));
  160.  
  161.                 PotionFont.DrawText(layout, rect.X, rect.Bottom - layout.Metrics.Height);
  162.             }
  163.         }
  164.     }
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement