-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathBidding.lua
1736 lines (1528 loc) · 70.1 KB
/
Bidding.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
------------------------------------------------------------------------
-- BIDDING
------------------------------------------------------------------------
-- Contains methods related to bidding and the bidding gui.
------------------------------------------------------------------------
local WebDKP_BidList = { }; -- Will hold the bids placed during run time
local WebDKP_bidInProgress = false; -- Bid in progress?.
local WebDKP_RollInProgress = false; -- Roll in progress?
WebDKP_bidItem = ""; -- Item name being bid on
WebDKP_bidItemLink = ""; -- This is the item link for the chat window.
local WebDKP_bidCountdown = 0; -- How many seconds until bid ends on its own
local WebDKP_startingBid = 0; -- the default starting bid if something cannot be found in the loot table (NOT the current starting bid which is read from the gui)
WebDKP_lastBidItem = ""; -- The last item that was bidded on and actually awarded. Flagged so that auto fill will not to show a popup when it is given out
WebDKP_Rolls = {}; -- Store the rolls
WebDKP_Roll_Total = 1;
defaultBIPmsg = "WebDKP: $name is winning with a high bid of $dkp. There are $time seconds remaining for bidding on $item!"
defaultSBIPmsg = "WebDKP: There are $time seconds remaining for bidding on $item!"
defaultRIPmsg = "WebDKP: The highest roller is $name with a $roll. There are $time seconds remaining to roll on $item."
-- Data structure for sorting the table
WebDKP_BidSort = {
["curr"] = 2, -- the column to sort
["way"] = 1 -- Desc
};
-- ================================
-- Toggles displaying the bidding panel
-- ================================
function WebDKP_Bid_ToggleUI()
if (WebDKP_BidFrame:IsShown()) then
WebDKP_BidFrame:Hide();
else
WebDKP_BidFrame:Show();
if WebDKP_Options["EPGPEnabled"] == 0 then
WebDKP_BidFrameBid:Show();
WebDKP_BidFrameDKP:Show();
WebDKP_BidFramePost:Show();
WebDKP_BidFrameStartingBid:Show();
WebDKP_BidFrameTop3Button:Show();
WebDKP_BidFrameTitle:Show();
WebDKP_BidFrameScrollFrame:Show();
WebDKP_BidFrameLP:Hide();
WebDKP_BidFramePost2:Hide();
WebDKP_BidFrameGPCost:Hide();
WebDKP_BidFrameTitle2:Hide();
WebDKP_BidFrameScrollFrameEPGP:Hide();
for i = 1, 13, 1 do
local line = getglobal("WebDKP_BidFrameLineEPGP" .. i);
line:Hide();
end
else
WebDKP_BidFrameBid:Hide();
WebDKP_BidFrameDKP:Hide();
WebDKP_BidFramePost:Hide();
WebDKP_BidFrameStartingBid:Hide();
WebDKP_BidFrameTop3Button:Hide();
WebDKP_BidFrameTitle:Hide();
WebDKP_BidFrameScrollFrame:Hide();
for i = 1, 13, 1 do
local line = getglobal("WebDKP_BidFrameLine" .. i);
line:Hide();
end
WebDKP_BidFrameLP:Show();
WebDKP_BidFramePost2:Show();
WebDKP_BidFrameGPCost:Show();
WebDKP_BidFrameTitle2:Show();
WebDKP_BidFrameScrollFrameEPGP:Show();
end
local time = WebDKP_BidFrameTime:GetText();
if (time == nil or time == "") then
WebDKP_BidFrameTime:SetText("0");
end
end
end
-- ================================
-- Shows the Bid UI
-- ================================
function WebDKP_Bid_ShowUI()
WebDKP_BidFrame:Show();
local time = WebDKP_BidFrameTime:GetText();
if (time == nil or time == "") then
WebDKP_BidFrameTime:SetText("0");
end
end
-- ================================
-- Hides the Bid UI
-- ================================
function WebDKP_Bid_HideUI()
WebDKP_BidFrame:Hide();
end
-- ================================
-- Called when mouse goes over a dkp line entry.
-- If that player is not selected causes that row
-- to become 'highlighted'
-- ================================
function WebDKP_Bid_HandleMouseOver(self)
local this = self;
local playerBid = 0;
local playerName = getglobal(this:GetName() .. "Name"):GetText();
if WebDKP_Options["EPGPEnabled"] == 0 then
playerBid = getglobal(this:GetName() .. "Bid"):GetText() + 0;
else
playerBid = getglobal(this:GetName() .. "DKP"):GetText() + 0;
end
if playerBid == nil then
playerBid = 0;
end
local selected = WebDKP_Bid_IsSelected(playerName, playerBid);
if (not selected) then
getglobal(this:GetName() .. "Background"):SetVertexColor(0.2, 0.2, 0.7, 0.5);
end
end
-- ================================
-- Called when a mouse leaves a dkp line entry.
-- If that player is not selected, causes that row
-- to return to normal (none highlighted)
-- ================================
function WebDKP_Bid_HandleMouseLeave(self)
local this = self;
local playerBid = 0;
local playerName = getglobal(this:GetName() .. "Name"):GetText();
if WebDKP_Options["EPGPEnabled"] == 0 then
playerBid = getglobal(this:GetName() .. "Bid"):GetText() + 0;
else
playerBid = getglobal(this:GetName() .. "DKP"):GetText() + 0;
end
if playerBid == nil then
playerBid = 0;
end
local selected = WebDKP_Bid_IsSelected(playerName, playerBid);
if (not selected) then
getglobal(this:GetName() .. "Background"):SetVertexColor(0, 0, 0, 0);
end
end
-- ================================
-- Called when the user clicks on a player entry. Causes
-- that entry to either become selected or normal
-- and updates the dkp table with the change
-- ================================
function WebDKP_Bid_SelectPlayerToggle(self)
local this = self;
local playerName = getglobal(this:GetName() .. "Name"):GetText();
local playerBid2 = 0;
if WebDKP_Options["EPGPEnabled"] == 0 then
playerBid2 = getglobal(this:GetName() .. "Bid"):GetText() + 0;
else
playerBid2 = getglobal(this:GetName() .. "DKP"):GetText() + 0;
end
if playerBid2 == nil then
playerBid2 = 0;
end
if WebDKP_Options["EPGPEnabled"] == 0 then
-- we need to search through the table and figure out which one was selected
-- an entry is considered a unique name / bid pair
-- once we find an entry we can toggle its selection state
for key, v in pairs(WebDKP_BidList) do
if (type(v) == "table") then
if (v["Name"] ~= nil and v["Bid"] ~= nil) then
if (v["Name"] == playerName and WebDKP_ROUND(v["Bid"], 2) == playerBid2) then
if (v["Selected"] == true) then
v["Selected"] = false;
getglobal(this:GetName() .. "Background"):SetVertexColor(0.2, 0.2, 0.7, 0.5);
else
-- deselect all the others on the table
WebDKP_Bid_DeselectAll();
v["Selected"] = true;
getglobal(this:GetName() .. "Background"):SetVertexColor(0.1, 0.1, 0.9, 0.8);
end
end
end
end
end
else
for key, v in pairs(WebDKP_BidList) do
if (type(v) == "table") then
if (v["Name"] ~= nil and v["DKP"] ~= nil) then
if (v["Name"] == playerName and WebDKP_ROUND(v["DKP"], 2) == playerBid2) then
if (v["Selected"] == true) then
v["Selected"] = false;
getglobal(this:GetName() .. "Background"):SetVertexColor(0.2, 0.2, 0.7, 0.5);
else
-- deselect all the others on the table
WebDKP_Bid_DeselectAll();
v["Selected"] = true;
getglobal(this:GetName() .. "Background"):SetVertexColor(0.1, 0.1, 0.9, 0.8);
end
end
end
end
end
end
if WebDKP_Options["EPGPEnabled"] == 0 then
WebDKP_Bid_UpdateTable();
else
WebDKP_Bid_UpdateTableEPGP();
end
end
-- ================================
-- Returns true if the given player name / bid value is selected
-- in the bid list table. false otherwise.
-- ================================
function WebDKP_Bid_IsSelected(playerName, playerBid)
playerBid = playerBid + 0;
playerbidcompare = 0;
if WebDKP_Options["EPGPEnabled"] == 0 then
for key, v in pairs(WebDKP_BidList) do
if (type(v) == "table") then
if (v["Name"] ~= nil and v["Bid"] ~= nil) then
playerbidcompare = v["Bid"];
playerbidcompare = tonumber(playerbidcompare);
playerbidcompare = WebDKP_ROUND(playerbidcompare, 2);
if (v["Name"] == playerName and playerbidcompare == playerBid) then
return v["Selected"];
end
end
end
end
else
for key, v in pairs(WebDKP_BidList) do
if (type(v) == "table") then
if (v["Name"] ~= nil and v["DKP"] ~= nil) then
playerbidcompare = v["Bid"];
playerbidcompare = tonumber(playerbidcompare);
playerbidcompare = WebDKP_ROUND(playerbidcompare, 2);
if (v["Name"] == playerName and playerbidcompare == playerBid) then
return v["Selected"];
end
end
end
end
end
return false;
end
-- ================================
-- Deselects all entries in the table
-- ================================
function WebDKP_Bid_DeselectAll()
if WebDKP_Options["EPGPEnabled"] == 0 then
for key, v in pairs(WebDKP_BidList) do
if (type(v) == "table") then
if (v["Name"] ~= nil and v["Bid"] ~= nil) then
v["Selected"] = false;
end
end
end
else
for key, v in pairs(WebDKP_BidList) do
if (type(v) == "table") then
if (v["Name"] ~= nil and v["DKP"] ~= nil) then
v["Selected"] = false;
end
end
end
end
end
-- ================================
-- Called when a player clicks on a column header on the table
-- Changes the sorting options / asc&desc.
-- Causes the table display to be refreshed afterwards
-- to player instantly sees changes
-- ================================
function WebDKP_Bid_SortBy(id)
if (WebDKP_BidSort["curr"] == id) then
WebDKP_BidSort["way"] = abs(WebDKP_BidSort["way"] - 1);
else
WebDKP_BidSort["curr"] = id;
if (id == 1) then
WebDKP_BidSort["way"] = 0;
elseif (id == 2) then
WebDKP_BidSort["way"] = 1; --columns with numbers need to be sorted different first in order to get DESC right
elseif (id == 3) then
WebDKP_BidSort["way"] = 1; --columns with numbers need to be sorted different first in order to get DESC right
else
WebDKP_BidSort["way"] = 1; --columns with numbers need to be sorted different first in order to get DESC right
end
end
-- update table so we can see sorting changes
if WebDKP_Options["EPGPEnabled"] == 0 then
WebDKP_Bid_UpdateTable();
else
WebDKP_Bid_UpdateTableEPGP();
end
end
-- ================================
-- Rerenders the sorted table to the screen. This is called
-- on a few instances - when the scroll frame throws an
-- event or when bids are placed or when a bid ends.
-- General structure:
-- First runs through the table to display and puts the data
-- into a temp array to work with
-- Then uses sorting options to sort the temp array
-- Calculates the offset of the table to determine
-- what information needs to be displayed and in what lines
-- of the table it should be displayed
-- ================================
function WebDKP_Bid_UpdateTable()
-- Copy data to the temporary array
local entries = { };
for key_name, v in pairs(WebDKP_BidList) do
if (type(v) == "table") then
if (v["Name"] ~= nil and v["Bid"] ~= nil and v["DKP"] ~= nil and v["Post"] ~= nil) then
tinsert(entries, { v["Name"], v["Bid"], v["DKP"], v["Post"], v["Date"], v["Roll"], v["Spec"], v["GuildRank"] }); -- copies over name, bid, dkp, dkp-bid,date,roll,spec, and guild rank
end
end
end
-- SORT
table.sort(
entries,
function(a1, a2)
if (a1 and a2) then
if (a1 == nil) then
return 1 > 0;
elseif (a2 == nil) then
return 1 < 0;
end
if (WebDKP_BidSort["way"] == 1) then
if (a1[WebDKP_BidSort["curr"]] == a2[WebDKP_BidSort["curr"]]) then
return a1[1] > a2[1];
else
return a1[WebDKP_BidSort["curr"]] > a2[WebDKP_BidSort["curr"]];
end
else
if (a1[WebDKP_BidSort["curr"]] == a2[WebDKP_BidSort["curr"]]) then
return a1[1] < a2[1];
else
return a1[WebDKP_BidSort["curr"]] < a2[WebDKP_BidSort["curr"]];
end
end
end
end
);
local numEntries = getn(entries);
local offset = FauxScrollFrame_GetOffset(WebDKP_BidFrameScrollFrame);
FauxScrollFrame_Update(WebDKP_BidFrameScrollFrame, numEntries, 13, 13);
-- Run through the table lines and put the appropriate information into each line
for i = 1, 13, 1 do
local line = getglobal("WebDKP_BidFrameLine" .. i);
local nameText = getglobal("WebDKP_BidFrameLine" .. i .. "Name");
local bidText = getglobal("WebDKP_BidFrameLine" .. i .. "Bid");
local dkpText = getglobal("WebDKP_BidFrameLine" .. i .. "DKP");
local postBidText = getglobal("WebDKP_BidFrameLine" .. i .. "Post");
local rollText = getglobal("WebDKP_BidFrameLine" .. i .. "Roll");
local SpecText = getglobal("WebDKP_BidFrameLine" .. i .. "Spec");
local GuildRankText = getglobal("WebDKP_BidFrameLine" .. i .. "GuildRank");
local index = i + FauxScrollFrame_GetOffset(WebDKP_BidFrameScrollFrame);
if (index <= numEntries) then
local playerName = entries[index][1];
local date = entries[index][5];
local charname = entries[index][1];
line:Show();
nameText:SetText(charname);
if WebDKP_DkpTable[charname] == nil then
WebDKP_DkpTable[charname] = {};
end
if WebDKP_DkpTable[charname]["class"] ~= nil then
local charclass = WebDKP_DkpTable[charname]["class"];
charclass = string.upper(charclass);
charclass = string.gsub(charclass, " ", "");
if RAID_CLASS_COLORS[charclass] ~= nil then
nameText:SetTextColor(RAID_CLASS_COLORS[charclass]["r"], RAID_CLASS_COLORS[charclass]["g"], RAID_CLASS_COLORS[charclass]["b"]);
end
end
bidText:SetText(WebDKP_ROUND(entries[index][2], 2));
dkpText:SetText(WebDKP_ROUND(entries[index][3], 2));
postBidText:SetText(WebDKP_ROUND(entries[index][3], 2));
rollText:SetText(entries[index][6]);
SpecText:SetText(entries[index][7]);
GuildRankText:SetText(entries[index][8]);
-- kill the background of this line if it is not selected
if (WebDKP_BidList[playerName .. date] and (not WebDKP_BidList[playerName .. date]["Selected"])) then
getglobal("WebDKP_BidFrameLine" .. i .. "Background"):SetVertexColor(0, 0, 0, 0);
else
getglobal("WebDKP_BidFrameLine" .. i .. "Background"):SetVertexColor(0.1, 0.1, 0.9, 0.8);
end
else
-- if the line isn't in use, hide it so we dont' have mouse overs
line:Hide();
end
end
end
-- ================================
-- Handles chat messages directed towards bidding. This includes
-- placing a bid and remotly starting / stopping a bid.
-- ================================
function WebDKP_Bid_Event(arg1, arg2)
local name = arg2;
local flag = 0;
local trigger = arg1;
local dkp = 0;
if (WebDKP_IsBidChat(name, trigger)) then
local cmd, subcmd = WebDKP_GetCmd(trigger);
cmd, subcmd = WebDKP_GetCommaCmd(subcmd);
startbiddingcmd = cmd;
cmd = tonumber(cmd);
-- SOMEONE HAS PLACED A BID
if (string.find(string.lower(trigger), "!bid ") == 1) then
if cmd == nil then
WebDKP_SendWhisper(name, "You did not bid properly, use !bid #");
else
if (WebDKP_bidInProgress == false) then
WebDKP_SendWhisper(name, "There is no bid in progress");
elseif (cmd == "" or cmd == nil) then
WebDKP_SendWhisper(name, "You did not specify a bid amount - bid not accepted");
elseif ((cmd) < WebDKP_GetStartingBid()) then
WebDKP_SendWhisper(name, "Bid not accepted. The minimum bid is " .. WebDKP_GetStartingBid());
elseif (WebDKP_Options["BidFixedBidding"] == 1) then
WebDKP_SendWhisper(name, "Bid not accepted. You must type !need");
elseif (WebDKP_Options["DisableBid"] == 1) then
WebDKP_SendWhisper(name, "Bid not accepted. Please use !main value or !off value");
else
flag = WebDKP_Bid_HandleBid(name, cmd, "NA");
if flag == 1 then
WebDKP_SendWhisper(name, "Bid for " .. cmd .. " dkp accepted");
end
end
end
-- SOMEONE WANTS TO BID ALL THEIR DKP
elseif (string.find(string.lower(trigger), "!bidall") == 1) then
local dkp = WebDKP_GetDKP(name);
if (WebDKP_bidInProgress == false) then
WebDKP_SendWhisper(name, "There is no bid in progress");
elseif (dkp < WebDKP_GetStartingBid()) then
WebDKP_SendWhisper(name, "Bid not accepted, you don't have enough DKP. The minimum bid is " .. WebDKP_GetStartingBid());
elseif (WebDKP_Options["BidFixedBidding"] == 1) then
WebDKP_SendWhisper(name, "Bid not accepted. You must type !need");
else
flag = WebDKP_Bid_HandleBid(name, dkp, "NA");
if flag == 1 then
WebDKP_SendWhisper(name, "Bid for " .. dkp .. " dkp accepted");
end
end
-- SOMEONE WANTS TO BID FOR MAIN SPEC
elseif (string.find(string.lower(trigger), "!main") == 1) then
if (WebDKP_bidInProgress == false) then
WebDKP_SendWhisper(name, "There is no bid in progress");
elseif (cmd == "" or cmd == nil) then
cmd = 0;
flag = WebDKP_Bid_HandleBid(name, cmd, "Main");
if flag == 1 then
if WebDKP_Options["BidFixedBidding"] == 1 then
WebDKP_SendWhisper(name, "Your mainspec need has been accepted.");
else
WebDKP_SendWhisper(name, "Mainspec Bid for " .. cmd .. " dkp accepted");
end
end
elseif (cmd < WebDKP_GetStartingBid()) then
WebDKP_SendWhisper(name, "Bid not accepted, you don't have enough DKP. The minimum bid is " .. WebDKP_GetStartingBid());
elseif (WebDKP_Options["BidFixedBidding"] == 1) then
WebDKP_SendWhisper(name, "Bid not accepted. You must type !need");
else
flag = WebDKP_Bid_HandleBid(name, cmd, "Main");
if flag == 1 then
WebDKP_SendWhisper(name, "Mainspec Bid for " .. cmd .. " dkp accepted");
end
end
-- SOMEONE WANTS TO BID FOR OFF SPEC
elseif (string.find(string.lower(trigger), "!off") == 1) then
if (WebDKP_bidInProgress == false) then
WebDKP_SendWhisper(name, "There is no bid in progress");
elseif (cmd == "" or cmd == nil) then
cmd = 0;
WebDKP_Bid_HandleBid(name, cmd, "Off");
if WebDKP_Options["BidFixedBidding"] == 1 then
WebDKP_SendWhisper(name, "Your offspec need has been accepted.");
else
WebDKP_SendWhisper(name, "Offspec Bid for " .. cmd .. " dkp accepted");
end
elseif (cmd < WebDKP_GetStartingBid()) then
WebDKP_SendWhisper(name, "Bid not accepted, you don't have enough DKP. The minimum bid is " .. WebDKP_GetStartingBid());
elseif (WebDKP_Options["BidFixedBidding"] == 1) then
WebDKP_SendWhisper(name, "Bid not accepted. You must type !greed");
else
flag = WebDKP_Bid_HandleBid(name, cmd, "Off");
if flag == 1 then
WebDKP_SendWhisper(name, "Offspec bid for " .. cmd .. " dkp accepted");
end
end
-- THEY WANT THE BIDDING TO START
elseif (string.find(string.lower(trigger), "!startbid") == 1) then
if (WebDKP_bidInProgress == true) then
WebDKP_SendWhisper(name, "There is already a bid in progress - you can't start another bid until the first one is finished");
elseif (startbiddingcmd == "" or startbiddingcmd == nil) then
WebDKP_SendWhisper(name, "You must specify an item to bid on. Example: !startbid [Giantstalker's Helm]");
else
WebDKP_Bid_StartBid(startbiddingcmd, subcmd);
WebDKP_BidFrameBidButton:SetText("Stop Bidding");
end
-- THEY WANT THE BIDDING TO STOP
elseif (string.find(string.lower(trigger), "!stopbid") == 1) then
if (WebDKP_bidInProgress == false) then
WebDKP_SendWhisper(name, "There is no bid in progress for you to cancel");
else
WebDKP_Bid_StopBid();
WebDKP_BidFrameBidButton:SetText("Start the Bidding!");
end
-- SOMEONE NEEDS AN ITEM (FOR FIXED BIDDING ONLY - BIDS ALL THEY HAVE)
elseif (string.find(string.lower(trigger), "!need") == 1 and WebDKP_Options["BidFixedBidding"] == 1) then
dkp = 0;
if WebDKP_Options["EPGPEnabled"] == 0 then
dkp = WebDKP_GetDKP(name); -- bid all their dkp. in a fixed bid they will only be charged the cost from the loot table - this is just for ordering
if dkp == nil then
dkp = 0;
end
else
if WebDKP_DkpTable[name] == nil then
WebDKP_DkpTable[name] = {};
end
if WebDKP_DkpTable[name]["ep_" .. tableid] == nil then
WebDKP_DkpTable[name]["ep_" .. tableid] = 0;
end
local playerEP = WebDKP_DkpTable[name]["ep_" .. tableid];
if playerEP == nil or playerEP == 0 then
playerEP = 0;
WebDKP_DkpTable[name]["ep_" .. tableid] = 0;
end
local playerGP = WebDKP_DkpTable[name]["gp_" .. tableid];
if playerGP == nil then
playerGP = 1;
WebDKP_DkpTable[name]["gp_" .. tableid] = 1;
end
dkp = playerEP / playerGP;
end
-- Check to see if custom percent is enabled for !need and if it is take the % of the DKP.
if WebDKP_Options["AllNeed"] == 1 and WebDKP_Options["TurnBase"] == 1 then
dkp = WebDKP_ROUND(dkp * ((tonumber(WebDKP_Options["NeedDKP"])) / 100), 0);
end
flag = WebDKP_Bid_HandleBid(name, dkp, "Main");
if flag == 1 then
WebDKP_SendWhisper(name, "Mainspec Bid for " .. dkp .. " dkp accepted");
end
-- SOMEONE GREEDS AN ITEM (FOR FIXED BIDDING ONLY - BIDS ALL THEY HAVE)
elseif (string.find(string.lower(trigger), "!greed") == 1 and WebDKP_Options["BidFixedBidding"] == 1) then
if WebDKP_Options["EPGPEnabled"] == 0 then
dkp = WebDKP_GetDKP(name); -- bid all their dkp. in a fixed bid they will only be charged the cost from the loot table - this is just for ordering
if dkp == nil then
dkp = 0;
end
else
local playerEP = WebDKP_DkpTable[name]["ep_" .. tableid];
if playerEP == nil or playerEP == 0 then
playerEP = 0;
WebDKP_DkpTable[name]["ep_" .. tableid] = 0;
end
local playerGP = WebDKP_DkpTable[name]["gp_" .. tableid];
if playerGP == nil then
playerGP = 1;
WebDKP_DkpTable[name]["gp_" .. tableid] = 1;
end
kp = playerEP / playerGP;
end
-- Check to see if 50% bidding is enabled for !greed and if it is take 50% of the DKP.
if WebDKP_Options["FiftyGreed"] == 1 and WebDKP_Options["TurnBase"] == 1 then
dkp = WebDKP_ROUND(dkp * ((tonumber(WebDKP_Options["GreedDKP"])) / 100), 0);
end
flag = WebDKP_Bid_HandleBid(name, dkp, "Off");
if flag == 1 then
WebDKP_SendWhisper(name, "Offspec bid for " .. dkp .. " dkp accepted");
end
end
end
end
-- ================================
-- Gets the current starting bid from the gui
-- ================================
function WebDKP_GetStartingBid()
local start = WebDKP_BidFrameStartingBid:GetText();
if (start == nil or start == "") then
start = 0;
end
return start + 0; -- add + 0 to convert it to an int
end
-- ================================
-- Returns true if the passed whisper is a chat message directed
-- towards web dkp bidding
-- ================================
function WebDKP_IsBidChat(name, trigger)
if (string.find(string.lower(trigger), "!bid") == 1 or
string.find(string.lower(trigger), "!bidall") == 1 or
string.find(string.lower(trigger), "!main") == 1 or
string.find(string.lower(trigger), "!off") == 1 or
string.find(string.lower(trigger), "!startbid") == 1 or
string.find(string.lower(trigger), "!stopbid") == 1 or
string.find(string.lower(trigger), "!need") == 1 or
string.find(string.lower(trigger), "!greed") == 1
) then
return true
end
return false
end
-- ================================
-- Triggers Bidding to Start
-- ================================
function WebDKP_Bid_StartBid(item, time)
if item ~= "" and item ~= nil then
WebDKP_BidFrameBidButton:SetText("Stop Bidding");
WebDKP_BidList = {};
if (time == "" or time == nil or time == "0" or time == " ") then
time = 0;
end
local quality, itemName, itemLink, itemLevel = WebDKP_GetItemInfo(item);
WebDKP_bidItem = itemName;
WebDKP_bidItemLink = itemLink;
WebDKP_BidFrameItem:SetText(itemName);
WebDKP_BidFrameTime:SetText(time);
WebDKP_Bid_ItemNameChanged();
-- if the options ask for it, also make an announcement in a raid warning
if (WebDKP_Options["BidAnnounceRaid"] == 1) then
WebDKP_SendAnnouncement("Bidding Has Started!", "RAID_WARNING");
end
WebDKP_AnnounceBidStart(itemLink, time, WebDKP_GetStartingBid());
WebDKP_bidInProgress = true;
WebDKP_BidFrameItem:SetText(itemLink);
if WebDKP_Options["EPGPEnabled"] == 0 then
WebDKP_Bid_UpdateTable();
else
WebDKP_Bid_UpdateTableEPGP();
end
WebDKP_Bid_ShowUI();
if (time ~= 0) then
WebDKP_bidCountdown = time;
WebDKP_Bid_UpdateFrame:Show();
else
WebDKP_Bid_UpdateFrame:Hide();
end
else
WebDKP_Print("You must enter an item to bid on.");
end
end
-- ================================
-- Stops the current bidding
-- ================================
function WebDKP_Bid_StopBid()
local totalbids = 0;
WebDKP_Bid_UpdateFrame:Hide(); -- stop any countdowns
WebDKP_BidFrame_Countdown:SetText("");
WebDKP_BidFrameBidButton:SetText("Start the Bidding!"); -- fix the button text
local bidder, bid = WebDKP_Bid_GetHighestBid(); -- find highest bidder (not used any more)
for key_name, v in pairs(WebDKP_BidList) do
if (type(v) == "table") then
totalbids = totalbids + 1;
end
end
WebDKP_AnnounceBidEnd(WebDKP_bidItem, bidder, bid, totalbids); -- make the announcement
WebDKP_bidInProgress = false;
WebDKP_Bid_ShowUI(); -- show the bid gui
end
-- ================================
-- Handles a bid placed by a player.
-- ================================
function WebDKP_Bid_HandleBid(playerName, bidAmount, spec)
local flag = 0;
local postDkp = 0;
if WebDKP_DkpTable[playerName] == nil then
WebDKP_DkpTable[playerName] = {};
end
local playerGP = WebDKP_DkpTable[playerName]["gp_" .. tableid];
-- if a bid is not in progress ignore it
if (WebDKP_bidInProgress) then
--load up some information about the player
local dkp = WebDKP_GetDKP(playerName); -- how much dkp do they have now
if WebDKP_Options["EPGPEnabled"] == 1 then
startingBid = WebDKP_BidFrameGPCost:GetText();
if startingBid == nil or startingBid == "" then
startingBid = 1;
end
dkp = bidAmount;
postDkp = dkp / (playerGP + startingBid);
postDkp = WebDKP_ROUND(postDkp, 2);
else
startingBid = WebDKP_GetStartingBid();
postDkp = dkp - bidAmount; -- what they will have if they spend this
end
if startingBid == nil or startingBid == "" then
startingBid = 0;
end
local postDkp2 = dkp - startingBid; -- Do they have enough based on the starting bid?
bidAmount = bidAmount + 0; -- make sure bid amount is an int
local date = date("%Y-%m-%d %H:%M:%S"); -- record when this bid was placed
local guildrank = WebDKP_GetGuildRank(playerName); -- Gets the guild rank
-- check to see if we should reject this bid if it makes the user go into negative balance
if (postDkp < 0 and WebDKP_Options["BidAllowNegativeBids"] == 0) then
WebDKP_SendWhisper(playerName, "Bid Rejected - you cannot bid more than you have.");
WebDKP_SendWhisper(playerName, "Your maximum bid is " .. dkp);
-- check to see if we should reject their !need because the startingBid/cost is too high
elseif (postDkp2 < 0 and WebDKP_Options["BidAllowNegativeBids"] == 0) then
WebDKP_SendWhisper(playerName, "Bid Rejected - The minimum DKP to win this item is " .. startingBid);
else
--Set the success flag to return
flag = 1;
-- If there is no existing Roll data then set it to NA.
--if WebDKP_BidList[playerName..date] == nil then
-- WebDKP_BidList[playerName..date] = {};
-- WebDKP_BidList[playerName..date]["Roll"] = 0;
--end
-- bid is ok, we can go ahead and record it
WebDKP_BidList[playerName .. date] = { -- place their bid in the bid table (combine it with the date so 1 player can have multiple bids / unique indices in the table)
["Name"] = playerName,
["Bid"] = bidAmount,
["DKP"] = dkp,
["Post"] = postDkp,
["Date"] = date,
["Roll"] = "NA",
["Spec"] = spec,
["GuildRank"] = guildrank;
}
if (WebDKP_BidList[playerName .. date]["Selected"] == nil) then
WebDKP_BidList[playerName .. date]["Selected"] = false;
end
if WebDKP_Options["EPGPEnabled"] == 0 then
WebDKP_Bid_UpdateTable();
else
WebDKP_Bid_UpdateTableEPGP();
end
WebDKP_SendWhisper(playerName, "Bid Received");
-- if they bid too low we should tell them
local highBidder, highBid = WebDKP_Bid_GetHighestBid();
if (highBidder == playerName and WebDKP_Options["BidNotifyLowBids"] == 1) then
WebDKP_SendWhisper(playerName, "You are the current high bidder");
elseif (highBidder ~= playerName and WebDKP_Options["BidNotifyLowBids"] == 1) then
WebDKP_SendWhisper(playerName, "You are NOT the high bidder. The current high bid is " .. highBid .. " dkp.");
end
end
return flag;
else
WebDKP_SendWhisper(playerName, "No bid is in progress");
end
end
-- ================================
-- Returns the highest bidder and what they bid.
-- ================================
function WebDKP_Bid_GetHighestBid()
local highestBidder = nil;
local highestBid = nil;
for key_name, v in pairs(WebDKP_BidList) do
if (type(v) == "table") then
if (v["Bid"] ~= nil) then
if highestBid == nil then
highestBidder = v["Name"];
highestBid = v["Bid"];
elseif (v["Bid"] > highestBid) then
highestBidder = v["Name"];
highestBid = v["Bid"];
end
end
end
end
return highestBidder, highestBid;
end
-- ================================
-- Returns the top 3 bidders and what they bid.
-- ================================
function WebDKP_Bid_GetTopThree()
local highestBidder = nil;
local highestBidder2 = nil;
local highestBidder3 = nil;
local highestBid = 0;
local highestBid2 = 0;
local highestBid3 = 0;
for key_name, v in pairs(WebDKP_BidList) do
if (type(v) == "table") then
if (v["Bid"] ~= nil) then
if (v["Bid"] > highestBid) then
highestBidder = v["Name"];
highestBid = v["Bid"];
elseif (v["Bid"] > highestBid2 and v["Bid"] ~= highestBid) then
highestBidder2 = v["Name"];
highestBid2 = v["Bid"];
elseif (v["Bid"] > highestBid3 and v["Bid"] ~= highestBid and v["Bid"] ~= highestBid2) then
highestBidder3 = v["Name"];
highestBid3 = v["Bid"];
end
end
end
end
return highestBidder, highestBidder2, highestBidder3, highestBid, highestBid2, highestBid3;
end
-- ===============================================================================
-- Returns the highest roller and what they rolled.
-- ===============================================================================
function WebDKP_Bid_GetHighestRoll()
local highestRoller = "No one";
local highestRoll = 0;
for key_name, v in pairs(WebDKP_BidList) do
if (type(v) == "table") then
if (v["Roll"] ~= nil and v["Roll"] ~= "NA") then
if (v["Roll"] > highestRoll) then
highestRoller = v["Name"];
highestRoll = v["Roll"];
end
end
end
end
return highestRoller, highestRoll;
end
-- ================================
-- Method invoked when the user clicks the award button the on
-- bid frame. Finds the first person who is selected
-- and awards them the item.
-- ================================
function WebDKP_Bid_AwardSelected()
-- find out who is selected
local player, bid, spec = WebDKP_Bid_GetSelected();
local _, item, link = WebDKP_GetItemInfo(WebDKP_bidItem);
local startingBid = WebDKP_BidFrameStartingBid:GetText();
if startingBid ~= nil then
startingBid = tonumber(startingBid);
end
-- Check to see if the persons bid is less than the startingBid or minimum. If it is then Negative Bids must be enabled so change their bid to the startingBid value for the confirmation box.
if startingBid ~= nil and bid < startingBid then
bid = startingBid;
end
-- if someone is selected, award them the item via the award class
if (player == nil) then
WebDKP_Print("Nobody selected - no one awarded");
PlaySound(847);
else
--since we are awarding, stop the bid
if (WebDKP_bidInProgress) then
WebDKP_Bid_StopBid();
end
if WebDKP_Options["EPGPEnabled"] == 1 then
-- The starting bid is the total Gear Points to be awarded
local gpcost = WebDKP_BidFrameGPCost:GetText();
bid = gpcost;
else
if (WebDKP_Options["BidFixedBidding"] == 1 and WebDKP_Options["TurnBase"] == 0) then
if spec == "Main" then
bid = WebDKP_GetLootTableCost(WebDKP_bidItem);
elseif spec == "Off" and WebDKP_Options["FiftyGreed"] == 1 then
multval = (tonumber(WebDKP_Options["GreedDKP"]) / 100);
tablevalue = WebDKP_GetLootTableCost(WebDKP_bidItem);
if tablevalue == nil then
tablevalue = WebDKP_GetDKP(player);
end
bid = WebDKP_ROUND(tablevalue * multval, 0);
else
bid = WebDKP_GetLootTableCost(WebDKP_bidItem);
end
end
if WebDKP_Options["ItemLevelEquation"] == 1 or WebDKP_Options["SlotLocMult"] == 1 then
bid = WebDKP_BidFrameStartingBid:GetText();
bid = tonumber(bid);
end
end
-- check the options to see if we need to display a confirmation box
if (WebDKP_Options["BidConfirmPopup"] == 1 or bid == nil) then
if (WebDKP_Options["BidFixedBidding"] == 1 and bid == nil) then
WebDKP_Bid_ShowConfirmFrame("Award " .. player .. " " .. link .. "? |cFFFF0000(Item not in loot table)|r", 0);
elseif (WebDKP_Options["BidFixedBidding"] == 1 and WebDKP_Options["EPGPEnabled"] == 0) then
WebDKP_Bid_ShowConfirmFrame("Award " .. player .. " " .. link .. " for " .. bid .. " dkp? (From LootTable or Item Level Mult)", bid);
elseif (WebDKP_Options["EPGPEnabled"] == 1) then
WebDKP_Bid_ShowConfirmFrame("Award " .. player .. " " .. link .. " for " .. bid .. " GP?", bid);
else
WebDKP_Bid_ShowConfirmFrame("Award " .. player .. " " .. link .. " for " .. bid .. " dkp? (Percents work. Ex:50%)", bid);
end
else
WebDKP_Bid_AwardPerson(bid);
end
end
end
-- ================================
-- Auto Assign the Loot Item.
-- Auto Give the Item.
-- Added by Zevious (Bronzebeard)
-- ================================
function Auto_Assign_Item_Player(player)
local _, item, link = WebDKP_GetItemInfo(WebDKP_bidItem);
for ci = 1, GetNumGroupMembers() do
candidate = GetMasterLootCandidate(ci);
-- name, rank, subgroup, level, class, fileName, zone, online, isDead, role, isML = GetRaidRosterInfo(ci);
if (candidate == player) then
for li = 1, GetNumLootItems() do
local lootIcon, lootName, lootQuantity, rarity, locked = GetLootSlotInfo(li);
if (lootName == item) then
GiveMasterLoot(li, ci);
ci = GetNumGroupMembers() + 1;
end
end
end
end
end
-- ================================
-- Event handler for the start / stop bid button.
-- This button toggles between states when clicked.
-- ================================
function WebDKP_Bid_ButtonHandler()
-- clear the rolling in case rolling and bidding are monitored at the same time
WebDKP_RollInProgress = false;
for i = 1, WebDKP_Roll_Total, 1 do
WebDKP_Rolls[i] = nil;
end