-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.lua
executable file
·1647 lines (1479 loc) · 60.1 KB
/
core.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
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--[[ RCLootCouncil by Potdisc
core.lua Contains core elements of the addon
--------------------------------
TODOs/Notes
Things marked with "todo"
- IDEA add an observer/council string to show players their role?
- If we truly want to be able to edit votingframe scrolltable with modules, it needs to have GetCol by name
- Pressing shift while hovering an item should do the same as vanilla
- The 4'th cell in @line81 in versionCheck should not be static
--------------------------------
CHANGELOG
-- SEE CHANGELOG.TXT
]]
RCLootCouncil = LibStub("AceAddon-3.0"):NewAddon("RCLootCouncil", "AceConsole-3.0", "AceEvent-3.0", "AceComm-3.0", "AceSerializer-3.0", "AceHook-3.0", "AceTimer-3.0");
local LibDialog = LibStub("LibDialog-1.0")
local L = LibStub("AceLocale-3.0"):GetLocale("RCLootCouncil")
local lwin = LibStub("LibWindow-1.1")
local Deflate = LibStub("LibDeflate")
local LibGroupTalents = LibStub("LibGroupTalents-1.0")
local GUILD_DEMOTE_PATTERN = "^".._G.ERR_GUILD_DEMOTE_SSS:gsub('%%s', '(.+)').."$"
local GUILD_PROMOTE_PATTERN = "^".._G.ERR_GUILD_PROMOTE_SSS:gsub('%%s', '(.+)').."$"
RCLootCouncil:SetDefaultModuleState(false)
-- Init shorthands
local db, historyDB, debugLog;-- = self.db.profile, self.lootDB.factionrealm, self.db.global.log
-- init modules
local defaultModules = {
masterlooter = "RCLootCouncilML",
lootframe = "RCLootFrame",
history = "RCLootHistory",
version = "RCVersionCheck",
sessionframe = "RCSessionFrame",
votingframe = "RCVotingFrame",
}
local userModules = {
masterlooter = nil,
lootframe = nil,
history = nil,
version = nil,
sessionframe = nil,
votingframe = nil,
}
local frames = {} -- Contains all frames created by RCLootCouncil:CreateFrame()
local unregisterGuildEvent = false
local player_relogged = true -- Determines if we potentially need data from the ML due to /rl
function RCLootCouncil:OnInitialize()
--IDEA Consider if we want everything on self, or just whatever modules could need.
self.version = "3.0.0" -- hard code the version so reload ui updates will report correct version
self.nnp = false
self.debug = false
self.tVersion = nil -- String or nil. Indicates test version, which alters stuff like version check. Is appended to 'version', i.e. "version-tVersion"
self.playerClass = select(2, UnitClass("player"))
self.guildRank = L["Unguilded"]
self.target = nil
self.isMasterLooter = false -- Are we the ML?
self.masterLooter = "" -- Name of the ML
self.isCouncil = false -- Are we in the Council?
self.enabled = true -- turn addon on/off
self.inCombat = false -- Are we in combat?
self.verCheckDisplayed = false -- Have we shown a "out-of-date"?
self.council = {} -- council from ML
self.mldb = {} -- db recived from ML
self.mlhistory = {} -- history received from ML
self.successful_history_requests = {} -- for the master looter, history requests that were done successfully
self.responses = {
NOTANNOUNCED = { color = {1,0,1,1}, sort = 501, text = L["Not announced"],},
ANNOUNCED = { color = {1,0,1,1}, sort = 502, text = L["Loot announced, waiting for answer"], },
WAIT = { color = {1,1,0,1}, sort = 503, text = L["Candidate is selecting response, please wait"], },
TIMEOUT = { color = {1,0,0,1}, sort = 504, text = L["Candidate didn't respond on time"], },
REMOVED = { color = {0.8,0.5,0,1}, sort = 505, text = L["Candidate removed"], },
NOTHING = { color = {0.5,0.5,0.5,1}, sort = 505, text = L["Offline or RCLootCouncil not installed"], },
PASS = { color = {0.7, 0.7,0.7,1}, sort = 800, text = L["Pass"],},
AUTOPASS = { color = {0.7,0.7,0.7,1}, sort = 801, text = L["Autopass"], },
DISABLED = { color = {0.3, 0.35, 0.5}, sort = 802, text = L["Candidate has disabled RCLootCouncil"], },
--[[1]] { color = {1, 0, 0.00392156862745098}, sort = 1, text = L["Best in Slot"],},
--[[2]] { color = {1, 0.5490196078431373, 0, 1}, sort = 2, text = L["Big Upgrade but not BiS"],},
--[[3]] { color = {0.9882352941176471, 1, 0}, sort = 3, text = L["Small Upgrade but not BiS"],},
--[[4]] { color = {0.00392156862745098, 0, 1}, sort = 4, text = L["Off Spec"],},
}
self.roleTable = {
TANK = L["Tank"],
HEALER = L["Healer"],
DAMAGER = L["DPS"],
NONE = L["None"],
}
self.testMode = false;
-- Option table defaults
self.defaults = {
global = {
logMaxEntries = 500,
log = {}, -- debug log
localizedSubTypes = {},
},
profile = {
usage = { -- State of enabledness
ml = false, -- Enable when ML
ask_ml = true, -- Ask before enabling when ML
leader = false, -- Enable when leader
ask_leader = true, -- Ask before enabling when leader
never = false, -- Never enable
state = "ask_ml", -- Current state
},
checkID = 1,
autoStart = false, -- start a session with all eligible items
autoLoot = true, -- Auto loot equippable items
autolootEverything = true,
autolootBoE = true,
autoOpen = true, -- auto open the voting frame
autoPassBoE = true,
autoPass = true,
altClickLooting = true,
acceptWhispers = true,
selfVote = true,
multiVote = true,
anonymousVoting = false,
showForML = false,
hideVotes = false, -- Hide the # votes until one have voted
allowNotes = true,
autoAward = false,
autoAwardLowerThreshold = 2,
autoAwardUpperThreshold = 3,
autoAwardTo = L["None"],
autoAwardReason = 1,
observe = false, -- observe mode on/off
silentAutoPass = false, -- Show autopass message
--neverML = false, -- Never use the addon as ML
minimizeInCombat = false,
UI = { -- stores all ui information
['**'] = { -- Defaults for Lib-Window
y = 0,
x = 0,
point = "CENTER",
scale = 0.8,
},
lootframe = { -- We want the Loot Frame to get a little lower
y = -200,
},
},
modules = { -- For storing module specific data
['*'] = {},
},
announceAward = true,
awardText = { -- Just max it at 2 channels
{ channel = "group", text = L["&p was awarded with &i for &r!"],},
{ channel = "NONE", text = "",},
},
announceItems = false,
announceText = L["Items under consideration:"],
announceChannel = "group",
responses = self.responses,
enableHistory = false,
sendHistory = true,
minRank = 3,
council = {},
maxButtons = 10,
numButtons = 4,
buttons = {
{ text = L["BiS"], whisperKey = L["whisperKey_bis"], }, -- 1
{ text = L["Big Upgrade"], whisperKey = L["whisperKey_bigupgrade"],}, -- 2
{ text = L["Small Upgrade"], whisperKey = L["whisperKey_smallupgrade"],}, -- 3
{ text = L["Off Spec"], whisperKey = L["whisperKey_offspec"],}, -- 4
},
maxAwardReasons = 10,
numAwardReasons = 3,
awardReasons = {
{ color = {1, 1, 1, 1}, disenchant = true, log = true, sort = 401, text = L["Disenchant"], },
{ color = {1, 1, 1, 1}, disenchant = false, log = true, sort = 402, text = L["Banking"], },
{ color = {1, 1, 1, 1}, disenchant = false, log = false, sort = 403, text = L["Free"],},
},
disenchant = true, -- Disenchant enabled, i.e. there's a true in awardReasons.disenchant
-- List of items to ignore:
ignore = {
43345, -- Dragon Hide Backpack
43347, -- Satchel of Spoils
43346, -- Large Satchel of Spoils
43986, -- Black Drake
43954, -- Twilight Drake
45038, -- Val'anyr fragment
45087, -- Runed Orb
},
},
} -- defaults end
-- create the other buttons/responses
for i = #self.defaults.profile.buttons+1, self.defaults.profile.maxButtons do
tinsert(self.defaults.profile.buttons, {
text = L["Button"].." "..i,
whisperKey = ""..i,
})
end
for i = self.defaults.profile.numButtons+1, self.defaults.profile.maxButtons do
tinsert(self.defaults.profile.responses, {
color = {0.7, 0.7,0.7,1},
sort = i,
text = L["Button"]..i,
})
end
-- create the other AwardReasons
for i = #self.defaults.profile.awardReasons+1, self.defaults.profile.maxAwardReasons do
tinsert(self.defaults.profile.awardReasons, {color = {1, 1, 1, 1}, disenchant = false, log = true, sort = 400+i, text = "Reason "..i,})
end
-- register chat and comms
self:RegisterChatCommand("rc", "ChatCommand")
self:RegisterChatCommand("rclc", "ChatCommand")
self:RegisterComm("RCLootCouncil")
self:RegisterComm("RCLootCouncil_WotLK")
self.db = LibStub("AceDB-3.0"):New("RCLootCouncilDB", self.defaults, true)
self.lootDB = LibStub("AceDB-3.0"):New("RCLootCouncilLootDB")
--[[ Format:
"playerName" = {
[#] = {"lootWon", "date (d/m/y)", "time (h:m:s)", "instance", "boss", "votes", "itemReplaced1", "itemReplaced2", "response", "responseID", "color", "class", "isAwardReason"}
},
]]
self.db.RegisterCallback(self, "OnProfileChanged", "RefreshConfig")
self.db.RegisterCallback(self, "OnProfileCopied", "RefreshConfig")
self.db.RegisterCallback(self, "OnProfileReset", "RefreshConfig")
-- add shortcuts
db = self.db.profile
historyDB = self.lootDB.factionrealm
debugLog = self.db.global.log
-- register the optionstable
self.options = self:OptionsTable()
self.options.args.settings.args.profiles = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("RCLootCouncil", self.options)
-- add it to blizz options
self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("RCLootCouncil", "RCLootCouncil", nil, "settings")
self.optionsFrame.ml = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("RCLootCouncil", "Master Looter", "RCLootCouncil", "mlSettings")
-- Add logged in message in the log
self:DebugLog("Logged In")
end
function RCLootCouncil:OnEnable()
-- Register the player's name
self.realmName = GetRealmName()
self.playerName = UnitName("player")
self:DebugLog(self.playerName, self.version, self.tVersion)
-- register events
self:RegisterEvent("PARTY_LOOT_METHOD_CHANGED", "OnEvent")
self:RegisterEvent("GUILD_ROSTER_UPDATE","OnEvent")
self:RegisterEvent("RAID_INSTANCE_WELCOME","OnEvent")
self:RegisterEvent("PLAYER_ENTERING_WORLD", "OnEvent")
self:RegisterEvent("PLAYER_REGEN_DISABLED", "EnterCombat")
self:RegisterEvent("PLAYER_REGEN_ENABLED", "LeaveCombat")
self:RegisterEvent("CHAT_MSG_SYSTEM", "CheckGuildUpdate")
--self:RegisterEvent("GROUP_ROSTER_UPDATE", "Debug", "event")
if IsInGuild() then
self.guildRank = select(2, GetGuildInfo("player"))
self:SendCommand("guild", "verTest", self.version, self.tVersion) -- send out a version check
end
-- Any upgrade to v2.0.0 or from Alpha.12 needs a db reset and possibly lootDB import
if (self.db.global.version and self.db.global.version < "2.0.0") or (self.db.global.tVersion and self.db.global.tVersion <= "Alpha.12") then -- Upgraded to v.2.0.0
self:Debug("First time v2.0.0 upgrade!")
local lootdb = {}
if self.db.factionrealm.lootDB then
self:Debug("Extracting old LootDB")
for k,v in pairs(self.db.factionrealm.lootDB) do
lootdb[k] = v
end
self:Debug("Done")
end
self:Debug("Resetting DB")
self.db:ResetDB("Default")
self:Debug("Done\nImporting LootDB")
for k,v in pairs(lootdb) do
self.lootDB.factionrealm[k] = v
end
self:Debug("Done")
self:Print("Your settings have been reset due to upgrading to v2.0.0")
end
if self.db.global.version and self.db.global.version ~= self.version then
self.db.global.localizedSubTypes.created = false -- re-cache incase we updated subtypes
self.db.global.version = self.version
end
self.db.global.logMaxEntries = self.defaults.global.logMaxEntries -- reset it now for zzz
if self.tVersion then
self.db.global.logMaxEntries = 1000 -- bump it for test version
end
if self.db.global.tVersion and self.debug then -- recently ran a test version, so reset debugLog
self.db.global.log = {}
end
self.db.global.tVersion = self.tVersion;
GuildRoster()
local filterFunc = function(_, event, msg, player, ...)
return strfind(msg, "[[RCLootCouncil]]:")
end
ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER_INFORM", filterFunc)
self:LocalizeSubTypes()
----------PopUp setups --------------
-------------------------------------
LibDialog:Register("RCLOOTCOUNCIL_CONFIRM_USAGE", {
text = L["confirm_usage_text"],
buttons = {
{ text = L["Yes"],
on_click = function()
local lootMethod = GetLootMethod()
if lootMethod ~= "master" then
self:Print(L["Changing LootMethod to Master Looting"])
SetLootMethod("master", self.playerName) -- activate ML
end
if db.autoAward and GetLootThreshold() ~= 2 and GetLootThreshold() > db.autoAwardLowerThreshold then
self:Print(L["Changing loot threshold to enable Auto Awarding"])
SetLootThreshold(db.autoAwardLowerThreshold >= 2 and db.autoAwardLowerThreshold or 2)
end
self:Print(L["Now handles looting"])
self.isMasterLooter = true
self.masterLooter = self.playerName
if #db.council == 0 then -- if there's no council
self:Print(L["You haven't set a council! You can edit your council by typing '/rc council'"])
end
self:CallModule("masterlooter")
self:GetActiveModule("masterlooter"):NewML(self.masterLooter)
end,
},
{ text = L["No"],
on_click = function()
RCLootCouncil:Print(L[" is not active in this raid."])
end,
},
},
hide_on_escape = true,
show_while_dead = true,
})
end
function RCLootCouncil:OnDisable()
self:Debug("OnDisable()")
--NOTE (not really needed as we probably never call .Disable() on the addon)
-- delete all windows
-- disable modules(?)
self:UnregisterAllEvents()
end
function RCLootCouncil:RefreshConfig(event, database, profile)
self:Debug("RefreshConfig",event, database, profile)
self.db.profile = database.profile
db = database.profile
end
function RCLootCouncil:ConfigTableChanged(val)
--[[ NOTE By default only ml_core needs to know about changes to the config table,
but we'll use AceEvent incase future modules also wants to know ]]
self:SendMessage("RCConfigTableChanged", val)
end
function RCLootCouncil:CheckGuildUpdate(_, msg)
local _, _, _, rank_name = strfind(msg, GUILD_PROMOTE_PATTERN) -- update on promotion
if rank_name == nil then
rank_name = select(4, strfind(msg, GUILD_DEMOTE_PATTERN))
end
if rank_name then
if not self.checkUpdateTimer then
self.checkUpdateTimer = self:ScheduleTimer("AddGuildRanksToCouncil", 2)
end
end
end
function RCLootCouncil:AddGuildRanksToCouncil(rank)
self.checkUpdateTimer = nil
rank = rank or self.db.profile.minRank
self.db.profile.council = {}
for i = 1, GetNumGuildMembers() do
local name, _, rankIndex = GetGuildRosterInfo(i) -- get info from all guild members
if rankIndex + 1 <= rank then -- if the member is the required rank, or above
tinsert(self.db.profile.council, name) -- then insert them to the council
end
end
self:CouncilChanged()
end
function RCLootCouncil:CouncilChanged()
if self.isMasterLooter then
self:GetActiveModule("masterlooter"):CouncilChanged()
end
end
--- Returns a table containing the the council members in the group
function RCLootCouncil:GetCouncilInGroup()
local council = {}
if self:IsInRaid() then
for k,v in ipairs(db.council) do
if UnitInRaid(v) then
tinsert(council, v)
end
end
elseif self:IsInGroup() then -- Party
for k,v in ipairs(db.council) do
if UnitInParty(v) then
tinsert(council, v)
end
end
elseif self.isCouncil then -- When we're alone
tinsert(council, self.playerName)
end
if #council == 0 and self.masterLooter then -- We can't have empty council
tinsert(council, self.masterLooter)
end
self:DebugLog("GetCouncilInGroup", unpack(council))
return council
end
function RCLootCouncil:ChatCommand(msg)
local input, arg1, arg2 = self:GetArgs(msg,3)
input = strlower(input or "")
if not input or input:trim() == "" or input == "help" or input == L["help"] then
if self.tVersion then print(format(L["chat tVersion string"],self.version, self.tVersion))
else print(format(L["chat version String"],self.version)) end
self:Print(L["chat_commands"])
self:Debug("- debug or d - Toggle debugging")
self:Debug("- log - display the debug log")
self:Debug("- clearLog - clear the debug log")
elseif input == 'config' or input == L["config"] or input == "c" then
-- Call it twice, because reasons..
--InterfaceOptionsFrame_OpenToCategory(self.optionsFrame)
--InterfaceOptionsFrame_OpenToCategory(self.optionsFrame)
LibStub("AceConfigDialog-3.0"):Open("RCLootCouncil")
elseif input == 'debug' or input == 'd' then
self.debug = not self.debug
self:Print("Debug = "..tostring(self.debug))
elseif input == 'open' or input == L["open"] then
if self.isCouncil or self.mldb.observe or self.nnp then -- only the right people may see the window during a raid since they otherwise could watch the entire voting
self:GetActiveModule("votingframe"):Show()
else
self:Print(L["You are not allowed to see the Voting Frame right now."])
end
elseif input == 'council' or input == L["council"] then
LibStub("AceConfigDialog-3.0"):Open("RCLootCouncil")
LibStub("AceConfigDialog-3.0"):SelectGroup("RCLootCouncil", "mlSettings", "councilTab")
elseif input == 'test' or input == L["test"] then
--self:Print(db.ui.versionCheckScale)
self:Test(tonumber(arg1) or 1)
elseif input == 'version' or input == L["version"] or input == "v" or input == "ver" then
self:CallModule("version")
elseif input == "history" or input == L["history"] or input == "h" or input == "his" then
self:CallModule("history")
--@debug@
elseif input == "nnp" then
self.nnp = not self.nnp
self:Print("nnp = "..tostring(self.nnp))
--@end-debug@
elseif input == "whisper" or input == L["whisper"] then
self:Print(L["whisper_help"])
elseif (input == "add" or input == L["add"]) then
if self.isMasterLooter then
self:GetActiveModule("masterlooter"):AddUserItem(arg1)
else
self:Print(L["You cannot use this command without being the Master Looter"])
end
elseif input == "award" or input == L["award"] then
if self.isMasterLooter then
self:GetActiveModule("masterlooter"):SessionFromBags()
else
self:Print(L["You cannot use this command without being the Master Looter"])
end
elseif input == "winners" or input == L["winners"] then
if self.isMasterLooter then
self:GetActiveModule("masterlooter"):PrintAwardedInBags()
else
self:Print(L["You cannot use this command without being the Master Looter"])
end
elseif input == "reset" or input == L["reset"] then
for k, v in pairs(db.UI) do -- We can't easily reset due to the wildcard in defaults
if k == "lootframe" then -- Loot Frame is special
v.y = -200
else
v.y = 0
end
v.point = "CENTER"
v.x = 0
v.scale = 0.8
end
for _, frame in ipairs(frames) do
frame:RestorePosition()
end
self:Print(L["Windows reset"])
elseif input == "debuglog" or input == "log" then
for k,v in ipairs(debugLog) do print(k,v); end
elseif input == "clearlog" then
wipe(debugLog)
self:Print("Debug Log cleared.")
--@debug@
elseif input == 't' then -- Tester cmd
printtable(historyDB)
--@end-debug@
elseif input == "share" then
if self.isMasterLooter then
else
self:Print(L["You cannot use this command without being the Master Looter"])
end
else
self:ChatCommand("help")
end
end
local deflate_level = {level = 9}
--- Send a RCLootCouncil Comm Message using AceComm-3.0
-- See RCLootCouncil:OnCommReceived() on how to receive these messages.
-- @param target The receiver of the message. Can be "group", "guild" or "playerName".
-- @param command The command to send.
-- @param vararg Any number of arguments to send along. Will be packaged as a table.
function RCLootCouncil:SendCommand(target, command, ...)
-- send all data as a table, and let receiver unpack it
local serialized = self:Serialize(command, {...})
local compressed = Deflate:CompressDeflate(serialized, deflate_level)
local toSend = Deflate:EncodeForPrint(compressed)
local prio = "NORMAL"
if target == "groupfast" then
target = "group"
prio = "ALERT"
end
if target == "group" then
if self:IsInRaid() then
self:SendCommMessage("RCLootCouncil", toSend, "RAID", nil, prio)
elseif self:IsInGroup() then
self:SendCommMessage("RCLootCouncil", toSend, "PARTY", nil, prio)
--[[elseif num > 0 then -- Party
self:SendCommMessage("RCLootCouncil", toSend, "PARTY")]]
else--if self.testMode then -- Alone (testing)
self:SendCommMessage("RCLootCouncil", toSend, "WHISPER", self.playerName, prio)
end
elseif target == "guild" then
self:SendCommMessage("RCLootCouncil", toSend, "GUILD")
else
if self:UnitIsUnit(target,"player") then -- If target == "player"
self:SendCommMessage("RCLootCouncil", toSend, "WHISPER", self.playerName)
elseif target then
-- We cannot send "WHISPER" to a crossrealm player
if target:find("-") then
if target:find(self.realmName) then -- Our own realm, just send it
self:SendCommMessage("RCLootCouncil", toSend, "WHISPER", target)
else -- Get creative
-- Remake command to be "xrealm" and put target and command in the table
-- See "RCLootCouncil:HandleXRealmComms()" for more info
toSend = self:Serialize("xrealm", {target, command, ...})
self:SendCommMessage("RCLootCouncil", toSend, "RAID")
end
else -- Should also be our own realm
self:SendCommMessage("RCLootCouncil", toSend, "WHISPER", target)
end
end
end
end
--- Receives RCLootCouncil commands
-- Params are delivered by AceComm-3.0, but we need to extract our data created with the
-- RCLootCouncil:SendCommand function.
-- @usage
-- To extract the original data using AceSerializer-3.0:
-- -- local success, command, data = self:Deserialize(serializedMsg)
-- 'data' is a table containing the varargs delivered to RCLootCouncil:SendCommand().
-- To ensure correct handling of x-realm commands, include this line aswell:
-- -- if RCLootCouncil:HandleXRealmComms(self, command, data, sender) then return end
function RCLootCouncil:OnCommReceived(prefix, serializedMsg, distri, sender)
if prefix == "RCLootCouncil" then
-- data is always a table to be unpacked
local decoded = Deflate:DecodeForPrint(serializedMsg)
if not decoded then
return -- probably an old version or somehow a bad message idk just throw this away
end
local decompressed = Deflate:DecompressDeflate(decoded)
local test, command, data = self:Deserialize(decompressed)
-- NOTE: Since I can't find a better way to do this, all xrealms comms is routed through here
-- to make sure they get delivered properly. Must be included in every OnCommReceived() function.
if self:HandleXRealmComms(self, command, data, sender) then return end
self:DebugLog("Comm received:", command, "from:", sender, "distri:", distri)
if test then
if command == "lootTable" then
self.isMasterLooter, self.masterLooter = self:GetML()
if self:UnitIsUnit(sender, self.masterLooter) then
local lootTable = unpack(data)
-- Send "DISABLED" response when not enabled
if not self.enabled then
for i = 1, #lootTable do
self:SendCommand("group", "response", i, self.playerName, {response = "DISABLED"})
end
return self:Debug("Sent 'DISABLED' response to", sender)
end
-- v2.0.1: It seems people somehow receives mldb with numButtons, so check for it aswell.
if not self.mldb or (self.mldb and not self.mldb.numButtons) then -- Really shouldn't happen, but I'm tired of people somehow not receiving it...
self:Debug("Received loot table without having mldb :(", sender)
self:SendCommand(self.masterLooter, "MLdb_request")
return self:ScheduleTimer("OnCommReceived", 1, prefix, serializedMsg, distri, sender)
end
self:SendCommand("group", "lootAck", self.playerName) -- send ack
if db.autoPass then -- Do autopassing
for ses, v in ipairs(lootTable) do
if (v.boe and db.autoPassBoE) or not v.boe then
if self:AutoPassCheck(v.subType, v.equipLoc, v.link) then
self:Debug("Autopassed on: ", v.link)
if not db.silentAutoPass then self:Print(format(L["Autopassed on 'item'"], v.link)) end
self:SendCommand("group", "response", self:CreateResponse(ses, v.link, v.ilvl, "AUTOPASS", v.equipLoc))
lootTable[ses].autopass = true
end
else
self:Debug("Didn't autopass on: "..v.link.." because it's BoE!")
end
end
end
-- Show the LootFrame
self:CallModule("lootframe")
self:GetActiveModule("lootframe"):Start(lootTable)
-- The votingFrame handles lootTable itself
else -- a non-ML send a lootTable?!
self:Debug(tostring(sender).." is not ML, but sent lootTable!")
end
elseif command == "council" and self:UnitIsUnit(sender, self.masterLooter) then -- only ML sends council
self.council = unpack(data)
self.isCouncil = self:IsCouncil(self.playerName)
-- prepare the voting frame for the right people
if self.isCouncil or self.mldb.observe then
self:CallModule("votingframe")
end
elseif command == "MLdb" and not self.isMasterLooter then -- ML sets his own mldb
if self:UnitIsUnit(sender, self.masterLooter) then
self.mldb = unpack(data)
else
self:Debug("Non-ML:", sender, "sent Mldb!")
end
elseif command == "verTest" and not self:UnitIsUnit(sender, "player") then -- Don't reply to our own verTests
local otherVersion, tVersion = unpack(data)
self:SendCommand(sender, "verTestReply", self.playerName, self.playerClass, self.guildRank, self.version, self.tVersion)
if self.version < otherVersion and not self.verCheckDisplayed and (not (tVersion or self.tVersion)) then
self:Print(format(L["version_outdated_msg"], self.version, otherVersion))
self.verCheckDisplayed = true
elseif tVersion and self.tVersion and not self.verCheckDisplayed and self.tVersion < tVersion then
self:Print(format(L["tVersion_outdated_msg"], tVersion))
self.verCheckDisplayed = true
end
elseif command == "verTestReply" then
local _,_,_, otherVersion, tVersion = unpack(data)
if self.version < otherVersion and not self.verCheckDisplayed and (not (tVersion or self.tVersion)) then
self:Print(format(L["version_outdated_msg"], self.version, otherVersion))
self.verCheckDisplayed = true
elseif tVersion and self.tVersion and not self.verCheckDisplayed and self.tVersion < tVersion then
self:Print(format(L["tVersion_outdated_msg"], tVersion))
self.verCheckDisplayed = true
end
elseif command == "history" and db.enableHistory then
local name, history = unpack(data)
if historyDB[name] then
tinsert(historyDB[name], history)
else
historyDB[name] = {history}
end
elseif command == "reroll" and self:UnitIsUnit(sender, self.masterLooter) and self.enabled then
self:Print(format(L["'player' has asked you to reroll"], sender))
self:CallModule("lootframe")
self:GetActiveModule("lootframe"):ReRoll(unpack(data))
elseif command == "playerInfoRequest" then
self:SendCommand(sender, "playerInfo", self:GetPlayerInfo())
elseif command == "message" then
self:Print(unpack(data))
elseif command == "session_end" and self.enabled then
if self:UnitIsUnit(sender, self.masterLooter) then
self:Print(format(L["'player' has ended the session"], self.masterLooter))
self:GetActiveModule("lootframe"):Disable()
if self.isCouncil or self.mldb.observe then -- Don't call the voting frame if it wasn't used
self:GetActiveModule("votingframe"):EndSession(true)
end
self.successful_history_requests = {}
self.mlhistory = {}
else
self:Debug("Non ML:", sender, "sent end session command!")
end
end
else
-- Most likely pre 2.0 command
local cmd = strsplit(" ", serializedMsg, 2)
if cmd and cmd == "verTest" then
self:SendCommand(sender, "verTestReply", self.playerName, self.playerClass, self.guildRank, self.version, self.tVersion)
return
end
self:Debug("Error in deserializing comm:", command, data);
end
elseif prefix == "RCLootCouncil_WotLK" then
local decoded_msg = Deflate:DecodeForPrint(serializedMsg)
local decompressed_msg = Deflate:DecompressDeflate(decoded_msg)
local ok, command, data = self:Deserialize(decompressed_msg)
if ok then
if command == "verTest" and not UnitIsUnit(sender, "player") then
local sendData = {select(2, UnitClass("player")), 1, self.version}
local serialized_data = self:Serialize("verTestReply", sendData)
local compressed_data = Deflate:CompressDeflate(serialized_data, deflate_level)
local encoded = Deflate:EncodeForPrint(compressed_data)
self:SendCommMessage("RCLootCouncil_WotLK", encoded, "WHISPER", sender)
end
end
end
end
-- Used to make sure "WHISPER" type xrealm comms is handled properly.
-- Include this right after unpacking messages. Assumes you use "OnCommReceived" as comm handler:
-- if RCLootCouncil:HandleXRealmComms(self, command, data, sender) then return end
function RCLootCouncil:HandleXRealmComms(mod, command, data, sender)
if command == "xrealm" then
local target = tremove(data, 1)
if self:UnitIsUnit(target, "player") then
local command = tremove(data, 1)
mod:OnCommReceived("RCLootCouncil", self:Serialize(command, data), "WHISPER", sender)
end
return true
end
return false
end
function RCLootCouncil:Debug(msg, ...)
if self.debug then
if select("#", ...) > 0 then
self:Print("|cffcb6700debug:|r "..tostring(msg).."|cffff6767", ...)
else
self:Print("|cffcb6700debug:|r "..tostring(msg).."|r")
end
end
RCLootCouncil:DebugLog(msg, ...)
end
local date_to_debug_log = true
function RCLootCouncil:DebugLog(msg, ...)
if date_to_debug_log then tinsert(debugLog, date("%x")); date_to_debug_log = false; end
local time = date("%X", time())
msg = time.." - ".. tostring(msg)
for i = 1, select("#", ...) do msg = msg.." ("..tostring(select(i,...))..")" end
if #debugLog > self.db.global.logMaxEntries then
tremove(debugLog, 1)
end
tinsert(debugLog, msg)
end
function RCLootCouncil:Test(num)
self:Debug("Test", num)
local testItems = {}
for i = 1, 18 do
local id = GetInventoryItemID("player", i)
tinsert(testItems, id)
end
if #testItems == 0 then
testItems = {40384,19019,46017,40343,40384,43952,40384,40399,46038,45038}
end
local items = {};
-- pick "num" random items
for i = 1, num do
local j = math.random(1, #testItems)
local name = GetItemInfo(testItems[j])
tinsert(items, testItems[j])
end
self.testMode = true;
self.isMasterLooter, self.masterLooter = self:GetML()
-- We must be in a group and not the ML
if not self.isMasterLooter then
self:Print(L["You cannot initiate a test while in a group without being the MasterLooter."])
self.testMode = false
return
end
-- Call ML module and let it handle the rest
self:CallModule("masterlooter")
self:GetActiveModule("masterlooter"):NewML(self.masterLooter)
self:GetActiveModule("masterlooter"):Test(items)
end
local interface_options_old_cancel = InterfaceOptionsFrameCancel:GetScript("OnClick")
function RCLootCouncil:EnterCombat()
-- Hack to remove CompactRaidGroup taint
-- Make clicking cancel the same as clicking okay
InterfaceOptionsFrameCancel:SetScript("OnClick", function()
InterfaceOptionsFrameOkay:Click()
end)
self.inCombat = true
if not db.minimizeInCombat then return end
for _,frame in ipairs(frames) do
if frame:IsVisible() and not frame.combatMinimized then -- only minimize for combat if it isn't already minimized
self:Debug("Minimizing for combat")
frame.combatMinimized = true -- flag it as being minimized for combat
frame:Minimize()
end
end
end
function RCLootCouncil:LeaveCombat()
-- Revert
InterfaceOptionsFrameCancel:SetScript("OnClick", interface_options_old_cancel)
self.inCombat = false
if not db.minimizeInCombat then return end
for _,frame in ipairs(frames) do
if frame.combatMinimized then -- Reshow it
self:Debug("Reshowing frame")
frame.combatMinimized = false
frame:Maximize()
end
end
end
--[[
Used by getCurrentGear to determine slot types
Inspired by EPGPLootMaster
--]]
RCLootCouncil.INVTYPE_Slots = {
INVTYPE_HEAD = "HeadSlot",
INVTYPE_NECK = "NeckSlot",
INVTYPE_SHOULDER = "ShoulderSlot",
INVTYPE_CLOAK = "BackSlot",
INVTYPE_CHEST = "ChestSlot",
INVTYPE_WRIST = "WristSlot",
INVTYPE_HAND = "HandsSlot",
INVTYPE_WAIST = "WaistSlot",
INVTYPE_LEGS = "LegsSlot",
INVTYPE_FEET = "FeetSlot",
INVTYPE_SHIELD = "SecondaryHandSlot",
INVTYPE_ROBE = "ChestSlot",
INVTYPE_2HWEAPON = {"MainHandSlot","SecondaryHandSlot"},
INVTYPE_WEAPONMAINHAND = "MainHandSlot",
INVTYPE_WEAPONOFFHAND = {"SecondaryHandSlot",["or"] = "MainHandSlot"},
INVTYPE_WEAPON = {"MainHandSlot","SecondaryHandSlot"},
INVTYPE_THROWN = {"RangedSlot"},
INVTYPE_RANGED = {"RangedSlot"},
INVTYPE_RANGEDRIGHT = {"RangedSlot"},
INVTYPE_FINGER = {"Finger0Slot","Finger1Slot"},
INVTYPE_HOLDABLE = {"SecondaryHandSlot", ["or"] = "MainHandSlot"},
INVTYPE_TRINKET = {"TRINKET0SLOT", "TRINKET1SLOT"},
INVTYPE_RELIC = {"RangedSlot"}
}
RCLootCouncil.Slots_INVTYPE = {
["HeadSlot"] = INVTYPE_HEAD,
["NeckSlot"] = INVTYPE_NECK,
["ShoulderSlot"] = INVTYPE_SHOULDER,
["BackSlot"] = INVTYPE_CLOAK,
["ChestSlot"] = INVTYPE_CHEST,
["WristSlot"] = INVTYPE_WRIST,
["HandsSlot"] = INVTYPE_HAND,
["WaistSlot"] = INVTYPE_WAIST,
["LegsSlot"] = INVTYPE_LEGS,
["FeetSlot"] = INVTYPE_FEET,
["SecondaryHandSlot"] = INVTYPE_SHIELD,
["ChestSlot"] = INVTYPE_ROBE,
["MainHandSlot"] = INVTYPE_2HWEAPON,
["SecondaryHandSlot"] = INVTYPE_2HWEAPON,
["MainHandSlot"] = INVTYPE_WEAPONMAINHAN,
["SecondaryHandSlot"] = INVTYPE_WEAPONOFFHAN,
["MainHandSlot"] = INVTYPE_WEAPONOFFHAN,
["MainHandSlot"] = INVTYPE_WEAPON,
["SecondaryHandSlot"] = INVTYPE_WEAPON,
["RangedSlot"] = INVTYPE_THROWN,
["RangedSlot"] = INVTYPE_RANGED,
["RangedSlot"] = INVTYPE_RANGEDRIGHT,
["Finger0Slot"] = INVTYPE_FINGER,
["Finger1Slot"] = INVTYPE_FINGER,
["SecondaryHandSlot"] = INVTYPE_HOLDABLE,
["MainHandSlot"] = INVTYPE_HOLDABLE,
["TRINKET0SLOT"] = INVTYPE_TRINKET,
["TRINKET1SLOT"] = INVTYPE_TRINKET,
["RangedSlot"] = INVTYPE_RELIC,
}
function RCLootCouncil:GetPlayersGear(link, equipLoc)
local itemID = self:GetItemIDFromLink(link) -- Convert to itemID
self:DebugLog("GetPlayersGear", itemID, equipLoc)
if not itemID then return nil, nil; end
local item1, item2;
-- check if the item is a token, and if it is, return the matching current gear
if RCTokenTable[itemID] then
if RCTokenTable[itemID] == "Trinket" then -- We need to return both trinkets
item1 = GetInventoryItemLink("player", GetInventorySlotInfo("TRINKET0SLOT"))
item2 = GetInventoryItemLink("player", GetInventorySlotInfo("TRINKET1SLOT"))
else -- Just return the slot from the tokentable
item1 = GetInventoryItemLink("player", GetInventorySlotInfo(RCTokenTable[itemID]))
end
return item1, item2
end
if type(equipLoc) == "table" then -- if you're looking to fix t9 and 10 tokens, look here :)
return nil, nil
end
local slot = self.INVTYPE_Slots[equipLoc]
if not slot and self.Slots_INVTYPE[equipLoc] then
slot = equipLoc
end
if not slot then return nil, nil; end;
item1 = GetInventoryItemLink("player", GetInventorySlotInfo(slot[1] or slot))
if not item1 and slot['or'] then
item1 = GetInventoryItemLink("player", GetInventorySlotInfo(slot['or']))
end;
if slot[2] then
item2 = GetInventoryItemLink("player", GetInventorySlotInfo(slot[2]))
end
return item1, item2;
end
function RCLootCouncil:Timer(type, ...)
self:Debug("Timer "..type.." passed")
if type == "LocalizeSubTypes" then
self:LocalizeSubTypes()
elseif type == "MLdb_check" then
-- If we have a ML
if self.masterLooter then
-- But haven't received the mldb, then request it
if not self.mldb then
self:SendCommand(self.masterLooter, "MLdb_request")
end
-- and if we haven't received a council, request it
if not self.council then
self:SendCommand(self.masterLooter, "council_request")
end
end
end
end
-- Classes that should auto pass a subtype
local autopassTable = {}
if not AscensionUI then -- Ascension don't auto pass anything
autopassTable = {
["Cloth"] = {"WARRIOR", "DEATHKNIGHT", "ROGUE", "HUNTER"},
["Leather"] = {"PRIEST", "MAGE", "WARLOCK"},
["Mail"] = {"DRUID", "ROGUE", "PRIEST", "MAGE", "WARLOCK"},
["Plate"] = {"DRUID", "ROGUE", "HUNTER", "SHAMAN", "PRIEST", "MAGE", "WARLOCK"},
["Shields"] = {"DEATHKNIGHT", "DRUID", "ROGUE", "HUNTER", "PRIEST", "MAGE", "WARLOCK"},
["Bows"] = {"DEATHKNIGHT", "PALADIN", "DRUID", "SHAMAN", "PRIEST", "MAGE", "WARLOCK"},
["Crossbows"] = {"DEATHKNIGHT", "PALADIN", "DRUID", "SHAMAN", "PRIEST", "MAGE", "WARLOCK"},
["Daggers"] = {"WARRIOR", "DEATHKNIGHT", "PALADIN", "DRUID", "HUNTER"},
["Guns"] = {"DEATHKNIGHT", "PALADIN", "DRUID","SHAMAN", "PRIEST", "MAGE", "WARLOCK"},