-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathCooldown.cs
87 lines (60 loc) · 2.93 KB
/
Cooldown.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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using ImGuiScene;
using static FFXIVClientStructs.FFXIV.Client.Game.ActionManager;
using Action = Lumina.Excel.GeneratedSheets.Action;
namespace RemindMe {
public class Cooldown : IDisposable {
private readonly Action action;
private readonly ActionManager actionManager;
private CooldownStruct cooldownStruct;
private readonly Stopwatch readyStopwatch = new Stopwatch();
public TextureWrap ActionIconTexture { get; private set; }
public Cooldown(ActionManager actionManager, Action action) {
this.actionManager = actionManager;
this.action = action;
cooldownStruct = new CooldownStruct() { ActionID = this.ActionID, CooldownElapsed = 0, CooldownTotal = 0, IsCooldown = false };
readyStopwatch.Start();
Update();
Task.Run(() => {
if (action.Icon > 0 && action.IsPlayerAction) ActionIconTexture = actionManager.GetActionIcon(action);
});
}
public void Update() {
var before = cooldownStruct.IsCooldown;
if (action.CooldownGroup > 0) {
var cooldownPtr = actionManager.GetCooldownPointer(action.CooldownGroup);
cooldownStruct = Marshal.PtrToStructure<CooldownStruct>(cooldownPtr);
} else {
cooldownStruct = new CooldownStruct() {ActionID = this.ActionID, CooldownElapsed = 0, CooldownTotal = 0, IsCooldown = false};
}
if (before && !cooldownStruct.IsCooldown) {
readyStopwatch.Restart();
}
}
public uint ActionID => action.RowId;
public byte CooldownGroup => action.CooldownGroup;
public float CooldownElapsed => cooldownStruct.CooldownElapsed;
public float Countdown => CooldownMax - cooldownStruct.CooldownElapsed;
public long CountdownTicks => (long) Countdown * 10000000;
public float CooldownTotal => cooldownStruct.CooldownTotal;
public float ChargesMultiplier => GetMaxCharges(ActionID, 0) / (float)GetMaxCharges(ActionID, 80);
public float CooldownMax => CooldownTotal * ChargesMultiplier;
public float CooldownFraction => Countdown <= 0 ? 1 : (cooldownStruct.CooldownElapsed / CooldownMax);
public float CompleteFor => IsOnCooldown ? 0 : readyStopwatch.ElapsedMilliseconds / 1000f;
public long CompleteForTicks => IsOnCooldown ? 0 : readyStopwatch.ElapsedTicks;
public bool IsOnCooldown => cooldownStruct.IsCooldown;
public void Dispose() {
readyStopwatch.Stop();
ActionIconTexture?.Dispose();
}
public void ResetReadyCountUp() {
if (!IsOnCooldown) readyStopwatch.Restart();
}
}
}