forked from Arecurius0/HealthBars
-
Notifications
You must be signed in to change notification settings - Fork 3
/
HealthBars.cs
422 lines (360 loc) · 16.6 KB
/
HealthBars.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using ExileCore;
using ExileCore.PoEMemory;
using ExileCore.PoEMemory.Components;
using ExileCore.PoEMemory.MemoryObjects;
using ExileCore.Shared.Cache;
using ExileCore.Shared.Enums;
using SharpDX;
namespace HealthBars
{
public class HealthBars : BaseSettingsPlugin<HealthBarsSettings>
{
private Camera camera;
private bool CanTick = true;
private readonly List<Element> ElementForSkip = new List<Element>();
private const string IGNORE_FILE = "IgnoredEntities.txt";
private List<string> IgnoredSum;
private List<string> Ignored = new List<string>
{
"Metadata/Monsters/Daemon/SilverPoolChillDaemon",
"Metadata/Monsters/Daemon",
"Metadata/Monsters/Frog/FrogGod/SilverOrb",
"Metadata/Monsters/Frog/FrogGod/SilverPool",
"Metadata/Monsters/Labyrinth/GoddessOfJusticeMapBoss@7",
"Metadata/Monsters/Labyrinth/GoddessOfJustice@",
"Metadata/Monsters/LeagueBetrayal/MasterNinjaCop",
//Delirium Ignores
"Metadata/Monsters/LeagueAffliction/DoodadDaemons/DoodadDaemonEyes1",
"Metadata/Monsters/LeagueAffliction/DoodadDaemons/DoodadDaemonEyes2",
"Metadata/Monsters/LeagueAffliction/DoodadDaemons/DoodadDaemonEyes3",
"Metadata/Monsters/LeagueAffliction/DoodadDaemons/DoodadDaemonSpikes",
"Metadata/Monsters/LeagueAffliction/DoodadDaemons/DoodadDaemonSpikes2",
"Metadata/Monsters/LeagueAffliction/DoodadDaemons/DoodadDaemonSpikes3",
"Metadata/Monsters/LeagueAffliction/DoodadDaemons/DoodadDaemonPimple1",
"Metadata/Monsters/LeagueAffliction/DoodadDaemons/DoodadDaemonPimple2",
"Metadata/Monsters/LeagueAffliction/DoodadDaemons/DoodadDaemonPimple3",
"Metadata/Monsters/LeagueAffliction/DoodadDaemons/DoodadDaemonGoatFillet1Vanish",
"Metadata/Monsters/LeagueAffliction/DoodadDaemons/DoodadDaemonGoatFillet2Vanish",
"Metadata/Monsters/LeagueAffliction/DoodadDaemons/DoodadDaemonGoatRhoa1Vanish",
"Metadata/Monsters/LeagueAffliction/DoodadDaemons/DoodadDaemonGoatRhoa2Vanish",
"Metadata/Monsters/InvisibleFire/InvisibleFireAfflictionCorpseDegen",
"Metadata/Monsters/InvisibleFire/InvisibleFireAfflictionDemonColdDegenUnique",
"Metadata/Monsters/VolatileCore/VolatileDeadCore",
};
private IngameUIElements ingameUI;
private CachedValue<bool> ingameUICheckVisible;
private Vector2 oldplayerCord;
private Entity Player;
private HealthBar PlayerBar;
private double time;
private RectangleF windowRectangle;
private Size2F windowSize;
public override void OnLoad()
{
CanUseMultiThreading = true;
Graphics.InitImage("healthbar.png");
}
public override bool Initialise()
{
Player = GameController.Player;
ingameUI = GameController.IngameState.IngameUi;
PlayerBar = new HealthBar(Player, Settings);
GameController.EntityListWrapper.PlayerUpdate += (sender, args) =>
{
Player = GameController.Player;
PlayerBar = new HealthBar(Player, Settings);
};
ingameUICheckVisible = new TimeCache<bool>(() =>
{
windowRectangle = GameController.Window.GetWindowRectangleReal();
windowSize = new Size2F(windowRectangle.Width / 2560, windowRectangle.Height / 1600);
camera = GameController.Game.IngameState.Camera;
return ingameUI.SyndicatePanel.IsVisibleLocal || ingameUI.SellWindow.IsVisibleLocal ||
ingameUI.DelveWindow.IsVisibleLocal || ingameUI.IncursionWindow.IsVisibleLocal ||
ingameUI.UnveilWindow.IsVisibleLocal || ingameUI.TreePanel.IsVisibleLocal || ingameUI.Atlas.IsVisibleLocal ||
ingameUI.CraftBench.IsVisibleLocal;
}, 250);
ReadIgnoreFile();
return true;
}
private void CreateIgnoreFile()
{
var path = $"{DirectoryFullName}\\{IGNORE_FILE}";
var defaultConfig =
#region default Config
"#default ignores\n" +
"Metadata/Monsters/Daemon/SilverPoolChillDaemon\n" +
"Metadata/Monsters/Daemon\n" +
"Metadata/Monsters/Frog/FrogGod/SilverOrb\n" +
"Metadata/Monsters/Frog/FrogGod/SilverPool\n" +
"Metadata/Monsters/Labyrinth/GoddessOfJusticeMapBoss@7\n" +
"Metadata/Monsters/Labyrinth/GoddessOfJustice@\n" +
"Metadata/Monsters/LeagueBetrayal/MasterNinjaCop\n" +
"#Delirium Ignores\n" +
"Metadata/Monsters/LeagueAffliction/DoodadDaemons/DoodadDaemonEyes1\n" +
"Metadata/Monsters/LeagueAffliction/DoodadDaemons/DoodadDaemonEyes2\n" +
"Metadata/Monsters/LeagueAffliction/DoodadDaemons/DoodadDaemonEyes3\n" +
"Metadata/Monsters/LeagueAffliction/DoodadDaemons/DoodadDaemonSpikes\n" +
"Metadata/Monsters/LeagueAffliction/DoodadDaemons/DoodadDaemonSpikes2\n" +
"Metadata/Monsters/LeagueAffliction/DoodadDaemons/DoodadDaemonSpikes3\n" +
"Metadata/Monsters/LeagueAffliction/DoodadDaemons/DoodadDaemonPimple1\n" +
"Metadata/Monsters/LeagueAffliction/DoodadDaemons/DoodadDaemonPimple2\n" +
"Metadata/Monsters/LeagueAffliction/DoodadDaemons/DoodadDaemonPimple3\n" +
"Metadata/Monsters/LeagueAffliction/DoodadDaemons/DoodadDaemonGoatFillet1Vanish\n" +
"Metadata/Monsters/LeagueAffliction/DoodadDaemons/DoodadDaemonGoatFillet2Vanish\n" +
"Metadata/Monsters/LeagueAffliction/DoodadDaemons/DoodadDaemonGoatRhoa1Vanish\n" +
"Metadata/Monsters/LeagueAffliction/DoodadDaemons/DoodadDaemonGoatRhoa2Vanish\n" +
"Metadata/Monsters/InvisibleFire/InvisibleFireAfflictionCorpseDegen\n" +
"Metadata/Monsters/InvisibleFire/InvisibleFireAfflictionDemonColdDegenUnique\n";
#endregion
if (File.Exists(path)) return;
using (var streamWriter = new StreamWriter(path, true))
{
streamWriter.Write(defaultConfig);
streamWriter.Close();
}
}
private void ReadIgnoreFile()
{
var path = $"{DirectoryFullName}\\{IGNORE_FILE}";
if (File.Exists(path))
{
var text = File.ReadAllLines(path).Where(line => !string.IsNullOrWhiteSpace(line) && !line.StartsWith("#")).ToList();
IgnoredSum = Ignored.Concat(text).ToList();
} else
CreateIgnoreFile();
}
public override void AreaChange(AreaInstance area)
{
ingameUI = GameController.IngameState.IngameUi;
ReadIgnoreFile();
}
public void HpBarWork(HealthBar healthBar)
{
if (healthBar.Life == null || healthBar.Settings == null || !healthBar.Settings.Enable)
{
healthBar.Skip = true;
return;
}
if (!healthBar.Entity.IsAlive)
{
healthBar.Skip = true;
return;
}
var healthBarDistance = healthBar.Distance;
if (healthBarDistance > Settings.LimitDrawDistance)
{
healthBar.Skip = true;
return;
}
healthBar.HpPercent = healthBar.Life.HPPercentage;
if (healthBar.HpPercent < 0.001f)
{
healthBar.Skip = true;
return;
}
if (healthBar.Type == CreatureType.Minion && healthBar.HpPercent * 100 > Settings.ShowMinionOnlyBelowHp)
{
healthBar.Skip = true;
return;
}
if (healthBar.Entity.League == LeagueType.Legion && healthBar.Entity.IsHidden && healthBar.Entity.Rarity != MonsterRarity.Unique)
{
healthBar.Skip = true;
return;
}
if (healthBar.Settings.ShowFloatingCombatDamage)
{
healthBar.DpsRefresh();
}
var _ = healthBar.IsHostile;
var worldCoords = healthBar.Entity.Pos;
worldCoords.Z += Settings.GlobalZ;
var mobScreenCoords = camera.WorldToScreen(worldCoords);
if (mobScreenCoords == Vector2.Zero) return;
var scaledWidth = healthBar.Settings.Width * windowSize.Width;
var scaledHeight = healthBar.Settings.Height * windowSize.Height;
healthBar.BackGround = new RectangleF(mobScreenCoords.X - scaledWidth / 2f, mobScreenCoords.Y - scaledHeight / 2f, scaledWidth,
scaledHeight);
if (healthBarDistance > 80 && !windowRectangle.Intersects(healthBar.BackGround))
{
healthBar.Skip = true;
return;
}
foreach (var forSkipBar in ElementForSkip)
{
if (forSkipBar.IsVisibleLocal && forSkipBar.GetClientRectCache.Intersects(healthBar.BackGround))
{
healthBar.Skip = true;
}
}
healthBar.HpWidth = healthBar.HpPercent * scaledWidth;
healthBar.EsWidth = healthBar.Life.ESPercentage * scaledWidth;
}
public override Job Tick()
{
if (Settings.MultiThreading && GameController.EntityListWrapper.ValidEntitiesByType[EntityType.Monster].Count >=
Settings.MultiThreadingCountEntities)
{
return new Job(nameof(HealthBars), TickLogic);
// return GameController.MultiThreadManager.AddJob(TickLogic, nameof(HealthBars));
}
TickLogic();
return null;
}
private void TickLogic()
{
CanTick = true;
if (ingameUICheckVisible?.Value ?? false)
{
CanTick = false;
return;
}
if (camera == null)
{
CanTick = false;
return;
}
if (GameController.Area.CurrentArea.IsTown && !Settings.ShowInTown)
{
CanTick = false;
return;
}
foreach (var validEntity in GameController.EntityListWrapper.ValidEntitiesByType[EntityType.Monster])
{
var healthBar = validEntity.GetHudComponent<HealthBar>();
if (healthBar != null)
HpBarWork(healthBar);
}
foreach (var validEntity in GameController.EntityListWrapper.ValidEntitiesByType[EntityType.Player])
{
var healthBar = validEntity.GetHudComponent<HealthBar>();
if (healthBar != null)
HpBarWork(healthBar);
}
}
public override void Render()
{
if (!CanTick)
return;
foreach (var entity in GameController.EntityListWrapper.ValidEntitiesByType[EntityType.Monster])
{
var healthBar = entity.GetHudComponent<HealthBar>();
if (healthBar == null) continue;
if (healthBar.Skip)
{
healthBar.Skip = false;
continue;
}
DrawBar(healthBar);
}
foreach (var entity in GameController.EntityListWrapper.ValidEntitiesByType[EntityType.Player])
{
var healthBar = entity.GetHudComponent<HealthBar>();
if (healthBar == null) continue;
if (healthBar.Skip)
{
healthBar.Skip = false;
continue;
}
DrawBar(healthBar);
}
if (Settings.SelfHealthBarShow)
{
var worldCoords = PlayerBar.Entity.Pos;
worldCoords.Z += Settings.PlayerZ;
var result = camera.WorldToScreen(worldCoords);
if (Math.Abs(oldplayerCord.X - result.X) < 40 || Math.Abs(oldplayerCord.X - result.Y) < 40)
result = oldplayerCord;
else
oldplayerCord = result;
var scaledWidth = PlayerBar.Settings.Width * windowSize.Width;
var scaledHeight = PlayerBar.Settings.Height * windowSize.Height;
PlayerBar.BackGround = new RectangleF(result.X - scaledWidth / 2f, result.Y - scaledHeight / 2f, scaledWidth,
scaledHeight);
PlayerBar.HpPercent = PlayerBar.Life.HPPercentage;
PlayerBar.HpWidth = PlayerBar.HpPercent * scaledWidth;
PlayerBar.EsWidth = PlayerBar.Life.ESPercentage * scaledWidth;
DrawBar(PlayerBar);
}
}
public void DrawBar(HealthBar bar)
{
if (Settings.ImGuiRender)
{
Graphics.DrawBox(bar.BackGround, bar.Settings.BackGround);
Graphics.DrawBox(new RectangleF(bar.BackGround.X, bar.BackGround.Y, bar.HpWidth, bar.BackGround.Height), bar.Color);
}
else
{
Graphics.DrawImage("healthbar.png", bar.BackGround, bar.Settings.BackGround);
Graphics.DrawImage("healthbar.png", new RectangleF(bar.BackGround.X, bar.BackGround.Y, bar.HpWidth, bar.BackGround.Height),
bar.Color);
}
Graphics.DrawBox(new RectangleF(bar.BackGround.X, bar.BackGround.Y, bar.EsWidth, bar.BackGround.Height * 0.33f), Color.Aqua);
bar.BackGround.Inflate(1, 1);
Graphics.DrawFrame(bar.BackGround, bar.Settings.Outline, 1);
if (bar.Settings.ShowPercents)
{
Graphics.DrawText($"{Math.Floor(bar.HpPercent * 100).ToString(CultureInfo.InvariantCulture)}",
new Vector2(bar.BackGround.Right, bar.BackGround.Center.Y - Graphics.Font.Size / 2f),
bar.Settings.PercentTextColor);
}
if (bar.Settings.ShowHealthText)
{
var formattableString = $"{bar.Life.CurHP}/{bar.MaxHp}";
Graphics.DrawText(formattableString,
new Vector2(bar.BackGround.Center.X, bar.BackGround.Center.Y - Graphics.Font.Size / 2f),
bar.Settings.HealthTextColor, FontAlign.Center);
}
if (bar.Settings.ShowFloatingCombatDamage)
{
ShowDps(bar, new Vector2(bar.BackGround.Center.X, bar.BackGround.Y));
}
}
private void ShowDps(HealthBar healthBar, Vector2 point)
{
const int MARGIN_TOP = 2;
const int LAST_DAMAGE_ADD_SIZE = 7;
var fontSize = healthBar.Settings.FloatingCombatTextSize + LAST_DAMAGE_ADD_SIZE;
var textHeight = Graphics.MeasureText("100500", fontSize).Y;
point.Y -= (textHeight + MARGIN_TOP);
int i = 0;
foreach (var dps in healthBar.DpsQueue)
{
i++;
var damageColor = healthBar.Settings.FloatingCombatDamageColor;
var sign = string.Empty;
if (dps > 0)
{
damageColor = healthBar.Settings.FloatingCombatHealColor;
sign = "+";
}
string dpsText = $"{sign}{dps}";
Graphics.DrawText(dpsText, point, Color.Black, fontSize, FontAlign.Center);
point.Y -= (Graphics.DrawText(dpsText, point, damageColor, fontSize, FontAlign.Center).Y + MARGIN_TOP);
if (i == 1)
{
fontSize -= LAST_DAMAGE_ADD_SIZE;
}
}
healthBar.DpsDequeue();
}
public override void EntityAdded(Entity Entity)
{
if (Entity.Type != EntityType.Monster && Entity.Type != EntityType.Player || Entity.Address == GameController.Player.Address ||
Entity.Type == EntityType.Daemon) return;
if (Entity.GetComponent<Life>() != null && !Entity.IsAlive) return;
if (IgnoredSum.Any(x => Entity.Path.StartsWith(x))) return;
Entity.SetHudComponent(new HealthBar(Entity, Settings));
}
public override void EntityRemoved(Entity Entity)
{
}
}
}