-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathEventHandler.lua
More file actions
390 lines (386 loc) · 19.9 KB
/
Copy pathEventHandler.lua
File metadata and controls
390 lines (386 loc) · 19.9 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
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
local _, NSI = ... -- Internal namespace
local f = NSI.NSRTFrame
f:RegisterEvent("ENCOUNTER_START")
f:RegisterEvent("ENCOUNTER_END")
f:RegisterEvent("READY_CHECK")
f:RegisterEvent("GROUP_FORMED")
f:RegisterEvent("ADDON_LOADED")
f:RegisterEvent("PLAYER_LOGIN")
f:RegisterEvent("ENCOUNTER_TIMELINE_EVENT_ADDED")
f:RegisterEvent("ENCOUNTER_TIMELINE_EVENT_REMOVED")
f:RegisterEvent("ENCOUNTER_TIMELINE_EVENT_STATE_CHANGED")
f:RegisterEvent("START_PLAYER_COUNTDOWN")
f:RegisterEvent("GROUP_ROSTER_UPDATE")
f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:RegisterEvent("PLAYER_LOGOUT")
function NSI:UpdateDebugLogEvents()
if NSRT.Settings.DebugLogs then
f:RegisterEvent("ENCOUNTER_WARNING")
else
f:UnregisterEvent("ENCOUNTER_WARNING")
end
end
f:SetScript("OnEvent", function(self, e, ...)
NSI:EventHandler(e, true, false, ...)
end)
function NSI:EventHandler(e, wowevent, internal, ...) -- internal checks whether the event comes from addon comms. We don't want to allow blizzard events to be fired manually
if e == "ADDON_LOADED" and wowevent then
local name = ...
if name == "NorthernSkyRaidTools" then
if not NSRTTimelineData then NSRTTimelineData = {} end
self.Reminder = ""
self.PersonalReminder = ""
self.DisplayedReminder = ""
self.DisplayedPersonalReminder = ""
self.DisplayedExtraReminder = ""
self.BlizzardNickNamesHook = false
self.MRTNickNamesHook = false
self.ReminderTimer = {}
self.PlayedSound = {}
self.StartedCountdown = {}
self.GlowStarted = {}
self:InitNickNames()
if self:GetProfileKey() then
self.LoadedProfile = true
self:LoadMyProfile()
self:CreateMoveFrames()
end
end
elseif e == "PLAYER_LOGIN" and wowevent then
if not self.LoadedProfile then
self.LoadedProfile = true
self:LoadMyProfile()
self:CreateMoveFrames()
end
self.NSUI:Init()
self:InitLDB()
self:InitQoL()
self:CacheSounds()
self.NSRTFrame:SetAllPoints(UIParent)
local MyFrame = self.LGF.GetUnitFrame("player") -- need to call this once to init the library properly I think
self:InitPrivateAuras(true)
self:UpdateLibSpecRegistration()
if NSRT.PASounds.UseDefaultPASounds then self:ApplyDefaultPASounds() end
if NSRT.PASounds.UseDefaultMPlusPASounds then self:ApplyDefaultPASounds(false, true) end
for spellID, info in pairs(NSRT.PASounds) do
if type(info) == "table" and info.sound then -- prevents user settings
self:AddPASound(spellID, info.sound)
end
end
self:UpdateDebugLogEvents()
-- only running this on login if enabled. It will only run with false when actively disabling the setting. Doing it this way should prevent conflicts with other addons.
if NSRT.PASettings.DebuffTypeBorder then C_UnitAuras.TriggerPrivateAuraShowDispelType(true) end
if NSRT.StoredSharedReminder then
self.Reminder = NSRT.StoredSharedReminder
else
self:SetReminder(NSRT.ActiveReminder, false, true) -- loading active reminder from last session
end
local charkey = self:GetProfileKey()
self:SetReminder(NSRT.StoredPersonalReminder[charkey], true, true) -- loading active personal reminder from last session
self:ProcessReminder()
self:UpdateReminderFrame(true)
if NSRT.Settings["Debug"] then
print("|cFF00FFFFNSRT|r Debug mode is currently enabled. Please disable it with '/ns debug' unless you are specifically testing something.")
end
self:ImportReloeReminders()
if self:Restricted() then return end
if NSRT.Settings["MyNickName"] then self:SendNickName("Any") end -- only send nickname if it exists. If user has ever interacted with it it will create an empty string instead which will serve as deleting the nickname
if NSRT.Settings["GlobalNickNames"] then -- add own nickname if not already in database (for new characters)
local name, realm = UnitName("player")
if not realm then
realm = GetNormalizedRealmName()
end
if (not NSRT.NickNames[name.."-"..realm]) or (NSRT.Settings["MyNickName"] ~= NSRT.NickNames[name.."-"..realm]) then
self:NewNickName("player", NSRT.Settings["MyNickName"], name, realm)
end
end
elseif e == "PLAYER_ENTERING_WORLD" then
local IsLogin, IsReload = ...
C_Timer.After(0.01, function()
local diff = select(3, GetInstanceInfo()) or 0
local ForceHide = diff > 17 or diff < 14
if ForceHide then self:HideAllReminders(true) end
if self.LoadedProfile then
self:UpdateNoteFrame("ReminderFrame", NSRT.ReminderSettings.ReminderFrame, "skip")
self:UpdateNoteFrame("PersonalReminderFrame", NSRT.ReminderSettings.PersonalReminderFrame, "skip")
self:UpdateNoteFrame("ExtraReminderFrame", NSRT.ReminderSettings.ExtraReminderFrame, "skip")
end
end)
elseif e == "ENCOUNTER_START" and wowevent then -- allow sending fake encounter_start if in debug mode, only send spec info in mythic, heroic and normal raids
local diff = select(3, GetInstanceInfo()) or 0
if internal then diff = 16 end
if not internal then self:LogTimeline(e, ...) end
if (diff < 14 or diff > 17) and diff ~= 220 and not NSRT.Settings["Debug"] then return end -- everything else is enabled in lfr, normal, heroic, mythic and story mode because people like to test in there.
self.NSRTFrame.generic_display:Hide()
self.EncounterID = ...
self:LoadPersReminder(self.EncounterID)
if not self.ProcessedReminder then -- should only happen if there was never a ready check, good to have this fallback though in case the user connected/zoned in after a ready check or they never did a ready check
self:ProcessReminder()
end
self.TestingReminder = false
self.IsInPreview = false
for _, v in ipairs({"IconMover", "BarMover", "TextMover", "CircleMover"}) do
self:MakeDraggable(self[v], nil, false)
end
self.Phase = 1
self.PhaseSwapTime = GetTime()
self.ReminderText = self.ReminderText or {}
self.ReminderIcon = self.ReminderIcon or {}
self.ReminderBar = self.ReminderBar or {}
self.ReminderTimer = self.ReminderTimer or {}
self.AllGlows = self.AllGlows or {}
self.PlayedSound = {}
self.StartedCountdown = {}
self.GlowStarted = {}
self.Timelines = {}
self.RemovedTimelines = {}
self.CustomEvents = self.CustomEvents or {}
self.DefaultAlertID = 10000
self.TLAlerts = {}
if self.AddAssignments[self.EncounterID] then self.AddAssignments[self.EncounterID](self) end
if self.EncounterAlertStart[self.EncounterID] then self.EncounterAlertStart[self.EncounterID](self) end
self:FireEncounterAlerts(self.EncounterID, diff)
self:StartReminders(self.Phase)
self:InitPrivateAuras()
if NSRT.ReminderSettings.NoteCountdown then
local frames = {"ReminderFrame", "PersonalReminderFrame"}
for i, name in ipairs(frames) do
if self[name] then
if self[name].UpdateTimer then
self[name].UpdateTimer:Cancel()
self[name].UpdateTimer = nil
end
if self[name]:IsShown() then
self[name].UpdateTimer = C_Timer.NewTicker(1, function()
self:CountdownNoteFrame(self[name])
end)
end
end
end
end
self:FireCallback("NSRT_ALERT_ADDED", self.TLAlerts)
elseif e == "ENCOUNTER_END" and wowevent then
self:LogTimeline(e, ...)
local encID, encounterName, _, _, kill = ...
local diff = select(3, GetInstanceInfo()) or 0
if internal then diff = 16 end
self.CustomEvents = {}
if (diff < 14 or diff > 17) and diff ~= 220 then return end
self:EncounterRegister(nil, nil, nil, nil, true)
self:InitPrivateAuras()
self:HideAllReminders(true)
C_Timer.After(1, function()
if self:Restricted() then return end
if self.SyncNickNamesStore then
self:EventHandler("NSI_NICKNAMES_SYNC", false, true, self.SyncNickNamesStore.unit, self.SyncNickNamesStore.nicknametable, self.SyncNickNamesStore.channel)
self.SyncNickNamesStore = nil
end
end)
if NSRT.ReminderSettings.NoteCountdown then
self:UpdateReminderFrame(true) -- need to recalculate reminders if the user has countdown enabled
local frames = {"ReminderFrame", "PersonalReminderFrame"}
for i, name in ipairs(frames) do
if self[name] and self[name].UpdateTimer then
self[name].UpdateTimer:Cancel()
self[name].UpdateTimer = nil
end
end
end
if kill and kill ~= 0 then
local NoteName = NSRT.AutoLoadNote and NSRT.AutoLoadNote[encID]
local HasAutoLoadNote = NoteName and NSRT.Reminders[NoteName]
if NSRT.ReminderSettings.ClearOnKill then
if not HasAutoLoadNote then NSI:SetReminder(nil) end
NSI:SetReminder(nil, true)
end
if HasAutoLoadNote then
C_Timer.After(2, function()
if self:Restricted() then return end
if UnitIsGroupLeader("player") or UnitIsGroupAssistant("player") then
self:Broadcast("NSI_REM_SHARE", "RAID", NSRT.Reminders[NoteName], nil, true)
end
end)
end
end
elseif e == "START_PLAYER_COUNTDOWN" and wowevent then -- do basically the same thing as ready check in case one of them is skipped
if self.LastBroadcast and self.LastBroadcast > GetTime() - 30 then return end -- only do this if there was no recent ready check basically
self.LastBroadcast = GetTime()
if UnitIsGroupLeader("player") and UnitInRaid("player") then
local tosend = false
if NSRT.ReminderSettings.AutoShare then
tosend = self.Reminder
end
self:Broadcast("NSI_REM_SHARE", "RAID", tosend, NSRT.AssignmentSettings, false)
self.Assignments = NSRT.AssignmentSettings
end
elseif e == "READY_CHECK" and wowevent then
self.ProcessDone = false
local diff= select(3, GetInstanceInfo()) or 0
if self:DifficultyCheck(14) or diff == 23 then
C_Timer.After(1, function()
self:EventHandler("NSI_READY_CHECK", false, true)
end)
end
if UnitIsGroupLeader("player") and UnitInRaid("player") then
-- always doing this, even outside of raid to allow outside raidleading to work. The difficulty check will instead happen client-side
local tosend = false
if NSRT.ReminderSettings.AutoShare then
tosend = self.Reminder
end
self:Broadcast("NSI_REM_SHARE", "RAID", tosend, NSRT.AssignmentSettings, false)
self.Assignments = NSRT.AssignmentSettings
end
if C_ChatInfo.InChatMessagingLockdown() then return end
self.LastBroadcast = GetTime()
if self:Restricted() then return end
if NSRT.Settings["CheckCooldowns"] and self:DifficultyCheck(15) and UnitInRaid("player") then -- only heroic& mythic because in normal you just wanna go fast and don't care about someone having a cd
self:CheckCooldowns()
end
elseif e == "NSI_REM_SHARE" and internal then
local unit, reminderstring, assigntable, skipcheck = ...
if (UnitIsGroupLeader(unit) or (UnitIsGroupAssistant(unit) and skipcheck)) and (self:DifficultyCheck(14) or skipcheck) then -- skipcheck allows manually sent reminders to bypass difficulty checks
if reminderstring and type(reminderstring) == "string" and reminderstring ~= "" and ((not NSRT.ReminderSettings.OnlyReceiveGuild) or self:IsInSameGuild(unit)) then
self.Reminder = reminderstring
NSRT.StoredSharedReminder = reminderstring
self.ReminderReceivedTime = GetTime()
self:FireCallback("NSRT_REMINDER_CHANGED", self.PersonalReminder, self.Reminder)
end
self:ProcessReminder()
self:UpdateReminderFrame(true)
self.ProcessDone = true
if skipcheck then self:FlashNoteBackgrounds() end -- only show animation if reminder was manually shared
if assigntable then self.Assignments = assigntable end
end
elseif e == "NSI_READY_CHECK" and internal then
if not self.ProcessDone then -- fallback do this here if no addon comms were received because the setting is disabled
self:ProcessReminder()
self:UpdateReminderFrame(true)
end
local diff = select(3, GetInstanceInfo()) or 0
local text = ""
if UnitLevel("player") < 90 then return end
self:CheckRaidBuff()
if NSRT.ReadyCheckSettings.RaidBuffCheck and not self:Restricted() then
local buff = self:BuffCheck()
if buff and buff ~= "" then text = buff end
end
if NSRT.ReadyCheckSettings.SoulstoneCheck and not self:Restricted() then
text = self:SoulstoneCheck(text)
end
if NSRT.ReadyCheckSettings.SourceOfMagicCheck and not self:Restricted() then
text = self:SourceOfMagicCheck(text)
end
if NSRT.ReadyCheckSettings.BlisteringScalesCheck and not self:Restricted() then
text = self:BlisteringScalesCheck(text)
end
if NSRT.ReadyCheckSettings.SymbioticRelationshipCheck and not self:Restricted() then
text = self:SymbioticRelationshipCheck(text)
end
if NSRT.ReadyCheckSettings.DisplayGroupCheck and not self:Restricted() then
local groupNumber = self:GetSubGroup("player")
if groupNumber then
local groupText = "You are in group |cFF00FFFF" ..groupNumber .. "|r"
if text == "" then
text = groupText
else
text = text.."\n"..groupText
end
end
end
text = self:GearCheck(text)
if text ~= "" then
self:DisplayText(text)
end
elseif e == "GROUP_FORMED" and wowevent then
if self:Restricted() then return end
if NSRT.Settings["MyNickName"] then self:SendNickName("Any", true) end -- only send nickname if it exists. If user has ever interacted with it it will create an empty string instead which will serve as deleting the nickname
if NSRT.NSUI and NSRT.NSUI.reminders_frame then NSUI.reminders_frame.UpdateButtonAccess() end
elseif e == "NSI_VERSION_CHECK" and internal then
if self:Restricted() then return end
if not self.VersionCheckData then return end -- ignore stale responses from a previous check
local unit, ver, ignoreCheck = ...
self:VersionResponse({name = UnitName(unit), version = ver, ignoreCheck = ignoreCheck})
elseif e == "NSI_VERSION_REQUEST" and internal then
local unit, type, name = ...
if UnitExists(unit) and UnitIsUnit("player", unit) then return end -- don't send to yourself
if UnitExists(unit) then
local u, ver, _, ignoreCheck = self:GetVersionNumber(type, name, unit)
self:Broadcast("NSI_VERSION_CHECK", "WHISPER", unit, ver, ignoreCheck)
end
elseif e == "NSI_NICKNAMES_COMMS" and internal then
if self:Restricted() then return end
local unit, nickname, name, realm, requestback, channel = ...
if UnitExists(unit) and UnitIsUnit("player", unit) then return end -- don't add new nickname if it's yourself because already adding it to the database when you edit it
if requestback and (UnitInRaid(unit) or UnitInParty(unit)) then self:SendNickName(channel, false) end -- send nickname back to the person who requested it
self:NewNickName(unit, nickname, name, realm, channel)
elseif e == "NSI_NICKNAMES_SYNC" and internal then
local unit, nicknametable, channel = ...
local setting = NSRT.Settings["NickNamesSyncAccept"]
if (setting == 3 or (setting == 2 and channel == "GUILD") or (setting == 1 and channel == "RAID") and (not C_ChallengeMode.IsChallengeModeActive())) then
if UnitExists(unit) and UnitIsUnit("player", unit) then return end -- don't accept sync requests from yourself
if self:Restricted() or UnitAffectingCombat("player") then
self.SyncNickNamesStore = {unit = unit, nicknametable = nicknametable, channel = channel}
else
self:NickNamesSyncPopup(unit, nicknametable)
end
end
elseif e == "GROUP_ROSTER_UPDATE" and wowevent then
self:ArrangeGroups()
if self.GroupUpdateTimer then self.GroupUpdateTimer:Cancel() end
self.GroupUpdateTimer = C_Timer.After(2, function()
self.GroupUpdateTimer = nil
self:InitPrivateAuras()
self:UpdateRaidBuffFrame()
end)
if self:Restricted() then return end
if self.InviteInProgress then
if not UnitInRaid("player") then
C_PartyInfo.ConvertToRaid()
C_Timer.After(1, function() -- send invites again if player is now in a raid
if UnitInRaid("player") then
self:InviteList(self.CurrentInviteList)
self.InviteInProgress = nil
end
end)
end
end
if not self:DifficultyCheck(14) then return end
elseif e == "ENCOUNTER_TIMELINE_EVENT_ADDED" and wowevent then
if not self:DifficultyCheck(14) then return end
local info = ...
if info.source ~= Enum.EncounterTimelineEventSource.Encounter then
self.CustomEvents = self.CustomEvents or {}
self.CustomEvents[info.id] = true
return
end
self:LogTimeline(e, ...)
if self:Restricted() and self.EncounterID and self.DetectPhaseChange[self.EncounterID] then self.DetectPhaseChange[self.EncounterID](self, e, info) end
elseif e == "ENCOUNTER_TIMELINE_EVENT_REMOVED" and wowevent then
if not self:DifficultyCheck(14) then return end
local eventID = ...
if self.CustomEvents and self.CustomEvents[eventID] then
return
end
self:LogTimeline(e, ...)
if self:Restricted() and self.EncounterID and self.DetectPhaseChange[self.EncounterID] then self.DetectPhaseChange[self.EncounterID](self, e, info) end
elseif e == "ENCOUNTER_TIMELINE_EVENT_STATE_CHANGED" and wowevent then
local eventID = ...
if not self:DifficultyCheck(14) then return end
if self.CustomEvents and self.CustomEvents[eventID] then
return
end
self:LogTimeline(e, ...)
local state = C_EncounterTimeline.GetEventState(eventID)
if state == Enum.EncounterTimelineEventState.Canceled then
self:EventHandler("ENCOUNTER_TIMELINE_EVENT_REMOVED", true, false, eventID)
end
elseif e == "ENCOUNTER_WARNING" and wowevent then
self:LogTimeline(e, ...)
elseif e == "QoL_Comms" and internal then
self:QoLEvents(e, ...)
elseif e == "INSTANCE_ENCOUNTER_ENGAGE_UNIT" then
if self:Restricted() and self.EncounterID and self.DetectPhaseChange[self.EncounterID] then self.DetectPhaseChange[self.EncounterID](self, e) end
elseif e == "PLAYER_LOGOUT" and wowevent then
self:SaveProfile()
end
end