Advertisement
RNNCode

Materials

Mar 25th, 2024
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.39 KB | None | 0 0
  1. using Turbo.Plugins.Default;
  2. using System.Globalization;
  3. using System;
  4. using System.Collections.Generic;
  5.  
  6. namespace Turbo.Plugins.RNN
  7. {
  8.     public class Materials : BasePlugin, ICustomizer, IInGameTopPainter
  9.     {
  10.         private float x { get; set; }
  11.         private float y { get; set; }
  12.         private float Space { get; set; } = 0;
  13.         private float sizeIcon { get; set; }
  14.  
  15.         private IBrush BorderBrushRed { get; set; }
  16.         private IFont FontDefault { get; set; }
  17.  
  18.         private delegate long AmountFunc();
  19.         private delegate bool WarningFunc();
  20.         private List<Tuple<ITexture, IFont, AmountFunc, WarningFunc, bool>> ListMaterials { get; set; } = new List<Tuple<ITexture, IFont, AmountFunc, WarningFunc, bool>>();
  21.  
  22.         public float Xpor { get; set; }
  23.         public float Ypor { get; set; }
  24.         public float SizeMultiplier { get; set; }
  25.         public float Separation { get; set; }
  26.         public bool ColorText  { get; set; }
  27.         public bool WarningBS { get; set; }
  28.         public long RemainingBS { get; set; }
  29.         public bool WarningIS { get; set; }
  30.         public long RemainingIS { get; set; }
  31.         public bool OnlyInTown  { get; set; }
  32.         public bool DisableBSIPlugins { get; set; }
  33.  
  34.         public enum MatsEnum { ReusableParts = 1, ArcaneDust = 2, VeiledCrystal = 3, DeathsBreath = 4, ForgottenSoul = 5, GreaterRiftKeystone = 6, BloodShard = 7, PrimordialAshes =8, InventorySpace = 9 }
  35.         public MatsEnum[] MaterialsOrderEnum { get; set; }
  36.  
  37.         public int[] MaterialsOrder { get; set; } = new int[]{1,2,3,4,5,8,6,7,9}; // Deprecated, 1=ReusableParts, 2=ArcaneDust, 3=VeiledCrystal, 4=DeathsBreath, 5=ForgottenSoul, 6=GreaterRiftKeystone, 7=BloodShard, 8=primordial Ashes, 9=InventorySpace
  38.  
  39.         public Materials()
  40.         {
  41.             Enabled = true;
  42.         }
  43.  
  44.         public override void Load(IController hud)
  45.         {
  46.             base.Load(hud);
  47.             Order = 30001;
  48.  
  49.             Xpor = 0.567f;              // Valid values: from 0 to 1
  50.             Ypor = 0.983f;              // Valid values: from 0 to 1
  51.             OnlyInTown = false;         // Show only in town
  52.             ColorText = true;           // Different colors will be used for the text or white if ColorText = false
  53.             SizeMultiplier = 1.1f;      // Size multiplier for text and icons
  54.             Separation = 0.5f;          // Valid values: equal to or greater than zero . Separation between one material and the next
  55.             WarningBS = true;           // Show Rectagle Red when Remaining Blood Shard < RemainingBS
  56.             RemainingBS = 250;          // Limit Blood Shard
  57.             WarningIS = true;           // Show Rectagle Red when Remaining free Inventory Space < RemainingIS
  58.             RemainingIS = 5;            // Limit free Inventory Space
  59.             DisableBSIPlugins = true;   // Disable default plugins BloodShardPlugin and InventoryFreeSpacePlugin
  60.             MaterialsOrderEnum = new MatsEnum[]
  61.             {
  62.                 MatsEnum.ReusableParts, MatsEnum.ArcaneDust, MatsEnum.VeiledCrystal, MatsEnum.DeathsBreath, MatsEnum.ForgottenSoul, MatsEnum.PrimordialAshes, MatsEnum.GreaterRiftKeystone, MatsEnum.BloodShard, MatsEnum.InventorySpace
  63.             };
  64.  
  65.             BorderBrushRed = Hud.Render.CreateBrush(255, 255, 0, 0, 1);
  66.         }
  67.  
  68.         public void Customize()
  69.         {
  70.             FontDefault = Hud.Render.CreateFont("tahoma", 7 * SizeMultiplier, 255, 255, 255, 255, false, false, 255, 0, 0, 0, true);
  71.  
  72.             sizeIcon = Hud.Texture.GetItemTexture(Hud.Sno.SnoItems.Crafting_AssortedParts_01).Width * 0.26f * SizeMultiplier;
  73.  
  74.             if (DisableBSIPlugins)  //if ((Xpor > 0.5f) && (Xpor < 0.65f) && (Ypor > 0.97f))
  75.             {
  76.                 Hud.TogglePlugin<BloodShardPlugin>(false);
  77.                 Hud.TogglePlugin<InventoryFreeSpacePlugin>(false);
  78.             }
  79.  
  80.             SortingOut(MaterialsOrderEnum);
  81.         }
  82.  
  83.         public void SortingOut (params MatsEnum[] m )
  84.         {
  85.             ListMaterials.Clear();
  86.  
  87.             WarningFunc WarningBSFunc = null; WarningFunc WarningISFunc = null;
  88.             if (WarningBS) {  WarningBSFunc = () => ((500 + (Hud.Game.Me.HighestSoloRiftLevel * 10) - Hud.Game.Me.Materials.BloodShard) < RemainingBS); }
  89.             if (WarningIS) {  WarningISFunc = () => ((Hud.Game.Me.InventorySpaceTotal - Hud.Game.InventorySpaceUsed) < RemainingIS); }
  90.  
  91.             for (var i = 0; i < m.Length ; i++)
  92.             {
  93.                 switch(m[i])
  94.                 {
  95.                     case MatsEnum.ReusableParts:
  96.                             ListMaterials.Add(
  97.                                 new Tuple<ITexture, IFont, AmountFunc, WarningFunc, bool>  // texture, font, amount, warning, text right
  98.                                 (
  99.                                     Hud.Texture.GetItemTexture(Hud.Sno.SnoItems.Crafting_AssortedParts_01),
  100.                                     ColorText? Hud.Render.CreateFont("tahoma", 7 * SizeMultiplier, 255, 175, 180, 175, false, false, 255, 0, 0, 0, true) : FontDefault ,
  101.                                     () => Hud.Game.Me.Materials.ReusableParts,
  102.                                     null,
  103.                                     true
  104.                                 )   );
  105.                             break;
  106.                     case MatsEnum.ArcaneDust:
  107.                             ListMaterials.Add(
  108.                                 new Tuple<ITexture, IFont, AmountFunc, WarningFunc, bool>
  109.                                 (
  110.                                     Hud.Texture.GetItemTexture(Hud.Sno.SnoItems.Crafting_Magic_01),
  111.                                     ColorText?  Hud.Render.CreateFont("tahoma", 7 * SizeMultiplier, 255, 102, 102, 255, false, false, 255, 0, 0, 0, true) : FontDefault ,
  112.                                     () => Hud.Game.Me.Materials.ArcaneDust,
  113.                                     null,
  114.                                     true
  115.                                 )   );
  116.                             break;
  117.                     case MatsEnum.VeiledCrystal:
  118.                             ListMaterials.Add(
  119.                                 new Tuple<ITexture, IFont, AmountFunc, WarningFunc, bool>
  120.                                 (
  121.                                     Hud.Texture.GetItemTexture(Hud.Sno.SnoItems.Crafting_Rare_01),
  122.                                     ColorText? Hud.Render.CreateFont("tahoma", 7 * SizeMultiplier, 255, 255, 255,   0, false, false, 255, 0, 0, 0, true) : FontDefault ,
  123.                                     () => Hud.Game.Me.Materials.VeiledCrystal,
  124.                                     null,
  125.                                     true
  126.                                 )   );
  127.                             break;
  128.                     case MatsEnum.DeathsBreath:
  129.                             ListMaterials.Add(
  130.                                 new Tuple<ITexture, IFont, AmountFunc, WarningFunc, bool>
  131.                                 (
  132.                                     Hud.Texture.GetItemTexture(Hud.Sno.SnoItems.Crafting_Looted_Reagent_01),
  133.                                     ColorText? Hud.Render.CreateFont("tahoma", 7 * SizeMultiplier, 255, 108, 216, 187, false, false, 255, 0, 0, 0, true) : FontDefault ,
  134.                                     () => Hud.Game.Me.Materials.DeathsBreath,
  135.                                     null,
  136.                                     true
  137.                                 )   );
  138.                             break;
  139.                     case MatsEnum.ForgottenSoul:
  140.                             ListMaterials.Add(
  141.                                 new Tuple<ITexture, IFont, AmountFunc, WarningFunc, bool>
  142.                                 (
  143.                                     Hud.Texture.GetItemTexture(Hud.Sno.SnoItems.Crafting_Legendary_01),
  144.                                     ColorText? Hud.Render.CreateFont("tahoma", 7 * SizeMultiplier, 255, 255, 128,   0, false, false, 255, 0, 0, 0, true) : FontDefault ,
  145.                                     () => Hud.Game.Me.Materials.ForgottenSoul,
  146.                                     null,
  147.                                     true
  148.                                 )   );
  149.                             break;
  150.                     case MatsEnum.GreaterRiftKeystone:
  151.                             ListMaterials.Add(
  152.                                 new Tuple<ITexture, IFont, AmountFunc, WarningFunc, bool>
  153.                                 (
  154.                                     Hud.Texture.GetItemTexture(Hud.Sno.SnoItems.GreaterLootRunKey),
  155.                                     ColorText? Hud.Render.CreateFont("tahoma", 7 * SizeMultiplier, 255, 220, 135, 220, false, false, 255, 0, 0, 0, true) : FontDefault ,
  156.                                     () => Hud.Game.Me.Materials.GreaterRiftKeystone,
  157.                                     null,
  158.                                     true
  159.                                 )   );
  160.                             break;
  161.                     case MatsEnum.BloodShard:
  162.                             ListMaterials.Add(
  163.                                 new Tuple<ITexture, IFont, AmountFunc, WarningFunc, bool>
  164.                                 (
  165.                                     Hud.Texture.GetItemTexture(Hud.Sno.SnoItems.HoradricRelic),
  166.                                     ColorText? Hud.Render.CreateFont("tahoma", 7 * SizeMultiplier, 255, 245,  75,  75, false, false, 255, 0, 0, 0, true) : FontDefault ,
  167.                                     () => Hud.Game.Me.Materials.BloodShard,
  168.                                     WarningBSFunc,
  169.                                     true
  170.                                 )   );
  171.                             break;
  172.                     case MatsEnum.PrimordialAshes:
  173.                             ListMaterials.Add(
  174.                                 new Tuple<ITexture, IFont, AmountFunc, WarningFunc, bool>
  175.                                 (
  176.                                     Hud.Texture.GetItemTexture(Hud.Sno.SnoItems.Crafting_Legendary_Primal_01),
  177.                                     ColorText? Hud.Render.CreateFont("tahoma", 7 * SizeMultiplier, 255, 255, 128,   0, false, false, 255, 0, 0, 0, true) : FontDefault ,
  178.                                     () => Hud.Game.Me.Materials.PrimordialAshes,
  179.                                     null,
  180.                                     true
  181.                                 )   );
  182.                             break;
  183.                     case MatsEnum.InventorySpace:
  184.                             ListMaterials.Add(
  185.                                 new Tuple<ITexture, IFont, AmountFunc, WarningFunc, bool>
  186.                                 (
  187.                                     Hud.Texture.Button2TextureBrown,
  188.                                     ColorText? Hud.Render.CreateFont("tahoma", 7 * SizeMultiplier, 255, 225, 135,  80, false, false, 255, 0, 0, 0, true) : FontDefault ,
  189.                                     () => Hud.Game.Me.InventorySpaceTotal - Hud.Game.InventorySpaceUsed,
  190.                                     WarningISFunc,
  191.                                     false
  192.                                 )   );
  193.                             break;
  194.                 }
  195.             }
  196.         }
  197.  
  198.         public string MatsToString(long value)
  199.         {
  200.             if      (value < 1000)      {   return value.ToString("#,0.#", CultureInfo.InvariantCulture);                   }
  201.             else if (value < 1000000)   {   return (value / 1000.0f).ToString("#,0.#K", CultureInfo.InvariantCulture);      }
  202.             else                        {   return (value / 1000000.0f).ToString("#,0.#M", CultureInfo.InvariantCulture);   }
  203.         }
  204.  
  205.         public void PaintTopInGame(ClipState clipState)
  206.         {
  207.             if (clipState != ClipState.BeforeClip) return;
  208.             if (!Hud.Game.IsInGame)  return;
  209.             if (OnlyInTown && !Hud.Game.IsInTown) return;
  210.  
  211.             x = Hud.Window.Size.Width * Xpor;   y = Hud.Window.Size.Height * Ypor;  Space = FontDefault.GetTextLayout("0").Metrics.Height * Separation;
  212.  
  213.             foreach(var m in ListMaterials)
  214.             {
  215.                 m.Item1.Draw(x, y, sizeIcon, sizeIcon);
  216.                 var layout = m.Item2.GetTextLayout( MatsToString(m.Item3()) );
  217.                 x += (m.Item5) ? sizeIcon : (sizeIcon - layout.Metrics.Width)/2f;
  218.                 var yt = y + (sizeIcon - layout.Metrics.Height)/2f ;
  219.                 m.Item2.DrawText(layout, x , yt );
  220.                 if (m.Item4 != null)
  221.                 {
  222.                     if (m.Item4()) BorderBrushRed.DrawRectangle(x - 2, yt + 1, layout.Metrics.Width + 4, layout.Metrics.Height - 1);
  223.                 }
  224.                 x += layout.Metrics.Width + Space;
  225.             }
  226.         }
  227.     }
  228. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement