Advertisement
lunamanx

GLQ_PlayerInfoPlugin.cs

Nov 8th, 2017
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.16 KB | None | 0 0
  1. namespace Turbo.Plugins.glq
  2. {
  3. using System.Globalization;
  4. using System.Linq;
  5. using Turbo.Plugins.Default;
  6. using Turbo.Plugins.Jack.Decorators.TopTables;
  7.  
  8. public class GLQ_PlayerInfoPlugin : BasePlugin, INewAreaHandler, IInGameTopPainter
  9. {
  10. public TopTable Table { get; set; }
  11.  
  12. private int lastPlayerCount = -1;
  13. private int hoveredPlayerIndex = -1;
  14.  
  15. public GLQ_PlayerInfoPlugin()
  16. {
  17. Enabled = true;
  18. Order = int.MaxValue;
  19. }
  20.  
  21. public override void Load(IController hud)
  22. {
  23. base.Load(hud);
  24.  
  25. Table = new TopTable(Hud)
  26. {
  27. RatioPositionX = 0.5f,
  28. RatioPositionY = 0.03f,
  29. HorizontalCenter = true,
  30. VerticalCenter = false,
  31. PositionFromRight = false,
  32. PositionFromBottom = false,
  33. ShowHeaderLeft = false,
  34. ShowHeaderTop = true,
  35. ShowHeaderRight = false,
  36. ShowHeaderBottom = false,
  37. DefaultCellDecorator = new TopTableCellDecorator(Hud)
  38. {
  39. BackgroundBrush = Hud.Render.CreateBrush(255, 0, 0, 0, 0),
  40. BorderBrush = Hud.Render.CreateBrush(255, 70, 56, 42, 1.5f),
  41. TextFont = Hud.Render.CreateFont("tahoma", 7, 255, 255, 255, 255, false, false, false),
  42. },
  43. DefaultHighlightDecorator = new TopTableCellDecorator(Hud)
  44. {
  45. BackgroundBrush = Hud.Render.CreateBrush(255, 0, 0, 242, 0),
  46. BorderBrush = Hud.Render.CreateBrush(255, 70, 56, 42, 1.5f),
  47. TextFont = Hud.Render.CreateFont("tahoma", 7, 255, 255, 255, 255, false, false, false),
  48. },
  49. DefaultHeaderDecorator = new TopTableCellDecorator(Hud)
  50. {
  51. BackgroundBrush = Hud.Render.CreateBrush(255, 0, 0, 0, 0),
  52. BorderBrush = Hud.Render.CreateBrush(255, 70, 56, 42, 1.5f),
  53. TextFont = Hud.Render.CreateFont("tahoma", 7, 255, 255, 255, 255, false, false, true),
  54. }
  55. };
  56. DefineColumns();
  57. }
  58.  
  59. public void OnNewArea(bool newGame, ISnoArea area)
  60. {
  61. if (!newGame) return;
  62.  
  63. lastPlayerCount = -1;
  64. }
  65.  
  66. private void DefineTable()
  67. {
  68. Table.Reset(true); // keep columns
  69.  
  70. foreach (var player in Hud.Game.Players.OrderBy(p => p.PortraitIndex))
  71. {
  72. if (player == null) continue;
  73.  
  74. Table.AddLine(
  75. new TopTableHeader(Hud, (pos, curPos) => "")
  76. {
  77. RatioWidth = 120 / 1080f,
  78. RatioHeight = 28 / 1080f,
  79. HighlightFunc = (pos, curPos) => hoveredPlayerIndex == pos,
  80. HighlightDecorator = new TopTableCellDecorator(Hud)
  81. {
  82. BackgroundBrush = Hud.Render.CreateBrush(255, 255, 255, 128, 0),
  83. BorderBrush = Hud.Render.CreateBrush(255, 70, 56, 42, 1.5f),
  84. TextFont = Hud.Render.CreateFont("tahoma", 7, 255, 0, 0, 0, true, false, false),
  85. },
  86. CellHighlightDecorator = new TopTableCellDecorator(Hud)
  87. {
  88. BackgroundBrush = Hud.Render.CreateBrush(255, 255, 0, 255, 0),
  89. BorderBrush = Hud.Render.CreateBrush(255, 70, 56, 42, 1.5f),
  90. TextFont = Hud.Render.CreateFont("tahoma", 7, 255, 255, 255, 255, true, false, true),
  91. },
  92. },
  93. new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  94. new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  95. new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  96. new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  97. new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  98. new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  99. new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  100. new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  101. new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  102. new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  103. new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  104. new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  105. new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  106. new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  107. new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c)),
  108. new TopTableCell(Hud, (l, c, ls, cs) => GetCellText(l, c))
  109. );
  110. }
  111. }
  112.  
  113. private string GetCellText(int line, int column)
  114. {
  115. var player = Hud.Game.Players.FirstOrDefault(p => p.PortraitIndex == line);
  116. if (player == null) return string.Empty;
  117.  
  118. switch (column)
  119. {
  120. case 0:
  121. return player.BattleTagAbovePortrait;
  122. case 1:
  123. return ValueToString((long)player.Defense.EhpCur, ValueFormat.LongNumber);
  124. case 2:
  125. return ValueToString((long)player.Defense.HealthCur, ValueFormat.LongNumber);
  126. case 3:
  127. return ValueToString((long)player.Offense.SheetDps, ValueFormat.LongNumber);
  128. case 4:
  129. return ValueToString((long)((player.Offense.HighestElementalDamageBonus + 1) * (player.Offense.SheetDps)), ValueFormat.LongNumber);
  130. case 5:
  131. return ValueToString((long)((player.Offense.BonusToElites + 1) * ((player.Offense.HighestElementalDamageBonus + 1) * (player.Offense.SheetDps))), ValueFormat.LongNumber);
  132. case 6:
  133. return player.Offense.AttackSpeed.ToString("F2", CultureInfo.InvariantCulture) + "/s";
  134. case 7:
  135. return player.Offense.AttackSpeedPets.ToString("F2", CultureInfo.InvariantCulture) + "/s";
  136. case 8:
  137. return player.Offense.CriticalHitChance.ToString("F2", CultureInfo.InvariantCulture) + "%";
  138. case 9:
  139. return player.Offense.CritDamage.ToString("F2", CultureInfo.InvariantCulture) + "%";
  140. case 10:
  141. return (player.Stats.CooldownReduction * 100).ToString("F1", CultureInfo.InvariantCulture) + "%";
  142. case 11:
  143. return (player.Stats.ResourceCostReduction * 100).ToString("F1", CultureInfo.InvariantCulture) + "%";
  144. case 12:
  145. return player.Offense.AreaDamageBonus.ToString() + "%";
  146. case 13:
  147. return player.Stats.PickupRange.ToString();
  148. case 14:
  149. return player.HighestSoloRiftLevel.ToString();
  150. case 15:
  151. return player.HighestSoloRiftLevel.ToString();
  152. default:
  153. return string.Empty;
  154. }
  155. }
  156.  
  157. private void DefineColumns()
  158. {
  159. Table.DefineColumns(
  160. new TopTableHeader(Hud, (pos, curPos) => "Player")
  161. {
  162. RatioHeight = 28 / 1080f,
  163. RatioWidth = 120 / 1080f,
  164. },
  165. new TopTableHeader(Hud, (pos, curPos) => "CurEHP")
  166. {
  167. RatioWidth = 0.04f,
  168. },
  169. new TopTableHeader(Hud, (pos, curPos) => "Health")
  170. {
  171. RatioWidth = 0.06f,
  172. },
  173. new TopTableHeader(Hud, (pos, curPos) => "SheetDPS")
  174. {
  175. RatioWidth = 0.06f,
  176. },
  177. new TopTableHeader(Hud, (pos, curPos) => "ElemDPS")
  178. {
  179. RatioWidth = 0.06f,
  180. },
  181. new TopTableHeader(Hud, (pos, curPos) => "EliteDPS")
  182. {
  183. RatioWidth = 0.06f,
  184. },
  185. new TopTableHeader(Hud, (pos, curPos) => "AS")
  186. {
  187. RatioWidth = 0.05f,
  188. },
  189. new TopTableHeader(Hud, (pos, curPos) => "ASPet")
  190. {
  191. RatioWidth = 0.05f,
  192. },
  193. new TopTableHeader(Hud, (pos, curPos) => "C-Hit")
  194. {
  195. RatioWidth = 0.05f,
  196. },
  197. new TopTableHeader(Hud, (pos, curPos) => "C-DMG")
  198. {
  199. RatioWidth = 0.06f,
  200. },
  201. new TopTableHeader(Hud, (pos, curPos) => "CDR")
  202. {
  203. RatioWidth = 0.045f,
  204. },
  205. new TopTableHeader(Hud, (pos, curPos) => "RCR")
  206. {
  207. RatioWidth = 0.045f,
  208. },
  209. new TopTableHeader(Hud, (pos, curPos) => "AreaD")
  210. {
  211. RatioWidth = 0.04f,
  212. },
  213. new TopTableHeader(Hud, (pos, curPos) => "PickUp")
  214. {
  215. RatioWidth = 0.04f,
  216. },
  217. new TopTableHeader(Hud, (pos, curPos) => "SoloGR")
  218. {
  219. RatioWidth = 0.04f,
  220. },
  221. new TopTableHeader(Hud, (pos, curPos) => "N/A")
  222. {
  223. RatioWidth = 0.04f,
  224. }
  225. );
  226. }
  227.  
  228. public void PaintTopInGame(ClipState clipState)
  229. {
  230. if (clipState != ClipState.BeforeClip) return;
  231. if (Hud.Inventory.StashMainUiElement.Visible) return;
  232. var myPortrait = Hud.Game.Me.PortraitUiElement.Rectangle;
  233. if (Hud.Window.CursorX > myPortrait.Right)
  234. {
  235. lastPlayerCount = -1;
  236. return; // cursor is too much to the right, no need to go further
  237. }
  238.  
  239. if (lastPlayerCount != Hud.Game.Players.Count())
  240. {
  241. lastPlayerCount = Hud.Game.Players.Count();
  242. DefineTable();
  243. return; // no need to lose more time within this frame
  244. }
  245.  
  246. var displayTable = false;
  247. foreach (var player in Hud.Game.Players.OrderBy(p => p.PortraitIndex))
  248. {
  249. if (player == null) continue;
  250. var portrait = player.PortraitUiElement.Rectangle;
  251. if (!Hud.Window.CursorInsideRect(portrait.X, portrait.Y, portrait.Width, portrait.Height)) continue;
  252.  
  253. hoveredPlayerIndex = (Hud.Game.NumberOfPlayersInGame > 1) ? player.PortraitIndex : -1;
  254. displayTable = true;
  255. }
  256.  
  257. if (displayTable && Table != null)
  258. Table.Paint();
  259. }
  260. }
  261. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement