Repository navigation
Expand file tree
/
Copy pathBossAdapter.lua
More file actions
163 lines (150 loc) · 6.24 KB
/
Copy pathBossAdapter.lua
File metadata and controls
163 lines (150 loc) · 6.24 KB
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
CastAheadBossAdapter = {}
local A = CastAheadBossAdapter
local M = CastAheadMatch
local connected
local barsSeen, encounterAt, healthWarned, inEncounter = false, nil, false, false
local barSpells = {}
local HEALTH_WAIT = 30
local function Key(source, barKey) return source .. ":" .. tostring(barKey) end
local function BigWigsSource(module) return "bw:" .. tostring(module) end
local function Secret(...)
if not issecretvalue then return false end
for i = 1, select("#", ...) do
if issecretvalue((select(i, ...))) then return true end
end
return false
end
local function Verdict(spellID)
if not CastAheadConfig.Enabled("bossAdapter") then return nil end
local row, resolvedId = M.SaveRow(spellID)
if not row then return nil end
local advice = M.Advice({ prio = CastAheadPriority and (CastAheadPriority[spellID] or CastAheadPriority[resolvedId]),
save = row })
if not M.IsSave(advice) then return nil end
return spellID, row.lead or 3, advice
end
function A.OnBar(source, barKey, spellID, duration, now)
barsSeen = true
if not CastAheadSaves then return end
if not (inEncounter or (IsEncounterInProgress and IsEncounterInProgress())) then return end
spellID, duration = tonumber(spellID), tonumber(duration)
if not (spellID and duration) or duration <= 0 then return end
local id, lead, advice = Verdict(spellID)
if not id then return end
local key = Key(source, barKey)
local endAt = now + duration
barSpells[key] = spellID
CastAheadSaves.Schedule(key, id, endAt - lead, endAt, advice)
end
function A.OnUpdate(source, barKey, elapsed, total, now)
if not CastAheadSaves then return end
local key = Key(source, barKey)
local spellID = barSpells[key]
elapsed, total = tonumber(elapsed), tonumber(total)
if not (spellID and elapsed and total) then return end
local id, lead = Verdict(spellID)
if not id then return end
if not CastAheadSaves.Move(key, total - elapsed, lead, now) then
A.OnBar(source, barKey, spellID, total - elapsed, now)
end
end
function A.OnStop(source, barKey)
if not CastAheadSaves then return end
local key = Key(source, barKey)
barSpells[key] = nil
CastAheadSaves.Cancel(key)
end
function A.OnStopAll(source)
if not CastAheadSaves then return end
local prefix = source .. ":"
for key in pairs(barSpells) do
if key:sub(1, #prefix) == prefix then barSpells[key] = nil end
end
CastAheadSaves.CancelPrefix(prefix)
end
function A.OnPause(source, barKey, now)
if not CastAheadSaves then return end
CastAheadSaves.Pause(Key(source, barKey), now)
end
function A.OnResume(source, barKey, now)
if not CastAheadSaves then return end
CastAheadSaves.Resume(Key(source, barKey), now)
end
function A.Connect()
local dbm, bw
if DBM and DBM.RegisterCallback then
DBM:RegisterCallback("DBM_TimerBegin", function(_, id, _, timer, _, _, spellId)
if Secret(id, timer, spellId) then barsSeen = true return end
A.OnBar("dbm", id, spellId, timer, GetTime())
end)
DBM:RegisterCallback("DBM_TimerStop", function(_, id)
if Secret(id) then return end
A.OnStop("dbm", id)
end)
DBM:RegisterCallback("DBM_TimerPause", function(_, id)
if Secret(id) then return end
A.OnPause("dbm", id, GetTime())
end)
DBM:RegisterCallback("DBM_TimerResume", function(_, id)
if Secret(id) then return end
A.OnResume("dbm", id, GetTime())
end)
DBM:RegisterCallback("DBM_TimerUpdate", function(_, id, elapsed, total)
if Secret(id, elapsed, total) then return end
A.OnUpdate("dbm", id, elapsed, total, GetTime())
end)
dbm = true
end
if not dbm and type(BigWigsLoader) == "table" and BigWigsLoader.RegisterMessage then
BigWigsLoader.RegisterMessage(A, "BigWigs_StartBar", function(_, module, key, text, duration)
if Secret(module, key, text, duration) then barsSeen = true return end
A.OnBar(BigWigsSource(module), text, key, duration, GetTime())
end)
BigWigsLoader.RegisterMessage(A, "BigWigs_Timer", function(_, module, key, duration, _, text, _, _, _, isBarEnabled)
if Secret(module, key, duration, text, isBarEnabled) then barsSeen = true return end
if isBarEnabled then return end
A.OnBar(BigWigsSource(module), text, key, duration, GetTime())
end)
BigWigsLoader.RegisterMessage(A, "BigWigs_StopBar", function(_, module, text)
if Secret(module, text) then return end
A.OnStop(BigWigsSource(module), text)
end)
BigWigsLoader.RegisterMessage(A, "BigWigs_PauseBar", function(_, module, text)
if Secret(module, text) then return end
A.OnPause(BigWigsSource(module), text, GetTime())
end)
BigWigsLoader.RegisterMessage(A, "BigWigs_ResumeBar", function(_, module, text)
if Secret(module, text) then return end
A.OnResume(BigWigsSource(module), text, GetTime())
end)
local function StopModule(_, module)
if Secret(module) then return end
A.OnStopAll(BigWigsSource(module))
end
BigWigsLoader.RegisterMessage(A, "BigWigs_StopBars", StopModule)
BigWigsLoader.RegisterMessage(A, "BigWigs_OnBossDisable", StopModule)
bw = true
end
connected = dbm and "DBM" or bw and "BigWigs" or nil
return connected
end
function A.Status()
if connected then return connected .. " connected" end
return "No boss mod"
end
function A.OnEncounter(event)
if event == "ENCOUNTER_START" then
barsSeen, encounterAt, inEncounter = false, GetTime(), true
else
encounterAt, inEncounter = nil, false
A.OnStopAll("dbm")
A.OnStopAll("bw")
end
end
function A.Tick(now)
if encounterAt and connected and not barsSeen and not healthWarned and now - encounterAt > HEALTH_WAIT
and CastAheadConfig.SaveCalls() and CastAheadConfig.Enabled("bossAdapter") then
encounterAt, healthWarned = nil, true
print("|cff33ff99CastAhead|r " .. connected .. " sent no boss timers this fight - boss save calls are off until it does.")
end
end