Advertisement
Guest User

LegendaryCountPlugin.cs

a guest
Apr 19th, 2017
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.21 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.Text;
  3. using Turbo.Plugins.Default;
  4.  
  5. namespace Turbo.Plugins.Csavo // Plugin for counting legendary drops. Credits to JackCeparou (http://www.ownedcore.com/forums/members/1164396-jackceparou.html) for helping out!
  6. {
  7.     public class LegendaryCountPlugin : BasePlugin, IInGameTopPainter, ILootGeneratedHandler, IItemLocationChangedHandler // version 1.0 - April 7th 2017
  8.     {
  9.         public bool ShowPercent { get; set; }
  10.         public bool Debug { get; set; }
  11.         public int LegendaryCount { get; private set; }
  12.         public int AncientCount { get; private set; }
  13.         public int PrimalCount { get; private set; }
  14.         public IFont TextFont { get; set; }
  15.         public Dictionary<ISnoItem, string> SeenItemsCollection { get; set; }
  16.         private StringBuilder lootBuilder;
  17.  
  18.         public LegendaryCountPlugin()
  19.         {
  20.             Enabled = true;
  21.         }
  22.  
  23.         public override void Load(IController hud)
  24.         {
  25.             base.Load(hud);
  26.  
  27.             ShowPercent = false;
  28.             Debug = true;
  29.  
  30.             LegendaryCount = 0;
  31.             AncientCount = 0;
  32.             PrimalCount = 0;
  33.  
  34.             TextFont = Hud.Render.CreateFont("tahoma", 7, 255, 255, 235, 170, false, false, true);
  35.  
  36.             SeenItemsCollection = new Dictionary<ISnoItem, string>();
  37.             lootBuilder = new StringBuilder();
  38.         }
  39.  
  40.         public void OnLootGenerated(IItem item, bool gambled)
  41.         {
  42.             if (item.IsLegendary)
  43.             {
  44.                 if (!SeenItemsCollection.ContainsKey(item.SnoItem))
  45.                 {
  46.                     SeenItemsCollection.Add(item.SnoItem, item.SnoItem.NameLocalized);
  47.                     if (item.AncientRank >= 0) LegendaryCount++;
  48.                     if (item.AncientRank == 1) AncientCount++;
  49.                     if (item.AncientRank == 2) PrimalCount++;
  50.                 }
  51.             }
  52.         }
  53.  
  54.         public void OnItemLocationChanged(IItem item, ItemLocation @from, ItemLocation to)
  55.         {
  56.             if (@from != ItemLocation.Floor || to != ItemLocation.Inventory) return;
  57.             // do what you want with the item you just looted on ground
  58.             if (item.IsLegendary && SeenItemsCollection.ContainsKey(item.SnoItem))
  59.                 {
  60.                     SeenItemsCollection.Remove(item.SnoItem);
  61.                 }
  62.         }
  63.  
  64.         public void PaintTopInGame(ClipState clipState)
  65.         {
  66.             if (clipState != ClipState.BeforeClip) return;
  67.             if (TextFont == null) return;
  68.  
  69.             var uiMinimap = Hud.Render.MinimapUiElement.Rectangle;
  70.             var uiRect = Hud.Render.GetUiElement("Root.NormalLayer.minimap_dialog_backgroundScreen.minimap_dialog_pve.BoostWrapper.BoostsDifficultyStackPanel.clock").Rectangle;
  71.  
  72.             if (!ShowPercent)
  73.             {
  74.                 var text = string.Format("Legos: {0} / {1} / {2}", LegendaryCount, AncientCount, PrimalCount);
  75.                 var layout = TextFont.GetTextLayout(text);
  76.                 TextFont.DrawText(layout, uiMinimap.Left, uiRect.Top + uiRect.Height * 1.15f);
  77.             }
  78.             else
  79.             {
  80.                 var text = string.Format("Legos: {0} / {1} ({2:0.#}%) / {3} ({4:0.##}%)", LegendaryCount, AncientCount, (AncientCount > 0 ? ((float)AncientCount * 100 / LegendaryCount) : 0f), PrimalCount, (PrimalCount > 0 ? ((float)PrimalCount * 100 / LegendaryCount) : 0f));
  81.                 var layout = TextFont.GetTextLayout(text);
  82.                 TextFont.DrawText(layout, uiMinimap.Left, uiRect.Top + uiRect.Height * 1.15f);
  83.             }
  84.             if (Debug)
  85.             {
  86.                 lootBuilder.Clear();
  87.                 lootBuilder.AppendFormat("Items:");
  88.                 lootBuilder.AppendLine();
  89.                 foreach (KeyValuePair<ISnoItem, string> type in SeenItemsCollection)
  90.                 {
  91.                     lootBuilder.AppendFormat("SnoItem: {0}", type.Key);
  92.                     lootBuilder.AppendLine();
  93.                 }
  94.                 var itemsLayout = TextFont.GetTextLayout(lootBuilder.ToString());
  95.                 TextFont.DrawText(itemsLayout, Hud.Window.Size.Width * 0.1f, Hud.Window.Size.Height * 0.1f);
  96.             }
  97.         }
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement