Advertisement
s4000

DAV_MainStatPlugin

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