-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPantheonDKP.lua
390 lines (317 loc) · 12.3 KB
/
PantheonDKP.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
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 _, core = ...;
local _G = _G;
local L = core.L;
local DKP = core.DKP;
local GUI = core.GUI;
local Item = core.Item;
local Util = core.Util;
local PDKP = core.PDKP;
local Guild = core.Guild;
local Shroud = core.Shroud;
local Defaults = core.defaults;
local Invites = core.Invites;
local Raid = core.Raid;
local Comms = core.Comms;
local Setup = core.Setup;
local Import = core.Import;
local item = core.Item;
local Member = core.Member;
local PlaySound = PlaySound
--[[
KNOWN BUGS:
]]
--[[
FEATURE REQUESTS:
TODO: SILENT MODE - Doesn't print when an update comes through.
TODO: Minimap Icon
TODO: Auto-shroud wishlist.
- Be able to move items up and down in priority when they are linked. That way your most coveted items are
- automatically shrouded upon first?
]]
PDKP.data = {} -- All of the data that is supposed to be shown.
PDKP.raidData = {}
GUI.selected = {}
core.initialized = false
core.filterOffline = nil
core.databasesInitialized = false
core.firstLogin = true
-- Generic event handler that handles all of the game events & directs them.
-- This is the FIRST function to run on load triggered registered events at bottom of file
local function PDKP_OnEvent(self, event, arg1, ...)
if event == "ADDON_LOADED" then
Util:Debug('Addon loaded')
PDKP:OnInitialize(event, arg1)
return UnregisterEvent(self, event)
elseif event == "ZONE_CHANGED_NEW_AREA" then -- This allows us to detect if the GuildInfo() event is available yet.
PDKP:InitializeGuildData()
return UnregisterEvent(self, event)
elseif event == "PLAYER_ENTERING_WORLD" then
local arg2 = ...
local initialLogin, uiReload = arg1, arg2
core.firstLogin = initialLogin
if uiReload then PDKP:InitializeGuildData() end
elseif event == 'WORLD_MAP_UPDATE' then
return UnregisterEvent(self, event)
elseif event == "GUILD_ROSTER_UPDATE" then
return UnregisterEvent(self, event)
elseif event == "GROUP_ROSTER_UPDATE" then
Raid:GetRaidInfo()
return
elseif event == "ENCOUNTER_START" then return -- for testing purposes
elseif event == "COMBAT_LOG_EVENT_UNFILTERED" then return -- NPC kill event
elseif event == "LOOT_OPENED" then
Raid:AnnounceLoot()
return -- when the loot bag is opened.
elseif event == "OPEN_MASTER_LOOT_LIST" then return -- when the master loot list is opened.
elseif event == "CHAT_MSG_RAID" then
local msg = arg1;
local playerName, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _= ...;
playerName = Util:RemoveServerName(playerName)
PDKP:MessageRecieved(msg, playerName)
return
elseif event == "CHAT_MSG_RAID_LEADER" then return
elseif event == "CHAT_MSG_WHISPER" then
local _, _, _, arg4,_, _, _,_, _, _, _, _ = ...;
local msg = arg1;
local name = arg4;
PDKP:MessageRecieved(msg, name)
return
elseif event == "CHAT_MSG_GUILD" then return
elseif event == "BOSS_KILL" then
-- PDKP:Print(self, event, arg1); -- TABLE, BOSS_KILL, EVENTID
-- Raid:BossKill(event, arg1);
return
end
end
-- event function that happens when the addon is initialized.
function PDKP:OnInitialize(event, name)
if (name ~= "PantheonDKP") then return end
PDKP:Print("Welcome,", Util:GetMyName(), "to:", core.defaults.addon_name)
-----------------------------
-- Register Slash Commands --
-----------------------------
self:RegisterChatCommand("pdkp", "HandleSlashCommands")
self:RegisterChatCommand("shroud", "HandleShroudCommands")
self:RegisterChatCommand("prio", "HandlePrioCommands")
-----------------------------
-- Register PDKP Databases --
-----------------------------
PDKP:InitializeDatabases();
-----------------------------
-- Initialize Addon Data --
-----------------------------
--
-- PDKP:BuildAllData();
-----------------------------
-- Register Communications --
-----------------------------
Comms:RegisterCommCommands()
end
function PDKP:InitializeGuildData()
Guild:GetGuildData(false);
DKP:VerifyTables()
PDKP:BuildAllData();
core.initialized = true
end
function PDKP:MessageRecieved(msg, name) -- Global handler of Messages
if Shroud.shroudPhrases[string.lower(msg)] and (Raid:isMasterLooter() or Defaults.debug) then
-- This should send the list to everyone in the raid, so that it just automatically pops up.
Shroud:UpdateShrouders(name)
end
end
-- Initializes the PDKP Databases.
function PDKP:InitializeDatabases()
Guild:InitGuildDB()
DKP:InitDKPDB()
core.databasesInitialized = true
end
function PDKP:HandleShroudCommands(item)
-- Normal shrouding command send by a non officer, bidding on an item.
if item == nil or string.len(item) == 0 then
return PDKP:MessageRecieved('shroud', Util:GetMyName())
-- Item linked by the officer.
elseif core.canEdit then -- NEED TO CHECK IF THEY ARE THE ML AS WELL.
-- Check to see if the GUI is open or not.
if not GUI.shown then PDKP:Show() end
GUI:UpdateShroudItemLink(Item:GetItemByName(item));
end
end
function PDKP:HandlePrioCommands(itemLink)
itemLink = itemLink or nil;
if itemLink ~= nil and itemLink ~= '' then
local prio = item:GetPriority(itemLink)
if prio == 'Undefined' then -- Possibly we have an item link.
local status, itemName = pcall(item:GetItemInfo(itemLink))
prio = item:GetPriority(itemName)
end
print(itemLink .. ' PRIO: ' .. prio)
else
end
end
-- Generic function that handles all the slash commands.
function PDKP:HandleSlashCommands(msg, item)
-- Commands:
-- pdkp - Opens / closes the GUI
-- pdkp show - Opens the GUI
-- pdkp hide - Hides the GUI
if string.len(msg) == 0 then
if GUI.shown then
return GUI:Hide()
else PDKP:Show()
end
elseif msg == 'show' then
return PDKP:Show()
elseif msg == 'hide' then
return GUI:Hide()
end
if msg == 'shroud' then
return PDKP:MessageRecieved('shroud', Util:GetMyName())
end
local splitMsg, name = strsplit(' ', msg)
if splitMsg == 'report' then
local dkp = DKP:GetPlayerDKP(name)
if dkp == 0 then
PDKP:Print(name .. ' has 0 dkp or was not found')
else
PDKP:Print(name .. ' has: ' .. dkp .. ' DKP')
end
end
-- OFFICER ONLY COMMANDS
if not core.canEdit then return end;
if msg == 'item' and item then
return Item:LinkItem();
end
if msg == 'invite' then
return Invites:Show();
-- local tempInvites = {'Sparklenips', 'Annaliese'}
-- for i=1, #tempInvites do
-- InviteUnit(tempInvites[i]);
-- end
end
if msg == 'sortHistory' then
DKP:SortHistory()
end
if msg == 'bossKill' then
return Raid:BossKill(663, 'Lucifron');
end
if msg == 'classes' then
return Guild:GetClassBreakdown();
end
if msg == 'timer' then
return GUI:CreateTimer()
end
if msg == 'pdkp_reset_all_db' and core.defaults.debug then
DKP:ResetDB()
Guild:ResetDB()
end
if msg == 'test_boss' then
Raid:GetCurrentRaid()
end
if msg == 'test_getML' then
Raid:isMasterLooter()
end
if msg == 'pdkp_testing_com' then
Comms:pdkp_send_comm()
end
if msg == 'pdkp_getTime' then
print(Util:Format12HrDateTime(GetServerTime()))
end
if msg == 'importDKP' then
DKP:ImportMonolithData()
end
if msg == 'TestImportData' then
Import:AcceptData()
end
if msg == 'enableDebugging' then
core.defaults.debug = true
end
if msg == 'validateTables' then
DKP:ValidateTables()
end
end
function PDKP:BuildAllData()
PDKP.data = {};
for _, member in pairs(Guild.members) do
if type(member) == type({}) then
setmetatable(member, Member); -- Set the metatable so we used Members's __index
table.insert(PDKP.data, member)
end
end
end
function PDKP:GetAllTableData()
return PDKP.data;
end
function PDKP:GetDataCount()
return table.getn(PDKP.data);
end
-----------------------------
-- UI FUNCTIONS --
-----------------------------
function PDKP:GetCharName()
return UnitName("PLAYER")
end
-- Shows the PDKP UI
function PDKP:Show()
if GUI.shown then return end -- Don't open more than one instance of PDKP
if not core.initialized then return PDKP:Print("Initialization has not finished...") end
PlaySound(826)
-- print('PDKP_UID: ', core.defaults.pdkp_is_in_guild)
Setup:MainUI()
pdkp_init_scrollbar()
-- Displays the current character's dkp at the top for accessability.
GUI:UpdateEasyStats()
-- Automatically update the online status regardless of whether it's checked, when the app is reopened.
GUI:UpdateOnlineStatus(core.filterOffline)
GUI.pdkp_frame:Show()
GUI.shown = true;
GUI.HistoryCheck.frame:Show()
if GUI.reasonDropdown then GUI.reasonDropdown.frame:Show() end;
if GUI.raidDropdown then GUI.raidDropdown.frame:Show() end;
end
-----------------------------
-- GLOBAL FUNCTIONS --
-----------------------------
-- General handler for template object clicks.
function pdkp_template_function_call(funcName, object, clickType, buttonName)
if funcName == "Hide" then return GUI:Hide() end
if funcName == "pdkp_entry_clicked" then return GUI:EntryClicked(object, clickType, buttonName) end;
if funcName == 'pdkp_entry_control_clicked' then return GUI:EntryControlClicked(object, clickType, buttonName) end;
if funcName == 'pdkp_entry_shift_clicked' then return GUI:EntryShiftClicked(object, clickType, buttonName) end;
if funcName == "pdkp_dkp_table_sort" then return GUI:pdkp_dkp_table_sort(object) end;
if funcName == "pdkp_dkp_scrollbar_Update" then return GUI:pdkp_dkp_scrollbar_Update() end;
if funcName == "pdkp_dkp_table_filter_class" then return GUI:pdkp_dkp_table_filter_class(object) end;
if funcName == 'pdkp_change_table_view' then return GUI:pdkp_change_view(object) end;
if funcName == 'pdkp_toggle_online' then return GUI:UpdateOnlineStatus(object) end;
if funcName == 'pdkp_in_raid_checkbox' then return GUI:ToggleInRaid(object) end;
if funcName == 'pdkp_dkp_table_filter' then return pdkp_dkp_table_filter() end;
if funcName == 'pdkp_toggle_selected' then return GUI:pdkp_toggle_selected() end;
if funcName == 'GetSelectedFilterStatus' then return GUI:GetSelectedFilterStatus() end;
if funcName == 'SearchInputUpdated' then return GUI:SearchInputUpdated(object) end
if funcName == 'pdkp_dkp_update' then return DKP:ConfirmChange() end;
if funcName == 'pdkp_boss_kill_dkp' then return Raid:AcceptDKPUpdate(object) end;
if funcName == 'pdkp_quick_shroud' then return GUI:QuickCalculate('shroud') end;
if funcName == 'pdkp_quick_roll' then return GUI:QuickCalculate('roll') end;
if funcName == 'toggleSubmitButton' then return GUI:ToggleSubmitButton() end;
if funcName == 'pdkp_select_all_classes' then return GUI:ToggleAllClasses(object) end;
if funcName == 'pdkp_prio_hide' then return GUI.prio:Hide() end;
if funcName == 'pdkp_select_all_filtered_checkbox' then return GUI:SelectAllVisible() end
end
function UnregisterEvent(self, event)
self:UnregisterEvent(event);
end
local events = CreateFrame("Frame", "EventsFrame");
events:RegisterEvent("ADDON_LOADED");
events:RegisterEvent("GUILD_ROSTER_UPDATE");
events:RegisterEvent("GROUP_ROSTER_UPDATE");
events:RegisterEvent("ENCOUNTER_START"); -- FOR TESTING PURPOSES.
events:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED"); -- NPC kill event
events:RegisterEvent("LOOT_OPENED");
events:RegisterEvent("CHAT_MSG_RAID");
events:RegisterEvent("CHAT_MSG_RAID_LEADER");
events:RegisterEvent("CHAT_MSG_WHISPER");
events:RegisterEvent("CHAT_MSG_GUILD");
events:RegisterEvent("CHAT_MSG_LOOT"); -- someone selects need, greed, passes, rolls, receives
events:RegisterEvent("PLAYER_ENTERING_WORLD");
events:RegisterEvent("ZONE_CHANGED_NEW_AREA");
events:RegisterEvent("BOSS_KILL");
events:SetScript("OnEvent", PDKP_OnEvent); -- calls the above MonDKP_OnEvent function to determine what to do with the event