-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSoundController.cs
83 lines (67 loc) · 3.15 KB
/
SoundController.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
using System.Diagnostics;
using Dalamud.Game.ClientState;
using Dalamud.Game.ClientState.Conditions;
using Dalamud.Logging;
namespace AudibleCharacterStatus
{
public class SoundController
{
private static float _lowHealthSoundTime;
private static float _lowMagicSoundTime;
public static void Update()
{
UpdateTimers();
LowHpTimer();
LowMpTimer();
}
private static void LowHpTimer()
{
var localPlayer = Service.ClientState.LocalPlayer;
if (localPlayer is null) return;
if (!Service.Config.LowHealthSoundEnabled) return;
//Do not allow sound if ToggleCombat is disabled, and the player is not in combat
if (!Service.Config.ToggleCombat && !Service.Condition[ConditionFlag.InCombat]) return;
if (_lowHealthSoundTime is <= 0 and > -100 && localPlayer.CurrentHp <= localPlayer.MaxHp * (Service.Config.LowHealthPercent / 100f) && localPlayer.CurrentHp > 0)
{
SoundEngine.PlaySound(Service.Config.LowHealthSoundPath, Service.Config.LowHealthSoundVolume);
_lowHealthSoundTime += Service.Config.LowHealthSoundDelay;
}
else if (localPlayer.CurrentHp > localPlayer.MaxHp * (Service.Config.LowHealthPercent / 100f) || localPlayer.CurrentHp == 0 ||
_lowHealthSoundTime == -100 && Service.Config.LowHealthSoundDelay != -100)
{
_lowHealthSoundTime = 0;
}
}
private static void LowMpTimer()
{
var localPlayer = Service.ClientState.LocalPlayer;
if (localPlayer is null) return;
if (Process.GetCurrentProcess().Id != ProcessUtils.GetForegroundProcessId()) return;
if (!Service.Config.LowMagicSoundEnabled) return;
//Do not allow sound if ToggleCombat is disabled, and the player is not in combat
if (!Service.Config.ToggleCombat && !Service.Condition[ConditionFlag.InCombat]) return;
if (localPlayer.MaxMp <= 0) return;
if (_lowMagicSoundTime is <= 0 and > -100 && localPlayer.CurrentMp <= localPlayer.MaxMp * (Service.Config.LowMagicPercent / 100f) && localPlayer.CurrentHp > 0)
{
SoundEngine.PlaySound(Service.Config.LowMagicSoundPath, Service.Config.LowMagicSoundVolume);
_lowMagicSoundTime += Service.Config.LowMagicSoundDelay;
}
else if (localPlayer.CurrentMp > localPlayer.MaxMp * (Service.Config.LowMagicPercent / 100f) || localPlayer.CurrentHp == 0 ||
_lowMagicSoundTime == -100 && Service.Config.LowMagicSoundDelay != -100)
{
_lowMagicSoundTime = 0;
}
}
private static void UpdateTimers()
{
if (_lowHealthSoundTime > 0)
{
_lowHealthSoundTime -= Service.Framework.UpdateDelta.Ticks / 10000000f;
}
if (_lowMagicSoundTime > 0)
{
_lowMagicSoundTime -= Service.Framework.UpdateDelta.Ticks / 10000000f;
}
}
}
}