Advertisement
Sunfire

TurboHUD Convention Of Elements single icon

Jul 15th, 2018
3,819
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.04 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Turbo.Plugins.Default;
  4. //
  5. // This plugin will show one single icon with the timedown to your best elemtnes on the top of your player.
  6. // If you wearing the Broken Promisses too, it will show another icon while 100% CHC is active.
  7. //
  8. namespace Turbo.Plugins.wq {
  9.     public class ConventionOfElementsAndBrokenPromissesBuffOnCenterPlugin : BasePlugin, IInGameTopPainter {
  10.  
  11.         public bool HideWhenUiIsHidden { get; set; }
  12.         public BuffPainter BuffPainter { get; set; }
  13.         public float PositionOffset { get; set; }
  14.         public float IconSizeMultiplier{get; set;}
  15.  
  16.         public const int ConventionElementID = 430674;
  17.         public const int BrokenPromissesID = 402462;
  18.         public const uint BrokenPromissesSnoItemID = 3106202140;
  19.        
  20.         //CoE means Convention Of Elements
  21.         private BuffRuleCalculator ruleCalculatorCoE;
  22.        
  23.         //BP means Broken Promisses
  24.         private BuffRuleCalculator ruleCalculatorBP;
  25.  
  26.         public ConventionOfElementsAndBrokenPromissesBuffOnCenterPlugin() {
  27.             Enabled = true;
  28.             PositionOffset = 0.04f;
  29.             IconSizeMultiplier = 1.0f;
  30.         }
  31.  
  32.         public override void Load(IController hud) {
  33.             base.Load(hud);
  34.  
  35.             HideWhenUiIsHidden = false;
  36.            
  37.             BuffPainter = new BuffPainter(Hud, true)
  38.             {
  39.                 Opacity = 1.0f,
  40.                 TimeLeftFont = Hud.Render.CreateFont("tahoma", 10, 255, 255, 255, 255, true, false, 255, 0, 0, 0, true),
  41.             };
  42.  
  43.             ruleCalculatorCoE = new BuffRuleCalculator(Hud);
  44.             ruleCalculatorCoE.SizeMultiplier = IconSizeMultiplier;
  45.  
  46.             ruleCalculatorCoE.Rules.Add(new BuffRule(ConventionElementID) { IconIndex = 1, MinimumIconCount = 0, DisableName = true }); // Arcane
  47.             ruleCalculatorCoE.Rules.Add(new BuffRule(ConventionElementID) { IconIndex = 2, MinimumIconCount = 0, DisableName = true }); // Cold
  48.             ruleCalculatorCoE.Rules.Add(new BuffRule(ConventionElementID) { IconIndex = 3, MinimumIconCount = 0, DisableName = true }); // Fire
  49.             ruleCalculatorCoE.Rules.Add(new BuffRule(ConventionElementID) { IconIndex = 4, MinimumIconCount = 0, DisableName = true }); // Holy
  50.             ruleCalculatorCoE.Rules.Add(new BuffRule(ConventionElementID) { IconIndex = 5, MinimumIconCount = 0, DisableName = true }); // Lightning
  51.             ruleCalculatorCoE.Rules.Add(new BuffRule(ConventionElementID) { IconIndex = 6, MinimumIconCount = 0, DisableName = true }); // Physical
  52.             ruleCalculatorCoE.Rules.Add(new BuffRule(ConventionElementID) { IconIndex = 7, MinimumIconCount = 0, DisableName = true }); // Poison
  53.            
  54.             ruleCalculatorBP = new BuffRuleCalculator(Hud);
  55.             ruleCalculatorBP.SizeMultiplier = IconSizeMultiplier;
  56.             ruleCalculatorBP.Rules.Add(new BuffRule(BrokenPromissesID) { IconIndex = 1, MinimumIconCount = 0, DisableName = true});   // Broken Promisses
  57.            
  58.         }
  59.        
  60. //-- Main Function to generate the paint list  
  61.    
  62.         private List<BuffPaintInfo> GeneratePaintList() {
  63.             var player = Hud.Game.Me;
  64.            
  65.             if (!player.HasValidActor) return null;
  66.            
  67.             var paintInfoList = new List<BuffPaintInfo>();
  68.  
  69.             //Add Convention Of Elements and caculate timedown
  70.             var elementPaintInfo = GetElementPaintInfo();
  71.             if(elementPaintInfo != null) {
  72.                 paintInfoList.Add(elementPaintInfo);
  73.             }
  74.            
  75.             var bpPaintInfo = GetBrokenPromissesPaintInfo();
  76.             if(bpPaintInfo != null) {
  77.                 paintInfoList.Add(bpPaintInfo);
  78.             }
  79.            
  80.             return paintInfoList;
  81.         }
  82. //-- End of Main function to generate the paint list
  83.        
  84. //-- Broken Promisses Buff part
  85.  
  86.         // I cant locate the texture of the buff itself(maybe the blizzard doesn't want to show the buff at all).
  87.         // So I use the legendary item instead. It will locate the cube first if there is no then use the
  88.         // inventory to find the ring on your finger.
  89.         private ISnoItem FindBPRing() {
  90.             ISnoItem item = Hud.Game.Me.CubeSnoItem3;
  91.             if(item != null && BrokenPromissesSnoItemID == item.Sno) return item;
  92.             item = Hud.Inventory.GetSnoItem(BrokenPromissesSnoItemID);
  93.             if(item!=null) return item;
  94.             return null;
  95.         }
  96.  
  97.         private BuffPaintInfo GetBrokenPromissesPaintInfo() {
  98.            
  99.             var player = Hud.Game.Me;
  100.            
  101.             ISnoItem item = FindBPRing();
  102.             if(item == null) return null;
  103.            
  104.             var buff = player.Powers.GetBuff(ruleCalculatorBP.Rules[0].PowerSno);
  105.            
  106.             if(buff == null || !buff.Active) return null;
  107.  
  108.             int index = 2; //I dont know why is 2, but it works on my computer.
  109.             var timeLeft = buff.TimeLeftSeconds[index];
  110.            
  111.             // Here I only show icon while the 100% CHC is active
  112.             if(timeLeft > 0) {
  113.                 ruleCalculatorBP.Rules[0].UseLegendaryItemTexture = item;
  114.                 ruleCalculatorBP.CalculatePaintInfo(player);
  115.                 if(ruleCalculatorBP.PaintInfoList.Count > 0) {
  116.                     var info = ruleCalculatorBP.PaintInfoList[0];
  117.                     if(timeLeft > 0) {
  118.                         info.TimeLeft = timeLeft;
  119.                     }
  120.                     return info;
  121.                 }
  122.             }
  123.             return null;
  124.         }
  125. //-- End of Broken Promisses Buff part
  126.  
  127. //-- Convention of Elements Buff part
  128.  
  129.         // This part copied from the Default plugins. Thanks for the job done.
  130.         private IEnumerable<BuffRule> GetCurrentRules(HeroClass heroClass) {
  131.             for (int i = 1; i <= 7; i++)
  132.             {
  133.                 switch (heroClass)
  134.                 {
  135.                     case HeroClass.Barbarian: if (i == 1 || i == 4 || i == 7) continue; break;
  136.                     case HeroClass.Crusader: if (i == 1 || i == 2 || i == 7) continue; break;
  137.                     case HeroClass.DemonHunter: if (i == 1 || i == 4 || i == 7) continue; break;
  138.                     case HeroClass.Monk: if (i == 1 || i == 7) continue; break;
  139.                     case HeroClass.Necromancer: if (i == 1 || i == 3 || i == 4 || i == 5) continue; break;
  140.                     case HeroClass.WitchDoctor: if (i == 1 || i == 4 || i == 5) continue; break;
  141.                     case HeroClass.Wizard: if (i == 4 || i == 6 || i == 7) continue; break;
  142.                 }
  143.                 yield return ruleCalculatorCoE.Rules[i - 1];
  144.             }
  145.         }
  146.        
  147.         private BuffPaintInfo GetElementPaintInfo() {
  148.             var player = Hud.Game.Me;
  149.             var classSpecificRules = GetCurrentRules(player.HeroClassDefinition.HeroClass);
  150.  
  151.             ruleCalculatorCoE.CalculatePaintInfo(player, classSpecificRules);
  152.            
  153.             if (ruleCalculatorCoE.PaintInfoList.Count == 0) return null;
  154.             if (!ruleCalculatorCoE.PaintInfoList.Any(info => info.TimeLeft > 0)) return null;
  155.            
  156.             var buff = Hud.Game.Me.Powers.GetBuff(ConventionElementID);
  157.            
  158.             if ((buff == null) || (buff.IconCounts[0] <= 0)) return null;
  159.            
  160.             var bestElementIndex = LocateBestElement();
  161.             var currentElementIndex = LocateCurrentElement();
  162.            
  163.             var paintInfo = ruleCalculatorCoE.PaintInfoList[currentElementIndex];
  164.  
  165.             if (bestElementIndex == currentElementIndex) {
  166.                 paintInfo.TimeLeftNumbersOverride = false;
  167.             } else if(bestElementIndex > currentElementIndex) {
  168.                 paintInfo.TimeLeft += (bestElementIndex - currentElementIndex - 1) * 4;
  169.             } else {
  170.                 paintInfo.TimeLeft += (ruleCalculatorCoE.PaintInfoList.Count - 1 - currentElementIndex + bestElementIndex) * 4;
  171.             }
  172.             return paintInfo;
  173.         }
  174.        
  175.         private int LocateCurrentElement() {
  176.             for (int index = 0; index < ruleCalculatorCoE.PaintInfoList.Count; index++) {
  177.                 if (ruleCalculatorCoE.PaintInfoList[index].TimeLeft > 0) return index;
  178.             }
  179.             return 0;
  180.         }
  181.        
  182.         private int LocateBestElement() {
  183.             var player = Hud.Game.Me;
  184.             var highestElementalBonus = player.Offense.HighestElementalDamageBonus;
  185.             var list = ruleCalculatorCoE.PaintInfoList;
  186.             for(int index = 0; index < list.Count - 1; index++) {
  187.                 var best = false;
  188.                 var info = list[index];
  189.                 switch (info.Rule.IconIndex) {
  190.                     case 1: best = player.Offense.BonusToArcane == highestElementalBonus; break;
  191.                     case 2: best = player.Offense.BonusToCold == highestElementalBonus; break;
  192.                     case 3: best = player.Offense.BonusToFire == highestElementalBonus; break;
  193.                     case 4: best = player.Offense.BonusToHoly == highestElementalBonus; break;
  194.                     case 5: best = player.Offense.BonusToLightning == highestElementalBonus; break;
  195.                     case 6: best = player.Offense.BonusToPhysical == highestElementalBonus; break;
  196.                     case 7: best = player.Offense.BonusToPoison == highestElementalBonus; break;
  197.                 }
  198.                 if (best) return index;
  199.             }
  200.             return 0;
  201.         }
  202. //-- End of Convention of Elements part
  203.  
  204.         private void debug(string message) {
  205.             Hud.TextLog.Log("Debug", message);
  206.         }
  207.        
  208.         public void PaintTopInGame(ClipState clipState) {
  209.             if (clipState != ClipState.BeforeClip) return;
  210.             if (HideWhenUiIsHidden && Hud.Render.UiHidden) return;
  211.             if(!Enabled) return;
  212.             var paintInfoList = GeneratePaintList();
  213.             if (paintInfoList == null || paintInfoList.Count == 0) return;
  214.            
  215.             var x = 0;
  216.             var y = Hud.Window.Size.Height * 0.25f - Hud.Window.Size.Height * PositionOffset;
  217.             BuffPainter.PaintHorizontalCenter(paintInfoList, x, y, Hud.Window.Size.Width, ruleCalculatorCoE.StandardIconSize, ruleCalculatorCoE.StandardIconSpacing);
  218.         }
  219.     }
  220.  
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement