forked from Screeder/SAwareness
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Health.cs
161 lines (147 loc) · 6.05 KB
/
Health.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LeagueSharp;
using LeagueSharp.Common;
using SharpDX;
using SharpDX.Direct3D9;
namespace SAwareness
{
class Health
{
Font font;
private bool drawActive = true;
public Health()
{
try
{
font = new Font(Drawing.Direct3DDevice, new System.Drawing.Font("Times New Roman", 8));
}
catch (Exception)
{
Menu.Health.ForceDisable = true;
Console.WriteLine("Health: Cannot create Font");
return;
}
Drawing.OnPreReset += Drawing_OnPreReset;
Drawing.OnPostReset += Drawing_OnPostReset;
Drawing.OnEndScene += Drawing_OnEndScene;
AppDomain.CurrentDomain.DomainUnload += delegate { Drawing_OnPreReset(new EventArgs()); };
AppDomain.CurrentDomain.ProcessExit += delegate { Drawing_OnPreReset(new EventArgs()); };
}
void Drawing_OnPostReset(EventArgs args)
{
if (Drawing.Direct3DDevice == null || Drawing.Direct3DDevice.IsDisposed)
return;
font.OnResetDevice();
drawActive = true;
}
void Drawing_OnPreReset(EventArgs args)
{
font.OnLostDevice();
drawActive = false;
}
void Drawing_OnEndScene(EventArgs args)
{
DrawTurrentHealth();
DrawInhibitorHealth();
}
~Health()
{
Drawing.OnPreReset -= Drawing_OnPreReset;
Drawing.OnPostReset -= Drawing_OnPostReset;
Drawing.OnEndScene -= Drawing_OnEndScene;
}
public bool IsActive()
{
return Menu.Health.GetActive();
}
private void DrawInhibitorHealth()
{
if (!IsActive() || !drawActive)
return;
if (!Menu.InhibitorHealth.GetActive())
return;
List<Obj_Barracks> _baseB = new List<Obj_Barracks>();
List<Obj_BarracksDampener> _baseBD = ObjectManager.Get<Obj_BarracksDampener>().ToList();
foreach (var inhibitor in _baseB)
{
if (!inhibitor.IsDead && inhibitor.IsValid && inhibitor.Health > 0)
{
Vector2 pos = Drawing.WorldToMinimap(inhibitor.Position);
int health = 0;
StringList mode =
Menu.Health.GetMenuItem("SAwarenessHealthMode")
.GetValue<StringList>();
switch (mode.SelectedIndex)
{
case 0:
health = (int)((inhibitor.Health / inhibitor.MaxHealth) * 100);
break;
case 1:
health = (int)inhibitor.Health;
break;
}
DirectXDrawer.DrawText(font, health.ToString(), (int)pos[0], (int)pos[1], Color.AliceBlue);
//Drawing.DrawText(pos[0], pos[1], System.Drawing.Color.Green, ((int)turret.Health).ToString());
//Drawing.DrawText(turret.HealthBarPosition.X, turret.HealthBarPosition.Y + 20, System.Drawing.Color.Green, ((int)turret.Health).ToString());
}
}
foreach (var inhibitor in _baseBD)
{
if (!inhibitor.IsDead && inhibitor.IsValid)
{
Vector2 pos = Drawing.WorldToMinimap(inhibitor.Position);
int health = 0;
StringList mode =
Menu.Health.GetMenuItem("SAwarenessHealthMode")
.GetValue<StringList>();
switch (mode.SelectedIndex)
{
case 0:
health = (int)((inhibitor.Health / inhibitor.MaxHealth) * 100);
break;
case 1:
health = (int)inhibitor.Health;
break;
}
DirectXDrawer.DrawText(font, health.ToString(), (int)pos[0], (int)pos[1], Color.AliceBlue);
//Drawing.DrawText(pos[0], pos[1], System.Drawing.Color.Green, ((int)turret.Health).ToString());
//Drawing.DrawText(turret.HealthBarPosition.X, turret.HealthBarPosition.Y + 20, System.Drawing.Color.Green, ((int)turret.Health).ToString());
}
}
}
private void DrawTurrentHealth() //TODO: Draw HP above BarPos
{
if (!IsActive())
return;
if (!Menu.TowerHealth.GetActive())
return;
foreach (Obj_AI_Turret turret in ObjectManager.Get<Obj_AI_Turret>())
{
if (!turret.IsDead && turret.IsValid && turret.Health != 9999)
{
Vector2 pos = Drawing.WorldToMinimap(turret.Position);
int health = 0;
StringList mode =
Menu.Health.GetMenuItem("SAwarenessHealthMode")
.GetValue<StringList>();
switch (mode.SelectedIndex)
{
case 0:
health = (int)((turret.Health / turret.MaxHealth) * 100);
break;
case 1:
health = (int)turret.Health;
break;
}
DirectXDrawer.DrawText(font, health.ToString(), (int)pos[0], (int)pos[1], Color.AliceBlue);
//Drawing.DrawText(pos[0], pos[1], System.Drawing.Color.Green, ((int)turret.Health).ToString());
//Drawing.DrawText(turret.HealthBarPosition.X, turret.HealthBarPosition.Y + 20, System.Drawing.Color.Green, ((int)turret.Health).ToString());
}
}
}
}
}