forked from Roeshambo/MonolithDKP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
610 lines (560 loc) · 25.4 KB
/
init.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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
local _, core = ...;
local _G = _G;
local MonDKP = core.MonDKP;
local L = core.L;
local lockouts = CreateFrame("Frame", "LockoutsFrame");
--------------------------------------
-- Slash Command
--------------------------------------
MonDKP.Commands = {
["config"] = function()
if core.Initialized then
local pass, err = pcall(MonDKP.Toggle)
if not pass then
print(err)
core.MonDKPUI:SetShown(false)
StaticPopupDialogs["SUGGEST_RELOAD"] = {
text = "|CFFFF0000"..L["WARNING"].."|r: "..L["MUSTRELOADUI"],
button1 = L["YES"],
button2 = L["NO"],
OnAccept = function()
ReloadUI();
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
preferredIndex = 3,
}
StaticPopup_Show ("SUGGEST_RELOAD")
end
else
MonDKP:Print("Monolith DKP has not completed initialization.")
end
end,
["reset"] = MonDKP.ResetPosition,
["bid"] = function(...)
if core.Initialized then
local item = strjoin(" ", ...)
MonDKP:CheckOfficer()
MonDKP:StatusVerify_Update()
if core.IsOfficer then
if ... == nil then
MonDKP.ToggleBidWindow()
else
local itemName,_,_,_,_,_,_,_,_,itemIcon = GetItemInfo(item)
MonDKP:Print("Opening Bid Window for: ".. item)
MonDKP:ToggleBidWindow(item, itemIcon, itemName)
end
end
MonDKP:BidInterface_Toggle()
else
MonDKP:Print("Monolith DKP has not completed initialization.")
end
end,
["migrate"] = function()
if not core.Migrated then MonDKP:MigrationFrame() end
end,
--[[["test"] = function() -- test new features
MonDKP:BidInterface_Toggle()
end,--]]
["award"] = function (name, ...)
if core.IsOfficer and core.Initialized then
MonDKP:StatusVerify_Update()
if not name or not strfind(name, ":::::") then
MonDKP:Print(L["AWARDWARNING"])
return
end
local item = strjoin(" ", ...)
if not item then return end
item = name.." "..item;
MonDKP:AwardConfirm(nil, 0, MonDKP_DB.bossargs.LastKilledBoss, MonDKP_DB.bossargs.CurrentRaidZone, item)
else
MonDKP:Print(L["NOPERMISSION"])
end
end,
["lockouts"] = function()
lockouts:RegisterEvent("UPDATE_INSTANCE_INFO");
lockouts:SetScript("OnEvent", MonDKP_OnEvent);
RequestRaidInfo()
end,
["timer"] = function(time, ...)
if time == nil then
MonDKP:BroadcastTimer(1, "...")
else
local title = strjoin(" ", ...)
MonDKP:BroadcastTimer(tonumber(time), title)
end
end,
["export"] = function(time, ...)
MonDKP:ToggleExportWindow()
end,
["modes"] = function()
if core.Initialized then
MonDKP:CheckOfficer()
if core.IsOfficer then
MonDKP:ToggleDKPModesWindow()
else
MonDKP:Print(L["NOPERMISSION"])
end
else
MonDKP:Print("Monolith DKP has not completed initialization.")
end
end,
["help"] = function()
print(" ");
MonDKP:Print(L["SLASHCOMMANDLIST"]..":")
MonDKP:Print("|cff00cc66/dkp|r - "..L["DKPLAUNCH"]);
MonDKP:Print("|cff00cc66/dkp ?|r - "..L["HELPINFO"]);
MonDKP:Print("|cff00cc66/dkp reset|r - "..L["DKPRESETPOS"]);
MonDKP:Print("|cff00cc66/dkp lockouts|r - "..L["DKPLOCKOUT"]);
MonDKP:Print("|cff00cc66/dkp timer|r - "..L["CREATERAIDTIMER"]);
MonDKP:Print("|cff00cc66/dkp bid|r - "..L["OPENBIDWINDOWHELP"]);
MonDKP:Print("|cff00cc66/dkp award [item link]|r - "..L["DKPAWARDHELP"]);
MonDKP:Print("|cff00cc66/dkp modes|r - "..L["DKPMODESHELP"]);
MonDKP:Print("|cff00cc66/dkp export|r - "..L["DKPEXPORTHELP"]);
print(" ");
MonDKP:Print(L["WHISPERCMDSHELP"]);
MonDKP:Print("|cff00cc66!bid (or !bid <"..L["VALUE"]..">)|r - "..L["BIDHELP"]);
MonDKP:Print("|cff00cc66!dkp (or !dkp <"..L["PLAYERNAME"]..">)|r - "..L["DKPCMDHELP"]);
end,
};
local function HandleSlashCommands(str)
if (#str == 0) then
MonDKP.Commands.config();
return;
end
local args = {};
for _, arg in ipairs({ string.split(' ', str) }) do
if (#arg > 0) then
table.insert(args, arg);
end
end
local path = MonDKP.Commands;
for id, arg in ipairs(args) do
if (#arg > 0) then
arg = arg:lower();
if (path[arg]) then
if (type(path[arg]) == "function") then
path[arg](select(id + 1, unpack(args)));
return;
elseif (type(path[arg]) == "table") then
path = path[arg];
end
else
MonDKP.Commands.help();
return;
end
end
end
end
function MonDKP_OnEvent(self, event, arg1, ...)
-- unregister unneccessary events
if event == "CHAT_MSG_WHISPER" and not MonDKP_DB.modes.channels.whisper then
self:UnregisterEvent("CHAT_MSG_WHISPER")
return
end
if (event == "CHAT_MSG_RAID" or event == "CHAT_MSG_RAID_LEADER") and not MonDKP_DB.modes.channels.raid then
self:UnregisterEvent("CHAT_MSG_RAID")
self:UnregisterEvent("CHAT_MSG_RAID_LEADER")
return
end
if event == "CHAT_MSG_GUILD" and not MonDKP_DB.modes.channels.guild and not MonDKP_DB.modes.StandbyOptIn then
self:UnregisterEvent("CHAT_MSG_GUILD")
return
end
if event == "ADDON_LOADED" then
MonDKP:OnInitialize(event, arg1)
self:UnregisterEvent("ADDON_LOADED")
elseif event == "BOSS_KILL" then
MonDKP:CheckOfficer()
if core.IsOfficer and IsInRaid() then
local boss_name = ...;
if MonDKP:Table_Search(core.EncounterList, arg1) then
MonDKP.ConfigTab2.BossKilledDropdown:SetValue(arg1)
if MonDKP_DB.modes.StandbyOptIn then
MonDKP_Standby_Announce(boss_name)
end
if MonDKP_DB.modes.AutoAward then
if not MonDKP_DB.modes.StandbyOptIn and MonDKP_DB.DKPBonus.IncStandby then
MonDKP:AutoAward(3, MonDKP_DB.DKPBonus.BossKillBonus, MonDKP_DB.bossargs.CurrentRaidZone..": "..MonDKP_DB.bossargs.LastKilledBoss)
else
MonDKP:AutoAward(1, MonDKP_DB.DKPBonus.BossKillBonus, MonDKP_DB.bossargs.CurrentRaidZone..": "..MonDKP_DB.bossargs.LastKilledBoss)
end
end
else
MonDKP:Print("Event ID: "..arg1.." - > "..boss_name.." Killed. Please report this Event ID at https://www.curseforge.com/wow/addons/monolith-dkp to update raid event handlers.")
end
elseif IsInRaid() then
MonDKP_DB.bossargs.LastKilledBoss = ...;
end
elseif event == "ENCOUNTER_START" then
if MonDKP_DB.defaults.AutoLog and IsInRaid() then
if not LoggingCombat() then
LoggingCombat(1)
MonDKP:Print(L["NOWLOGGINGCOMBAT"])
end
end
elseif event == "PLAYER_ENTERING_WORLD" or event == "ZONE_CHANGED_NEW_AREA" then -- logs 15 recent zones entered while in a raid party
if IsInRaid() and core.Initialized then -- only processes combat log events if in raid
MonDKP:CheckOfficer()
if core.IsOfficer then
if not MonDKP:Table_Search(MonDKP_DB.bossargs.RecentZones, GetRealZoneText()) then -- only adds it if it doesn't already exist in the table
if #MonDKP_DB.bossargs.RecentZones > 14 then
for i=15, #MonDKP_DB.bossargs.RecentZones do -- trims the tail end of the stack
table.remove(MonDKP_DB.bossargs.RecentZones, i)
end
end
table.insert(MonDKP_DB.bossargs.RecentZones, 1, GetRealZoneText())
end
end
if MonDKP_DB.defaults.AutoLog and MonDKP:Table_Search(core.ZoneList, GetRealZoneText()) then
if not LoggingCombat() then
LoggingCombat(1)
MonDKP:Print(L["NOWLOGGINGCOMBAT"])
end
end
end
MonDKP:ErrantCheck()
MonDKP:UpdateIndexes()
elseif event == "CHAT_MSG_WHISPER" then
MonDKP:CheckOfficer()
arg1 = strlower(arg1)
if (core.BidInProgress or string.find(arg1, "!dkp") == 1 or string.find(arg1, "!dkp") == 1) and core.IsOfficer == true then
MonDKP_CHAT_MSG_WHISPER(arg1, ...)
end
elseif event == "GUILD_ROSTER_UPDATE" then
if IsInGuild() and not core.InitStart then
GuildRoster()
core.InitStart = true
--self:UnregisterEvent("GUILD_ROSTER_UPDATE")
-- Prints info after all addons have loaded. Circumvents addons that load saved chat messages pushing info out of view.
C_Timer.After(3, function ()
core.MonDKPUI = MonDKP.UIConfig or MonDKP:CreateMenu(); -- creates main menu
MonDKP:CheckOfficer()
MonDKP:Print(L["VERSION"].." "..core.MonVersion..", "..L["CREATEDMAINTAIN"].." Roeshambo@Stalagg-PvP");
MonDKP:Print(L["LOADED"].." "..#MonDKP_DKPTable.." "..L["PLAYERRECORDS"]..", "..#MonDKP_Loot.." "..L["LOOTHISTRECORDS"].." "..#MonDKP_DKPHistory.." "..L["DKPHISTRECORDS"]..".");
MonDKP:Print(L["USE"].." /dkp ? "..L["SUBMITBUGS"].." @ https://github.com/Roeshambo/MonolithDKP/issues");
MonDKP.Sync:SendData("MonDKPBuild", tostring(core.BuildNumber)) -- broadcasts build number to guild to check if a newer version is available
if not core.Migrated and core.IsOfficer then -- prompts for migration (if officer and not migrated)
-- initiate migration setup
MonDKP:MigrationFrame()
elseif not core.Migrated and not core.IsOfficer then -- wipes tables if non officer
MonDKP_DKPTable = nil
MonDKP_Loot = nil
MonDKP_DKPHistory = nil
MonDKP_DKPTable = {}
MonDKP_Loot = {}
MonDKP_DKPHistory = {}
core.Migrated = true
MonDKP:FilterDKPTable(core.currentSort, "reset")
MonDKP:RequestSync()
else
if core.IsOfficer and not MonDKP_Meta.DKP[UnitName("player")] then
MonDKP_Meta.DKP[UnitName("player")] = { current=0, lowest=0 }
MonDKP_Meta.Loot[UnitName("player")] = { current=0, lowest=0 }
end
MonDKP:RequestSync() -- Initiates sync, if officer. Requests a random officer to initiate sync if not an officer.
end
end)
end
if IsInGuild() then
local GuildName = GetGuildInfo("player")
if not MonDKP_DB.defaults.CurrentGuild[UnitName("player")] and GuildName then
MonDKP_DB.defaults.CurrentGuild = {}
MonDKP_DB.defaults.CurrentGuild[UnitName("player")] = GuildName
elseif GuildName and MonDKP_DB.defaults.CurrentGuild[UnitName("player")] ~= GuildName then -- prompt to wipes tables if guild changes
StaticPopupDialogs["GUILD_CHANGED"] = {
text = L["CHANGEDGUILDS"],
button1 = L["YES"],
button2 = L["NO"],
OnAccept = function()
MonDKP_DB.defaults.CurrentGuild[UnitName("player")] = GuildName
MonDKP_DKPTable = nil
MonDKP_Loot = nil
MonDKP_DKPHistory = nil
MonDKP_Meta = nil
MonDKP_Meta_Remote = nil
MonDKP_Archive = nil
MonDKP_DKPTable = {}
MonDKP_Loot = {}
MonDKP_DKPHistory = {}
MonDKP_Meta = {}
MonDKP_Meta_Remote = {}
MonDKP_Archive = {}
core.Migrated = true
MonDKP:FilterDKPTable(core.currentSort, "reset")
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
preferredIndex = 3,
}
StaticPopup_Show ("GUILD_CHANGED")
end
end
elseif event == "CHAT_MSG_RAID" or event == "CHAT_MSG_RAID_LEADER" then
MonDKP:CheckOfficer()
arg1 = strlower(arg1)
if (core.BidInProgress or string.find(arg1, "!dkp") == 1 or string.find(arg1, "!standby") == 1 or string.find(arg1, "!dkp") == 1) and core.IsOfficer == true then
MonDKP_CHAT_MSG_WHISPER(arg1, ...)
end
elseif event == "UPDATE_INSTANCE_INFO" then
local num = GetNumSavedInstances()
local raidString, reset, newreset, days, hours, mins, maxPlayers, numEncounter, curLength;
if not MonDKP_DB.Lockouts then MonDKP_DB.Lockouts = {Three = 0, Five = 1570032000, Seven = 1569945600} end
for i=1, num do -- corrects reset timestamp for any raids where an active lockout exists
_,_,reset,_,_,_,_,_,maxPlayers,_,numEncounter = GetSavedInstanceInfo(i)
newreset = time() + reset + 2 -- returned time is 2 seconds off
if maxPlayers == 40 and numEncounter > 1 then
curLength = "Seven"
elseif maxPlayers == 40 and numEncounter == 1 then
curLength = "Five"
elseif maxPlayers == 20 then
curLength = "Three"
end
if MonDKP_DB.Lockouts[curLength] < newreset then
MonDKP_DB.Lockouts[curLength] = newreset
end
end
-- Updates lockout timer if no lockouts were found to do so.
while MonDKP_DB.Lockouts.Three < time() do MonDKP_DB.Lockouts.Three = MonDKP_DB.Lockouts.Three + 259200 end
while MonDKP_DB.Lockouts.Five < time() do MonDKP_DB.Lockouts.Five = MonDKP_DB.Lockouts.Five + 432000 end
while MonDKP_DB.Lockouts.Seven < time() do MonDKP_DB.Lockouts.Seven = MonDKP_DB.Lockouts.Seven + 604800 end
for k,v in pairs(MonDKP_DB.Lockouts) do
reset = v - time();
days = math.floor(reset / 86400)
hours = math.floor(math.floor(reset % 86400) / 3600)
mins = math.ceil((reset % 3600) / 60)
if days > 1 then days = " "..days.." "..L["DAYS"] elseif days == 0 then days = "" else days = " "..days.." "..L["DAY"] end
if hours > 1 then hours = " "..hours.." "..L["HOURS"] elseif hours == 0 then hours = "" else hours = " "..hours.." "..L["HOUR"].."." end
if mins > 1 then mins = " "..mins.." "..L["MINUTES"].."." elseif mins == 0 then mins = "" else mins = " "..mins.." "..L["MINUTE"].."." end
if k == "Three" then raidString = "ZG, AQ20"
elseif k == "Five" then raidString = "Onyxia"
elseif k == "Seven" then raidString = "MC, BWL, AQ40"
end
if k ~= "Three" then -- remove when three day raid lockouts are added
MonDKP:Print(raidString.." "..L["RESETSIN"]..days..hours..mins.." ("..date("%A @ %H:%M:%S%p", v)..")")
end
end
self:UnregisterEvent("UPDATE_INSTANCE_INFO");
elseif event == "CHAT_MSG_GUILD" then
MonDKP:CheckOfficer()
if core.IsOfficer then
arg1 = strlower(arg1)
if (core.BidInProgress or string.find(arg1, "!dkp") == 1 or string.find(arg1, "!dkp") == 1) and MonDKP_DB.modes.channels.guild then
MonDKP_CHAT_MSG_WHISPER(arg1, ...)
elseif string.find(arg1, "!standby") == 1 and core.StandbyActive then
MonDKP_Standby_Handler(arg1, ...)
end
end
--elseif event == "CHAT_MSG_SYSTEM" then
--MonoDKP_CHAT_MSG_SYSTEM(arg1)
elseif event == "GROUP_ROSTER_UPDATE" then --updates raid listing if window is open
if MonDKP.UIConfig and core.MonDKPUI:IsShown() then
if core.CurSubView == "raid" then
MonDKP:ViewLimited(true)
elseif core.CurSubView == "raid and standby" then
MonDKP:ViewLimited(true, true)
end
end
elseif event == "COMBAT_LOG_EVENT_UNFILTERED" then -- logs last 15 NPCs killed while in raid
if IsInRaid() then -- only processes combat log events if in raid
local _,arg1,_,_,_,_,_,arg2,arg3 = CombatLogGetCurrentEventInfo();
if arg1 == "UNIT_DIED" and not strfind(arg2, "Player") and not strfind(arg2, "Pet-") then
MonDKP:CheckOfficer()
if core.IsOfficer then
if not MonDKP:Table_Search(MonDKP_DB.bossargs.LastKilledNPC, arg3) then -- only adds it if it doesn't already exist in the table
if #MonDKP_DB.bossargs.LastKilledNPC > 14 then
for i=15, #MonDKP_DB.bossargs.LastKilledNPC do -- trims the tail end of the stack
table.remove(MonDKP_DB.bossargs.LastKilledNPC, i)
end
end
table.insert(MonDKP_DB.bossargs.LastKilledNPC, 1, arg3)
end
end
end
end
--[[elseif event == "COMBAT_LOG_EVENT_UNFILTERED" then -- replaced with above BOSS_KILL event handler
if IsInRaid() then -- only processes combat log events if in raid
local _,arg1,_,_,_,_,_,_,arg2 = CombatLogGetCurrentEventInfo(); -- run operation when boss is killed
if arg1 == "UNIT_DIED" then
MonDKP:CheckOfficer()
if core.IsOfficer == true then
if MonDKP:TableStrFind(core.BossList, arg2) then
MonDKP.ConfigTab2.BossKilledDropdown:SetValue(arg2)
elseif arg2 == "Flamewalker Elite" or arg2 == "Flamewalker Healer" then
MonDKP.ConfigTab2.BossKilledDropdown:SetValue("Majordomo Executus")
elseif arg2 == "Emperor Vek'lor" or arg2 == "Emperor Vek'nilash" then
MonDKP.ConfigTab2.BossKilledDropdown:SetValue("Twin Emperors")
elseif arg2 == "Princess Yauj" or arg2 == "Vem" or arg2 == "Lord Kri" then
MonDKP.ConfigTab2.BossKilledDropdown:SetValue("Bug Family")
elseif arg2 == "Highlord Mograine" or arg2 == "Thane Korth'azz" or arg2 == "Sir Zeliek" or arg2 == "Lady Blaumeux" then
MonDKP.ConfigTab2.BossKilledDropdown:SetValue("The Four Horsemen")
elseif arg2 == "Gri'lek" or arg2 == "Hazza'rah" or arg2 == "Renataki" or arg2 == "Wushoolay" then
MonDKP.ConfigTab2.BossKilledDropdown:SetValue("Edge of Madness")
end
end
end
end--]]
elseif event == "LOOT_OPENED" then
if core.IsOfficer then
MonDKP_Register_ShiftClickLootWindowHook()
local lootTable = {}
local lootList = {};
for i=1, GetNumLootItems() do
if not GetLootSlotLink(i) then return end -- prevent errors if auto loot is used causing the items to be removed from the frame before loop completes
if LootSlotHasItem(i) and GetLootSlotLink(i) then
local _,link,quality = GetItemInfo(GetLootSlotLink(i))
if quality >= 4 then
table.insert(lootTable, link)
end
end
end
lootTable.boss=UnitName("target")
MonDKP.Sync:SendData("MonDKPBossLoot", lootTable)
for i=1, #lootTable do
local item = Item:CreateFromItemLink(lootTable[i]);
item:ContinueOnItemLoad(function()
local icon = item:GetItemIcon()
table.insert(lootList, {icon=icon, link=item:GetItemLink()})
end);
end
MonDKP:LootTable_Set(lootList)
end
end
end
function MonDKP:OnInitialize(event, name) -- This is the FIRST function to run on load triggered registered events at bottom of file
if (name ~= "MonolithDKP") then return end
-- allows using left and right buttons to move through chat 'edit' box
for i = 1, NUM_CHAT_WINDOWS do
_G["ChatFrame"..i.."EditBox"]:SetAltArrowKeyMode(false);
end
----------------------------------
-- Register Slash Commands
----------------------------------
SLASH_MonolithDKP1 = "/dkp";
SLASH_MonolithDKP2 = "/mondkp";
SlashCmdList.MonolithDKP = HandleSlashCommands;
--[[SLASH_RELOADUI1 = "/rl"; -- new slash command for reloading UI -- for debugging
SlashCmdList.RELOADUI = ReloadUI;
SLASH_FRAMESTK1 = "/fs"; -- new slash command for showing framestack tool
SlashCmdList.FRAMESTK = function()
LoadAddOn("Blizzard_DebugTools");
FrameStackTooltip_Toggle();
end--]]
if(event == "ADDON_LOADED") then
core.Initialized = false
core.InitStart = false
core.IsOfficer = ""
if not MonDKP_DKPTable then MonDKP_DKPTable = {} end;
if not MonDKP_Loot then MonDKP_Loot = {} end;
if not MonDKP_DKPHistory then MonDKP_DKPHistory = {} end;
if not MonDKP_MinBids then MonDKP_MinBids = {} end;
if not MonDKP_Whitelist then MonDKP_Whitelist = {} end;
if not MonDKP_Standby then MonDKP_Standby = {} end;
if not MonDKP_Archive then MonDKP_Archive = {} end;
if not MonDKP_DB then MonDKP_DB = {} end
if ((#MonDKP_Loot == 0 or MonDKP_Loot[1].index) and (#MonDKP_DKPHistory == 0 or MonDKP_DKPHistory[1].index)) then core.Migrated = true end; -- determines if migration is necessary
if not MonDKP_DB.DKPBonus or not MonDKP_DB.DKPBonus.OnTimeBonus then
MonDKP_DB.DKPBonus = {
OnTimeBonus = 15, BossKillBonus = 5, CompletionBonus = 10, NewBossKillBonus = 10, UnexcusedAbsence = -25, BidTimer = 30, DecayPercentage = 20, GiveRaidStart = false, IncStandby = false,
}
end
if not MonDKP_DB.defaults or not MonDKP_DB.defaults.HistoryLimit then
MonDKP_DB.defaults = {
HistoryLimit = 2500, DKPHistoryLimit = 2500, BidTimerSize = 1.0, MonDKPScaleSize = 1.0, supressNotifications = false, TooltipHistoryCount = 15,
}
end
if not MonDKP_DB.raiders then MonDKP_DB.raiders = {} end
if not MonDKP_DB.MinBidBySlot or not MonDKP_DB.MinBidBySlot.Head then
MonDKP_DB.MinBidBySlot = {
Head = 70, Neck = 70, Shoulders = 70, Cloak = 70, Chest = 70, Bracers = 70, Hands = 70, Belt = 70, Legs = 70, Boots = 70, Ring = 70, Trinket = 70, OneHanded = 70, TwoHanded = 70, OffHand = 70, Range = 70, Other = 70,
}
end
if not MonDKP_DB.bossargs then MonDKP_DB.bossargs = { CurrentRaidZone = "Molten Core", LastKilledBoss = "Lucifron" } end
if not MonDKP_DB.modes or not MonDKP_DB.modes.mode then MonDKP_DB.modes = { mode = "Minimum Bid Values", SubZeroBidding = false, rounding = 0, AddToNegative = false, increment = 60, ZeroSumBidType = "Static", AllowNegativeBidders = false } end;
if not MonDKP_DB.modes.ZeroSumBank then MonDKP_DB.modes.ZeroSumBank = { balance = 0 } end
if not MonDKP_DB.modes.channels then MonDKP_DB.modes.channels = { raid = true, whisper = true, guild = true } end
if not MonDKP_DB.modes.costvalue then MonDKP_DB.modes.costvalue = "Integer" end
if not MonDKP_DB.modes.rolls or not MonDKP_DB.modes.rolls.min then MonDKP_DB.modes.rolls = { min = 1, max = 100, UsePerc = false, AddToMax = 0 } end
if not MonDKP_DB.bossargs.LastKilledNPC then MonDKP_DB.bossargs.LastKilledNPC = {} end
if not MonDKP_DB.bossargs.RecentZones then MonDKP_DB.bossargs.RecentZones = {} end
if not MonDKP_DB.defaults.HideChangeLogs then MonDKP_DB.defaults.HideChangeLogs = 0 end
if not MonDKP_DB.modes.AntiSnipe then MonDKP_DB.modes.AntiSnipe = 0 end
if not MonDKP_Meta then MonDKP_Meta = { DKP={}, Loot={} } end
if not MonDKP_Meta_Remote or not MonDKP_Meta_Remote.DKP or not MonDKP_Meta_Remote.Loot then MonDKP_Meta_Remote = { DKP={}, Loot={} } end
if not MonDKP_DB.defaults.CurrentGuild then MonDKP_DB.defaults.CurrentGuild = {} end
for i=1, #MonDKP_DKPTable do
if not MonDKP_DKPTable[i].rank or not MonDKP_DKPTable[i].rankName or MonDKP_DKPTable[i].rank == "None" then
MonDKP_DKPTable[i].rank = 20
MonDKP_DKPTable[i].rankName = "None"
end
if not MonDKP_DKPTable[i].spec then
MonDKP_DKPTable[i].spec = L["NOSPECREPORTED"]
end
if not MonDKP_DKPTable[i].role then
MonDKP_DKPTable[i].role = L["NOROLEDETECTED"]
end
if MonDKP_DKPTable[i].class == "NONE" then
MonDKP.Sync:SendData("MonDKPProfileReq", MonDKP_DKPTable[i].player)
end
end
for i=1, #MonDKP_DKPHistory do
if MonDKP_DKPHistory[i].deletes then
local search = MonDKP:Table_Search(MonDKP_DKPHistory, MonDKP_DKPHistory[i].deletes, "index")
if search and not MonDKP_DKPHistory[search[1][1]].deletedby then
MonDKP_DKPHistory[search[1][1]].deletedby = MonDKP_DKPHistory[i].index -- adds deltedby index to field if it was received after a delete entry was received but was sent by someone that did not have the delete entry
end
end
end
------------------------------------
-- Validate Tables - Rebuilds DKPTable based off of DKP History, Loot History, and archived data
------------------------------------
if core.Migrated then -- only allow this to fire if the migration has already occurred.
MonDKP:ValidateLootTable() -- clears duplicate entries in loot table
MonDKP:ValidateDKPHistory() -- clears duplicate entries in dkp history table
MonDKP:ValidateDKPTable_Loot() -- adds up all entries in the loot table
MonDKP:ValidateDKPTable_DKP() -- adds up all entries in DKP table
MonDKP:ValidateDKPTable_Final() -- rectifies incorrect DKPTable data based off of the above 2 functions
end
------------------------------------
-- Import SavedVariables
------------------------------------
core.settings.DKPBonus = MonDKP_DB.DKPBonus -- imports default settings (Options Tab)
core.settings.MinBidBySlot = MonDKP_DB.MinBidBySlot -- imports default minimum bids (Options Tab)
core.settings.defaults = MonDKP_DB.defaults -- imports default UI settings
core.WorkingTable = MonDKP_DKPTable; -- imports full DKP table to WorkingTable for list manipulation without altering the SavedVariable
core.CurrentRaidZone = MonDKP_DB.bossargs.CurrentRaidZone; -- stores raid zone as a redundency
core.LastKilledBoss = MonDKP_DB.bossargs.LastKilledBoss; -- stores last boss killed as a redundency
core.LastKilledNPC = MonDKP_DB.bossargs.LastKilledNPC -- Stores last 30 mobs killed in raid.
core.RecentZones = MonDKP_DB.bossargs.RecentZones -- Stores last 30 zones entered within a raid party.
table.sort(MonDKP_DKPTable, function(a, b)
return a["player"] < b["player"]
end)
for i=1, #MonDKP_DKPTable do
MonDKP_DKPTable[i].class = string.upper(MonDKP_DKPTable[i].class) -- hotfix for migrating previous class listings to localization neutral classes
end
MonDKP:StartBidTimer("seconds", nil) -- initiates timer frame for use
MonDKP:PurgeLootHistory() -- purges Loot History entries that exceed the "HistoryLimit" option variable (oldest entries) and populates MonDKP_Archive with deleted values
MonDKP:PurgeDKPHistory() -- purges DKP History entries that exceed the "DKPHistoryLimit" option variable (oldest entries) and populates MonDKP_Archive with deleted values
MonDKP:UpdateIndexes()
end
end
----------------------------------
-- Register Events and Initiallize AddOn
----------------------------------
local events = CreateFrame("Frame", "EventsFrame");
events:RegisterEvent("ADDON_LOADED");
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("GUILD_ROSTER_UPDATE")
events:RegisterEvent("PLAYER_ENTERING_WORLD")
events:RegisterEvent("ZONE_CHANGED_NEW_AREA")
events:RegisterEvent("BOSS_KILL")
events:SetScript("OnEvent", MonDKP_OnEvent); -- calls the above MonDKP_OnEvent function to determine what to do with the event