forked from kahluamods/konfersk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKSK-Loot.lua
4544 lines (3985 loc) · 129 KB
/
KSK-Loot.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
--[[
KahLua KonferSK - a suicide kings loot distribution addon.
WWW: http://kahluamod.com/ksk
Git: https://github.com/kahluamods/konfersk
IRC: #KahLua on irc.freenode.net
E-mail: [email protected]
Please refer to the file LICENSE.txt for the Apache License, Version 2.0.
Copyright 2008-2020 James Kean Johnston. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]
local K = LibStub:GetLibrary("KKore")
local LibDeformat = LibStub:GetLibrary("LibDeformat-3.0")
if (not K or not LibDeformat) then
return
end
local dfmt = LibDeformat.Deformat
local ksk = K:GetAddon("KKonferSK")
local L = ksk.L
local KUI = ksk.KUI
local KRP = ksk.KRP
local KLD = ksk.KLD
local KK = ksk.KK
local MakeFrame = KUI.MakeFrame
-- Local aliases for global or Lua library functions
local _G = _G
local tinsert = table.insert
local tremove = table.remove
local tconcat = table.concat
local tsort = table.sort
local tostring, tonumber = tostring, tonumber
local strfmt = string.format
local strsub = string.sub
local strlen = string.len
local strfind = string.find
local strlower = string.lower
local strmatch = string.match
local gsub = string.gsub
local pairs, ipairs = pairs, ipairs
local assert = assert
local printf = K.printf
local unpack = unpack
local GetTime = GetTime
local tsize = K.tsize
local icolor = K.icolor
local info = ksk.info
local err = ksk.err
local white = ksk.white
local class = ksk.class
local shortclass = ksk.shortclass
local aclass = ksk.aclass
local shortaclass = ksk.shortaclass
local debug = ksk.debug
local HIST_WHEN = ksk.HIST_WHEN
local HIST_WHAT = ksk.HIST_WHAT
local HIST_WHO = ksk.HIST_WHO
local HIST_HOW = ksk.HIST_HOW
local HIST_EXP_XML = 1
local HIST_EXP_JSON = 2
--
-- This file contains all of the UI handling code for the loot panel,
-- as well as all loot manipulation functions. This is a fairly complicated UI
-- with lots of moving parts so it's a good idea to understand what is going
-- on here.
--
-- We have 3 panels - loot distribution (qf.assign), the item editor
-- (qf.itemedit) and the loot history page (qf.history). Only the first two
-- are vaguely interesting. The history page is just a list with a few simple
-- buttons.
--
-- The loot page is divided into 5 main regions:
-- top left - the list of roll lists (qf.lists)
-- bottom left - the list of members of the selected list (qf.members)
-- top right - the loot selection list (qf.lootwin is the frame,
-- qf.lootwin.slist and ksk.qf.lootscroll is the actual scroll list). It also
-- contains all of the buttons for controlling loot distribution. These are
-- only displayed for the master looter. These buttons are all children of
-- qf.lootwin. .oclbids is for open / close bids. It toggles between the two.
-- .orpause either starts an open roll or pauses one in progress. And last
-- .remcancel is either the button to remove a bid item or to cancel a bid
-- or open roll.
-- middle right is the loot rules frame, the open roll timer frame and the
-- auto loot assignment confirmation frame. This is also known as the ALF
-- frame and one of those three pages is selected with select_alf().
-- qf.lootrules, qf.lootroll and qf.autoloot are the shortcuts for these
-- 3 frames, only one of which can ever be visible at a time.
-- bottom right - the bidders / rollers frame. This is where the list of
-- bidders or rollers is displayed, along with buttons for both normal users
-- and the master looter to control those bidders / bids. qf.bidders is the
-- encosing frame. This has two portions - the actual scroll list of bidders
-- on the left (qf.bidscroll) and several buttons on the right. These are
-- not encosed in their own frame but are direct children of qf.bidders.
-- .mybid is the button used by users to bid on an item. When they press it
-- it will change into the retract button to retract a bid. If we are rolling
-- on an item it becomes the "main spec" roll button. .forcebid is only
-- enabled for the master looter and it forces the selected member to bid as
-- if they has pressed bid themselves. If we are rolling then this becomes
-- the "offspec roll" button, if that feature is enabled in the config UI.
-- .forceret is the "force retract" button for the ML. If we are rolling it
-- becomes the "cancel roll" button. .undo (qf.undobutton) is for the ML
-- only and does an undo of the last suicide on the list.
--
-- The ALF frame is the middle right frame and it is used for 3 different
-- things using select_alf():
-- ALF_LOOT - the loot rules frame. This is the frame shown while bids are
-- open or before open rolls are started. This contains all of the class
-- specific check boxes (for class filtering), the role filter, the guild
-- rank filter, and the strict armor / class checkboxes. The containing
-- frame is qf.lootrules and has the following children:
-- .warrior, .paladin, .druid etc for all 12 classes
-- .role - the drop down for the user role
-- .rank - the dropdown for the guild rank
-- .nextrank - the button for moving to the next lower rank
-- .strictarmor - checkbox for strict armor filtering
-- .strictrole - checkbox for string role filtering
-- ALF_CONFIRM - the auto-loot confirmation frame. This is displayed when an
-- item is about to be assigned to a user, for whatever reason. It is always
-- displayed before the mod assigns loot (except under very special cases
-- too complex to describe here). This frame has both UI elements and loot
-- related variables (non UI widgets) associated with it. Its base is
-- qf.autoloot and the widget children are:
-- .item (and qf.autoassign_item) - a text label designed to hold the name of
-- the item being assigned. This is almost always an item link.
-- .str (and qf.autoassign_msg) - a text string that contains any assignment
-- message instructions.
-- .ok - a button that will perform the assignment
-- .cancel - a button that closes the ALF window but doesn't assign the item.
-- Data items set on qf.autoloot and used by the Ok and cancel button
-- handlers are:
-- .slot - the slot number on the corpse of the item to be assigned
-- .bosslootidx - the boss loot index number of the item being awarded.
-- .uid - the KSK internal user ID of the user to receive the item
-- .name - full player name
-- .party - the raid party the winner is in
-- .announce - a boolean true if we are to announce the asignment
-- .suicide - the list on which the user will be suicided (if any)
-- .ilink - the item being awarded
-- .autodel - true if the item should be removed from the items database.
-- This is set when there is a once-off assignment of an item setup in the
-- items database, for a specific user, and this is that assignment. Since
-- the assignment has now been done it can be removed from the database.
-- .denched - true if the item is being assigned to a dencher for mats.
-- .rolled - true if the item was won by a roll not a bid.
-- .leaveloot - only used by the cancel button and indicates that the loot
-- should be left in the loot list. The default is to remove it.
--
--
local lootlistid = nil
local members = nil
local memberid = nil
local realmemberid = nil
local biditem = nil
local selitemid = nil
local iinfo = {}
-- The index into ksk.bossloot of the currently selected loot item.
local selectedloot = nil
-- Data table of the currently selected loot item.
-- idx - same as selectedloot above.
-- itemid - the item ID
-- filter - the class filter
-- role - the role filter
-- list - the desired roll list
-- rank - the rank filter
-- loot - ksk.bossloot[selectedloot]
-- slot - the loot slot index for Blizzard API functions
-- itemid - the item ID
-- ilink - the item link text
-- quant - the number of this item on the corpse
-- boe - true if the item is BoE
-- strict - the strict class filter
-- relaxed - the relaxed class filter
local lootitem = nil
local lootroll = nil
-- Table of people who have bid on the current item.
local bidders = nil
-- Index into bidders of the currently selected bidder and that user's uid.
local selectedbidder = nil
local selectedbiduid = nil
local qf = {}
local exphistdlg = nil
local undodlg = nil
--
-- This can have 4 possible values:
-- nil - No rolling taking place
-- 1 - roll actively underway.
-- 2 - active roll paused.
-- 3 - roll paused and window closed.
local rolling = nil
--
-- The top right division of the loot assignment page serves 3 main purposes:
-- loot selection, assignment confirmation and open rolls. Only one of these
-- can be active at a time as they all overlay each other. This function
-- ensures that only one of these three frames is active.
--
local ALF_LOOT = 1
local ALF_CONFIRM = 2
local ALF_ROLL = 3
local function select_alf(which)
if (which == ALF_CONFIRM) then
qf.lootrules:Hide()
qf.lootroll:Hide()
qf.autoloot:Show()
elseif (which == ALF_ROLL) then
qf.lootrules:Hide()
qf.autoloot:Hide()
qf.lootroll:Show()
else
qf.autoloot:Hide()
qf.lootroll:Hide()
qf.lootrules:Show()
end
end
local function hide_popup()
if (ksk.popupwindow) then
ksk.popupwindow:Hide()
ksk.popupwindow = nil
end
end
--
-- We have a few places where we have very similar widgets, such as the
-- class filtering stuff. All of the containing widgets have sub-widgets of
-- the same name and all of them have the same requirement of needing to
-- either be enabled/disabled or have their value set according to a filter
-- string. These three functions are helpers for those cases and do the busy
-- work in this one place rather than repeating it in several places.
--
local function classes_setenabled(tbl, onoff)
local onoff = onoff or false
for k, v in pairs(K.IndexClass) do
if (v.w and tbl[v.w]) then
tbl[v.w]:SetEnabled(onoff)
end
end
end
local function classes_setchecked(tbl, onoff)
local onoff = onoff or false
for k, v in pairs(K.IndexClass) do
if (v.w and tbl[v.w]) then
tbl[v.w]:SetChecked(onoff)
end
end
end
local function classes_cfilter(tbl, cfilter)
for k, v in pairs(K.IndexClass) do
if (v.w and tbl[v.w]) then
tbl[v.w]:SetChecked(cfilter[k])
end
end
end
--
-- Check to see if any of the current raiders are not on the currently
-- selected list.
--
local function check_missing_members()
if (not ksk.cfg.settings.ann_missing or not ksk.users or not lootlistid) then
return
end
if (not ksk.csd.warns.lists[lootlistid]) then
ksk.csd.warns.lists[lootlistid] = {}
end
local mwarn = ksk.csd.warns.lists[lootlistid]
local missing = {}
for k,v in pairs(KRP.players) do
local uid = v["ksk_uid"]
if (not uid) then
if (not mwarn[v.name]) then
mwarn[v.name] = true
tinsert(missing, shortaclass(v))
end
else
if (not mwarn[v.name]) then
if (not ksk.UserInList(uid, lootlistid)) then
mwarn[v.name] = true
tinsert(missing, shortaclass(ksk.cfg.users[uid]))
end
end
end
end
if (#missing == 0) then
return
end
local lootlist = ksk.cfg.lists[lootlistid]
info(L["users not on the %q list: %s"], lootlist.name, tconcat(missing, ", "))
end
local function changed(res, user)
if (not user) then
return
end
local res = res or false
if (not selitemid) then
res = true
end
qf.itemupdbtn:SetEnabled(not res)
end
local function lootrules_setenabled(val)
if (not qf.lootrules) then
return
end
local val = val or false
local onoff = ksk.AmIML() and val
classes_setenabled(qf.lootrules, onoff)
qf.lootrules.role:SetEnabled(onoff)
qf.lootrules.rank:SetEnabled(onoff)
qf.lootrules.nextrank:SetEnabled(onoff)
qf.lootrules.strictarmour:SetEnabled(onoff)
qf.lootrules.strictrole:SetEnabled(onoff)
if (ksk.cfg.cfgtype == KK.CFGTYPE_PUG) then
qf.lootrules.rank:SetEnabled(false)
qf.lootrules.nextrank:SetEnabled(false)
end
end
local function lootbid_setenabled(val)
if (not qf.lootwin or not qf.bidders) then
return
end
local val = val or false
local onoff = ksk.AmIML() and val
qf.lootwin.oclbids:SetEnabled(onoff)
qf.lootwin.orpause:SetEnabled(onoff)
qf.lootwin.remcancel:SetEnabled(onoff)
qf.bidders.mybid:SetEnabled(onoff)
end
local function verify_user_class(user, class, what)
local w = K.IndexClass[class].w
if (not qf.lootrules[w]:GetChecked()) then
local clist = {}
for k,v in pairs(K.IndexClass) do
if (v.w) then
if (qf.lootrules[v.w]:GetChecked()) then
tinsert(clist, v.c)
end
end
end
ksk:SendWhisper(strfmt(L["%s: you do not meet the current class restrictions (%s) - %s ignored."], L["MODTITLE"], tconcat(clist, ", "), what), user)
return false
end
return true
end
--
-- Setup the auto-assign loot confirmation frame. The sole parameter is the
-- name of the person who either won the item or is going to have the item
-- assigned to them (for DE or guild bank).
--
local function set_autoloot_win(name)
if (not lootitem or not selectedloot or not name or name == "") then
return
end
local uid = KRP.players[name]["ksk_uid"]
qf.autoassign_item:SetText(lootitem.loot.ilink)
qf.autoloot.slot = lootitem.loot.slot or nil
qf.autoloot.bosslootidx = selectedloot
qf.autoloot.ilink = lootitem.loot.ilink
qf.autoloot.uid = uid
qf.autoloot.name = name
qf.autoloot.party = KRP.players[name].subgroup
qf.autoloot.announce = false
qf.autoloot.leaveloot = false
qf.autoloot.denched = false
qf.autoloot.rolled = 0
qf.autoloot.autodel = false
qf.autoloot.suicide = nil
lootbid_setenabled(false)
select_alf(ALF_CONFIRM)
end
function ksk.PauseResumeRoll(pause, timeout)
if (not lootroll) then
return
end
if (pause) then
if (rolling == 1) then
rolling = 2
end
else
if (rolling == 2) then
rolling = 1
lootroll.endtime = GetTime() + timeout
end
end
end
--
-- Start an open roll or pause one that is currently in progress. Called when
-- the Open Roll / Pause button is pressed.
--
local function open_roll_or_pause()
local tr = qf.lootwin
if (rolling) then
if (rolling == 1) then
local rem = floor(lootroll.endtime - GetTime()) + 1
tr.orpause:SetText(L["Resume"])
rolling = 2
if (rem < 6) then
rem = ksk.cfg.settings.roll_extend + 1
end
lootroll.resume = rem
ksk:SendAM("PROLL", "ALERT", true, 0)
else
lootroll.endtime = GetTime() + lootroll.resume
lootroll.lastwarn = nil
ksk:SendAM("PROLL", "ALERT", false, lootroll.resume)
lootroll.resume = nil
tr.orpause:SetText(L["Pause"])
rolling = 1
end
else
local sroll = ksk.cfg.settings.suicide_rolls
if (IsShiftKeyDown()) then
sroll = not sroll
end
if (sroll) then
local lootlist = ksk.cfg.lists[lootlistid]
ksk:SendWarning(strfmt(L["Suicide Roll (on list %q) for %s within %d seconds."], lootlist.name, lootitem.loot.ilink, ksk.cfg.settings.roll_timeout))
else
ksk:SendWarning(strfmt(L["Roll for %s within %d seconds."], lootitem.loot.ilink, ksk.cfg.settings.roll_timeout))
end
if (ksk.cfg.settings.ann_roll_usage) then
if (ksk.cfg.settings.offspec_rolls) then
ksk:SendText(strfmt(L["%s: type '/roll' for main spec, '/roll 101-200' for off-spec or '/roll 1-1' to cancel a roll."], L["MODABBREV"]))
else
ksk:SendText(strfmt(L["%s: type '/roll' for main spec or '/roll 1-1' to cancel a roll."], L["MODABBREV"]))
end
end
qf.lootroll.StartRoll(sroll)
end
end
local function boe_to_ml_or_de(isroll)
ksk.ResetBidders(true)
if (not lootitem or not KLD.items) then
return false
end
local loot = lootitem.loot
local slot = loot.slot
local klid = KLD.items[slot]
local ilink = loot.ilink
if (loot.boe and ksk.cfg.settings.boe_to_ml) then
ksk.AddLootHistory(nil, K.time(), ilink, ksk.csd.myuid, "B")
KLD.GiveMasterLoot(slot, KRP.master_looter)
ksk.RemoveItemByIdx(selectedloot, false)
select_alf(ALF_LOOT)
return true
else
if (not isroll and ksk.cfg.settings.try_roll) then
open_roll_or_pause()
return true
end
if (isroll) then
ksk.EndOpenRoll(true)
end
if (ksk.cfg.settings.disenchant) then
local rdenchers = #ksk.denchers
if (rdenchers > 0) then
--
-- Must see if the denchers are eligible for loot. They may not
-- have been present for the boss kill.
--
for de = 1, rdenchers do
local tname = ksk.denchers[de]
local uid = KRP.players[tname]["ksk_uid"]
local vtarget = false
local rs = ""
if (slot == 0 or not klid.candidates[tname]) then
rs = "\n\n" .. white(L["Note: player will need to pick item up manually."])
if (UnitInRange(tname) == 1) then
vtarget = true
end
else
if (klid.candidates[tname]) then
vtarget = true
end
end
if (vtarget) then
local cname = shortaclass(ksk.cfg.users[uid])
if (isroll) then
qf.autoassign_msg:SetText(strfmt(L["AUTODENCHNR"], cname, cname) .. rs)
else
qf.autoassign_msg:SetText(strfmt(L["AUTODENCH"], cname, cname) .. rs)
end
set_autoloot_win(tname)
qf.autoloot.denched = true
qf.autoloot.leaveloot = not isroll
return true
end
end
end
end
end
return false
end
--
-- This is called when a user presses the 'Ok' button in the autoloot panel
-- in the bidding window. This window is displayed when an item has been
-- won by a bid, a roll, or is being auto-assigned to a disenchanter if no
-- bids or rolls were received.
--
local function auto_loot_ok()
local li = qf.autoloot
local lh = li.listid
local uname = li.name
if (li.slot) then
KLD.GiveMasterLoot(li.slot, li.name)
end
if (li.announce) then
local pos = ""
if (li.suicide) then
local il, lp = ksk.UserInList(li.uid, li.suicide)
if (il) then
pos = strfmt("[%d]", lp)
end
end
if (ksk.cfg.settings.ann_winners_raid) then
ksk:SendText(strfmt(L["%s: %s%s (group %d) won %s. Grats!"],
L["MODABBREV"], uname, pos, li.party, li.ilink))
end
if (ksk.cfg.settings.ann_winners_guild) then
ksk:SendGuildText(strfmt(L["%s: %s%s won %s. Grats!"],
L["MODABBREV"], uname, pos, li.ilink))
end
end
if (li.suicide) then
lh = li.suicide
local sulist = ksk.CreateRaidList(li.suicide)
ksk.SuicideUser(li.suicide, sulist, li.uid, ksk.currentid, li.ilink, true)
li.suicide = nil
end
if (li.autodel) then
li.autodel = nil
ksk.DeleteItem(lootitem.loot.itemid)
end
if (li.uid) then
if (li.denched) then
lh = "D"
elseif (li.rolled and li.rolled == 1) then
lh = "M"
elseif (li.rolled and li.rolled == 101) then
lh = "O"
elseif (not lh) then
lh = "A"
end
ksk.AddLootHistory(nil, K.time(), li.ilink, li.uid, lh)
end
ksk.RemoveItemByIdx(li.bosslootidx, false)
ksk.ResetBidders(true)
select_alf(ALF_LOOT)
end
--
-- Called when a user presses 'Cancel' in the autoloot panel.
--
local function auto_loot_cancel()
local li = qf.autoloot
if (not li.announce and not li.leaveloot) then
if (li.uid) then
local lh = li.listid
if (li.denched) then
lh = "D"
elseif (li.rolled and li.rolled == 1) then
lh = "M"
elseif (li.rolled and li.rolled == 101) then
lh = "O"
elseif (not lh) then
lh = "A"
end
ksk.AddLootHistory(nil, K.time(), li.ilink, li.uid, lh)
end
ksk.RemoveItemByIdx(li.bosslootidx, false)
ksk.ResetBidders(true)
end
select_alf (ALF_LOOT)
end
--
-- OnUpdate script handler for the open roll timer bar. This needs to examine
-- the remaining time, move the bar and set its color accordingly (it changes
-- from green to red gradualy as the timeout gets closer and closer) and
-- deals with the timer expiring. There are actually two versions of this.
-- One is for the master looter and the other for everyone else. The former
-- does all kinds of checking and processing based on the timeout and the
-- latter simply updates the spark.
--
local function rolltimer_onupdate_user()
local rlf = qf.lootroll
if (not lootroll) then
rlf.timerbar:SetScript("OnUpdate", nil)
return
end
if (rolling >= 2) then
return
end
local now = GetTime()
local remt = lootroll.endtime - now
local pct = remt / lootroll.timeout
rlf.timerbar:SetStatusBarColor(1-pct, pct, 0)
rlf.timerbar:SetValue(pct)
rlf.timertext:SetText(strfmt(L["Roll closing in %s"], ("%.1f)"):format(remt)))
rlf.timerspark:ClearAllPoints()
rlf.timerspark:SetPoint("CENTER", rlf.timerbar, "LEFT", pct * 200, 0)
end
local function rolltimer_onupdate_ml()
local rlf = qf.lootroll
if (not lootroll) then
rlf.timerbar:SetScript("OnUpdate", nil)
return
end
if (rolling >= 2) then
return
end
local now = GetTime()
if (now > lootroll.endtime) then
rlf.timerbar:SetScript("OnUpdate", nil)
rolling = nil
local topmain = {}
local topalts = {}
local nummain = 0
local numalts = 0
-- Stop the end user's timer spark and reset their UI.
if (ksk.AmIML()) then
ksk:SendAM("EROLL", "ALERT")
end
lootroll.sorted = lootroll.sorted or {}
for i = 1, #lootroll.sorted do
local nm = lootroll.sorted[i]
local ru = lootroll.rollers[nm]
if (ru.minr == 1 and nummain < 5) then
tinsert(topmain, shortaclass(nm, ru.class) .. " [" .. ru.roll .. "]")
nummain = nummain + 1
elseif (ru.minr == 101 and numalts < 5) then
tinsert(topalts, shortaclass(nm, ru.class) .. " [" .. ru.roll .. "]")
numalts = numalts + 1
end
end
if (nummain > 0 ) then
info(L["top main spec rollers: %s"], tconcat(topmain, ", "))
end
if (numalts > 0 ) then
info(L["top off-spec rollers: %s"], tconcat(topalts, ", "))
end
topmain = nil
topalts = nil
local winner = lootroll.sorted[1]
if (winner) then
local ilink = lootitem.loot.ilink
local nwinners = 1
local winners = {}
local winnames = {}
winners[winner] = lootroll.rollers[winner].class
tinsert(winnames, winner)
local winroll = lootroll.rollers[winner].roll
for i = 2, #lootroll.sorted do
local nm = lootroll.sorted[i]
local ru = lootroll.rollers[nm]
if (ru.roll == winroll) then
winners[nm] = ru.class
tinsert(winnames, nm)
nwinners = nwinners + 1
end
end
if (nwinners > 1) then
-- Deal with ties here.
if (ksk.cfg.settings.ann_roll_ties) then
ksk:SendText(strfmt(L["%s: the following users tied with %d: %s. Roll again."], L["MODABBREV"], winroll, tconcat(winnames, ", ")))
end
winnames = nil
lootroll.rollers = {}
lootroll.sorted = nil
lootroll.restrict = winners
for i = 1,5 do
rlf["pos"..i]:SetText("")
rlf["rem"..i]:SetEnabled(false)
end
lootroll.endtime = GetTime() + ksk.cfg.settings.roll_timeout + 1
lootroll.lastwarn = nil
rolling = 1
rlf.timerbar:SetScript("OnUpdate", rolltimer_onupdate_ml)
ksk:SendAM("RROLL", "ALERT", ilink, timeout, winners)
return
end
local winclass = lootroll.rollers[winner].class
local winbase = lootroll.rollers[winner].minr
local party = KRP.players[winner].subgroup
local uid = KRP.players[winner]["ksk_uid"] or winner
local missing = KRP.players[winner]["ksk_missing"]
local suicide = nil
local gpos = ""
if (lootroll.suicide and not missing) then
local il, lp = ksk.UserInList(uid, suicide)
if (il) then
gpos = strfmt("[%d]", lp)
end
suicide = lootlistid
local sulist = ksk.CreateRaidList(lootlistid)
ksk.SuicideUser(suicide, sulist, uid, ksk.currentid, ilink, true)
ksk.AddLootHistory(nil, K.time(), ilink, uid, suicide)
end
local ts = strfmt(L["%s: %s%s (group %d) won %s. Grats!"],
L["MODABBREV"], winner, gpos, party, ilink)
if (ksk.cfg.settings.ann_winners_raid) then
ksk:SendText(ts)
end
printf(icolor, "%s", ts)
if (ksk.cfg.settings.ann_winners_guild) then
ksk:SendGuildText(strfmt(L["%s: %s%s won %s. Grats!"], L["MODABBREV"], winner, gpos, ilink))
end
if (lootitem.loot.slot ~= 0 and ksk.cfg.settings.auto_loot) then
local cname = shortaclass(winner, winclass)
qf.autoassign_msg:SetText(strfmt(L["AUTOLOOT"], cname, cname, cname))
set_autoloot_win(winner)
qf.autoloot.rolled = winbase
return
else
local lh = "M"
if (winbase == 101) then
lh = "O"
end
if (not suicide) then
ksk.AddLootHistory(nil, K.time(), ilink, uid, lh)
end
ksk.RemoveItemByIdx(selectedloot, false)
ksk.ResetBidders(false)
end
else -- No winner because no-one rolled
info(strfmt(L["no-one rolled for %s."], lootitem.loot.ilink))
if (boe_to_ml_or_de(true)) then
return
end
--
-- No-one rolled and they didn't assign it to a dencher. We don't
-- really know what they are going to do with it, so we can not
-- record a loot history event. Yes it would be possible to trap
-- the loot assignment message in case they manually assign the item,
-- but that is highly unreliable as it wont be displayed if the
-- recipient is out of range. No-one ever said this was a perfect
-- system.
--
ksk.EndOpenRoll()
ksk.RemoveItemByIdx(selectedloot, false)
end
select_alf(ALF_LOOT)
return
end
local remt = lootroll.endtime - now
local warnt = floor(remt)
local pct = remt / (ksk.cfg.settings.roll_timeout + 1)
rlf.timerbar:SetStatusBarColor(1-pct, pct, 0)
rlf.timerbar:SetValue(pct)
rlf.timertext:SetText(strfmt(L["Roll closing in %s"], ("%.1f)"):format(remt)))
rlf.timerspark:ClearAllPoints()
rlf.timerspark:SetPoint("CENTER", rlf.timerbar, "LEFT", pct * 200, 0)
if (warnt < 5) then
if (not lootroll.lastwarn or warnt ~= lootroll.lastwarn) then
lootroll.lastwarn = warnt
if (ksk.cfg.settings.ann_countdown) then
ksk:SendText(strfmt(L["%s: roll closing in: %d"], L["MODABBREV"], warnt+1))
end
end
end
end
--
-- This is called when a valid player has typed /roll.
--
local function player_rolled(player, roll, minr, maxr)
if (not rolling) then
return
end
local rp
if (lootroll.rollers[player]) then
--
-- If they had rolled before but were using a different min and max,
-- recheck things, as they may be correcting a main spec versus offspec
-- roll. Seems like /roll 101-200 is really hard for people to do right
-- the first time!
--
rp = lootroll.rollers[player]
if ((rp.minr == minr) and (rp.maxr == maxr)) then
ksk:SendWhisper(strfmt(L["%s: you already rolled %d. New roll ignored."], L["MODTITLE"], lootroll.rollers[player].roll), player)
return
end
--
-- We dont actually accept the new roll value. Rather, we either add
-- or subtract 100 from the original roll, so that the user doesn't
-- end up with two chances to roll and improve their score.
--
if (rp.minr == 1 and minr == 101) then
rp.roll = rp.roll + 100
elseif (rp.minr == 101 and minr == 1) then
rp.roll = rp.roll - 100
elseif (rp.maxr == 1) then
if (rp.roll >= 101) then
rp.roll = rp.roll - 100
end
elseif (minr == 1 and maxr == 1) then
-- Do nothing
else
return
end
rp.minr = minr
rp.maxr = maxr
else
if (minr == 1 and maxr == 1) then
return
end
local class
if (lootroll.restrict) then
if (not lootroll.restrict[player]) then
ksk:SendWhisper(strfmt(L["%s: sorry you are not allowed to roll right now."], L["MODTITLE"]), player)
return
end
class = lootroll.restrict[player]
if (minr == 101) then
minr = 1
maxr = 100
roll = roll - 100
end
else
--
-- Check to see if they are eligible for loot. We may have a case here
-- where no-one is marked as a master loot candidate because the
-- raid leader had loot set incorrectly, and subsequently changed it
-- to master looting. In this case we don't want to block the user
-- from rolling.
--
local loot = lootitem.loot
local slot = loot.slot
if (slot > 0) then
-- Slot 0 is for manually added items
local klid = KLD.items[slot]
if (klid.candidates and not klid.candidates[player]) then
ksk:SendWhisper(strfmt(L["%s: you are not eligible to receive loot - %s ignored."], L["MODTITLE"], L["roll"]), player)
return
end
end
class = KRP.players[player].class
assert(class)
--
-- Verify that they meet the class requirements
--
if (not verify_user_class(player, class, L["roll"])) then
return
end
end
lootroll.rollers[player] = {}
rp = lootroll.rollers[player]
rp.roll = roll
rp.minr = minr
rp.maxr = maxr
rp.class = class
end
--
-- Create the sorted list of rollers
--
lootroll.sorted = {}
for k,v in pairs(lootroll.rollers) do
if (v.maxr ~= 1) then
tinsert(lootroll.sorted, k)
end
end
tsort(lootroll.sorted, function(a,b)
if (lootroll.rollers[a].minr > lootroll.rollers[b].minr) then
return false
elseif (lootroll.rollers[a].minr < lootroll.rollers[b].minr) then
return true
elseif (lootroll.rollers[a].roll > lootroll.rollers[b].roll) then
return true
end
return false
end)
--
-- Display the top 5 in the dialog
--
local rlf = qf.lootroll
for i = 1,5 do
rlf["pos"..i]:SetText("")
rlf["rem"..i]:SetEnabled(false)
end
local toprolls = {}
for i = 1,5 do
local nm = lootroll.sorted[i]
if (nm) then
local ru = lootroll.rollers[nm]
local ts = shortaclass(nm, ru.class) .. "[" .. tostring(ru.roll) .. "]"
rlf["pos"..i]:SetText(ts)
rlf["rem"..i]:SetEnabled(true)
tinsert(toprolls, ts)
end
end
ksk:SendAM("TROLL", "ALERT", toprolls)
--