-
Notifications
You must be signed in to change notification settings - Fork 10
/
HealthBar.cs
149 lines (136 loc) · 4.79 KB
/
HealthBar.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
using ExileCore.PoEMemory.Components;
using ExileCore.PoEMemory.MemoryObjects;
using ExileCore.Shared.Cache;
using ExileCore.Shared.Enums;
using SharpDX;
using System;
namespace HealthBars
{
public class HealthBar
{
public bool Skip { get; set; } = false;
public UnitSettings Settings { get; private set; }
public RectangleF BackGround { get; set; }
public DebuffPanel DebuffPanel { get; set; }
private TimeCache<float> _DistanceCache { get; set; }
public float Distance => _DistanceCache.Value;
public Entity Entity { get; }
public CreatureType Type { get; private set; }
public Life Life => Entity.GetComponent<Life>();
public float HpPercent => Life?.HPPercentage ?? 100;
public float HpWidth { get; set; }
public float EsWidth { get; set; }
private readonly Action OnHostileChange = delegate { };
private bool isHostile;
public bool CanNotDie;
private bool _init;
public HealthBar(Entity entity, HealthBarsSettings settings)
{
Entity = entity;
_DistanceCache = new TimeCache<float>(() => entity.DistancePlayer, 200);
DebuffPanel = new DebuffPanel(entity);
Update(entity, settings);
CanNotDie = entity.Path.StartsWith("Metadata/Monsters/Totems/Labyrinth");
var mods = entity?.GetComponent<ObjectMagicProperties>()?.Mods;
if (mods != null && mods.Contains("MonsterConvertsOnDeath_"))
{
OnHostileChange = () =>
{
if (_init) Update(Entity, settings);
};
}
}
public bool IsHostile
{
get
{
var entityIsHostile = Entity.IsHostile;
if (isHostile != entityIsHostile)
{
isHostile = entityIsHostile;
OnHostileChange?.Invoke();
}
return entityIsHostile;
}
}
public Color Color
{
get
{
if (IsHidden(Entity))
return Color.LightGray;
if (HpPercent <= 0.1f)
return Settings.Under10Percent;
return Settings.Color;
}
}
private bool IsHidden(Entity entity)
{
try
{
return entity.IsHidden;
}
catch
{
return false;
}
}
public bool IsShow(bool showEnemy)
{
if (Settings == null)
return false;
return !IsHostile ? Settings.Enable.Value : Settings.Enable.Value && showEnemy && IsHostile;
}
public void Update(Entity entity, HealthBarsSettings settings)
{
if (entity.HasComponent<Player>())
{
Type = CreatureType.Player;
Settings = settings.Players;
}
else if (entity.HasComponent<Monster>())
{
if (entity.IsHostile)
{
var rarity = entity.GetComponent<ObjectMagicProperties>();
if(rarity == null)
{
Type = CreatureType.Minion;
Settings = settings.Minions;
}
else
{
switch (rarity.Rarity)
{
case MonsterRarity.White:
Type = CreatureType.Normal;
Settings = settings.NormalEnemy;
break;
case MonsterRarity.Magic:
Type = CreatureType.Magic;
Settings = settings.MagicEnemy;
break;
case MonsterRarity.Rare:
Settings = settings.RareEnemy;
Type = CreatureType.Rare;
break;
case MonsterRarity.Unique:
Settings = settings.UniqueEnemy;
Type = CreatureType.Unique;
break;
default:
Settings = settings.Minions;
Type = CreatureType.Minion;
break;
}
}
}
else
{
Type = CreatureType.Minion;
Settings = settings.Minions;
}
}
}
}
}