Advertisement
zjqyf

GLQ_ConventionOfElementsBuffListPlugin.cs

Jan 31st, 2018
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.85 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Turbo.Plugins.Default;
  4.  
  5. namespace Turbo.Plugins.glq
  6. {
  7. public class GLQ_ConventionOfElementsBuffListPlugin : BasePlugin, IInGameTopPainter
  8. {
  9.  
  10. public bool HideWhenUiIsHidden { get; set; }
  11. public BuffPainter BuffPainter { get; set; }
  12.  
  13. private BuffRuleCalculator _ruleCalculator;
  14. public bool MePortraitPaint { get; set; }
  15. public bool MeScreenPaint { get; set; }
  16. public bool OtherPortraitPaint { get; set; }
  17. public bool OtherScreenPaint { get; set; }
  18. public GLQ_ConventionOfElementsBuffListPlugin()
  19. {
  20. Enabled = true;
  21. MeScreenPaint = true;
  22. MePortraitPaint = true;
  23. OtherScreenPaint = true;
  24. OtherPortraitPaint = true;
  25. }
  26.  
  27. public override void Load(IController hud)
  28. {
  29. base.Load(hud);
  30.  
  31. HideWhenUiIsHidden = false;
  32. BuffPainter = new BuffPainter(Hud, true)
  33. {
  34. Opacity = 1.0f,
  35. TimeLeftFont = Hud.Render.CreateFont("tahoma", 8, 255, 255, 255, 255, true, false, 255, 0, 0, 0, true),
  36. };
  37.  
  38. _ruleCalculator = new BuffRuleCalculator(Hud);
  39. _ruleCalculator.SizeMultiplier = 0.55f;
  40.  
  41. _ruleCalculator.Rules.Add(new BuffRule(430674) { IconIndex = 1, MinimumIconCount = 0, DisableName = true }); // Arcane
  42. _ruleCalculator.Rules.Add(new BuffRule(430674) { IconIndex = 2, MinimumIconCount = 0, DisableName = true }); // Cold
  43. _ruleCalculator.Rules.Add(new BuffRule(430674) { IconIndex = 3, MinimumIconCount = 0, DisableName = true }); // Fire
  44. _ruleCalculator.Rules.Add(new BuffRule(430674) { IconIndex = 4, MinimumIconCount = 0, DisableName = true }); // Holy
  45. _ruleCalculator.Rules.Add(new BuffRule(430674) { IconIndex = 5, MinimumIconCount = 0, DisableName = true }); // Lightning
  46. _ruleCalculator.Rules.Add(new BuffRule(430674) { IconIndex = 6, MinimumIconCount = 0, DisableName = true }); // Physical
  47. _ruleCalculator.Rules.Add(new BuffRule(430674) { IconIndex = 7, MinimumIconCount = 0, DisableName = true }); // Poison
  48. }
  49.  
  50. private IEnumerable<BuffRule> GetCurrentRules(HeroClass heroClass)
  51. {
  52. for (int i = 1; i <= 7; i++)
  53. {
  54. switch (heroClass)
  55. {
  56. case HeroClass.Barbarian: if (i == 1 || i == 4 || i == 7) continue; break;
  57. case HeroClass.Crusader: if (i == 1 || i == 2 || i == 7) continue; break;
  58. case HeroClass.DemonHunter: if (i == 1 || i == 4 || i == 7) continue; break;
  59. case HeroClass.Monk: if (i == 1 || i == 7) continue; break;
  60. case HeroClass.WitchDoctor: if (i == 1 || i == 4 || i == 5) continue; break;
  61. case HeroClass.Wizard: if (i == 4 || i == 6 || i == 7) continue; break;
  62. case HeroClass.Necromancer: if (i == 1 || i == 3 || i == 4 || i == 5) continue; break;
  63. }
  64. yield return _ruleCalculator.Rules[i - 1];
  65. }
  66. }
  67.  
  68. public void PaintTopInGame(ClipState clipState)
  69. {
  70. if (clipState != ClipState.BeforeClip) return;
  71. if (HideWhenUiIsHidden && Hud.Render.UiHidden) return;
  72.  
  73. foreach (var player in Hud.Game.Players)
  74. {
  75. if (!player.HasValidActor) continue;
  76.  
  77. var buff = player.Powers.GetBuff(430674);
  78. if ((buff == null) || (buff.IconCounts[0] <= 0)) continue;
  79.  
  80. var classSpecificRules = GetCurrentRules(player.HeroClassDefinition.HeroClass);
  81.  
  82. _ruleCalculator.CalculatePaintInfo(player, classSpecificRules);
  83.  
  84. if (_ruleCalculator.PaintInfoList.Count == 0) return;
  85. if (!_ruleCalculator.PaintInfoList.Any(info => info.TimeLeft > 0)) return;
  86.  
  87. var highestElementalBonus = player.Offense.HighestElementalDamageBonus;
  88.  
  89. for (int i = 0; i < _ruleCalculator.PaintInfoList.Count; i++)
  90. {
  91. var info = _ruleCalculator.PaintInfoList[0];
  92. if (info.TimeLeft <= 0)
  93. {
  94. _ruleCalculator.PaintInfoList.RemoveAt(0);
  95. _ruleCalculator.PaintInfoList.Add(info);
  96. }
  97. else break;
  98. }
  99.  
  100. for (int orderIndex = 0; orderIndex < _ruleCalculator.PaintInfoList.Count; orderIndex++)
  101. {
  102. var info = _ruleCalculator.PaintInfoList[orderIndex];
  103. var best = false;
  104. switch (info.Rule.IconIndex)
  105. {
  106. case 1: best = player.Offense.BonusToArcane == highestElementalBonus; break;
  107. case 2: best = player.Offense.BonusToCold == highestElementalBonus; break;
  108. case 3: best = player.Offense.BonusToFire == highestElementalBonus; break;
  109. case 4: best = player.Offense.BonusToHoly == highestElementalBonus; break;
  110. case 5: best = player.Offense.BonusToLightning == highestElementalBonus; break;
  111. case 6: best = player.Offense.BonusToPhysical == highestElementalBonus; break;
  112. case 7: best = player.Offense.BonusToPoison == highestElementalBonus; break;
  113. }
  114. if (best) info.Size *= 1.35f;
  115. if (best && orderIndex > 0)
  116. {
  117. info.TimeLeft = (orderIndex - 1) * 4 + _ruleCalculator.PaintInfoList[0].TimeLeft;
  118. }
  119. else info.TimeLeftNumbersOverride = false;
  120. }
  121. var portraitRect = player.PortraitUiElement.Rectangle;
  122.  
  123. var x = portraitRect.Right;
  124. var y = portraitRect.Top + portraitRect.Height * 0.51f;
  125. if(player.IsMe)
  126. {
  127. if(MeScreenPaint)
  128. {
  129. BuffPainter.PaintHorizontalCenter(_ruleCalculator.PaintInfoList, 0, Hud.Window.Size.Height * 0.5f - Hud.Window.Size.Height * 0.2f, Hud.Window.Size.Width, _ruleCalculator.StandardIconSize, 0);
  130. }
  131. if(MePortraitPaint)
  132. {
  133. BuffPainter.PaintHorizontal(_ruleCalculator.PaintInfoList, x, y, _ruleCalculator.StandardIconSize, 0);
  134. }
  135. }
  136. else
  137. {
  138. if(OtherScreenPaint)
  139. {
  140. BuffPainter.PaintHorizontalCenter(_ruleCalculator.PaintInfoList, player.ScreenCoordinate.X, player.ScreenCoordinate.Y - Hud.Window.Size.Height * 0.1f, 0, _ruleCalculator.StandardIconSize, 0);
  141. }
  142. if(OtherPortraitPaint)
  143. {
  144. BuffPainter.PaintHorizontal(_ruleCalculator.PaintInfoList, x, y, _ruleCalculator.StandardIconSize, 0);
  145. }
  146. }
  147.  
  148.  
  149.  
  150.  
  151. }
  152. }
  153.  
  154. }
  155.  
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement