HPbar


SUBMITTED BY: Alerand

DATE: May 4, 2016, 9:20 a.m.

FORMAT: Text only

SIZE: 3.0 kB

HITS: 18739

  1. using System;
  2. using LeagueSharp;
  3. using SharpDX;
  4. using SharpDX.Direct3D9;
  5. using Color = System.Drawing.Color;
  6. namespace HoolaRiven
  7. {
  8. internal class HpBarIndicator
  9. {
  10. public static Device dxDevice = Drawing.Direct3DDevice;
  11. public static Line dxLine;
  12. public float hight = 9;
  13. public float width = 104;
  14. public HpBarIndicator()
  15. {
  16. dxLine = new Line(dxDevice) { Width = 9 };
  17. Drawing.OnPreReset += DrawingOnOnPreReset;
  18. Drawing.OnPostReset += DrawingOnOnPostReset;
  19. AppDomain.CurrentDomain.DomainUnload += CurrentDomainOnDomainUnload;
  20. AppDomain.CurrentDomain.ProcessExit += CurrentDomainOnDomainUnload;
  21. }
  22. public Obj_AI_Hero unit { get; set; }
  23. private Vector2 Offset
  24. {
  25. get
  26. {
  27. if (unit != null)
  28. {
  29. return unit.IsAlly ? new Vector2(34, 9) : new Vector2(10, 20);
  30. }
  31. return new Vector2();
  32. }
  33. }
  34. public Vector2 startPosition
  35. {
  36. get { return new Vector2(unit.HPBarPosition.X + Offset.X, unit.HPBarPosition.Y + Offset.Y); }
  37. }
  38. private static void CurrentDomainOnDomainUnload(object sender, EventArgs eventArgs)
  39. {
  40. dxLine.Dispose();
  41. }
  42. private static void DrawingOnOnPostReset(EventArgs args)
  43. {
  44. dxLine.OnResetDevice();
  45. }
  46. private static void DrawingOnOnPreReset(EventArgs args)
  47. {
  48. dxLine.OnLostDevice();
  49. }
  50. private float getHpProc(float dmg = 0)
  51. {
  52. float health = ((unit.Health - dmg) > 0) ? (unit.Health - dmg) : 0;
  53. return (health / unit.MaxHealth);
  54. }
  55. private Vector2 getHpPosAfterDmg(float dmg)
  56. {
  57. float w = getHpProc(dmg) * width;
  58. return new Vector2(startPosition.X + w, startPosition.Y);
  59. }
  60. public void drawDmg(float dmg, ColorBGRA color)
  61. {
  62. Vector2 hpPosNow = getHpPosAfterDmg(0);
  63. Vector2 hpPosAfter = getHpPosAfterDmg(dmg);
  64. fillHPBar(hpPosNow, hpPosAfter, color);
  65. //fillHPBar((int)(hpPosNow.X - startPosition.X), (int)(hpPosAfter.X- startPosition.X), color);
  66. }
  67. private void fillHPBar(int to, int from, Color color)
  68. {
  69. var sPos = startPosition;
  70. for (var i = from; i < to; i++)
  71. {
  72. Drawing.DrawLine(sPos.X + i, sPos.Y, sPos.X + i, sPos.Y + 9, 1, color);
  73. }
  74. }
  75. private void fillHPBar(Vector2 from, Vector2 to, ColorBGRA color)
  76. {
  77. dxLine.Begin();
  78. dxLine.Draw(new[] {
  79. new Vector2((int) from.X, (int) from.Y + 4f),
  80. new Vector2((int) to.X, (int) to.Y + 4f) }, color);
  81. dxLine.End();
  82. }
  83. }
  84. }

comments powered by Disqus