-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathEvents.lua
291 lines (234 loc) · 7.84 KB
/
Events.lua
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
local Util = WarpDeplete.Util
local L = WarpDeplete.L
---@type table<string, boolean>
WarpDeplete.registeredChallengeEvents = {}
function WarpDeplete:RegisterGlobalEvent(event)
self:RegisterEvent(event, event)
end
function WarpDeplete:RegisterChallengeEvent(event)
self:RegisterEvent(event, event)
self.registeredChallengeEvents[event] = true
end
function WarpDeplete:UnregisterChallengeEvents()
for event, _ in pairs(self.registeredChallengeEvents) do
self:UnregisterEvent(event)
end
self.registeredChallengeEvents = {}
end
-- These events are used to detect whether we are in challenge mode
-- or whether we should put a key in the socket, and will always stay registered.
function WarpDeplete:RegisterGlobalEvents()
-- Events where we could theoretically need to check for an active challenge mode
self:RegisterGlobalEvent("PLAYER_ENTERING_WORLD")
self:RegisterGlobalEvent("ZONE_CHANGED")
self:RegisterGlobalEvent("ZONE_CHANGED_NEW_AREA")
self:RegisterGlobalEvent("ZONE_CHANGED_INDOORS")
self:RegisterGlobalEvent("PLAYER_DIFFICULTY_CHANGED")
self:RegisterGlobalEvent("CHALLENGE_MODE_START")
-- Fired when we open the keystone socket
self:RegisterGlobalEvent("CHALLENGE_MODE_KEYSTONE_RECEPTABLE_OPEN")
-- Register tooltip count display
TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Unit, WarpDeplete.DisplayCountInTooltip)
-- Tooltip events
self.frames.deathsTooltip:SetScript("OnEnter", WarpDeplete.TooltipOnEnter)
self.frames.deathsTooltip:SetScript("OnLeave", WarpDeplete.TooltipOnLeave)
end
function WarpDeplete:RegisterChallengeEvents()
-- Challenge mode triggers
self:RegisterChallengeEvent("CHALLENGE_MODE_COMPLETED")
self:RegisterChallengeEvent("CHALLENGE_MODE_DEATH_COUNT_UPDATED")
self:RegisterChallengeEvent("WORLD_STATE_TIMER_START")
-- Scenario Triggers
self:RegisterChallengeEvent("SCENARIO_POI_UPDATE")
self:RegisterChallengeEvent("SCENARIO_CRITERIA_UPDATE")
-- Combat triggers
self:RegisterChallengeEvent("ENCOUNTER_END")
self:RegisterChallengeEvent("PLAYER_REGEN_ENABLED")
self:RegisterChallengeEvent("COMBAT_LOG_EVENT_UNFILTERED")
self:RegisterChallengeEvent("UNIT_THREAT_LIST_UPDATE")
end
function WarpDeplete:PLAYER_ENTERING_WORLD()
self:CheckForChallengeMode()
end
function WarpDeplete:ZONE_CHANGED()
self:CheckForChallengeMode()
end
function WarpDeplete:ZONE_CHANGED_NEW_AREA()
self:CheckForChallengeMode()
end
function WarpDeplete:ZONE_CHANGED_INDOORS()
self:CheckForChallengeMode()
end
function WarpDeplete:PLAYER_DIFFICULTY_CHANGED()
self:CheckForChallengeMode()
end
-- We receive this when the 10s countdown after key insertion starts
function WarpDeplete:CHALLENGE_MODE_START()
self:EnableChallengeMode()
end
function WarpDeplete:CHALLENGE_MODE_KEYSTONE_RECEPTABLE_OPEN()
if not self.db.profile.insertKeystoneAutomatically then
return
end
local difficulty = select(3, GetInstanceInfo())
if difficulty ~= 8 and difficulty ~= 23 then
return
end
local found = nil
for bagIndex = 0, NUM_BAG_SLOTS do
for invIndex = 1, C_Container.GetContainerNumSlots(bagIndex) do
local itemID = C_Container.GetContainerItemID(bagIndex, invIndex)
if itemID and C_Item.IsItemKeystoneByID(itemID) then
found = { bagIndex = bagIndex, invIndex = invIndex }
break
end
end
if found then
break
end
end
if found then
C_Container.UseContainerItem(found.bagIndex, found.invIndex)
end
end
function WarpDeplete:CHALLENGE_MODE_COMPLETED()
self:CompleteChallenge()
end
function WarpDeplete:WORLD_STATE_TIMER_START()
-- Rerender everything once in case we were displaying PBs
self.state.timerStarted = true
self:RenderTimer()
self:RenderForces()
self:RenderObjectives()
end
function WarpDeplete:CHALLENGE_MODE_DEATH_COUNT_UPDATED()
self:SetDeathCount(C_ChallengeMode.GetDeathCount() or 0)
end
function WarpDeplete:SCENARIO_POI_UPDATE()
self:UpdateObjectives()
end
function WarpDeplete:SCENARIO_CRITERIA_UPDATE()
self:UpdateObjectives()
end
function WarpDeplete:ENCOUNTER_END()
self:ResetCurrentPull()
end
function WarpDeplete:PLAYER_REGEN_ENABLED()
self:ResetCurrentPull()
end
function WarpDeplete:COMBAT_LOG_EVENT_UNFILTERED()
local _, subEv, _, _, _, _, _, guid, name = CombatLogGetCurrentEventInfo()
if subEv ~= "UNIT_DIED" then
return
end
if not guid then
return
end
-- NOTE: We have to check health since we'd count feign death otherwise
if UnitInParty(name) and UnitHealth(name) <= 1 then
local unitName = UnitName(name)
local class = select(2, UnitClass(name))
self:AddDeathDetails(self.state.timer, unitName, class)
return
end
if not self.state.currentPull[guid] then
return
end
self.state.currentPull[guid] = "DEAD"
local pullCount = Util.calcPullCount(self.state.currentPull, self.state.totalCount)
self:SetForcesPull(pullCount)
end
function WarpDeplete:UNIT_THREAT_LIST_UPDATE(_, unit)
if not MDT then
return
end
if not InCombatLockdown() or not unit or not UnitExists(unit) then
return
end
-- NOTE: There seem to be cases where a Unit will throw a threat list update
-- after it has died, which falsely re-adds it to the current pull. We set that units'
-- count value to "DEAD" when it dies, and due to the check if the guid already exists
-- in the table, it won't be overwritten after the unit has died.
local guid = UnitGUID(unit)
if not guid or self.state.currentPull[guid] then
return
end
local npcID = select(6, strsplit("-", guid))
local count = MDT:GetEnemyForces(tonumber(npcID))
if not count or count <= 0 then
return
end
self.state.currentPull[guid] = count
local pullCount = Util.calcPullCount(self.state.currentPull, self.state.totalCount)
self:SetForcesPull(pullCount)
end
function WarpDeplete.TooltipOnEnter()
local self = WarpDeplete
if not self.db.profile.showDeathsTooltip then
return
end
GameTooltip:SetOwner(self.frames.deathsTooltip, "ANCHOR_BOTTOMLEFT", self.frames.deathsTooltip.offsetWidth)
GameTooltip:ClearLines()
local count = #self.state.deathDetails
if count == 0 then
GameTooltip:AddLine(L["No Recorded Player Deaths"], 1, 1, 1)
GameTooltip:Show()
return
end
GameTooltip:AddLine(L["Player Deaths"], 1, 1, 1)
if self.db.profile.deathLogStyle == "time" then
local showFrom = 0
if count > 20 then
showFrom = count - 20
end
for i, d in ipairs(self.state.deathDetails) do
if i >= showFrom then
local color = select(4, GetClassColor(d.class))
local time = Util.formatTime(d.time)
GameTooltip:AddLine(time .. " - |c" .. color .. d.name .. "|r")
end
end
elseif self.db.profile.deathLogStyle == "count" then
local countTable = {}
for _, d in ipairs(self.state.deathDetails) do
if not countTable[d.name] then
countTable[d.name] = {
color = select(4, GetClassColor(d.class)),
count = 0,
}
end
countTable[d.name].count = countTable[d.name].count + 1
end
for name, deaths in pairs(countTable) do
GameTooltip:AddLine("|c" .. deaths.color .. name .. "|r|cFFFFFFFF: " .. tostring(deaths.count) .. "|r")
end
end
GameTooltip:Show()
end
function WarpDeplete.TooltipOnLeave()
GameTooltip_Hide()
end
function WarpDeplete.DisplayCountInTooltip(tt, data)
if not tt or tt ~= GameTooltip or not data or not data.guid then
return
end
if not WarpDeplete.state.inChallenge then
return
end
if not MDT or not WarpDeplete.db.profile.showTooltipCount then
return
end
local npcID = select(6, strsplit("-", data.guid))
local count, max = MDT:GetEnemyForces(tonumber(npcID))
if count and max and count ~= 0 and max ~= 0 then
local percentText = ("%.2f"):format(count / max * 100)
local countText = ("%d"):format(count)
local result = WarpDeplete.db.profile.tooltipCountFormat ~= ":custom:"
and WarpDeplete.db.profile.tooltipCountFormat
or WarpDeplete.db.profile.customTooltipCountFormat
result = gsub(result, ":percent:", percentText .. "%%")
result = gsub(result, ":count:", countText)
GameTooltip:AddLine("Count: |cFFFFFFFF" .. result .. "|r")
GameTooltip:Show()
end
end