-
Notifications
You must be signed in to change notification settings - Fork 28
/
Utility.lua
1318 lines (1237 loc) · 44.6 KB
/
Utility.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
function CEPGP_initialise()
_, _, _, CEPGP_ElvUI = GetAddOnInfo("ElvUI");
_G["CEPGP_version_number"]:SetText("Running Version: " .. CEPGP_VERSION);
local ver2 = string.gsub(CEPGP_VERSION, "%.", ",");
if not CEPGP_notice then
CEPGP_notice = false;
end
if CHANNEL == nil then
CHANNEL = "GUILD";
end
if MOD == nil then
MOD = 1;
end
if COEF == nil then
COEF = 4.83;
end
if MOD_COEF == nil then
MOD_COEF = 1;
end
if BASEGP == nil then
BASEGP = 1;
end
if CEPGP_keyword == nil then
CEPGP_keyword = "!need";
end
if CEPGP_ntgetn(AUTOEP) == 0 then
for k, v in pairs(bossNameIndex) do
AUTOEP[k] = true;
end
end
if CEPGP_ntgetn(EPVALS) == 0 then
for k, v in pairs(bossNameIndex) do
EPVALS[k] = v;
end
end
if CEPGP_ntgetn(SLOTWEIGHTS) == 0 then
SLOTWEIGHTS = {
["2HWEAPON"] = 2,
["WEAPONMAINHAND"] = 1.5,
["WEAPON"] = 1.5,
["WEAPONOFFHAND"] = 0.5,
["HOLDABLE"] = 0.5,
["SHIELD"] = 0.5,
["RANGED"] = 0.5,
["RANGEDRIGHT"] = 0.5,
["THROWN"] = 0.5,
["RELIC"] = 0.5,
["HEAD"] = 1,
["NECK"] = 0.5,
["SHOULDER"] = 0.75,
["CLOAK"] = 0.5,
["CHEST"] = 1,
["ROBE"] = 1,
["WRIST"] = 0.5,
["HAND"] = 0.75,
["WAIST"] = 0.75,
["LEGS"] = 1,
["FEET"] = 0.75,
["FINGER"] = 0.5,
["TRINKET"] = 0.75,
["EXCEPTION"] = 1
}
end
if STANDBYPERCENT == nil then
STANDBYPERCENT = 0;
end
if CEPGP_ntgetn(STANDBYRANKS) == 0 then
for i = 1, 10 do
STANDBYRANKS[i] = {};
STANDBYRANKS[i][1] = GuildControlGetRankName(i);
STANDBYRANKS[i][2] = false;
end
end
if UnitInRaid("player") then
for i = 1, GetNumGroupMembers() do
name = GetRaidRosterInfo(i);
CEPGP_raidRoster[i] = name;
end
end
if CEPGP_force_sync_rank == nil then
CEPGP_force_sync_rank = 1;
end
tinsert(UISpecialFrames, "CEPGP_frame");
tinsert(UISpecialFrames, "CEPGP_context_popup");
tinsert(UISpecialFrames, "CEPGP_save_guild_logs");
tinsert(UISpecialFrames, "CEPGP_restore_guild_logs");
tinsert(UISpecialFrames, "CEPGP_settings_import");
tinsert(UISpecialFrames, "CEPGP_override");
tinsert(UISpecialFrames, "CEPGP_traffic");
C_ChatInfo.RegisterAddonMessagePrefix("CEPGP"); --Registers CEPGP for use in the addon comms environment
CEPGP_SendAddonMsg("version-check", "GUILD");
DEFAULT_CHAT_FRAME:AddMessage("|c00FFC100Classic EPGP Version: " .. CEPGP_VERSION .. " Loaded|r");
DEFAULT_CHAT_FRAME:AddMessage("|c00FFC100CEPGP: Currently reporting to channel - " .. CHANNEL .. "|r");
if not CEPGP_notice then
CEPGP_notice_frame:Show();
end
if IsInRaid("player") and CEPGP_isML() == 0 then
_G["CEPGP_confirmation"]:Show();
end
end
function CEPGP_calcGP(link, quantity, id)
local name, rarity, ilvl, itemType, subType, slot;
if id then
name, link, rarity, ilvl, itemType, subType, _, _, slot = GetItemInfo(id);
elseif link then
name, _, rarity, ilvl, itemType, subType, _, _, slot = GetItemInfo(link);
else
return 0;
end
if not name then return 0; end
if not ilvl then ilvl = 0; end
for k, v in pairs(OVERRIDE_INDEX) do
if string.lower(name) == string.lower(k) then
return OVERRIDE_INDEX[k];
end
end
local found = false;
--[[if not found then
if ((slot ~= "" and level == 60 and rarity > 3) or (slot == "" and rarity > 3))
and (itemType ~= "Blacksmithing" and itemType ~= "Tailoring" and itemType ~= "Alchemy" and itemType ~= "Leatherworking"
and itemType ~= "Enchanting" and itemType ~= "Engineering" and itemType ~= "Mining") then
local quality = rarity == 0 and "Poor" or rarity == 1 and "Common" or rarity == 2 and "Uncommon" or rarity == 3 and "Rare" or rarity == 4 and "Epic" or "Legendary";
CEPGP_print("Warning: " .. name .. " not found in index! Please report this to the addon developer");
if slot ~= "" then
slot = strsub(slot,strfind(slot,"INVTYPE_")+8,string.len(slot));
end
end
return 0;
end]]
if slot == "" or slot == nil then
--Tier 3 slots
if strfind(name, "desecrated") and rarity == 4 then
if (name == "desecratedshoulderpads" or name == "desecratedspaulders" or name == "desecratedpauldrons") then slot = "INVTYPE_SHOULDER";
elseif (name == "desecratedsandals" or name == "desecratedboots" or name == "desecratedsabatons") then slot = "INVTYPE_FEET";
elseif (name == "desecratedbindings" or name == "desecratedwristguards" or name == "desecratedbracers") then slot = "INVTYPE_WRIST";
elseif (name == "desecratedgloves" or name == "desecratedhandguards" or name == "desecratedgauntlets") then slot = "INVTYPE_HAND";
elseif (name == "desecratedbelt" or name == "desecratedwaistguard" or name == "desecratedgirdle") then slot = "INVTYPE_WAIST";
elseif (name == "desecratedleggings" or name == "desecratedlegguards" or name == "desecratedlegplates") then slot = "INVTYPE_LEGS";
elseif (name == "desecratedcirclet" or name == "desecratedheadpiece" or name == "desecratedhelmet") then slot = "INVTYPE_HEAD";
elseif name == "desecratedrobe" then slot = "INVTYPE_ROBE";
elseif (name == "desecratedtunic" or name == "desecratedbreastplate") then slot = "INVTYPE_CHEST";
end
elseif strfind(name, "primalhakkari") and rarity == 4 then
if (name == "primalhakkari bindings" or name == "primalhakkari armsplint" or name == "primalhakkari stanchion") then slot = "INVTYPE_WRIST";
elseif (name == "primalhakkari girdle" or name == "primalhakkari sash" or name == "primalhakkari shawl") then slot = "INVTYPE_WAIST";
elseif (name == "primalhakkari tabard" or name == "primalhakkari kossack" or name == "primalhakkari aegis") then slot = "INVTYPE_CHEST";
end
elseif strfind(name, "qiraji") then
if (name == "qirajispikedhilt" or name == "qirajiornatehilt") then slot = "INVTYPE_WEAPONMAINHAND";
elseif (name == "qirajiregaldrape" or name == "qirajimartialdrape") then slot = "INVTYPE_CLOAK";
elseif (name == "qirajimagisterialring" or name == "qirajiceremonialring") then slot = "INVTYPE_FINGER";
elseif (name == "imperialqirajiarmaments" or name == "imperialqirajiregalia") then slot = "INVTYPE_2HWEAPON";
elseif (name == "qirajibindingsofcommand" or name == "qirajibindingsofdominance") then slot = "INVTYPE_WRIST";
end
elseif name == "headofossiriantheunscarred" or name == "headofonyxia" or name == "headofnefarian" or name == "eyeofcthun" then
slot = "INVTYPE_NECK";
elseif name == "thephylacteryofkel'thuzad" or name == "heartofhakkar" then
slot = "INVTYPE_TRINKET";
elseif name == "huskoftheoldgod" or name == "carapaceoftheoldgod" then
slot = "INVTYPE_CHEST";
elseif name == "ourosintacthide" or name == "skinofthegreatsandworm" then
slot = "INVTYPE_LEGS";
--Exceptions: Items that should not carry GP but still need to be distributed
elseif name == "splinterofatiesh"
or name == "tomeoftranquilizingshot"
or name == "bindingsofthewindseeker"
or name == "resilienceofthescourge"
or name == "fortitudeofthescourge"
or name == "mightofthescourge"
or name == "powerofthescourge"
or name == "sulfuroningot"
or name == "matureblackdragonsinew"
or name == "nightmareengulfedobject"
or name == "ancientpetrifiedleaf" then
slot = "INVTYPE_EXCEPTION";
else
slot = "INVTYPE_EXCEPTION";
end
end
if CEPGP_debugMode then
local quality = rarity == 0 and "Poor" or rarity == 1 and "Common" or rarity == 2 and "Uncommon" or rarity == 3 and "Rare" or rarity == 4 and "Epic" or "Legendary";
CEPGP_print("Name: " .. name);
CEPGP_print("Rarity: " .. quality);
CEPGP_print("Item Level: " .. ilvl);
CEPGP_print("Item Type: " .. itemType);
CEPGP_print("Subtype: " .. subType);
CEPGP_print("Slot: " .. slot);
end
slot = strsub(slot,strfind(slot,"INVTYPE_")+8,string.len(slot));
slot = SLOTWEIGHTS[slot];
name, quality, itemType, subType = nil;
if ilvl and rarity and slot then
return (math.floor((COEF * (MOD_COEF^((ilvl/26) + (rarity-4))) * slot)*MOD)*quantity);
else
return 0;
end
end
function CEPGP_populateFrame(CEPGP_criteria, items)
local sorting = nil;
local subframe = nil;
if CEPGP_criteria == "name" or CEPGP_criteria == "rank" then
SortGuildRoster(CEPGP_criteria);
elseif CEPGP_criteria == "group" or CEPGP_criteria == "EP" or CEPGP_criteria == "GP" or CEPGP_criteria == "PR" then
sorting = CEPGP_criteria;
else
sorting = "group";
end
if CEPGP_mode == "loot" then
CEPGP_cleanTable();
elseif CEPGP_mode ~= "loot" then
CEPGP_cleanTable();
end
local tempItems = {};
local total;
if CEPGP_mode == "guild" then
CEPGP_UpdateGuildScrollBar();
elseif CEPGP_mode == "raid" then
CEPGP_UpdateRaidScrollBar();
elseif CEPGP_mode == "loot" then
subframe = CEPGP_loot;
local count = 0;
if not items then
total = 0;
else
local i = 1;
for _,value in pairs(items) do
tempItems[i] = value;
i = i + 1;
count = count + 1;
end
i = nil;
end
total = count;
end
if CEPGP_mode == "loot" then
for i = 1, total do
local texture, name, quality, gp, colour, iString, link, slot, x, quantity;
x = i;
texture = tempItems[i][1];
name = tempItems[i][2];
colour = ITEM_QUALITY_COLORS[tempItems[i][3]];
link = tempItems[i][4];
iString = tempItems[i][5];
slot = tempItems[i][6];
quantity = tempItems[i][7];
gp = CEPGP_calcGP(link, quantity, CEPGP_getItemID(iString));
if _G[CEPGP_mode..'item'..i] ~= nil then
_G[CEPGP_mode..'announce'..i]:Show();
_G[CEPGP_mode..'announce'..i]:SetWidth(20);
_G[CEPGP_mode..'announce'..i]:SetScript('OnClick', function() CEPGP_announce(link, x, slot, quantity) CEPGP_distribute:SetID(_G[CEPGP_mode..'announce'..i]:GetID()) end);
_G[CEPGP_mode..'announce'..i]:SetID(slot);
_G[CEPGP_mode..'icon'..i]:Show();
_G[CEPGP_mode..'icon'..i]:SetScript('OnEnter', function() GameTooltip:SetOwner(_G[CEPGP_mode..'icon'..i], "ANCHOR_BOTTOMLEFT") GameTooltip:SetHyperlink(iString) GameTooltip:Show() end);
_G[CEPGP_mode..'icon'..i]:SetScript('OnLeave', function() GameTooltip:Hide() end);
_G[CEPGP_mode..'texture'..i]:Show();
_G[CEPGP_mode..'texture'..i]:SetTexture(texture);
_G[CEPGP_mode..'item'..i]:Show();
_G[CEPGP_mode..'item'..i].text:SetText(link);
_G[CEPGP_mode..'item'..i].text:SetTextColor(colour.r, colour.g, colour.b);
_G[CEPGP_mode..'item'..i].text:SetPoint('CENTER',_G[CEPGP_mode..'item'..i]);
_G[CEPGP_mode..'item'..i]:SetWidth(_G[CEPGP_mode..'item'..i].text:GetStringWidth());
_G[CEPGP_mode..'item'..i]:SetScript('OnClick', function() SetItemRef(link, iString) end);
_G[CEPGP_mode..'itemGP'..i]:SetText(gp);
_G[CEPGP_mode..'itemGP'..i]:SetTextColor(colour.r, colour.g, colour.b);
_G[CEPGP_mode..'itemGP'..i]:SetWidth(35);
_G[CEPGP_mode..'itemGP'..i]:SetScript('OnEnterPressed', function() _G[CEPGP_mode..'itemGP'..i]:ClearFocus() end);
_G[CEPGP_mode..'itemGP'..i]:SetAutoFocus(false);
_G[CEPGP_mode..'itemGP'..i]:Show();
else
subframe.announce = CreateFrame('Button', CEPGP_mode..'announce'..i, subframe, 'UIPanelButtonTemplate');
subframe.announce:SetHeight(20);
subframe.announce:SetWidth(20);
subframe.announce:SetScript('OnClick', function() CEPGP_announce(link, x, slot, quantity) CEPGP_distribute:SetID(_G[CEPGP_mode..'announce'..i]:GetID()); end);
subframe.announce:SetID(slot);
subframe.icon = CreateFrame('Button', CEPGP_mode..'icon'..i, subframe);
subframe.icon:SetHeight(20);
subframe.icon:SetWidth(20);
subframe.icon:SetScript('OnEnter', function() GameTooltip:SetOwner(_G[CEPGP_mode..'icon'..i], "ANCHOR_BOTTOMLEFT") GameTooltip:SetHyperlink(link) GameTooltip:Show() end);
subframe.icon:SetScript('OnLeave', function() GameTooltip:Hide() end);
local tex = subframe.icon:CreateTexture(CEPGP_mode..'texture'..i, "BACKGROUND");
tex:SetAllPoints();
tex:SetTexture(texture);
subframe.itemName = CreateFrame('Button', CEPGP_mode..'item'..i, subframe);
subframe.itemName:SetHeight(20);
subframe.itemGP = CreateFrame('EditBox', CEPGP_mode..'itemGP'..i, subframe, 'InputBoxTemplate');
subframe.itemGP:SetHeight(20);
subframe.itemGP:SetWidth(35);
if i == 1 then
subframe.announce:SetPoint('CENTER', _G['CEPGP_'..CEPGP_mode..'_announce'], 'BOTTOM', -10, -20);
subframe.icon:SetPoint('LEFT', _G[CEPGP_mode..'announce'..i], 'RIGHT', 10, 0);
tex:SetPoint('LEFT', _G[CEPGP_mode..'announce'..i], 'RIGHT', 10, 0);
subframe.itemName:SetPoint('LEFT', _G[CEPGP_mode..'icon'..i], 'RIGHT', 10, 0);
subframe.itemGP:SetPoint('CENTER', _G['CEPGP_'..CEPGP_mode..'_GP'], 'BOTTOM', 10, -20);
else
subframe.announce:SetPoint('CENTER', _G[CEPGP_mode..'announce'..(i-1)], 'BOTTOM', 0, -20);
subframe.icon:SetPoint('LEFT', _G[CEPGP_mode..'announce'..i], 'RIGHT', 10, 0);
tex:SetPoint('LEFT', _G[CEPGP_mode..'announce'..i], 'RIGHT', 10, 0);
subframe.itemName:SetPoint('LEFT', _G[CEPGP_mode..'icon'..i], 'RIGHT', 10, 0);
subframe.itemGP:SetPoint('CENTER', _G[CEPGP_mode..'itemGP'..(i-1)], 'BOTTOM', 0, -20);
end
subframe.icon:SetScript('OnClick', function() SetItemRef(link, iString) end);
subframe.itemName.text = subframe.itemName:CreateFontString(CEPGP_mode..'EPGP_i'..name..'text', 'OVERLAY', 'GameFontNormal');
subframe.itemName.text:SetPoint('CENTER', _G[CEPGP_mode..'item'..i]);
subframe.itemName.text:SetText(link);
subframe.itemName.text:SetTextColor(colour.r, colour.g, colour.b);
subframe.itemName:SetWidth(subframe.itemName.text:GetStringWidth());
subframe.itemName:SetScript('OnClick', function() SetItemRef(link, iString) end);
subframe.itemGP:SetText(gp);
subframe.itemGP:SetTextColor(colour.r, colour.g, colour.b);
subframe.itemGP:SetWidth(35);
subframe.itemGP:SetScript('OnEnterPressed', function() _G[CEPGP_mode..'itemGP'..i]:ClearFocus() end);
subframe.itemGP:SetAutoFocus(false);
subframe.itemGP:Show();
end
end
texture, name, colour, link, iString, slot, quantity, gp, tempItems = nil;
end
end
function CEPGP_strSplit(msgStr, c)
if not msgStr then
return nil;
end
local table_str = {};
local capture = string.format("(.-)%s", c);
for v in string.gmatch(msgStr, capture) do
table.insert(table_str, v);
end
return unpack(table_str);
end
function CEPGP_print(str, err)
if not str then return; end;
if err == nil then
DEFAULT_CHAT_FRAME:AddMessage("|c006969FFCEPGP: " .. tostring(str) .. "|r");
else
DEFAULT_CHAT_FRAME:AddMessage("|c006969FFCEPGP:|r " .. "|c00FF0000Error|r|c006969FF - " .. tostring(str) .. "|r");
end
end
function CEPGP_cleanTable()
local i = 1;
while _G[CEPGP_mode..'member_name'..i] ~= nil do
_G[CEPGP_mode..'member_group'..i].text:SetText("");
_G[CEPGP_mode..'member_name'..i].text:SetText("");
_G[CEPGP_mode..'member_rank'..i].text:SetText("");
_G[CEPGP_mode..'member_EP'..i].text:SetText("");
_G[CEPGP_mode..'member_GP'..i].text:SetText("");
_G[CEPGP_mode..'member_PR'..i].text:SetText("");
i = i + 1;
end
i = 1;
while _G[CEPGP_mode..'item'..i] ~= nil do
_G[CEPGP_mode..'announce'..i]:Hide();
_G[CEPGP_mode..'icon'..i]:Hide();
_G[CEPGP_mode..'texture'..i]:Hide();
_G[CEPGP_mode..'item'..i].text:SetText("");
_G[CEPGP_mode..'itemGP'..i]:Hide();
i = i + 1;
end
end
function CEPGP_toggleFrame(frame)
for i = 1, table.getn(CEPGP_frames) do
if CEPGP_frames[i]:GetName() == frame then
CEPGP_frames[i]:Show();
else
CEPGP_frames[i]:Hide();
end
end
end
function CEPGP_rosterUpdate(event)
if event == "GUILD_ROSTER_UPDATE" then
_G["CEPGP_frame"]:UnregisterEvent("GUILD_ROSTER_UPDATE");
CEPGP_roster = {};
if CanEditOfficerNote() then
ShowUIPanel(CEPGP_guild_add_EP);
ShowUIPanel(CEPGP_guild_decay);
ShowUIPanel(CEPGP_guild_reset);
ShowUIPanel(CEPGP_raid_add_EP);
ShowUIPanel(CEPGP_button_guild_restore);
else --[[ Hides context sensitive options if player cannot edit officer notes ]]--
HideUIPanel(CEPGP_guild_add_EP);
HideUIPanel(CEPGP_guild_decay);
HideUIPanel(CEPGP_guild_reset);
HideUIPanel(CEPGP_raid_add_EP);
HideUIPanel(CEPGP_button_guild_restore);
end
for i = 1, GetNumGuildMembers() do
local name, rank, rankIndex, _, class, _, _, officerNote = GetGuildRosterInfo(i);
if string.find(name, "-") then
name = string.sub(name, 0, string.find(name, "-")-1);
end
if name then
local EP, GP = CEPGP_getEPGP(officerNote, i, name);
local PR = math.floor((EP/GP)*100)/100;
CEPGP_roster[name] = {
[1] = i,
[2] = class,
[3] = rank,
[4] = rankIndex,
[5] = officerNote,
[6] = PR
};
end
name, rank, rankIndex, class, officerNote, EP, GP, PR = nil;
end
if CEPGP_mode == "guild" then
CEPGP_UpdateGuildScrollBar();
elseif CEPGP_mode == "raid" then
CEPGP_UpdateRaidScrollBar();
end
_G["CEPGP_frame"]:RegisterEvent("GUILD_ROSTER_UPDATE");
elseif event == "GROUP_ROSTER_UPDATE" then
if IsInRaid("player") and CEPGP_isML() == 0 then
if not CEPGP_use then
_G["CEPGP_confirmation"]:Show();
end
end
CEPGP_raidRoster = {};
_G["CEPGP_frame"]:UnregisterEvent("GROUP_ROSTER_UPDATE");
for i = 1, GetNumGroupMembers() do
local name = GetRaidRosterInfo(i);
if not name then break; end
if CEPGP_tContains(CEPGP_standbyRoster, name) then
for k, v in pairs(CEPGP_standbyRoster) do
if v == name then
table.remove(CEPGP_standbyRoster, k); --Removes player from standby list if they have joined the raid1
end
end
--CEPGP_UpdateStandbyScrollBar();
end
CEPGP_raidRoster[i] = name;
name = nil;
end
_G["CEPGP_frame"]:RegisterEvent("GROUP_ROSTER_UPDATE");
if UnitInRaid("player") then
ShowUIPanel(CEPGP_button_raid);
else --[[ Hides the raid and loot distribution buttons if the player is not in a raid group ]]--
CEPGP_mode = "guild";
CEPGP_toggleFrame("CEPGP_guild");
end
CEPGP_UpdateRaidScrollBar();
end
end
function CEPGP_addToStandby(player)
if not player then return; end
player = CEPGP_standardiseString(player);
if not CEPGP_tContains(CEPGP_roster, player, true) then
CEPGP_print(player .. " is not a guild member", true);
return;
elseif CEPGP_tContains(CEPGP_standbyRoster, player) then
CEPGP_print(player .. " is already in the standby roster", true);
return;
elseif CEPGP_tContains(CEPGP_raidRoster, player, true) then
CEPGP_print(player .. " is part of the raid", true);
return;
else
table.insert(CEPGP_standbyRoster, player);
CEPGP_UpdateStandbyScrollBar();
end
end
function CEPGP_standardiseString(str)
--Returns the string with proper nouns capitalised
if not str then return; end
local result = "";
local _, delims = string.gsub(str, " ", ""); --accommodates for spaces
local values = CEPGP_split(str, " ", delims);
for k, v in pairs(values) do
if string.find(v, "%-") then
_, delims2 = string.gsub(v, "%-", ""); --accommodates for hyphens
values2 = CEPGP_split(v, "%-", delims2);
for index, value in pairs(values2) do
local first = string.upper(string.sub(value, 1, 1));
if index <= delims2 then
result = result .. first .. string.sub(value, 2, string.len(value)) .. "-";
else
result = result .. first .. string.lower(string.sub(value, 2, string.len(value)));
end
end
else
if v == "of" or (v == "the" and k > 1) then
result = result .. v .. " ";
else
local first = string.upper(string.sub(v, 1, 1));
if k <= delims then
result = result .. first .. string.lower(string.sub(v, 2, string.len(v))) .. " ";
else
result = result .. first .. string.lower(string.sub(v, 2, string.len(v)));
end
end
end
end
return result;
end
function CEPGP_split(str, delim, iters) --String to be split, delimiter, number of iterations
local frags = {};
local remainder = str;
local count = 1;
for i = 1, iters+1 do
if string.find(remainder, delim) then
frags[count] = string.sub(remainder, 1, string.find(remainder, delim)-1);
remainder = string.sub(remainder, string.find(remainder, delim)+1, string.len(remainder));
else
frags[count] = string.sub(remainder, 1, string.len(remainder));
end
count = count + 1;
end
return frags;
end
function CEPGP_toggleStandbyRanks(show)
if show and CEPGP_ntgetn(STANDBYRANKS) > 0 then
for i = 1, 10 do
STANDBYRANKS[i][1] = GuildControlGetRankName(i);
end
for i = 1, 10 do
if STANDBYRANKS[i][1] then
_G["CEPGP_options_standby_ep_rank_"..i]:Show();
_G["CEPGP_options_standby_ep_rank_"..i]:SetText(tostring(STANDBYRANKS[i][1]));
_G["CEPGP_options_standby_ep_check_rank_"..i]:Show();
if STANDBYRANKS[i][2] == true then
_G["CEPGP_options_standby_ep_check_rank_"..i]:SetChecked(true);
else
_G["CEPGP_options_standby_ep_check_rank_"..i]:SetChecked(false);
end
else
_G["CEPGP_options_standby_ep_rank_"..i]:Hide();
_G["CEPGP_options_standby_ep_check_rank_"..i]:Hide();
end
if GuildControlGetRankName(i) == "" then
_G["CEPGP_options_standby_ep_rank_"..i]:Hide();
_G["CEPGP_options_standby_ep_check_rank_"..i]:Hide();
_G["CEPGP_options_standby_ep_check_rank_"..i]:SetChecked(false);
end
end
CEPGP_options_standby_ep_list_button:Hide();
CEPGP_options_standby_ep_accept_whispers_check:Hide();
CEPGP_options_standby_ep_accept_whispers:Hide();
CEPGP_options_standby_ep_offline_check:Hide();
CEPGP_options_standby_ep_offline:Hide();
CEPGP_options_standby_ep_message_val:Hide();
CEPGP_options_standby_ep_whisper_message:Hide();
CEPGP_options_standby_ep_byrank_check:SetChecked(true);
CEPGP_options_standby_ep_manual_check:SetChecked(false);
else
for i = 1, 10 do
_G["CEPGP_options_standby_ep_rank_"..i]:Hide();
_G["CEPGP_options_standby_ep_check_rank_"..i]:Hide();
end
CEPGP_options_standby_ep_list_button:Show();
CEPGP_options_standby_ep_accept_whispers_check:Show();
CEPGP_options_standby_ep_accept_whispers:Show();
CEPGP_options_standby_ep_offline_check:Show();
CEPGP_options_standby_ep_offline:Show();
CEPGP_options_standby_ep_message_val:Show();
CEPGP_options_standby_ep_byrank_check:SetChecked(false);
CEPGP_options_standby_ep_manual_check:SetChecked(true);
end
end
function CEPGP_getGuildInfo(name)
if CEPGP_tContains(CEPGP_roster, name, true) then
return CEPGP_roster[name][1], CEPGP_roster[name][2], CEPGP_roster[name][3], CEPGP_roster[name][4], CEPGP_roster[name][5], CEPGP_roster[name][6]; -- index, class, Rank, RankIndex, Class, OfficerNote, PR
else
return nil;
end
end
function CEPGP_getVal(str)
local val = nil;
val = strsub(str, strfind(str, " ")+1, string.len(str));
return val;
end
function CEPGP_indexToName(index)
for name,value in pairs(CEPGP_roster) do
if value[1] == index then
return name;
end
end
end
function CEPGP_nameToIndex(name)
for key,index in pairs(CEPGP_roster) do
if key == name then
return index[1];
end
end
end
function CEPGP_getEPGP(offNote, index, name)
if not name then index = CEPGP_nameToIndex(name); end
--if not index then return 0, 1; end --Happens when character logs initiailly
if offNote ~= "" then
if not CEPGP_checkEPGP(offNote) then
if not index then return 0, BASEGP; end
local EP, GP;
--Error with player's EPGP has been detected and will attempt to be salvaged
if string.find(offNote, '^[0-9]+,') then --EP is assumed in tact
if string.find(offNote, ',[0-9]+') then
EP = tonumber(strsub(offNote, 1, strfind(offNote, ",")-1));
GP = strsub(offNote, string.find(offNote, ',[0-9]+')+1, string.find(offNote, '[^0-9,]')-1);
if CanEditOfficerNote() then
GuildRosterSetOfficerNote(index, EP .. "," .. GP);
CEPGP_print("An error was found with " .. name .. "'s GP. Their EPGP has been salvaged as " .. EP .. "," .. GP .. ". Please confirm if this is correct and modify the officer note if required.");
end
return EP,GP;
elseif string.find(offNote, '[0-9]+$') then
EP = tonumber(strsub(offNote, 1, strfind(offNote, ",")-1));
GP = strsub(offNote, string.find(offNote, '[0-9]+$'), string.len(offNote));
if CanEditOfficerNote() then
GuildRosterSetOfficerNote(index, EP .. "," .. GP);
CEPGP_print("An error was found with " .. name .. "'s GP. Their EPGP has been salvaged as " .. EP .. "," .. GP .. ". Please confirm if this is correct and modify the officer note if required.");
end
return EP,GP;
else
EP = tonumber(strsub(offNote, 1, strfind(offNote, ",")-1));
if CanEditOfficerNote() then
GuildRosterSetOfficerNote(index, EP .. "," .. BASEGP);
CEPGP_print("An error was found with " .. name .. "'s GP. Their EP has been retained as " .. EP .. " but their GP will need to be manually set if known.");
end
return EP, BASEGP;
end
return EP, BASEGP;
elseif string.find(offNote, ',[0-9]+$') then --GP is assumed in tact
GP = tonumber(strsub(offNote, strfind(offNote, ",")+1, string.len(offNote)));
if string.find(offNote, '[^0-9]+,[0-9]+$') then --EP might still be intact, but characters might be padding between EP and the comma
EP = strsub(offNote, 1, string.find(offNote, '[^0-9]+,')-1);
if CanEditOfficerNote() then
GuildRosterSetOfficerNote(index, EP .. "," .. GP);
CEPGP_print("An error was found with " .. name .. "'s EP. Their EPGP has been salvaged as " .. EP .. "," .. GP .. ". Please confirm if this is correct and modify the officer note if required.");
end
return EP, GP;
elseif string.find(offNote, '^[^0-9]+[0-9]+,[0-9]+$') then --or pheraps the error is at the start of the string?
EP = strsub(offNote, string.find(offNote, '[0-9]+,'), string.find(offNote, ',[0-9]+$')-1);
if CanEditOfficerNote() then
GuildRosterSetOfficerNote(index, EP .. "," .. GP);
CEPGP_print("An error was found with " .. name .. "'s EP. Their EPGP has been salvaged as " .. EP .. "," .. GP .. ". Please confirm if this is correct and modify the officer note if required.");
end
return EP, GP;
else --EP cannot be salvaged
if CanEditOfficerNote() then
GuildRosterSetOfficerNote(index, "0," .. GP);
CEPGP_print("An error was found with " .. name .. "'s EP. Their GP has been retained as " .. GP .. " but their EP will need to be manually set if known. For now, their EP has defaulted to 0.");
end
return 0, GP;
end
else --Neither are in tact
GuildRosterSetOfficerNote(index, "0," .. BASEGP);
return 0, BASEGP;
end
end
end
local EP, GP = nil;
if offNote == "" then --Click here to set an officer note qualifies as blank, also occurs if the officer notes are not visible
return 0, 1;
end
EP = tonumber(strsub(offNote, 1, strfind(offNote, ",")-1));
GP = tonumber(strsub(offNote, strfind(offNote, ",")+1, string.len(offNote)));
return EP, GP;
end
function CEPGP_checkEPGP(note)
if string.find(note, '^[0-9]+,[0-9]+$') then
return true;
else
return false;
end
end
function CEPGP_getItemString(link)
if not link then
return nil;
end
local itemString = string.find(link, "item[%-?%d:]+");
itemString = strsub(link, itemString, string.len(link)-(string.len(link)-2)-6);
return itemString;
end
function CEPGP_getItemID(iString)
if not iString then
return nil;
end
local itemString = string.sub(iString, 6, string.len(iString)-1)--"^[%-?%d:]+");
return string.sub(itemString, 1, string.find(itemString, ":")-1);
end
function CEPGP_getItemLink(id)
local name, _, rarity = GetItemInfo(id);
if rarity == 0 then -- Poor
return "\124cff9d9d9d\124Hitem:" .. id .. "::::::::110:::::\124h[" .. name .. "]\124h\124r";
elseif rarity == 1 then -- Common
return "\124cffffffff\124Hitem:" .. id .. "::::::::110:::::\124h[" .. name .. "]\124h\124r";
elseif rarity == 2 then -- Uncommon
return "\124cff1eff00\124Hitem:" .. id .. "::::::::110:::::\124h[" .. name .. "]\124h\124r";
elseif rarity == 3 then -- Rare
return "\124cff0070dd\124Hitem:" .. id .. "::::::::110:::::\124h[" .. name .. "]\124h\124r";
elseif rarity == 4 then -- Epic
return "\124cffa335ee\124Hitem:" .. id .. "::::::::110:::::\124h[" .. name .. "]\124h\124r";
elseif rarity == 5 then -- Legendary
return "\124cffff8000\124Hitem:" .. id .. "::::::::110:::::\124h[" .. name .. "]\124h\124r";
end
end
function CEPGP_SlotNameToID(name)
if name == nil then
return nil
end
if name == "HEAD" then
return 1;
elseif name == "NECK" then
return 2;
elseif name == "SHOULDER" then
return 3;
elseif name == "CHEST" or name == "ROBE" then
return 5;
elseif name == "WAIST" then
return 6;
elseif name == "LEGS" then
return 7;
elseif name == "FEET" then
return 8;
elseif name == "WRIST" then
return 9;
elseif name == "HAND" then
return 10;
elseif name == "FINGER" then
return 11, 12;
elseif name == "TRINKET" then
return 13, 14;
elseif name == "CLOAK" then
return 15;
elseif name == "2HWEAPON" or name == "WEAPON" or name == "WEAPONMAINHAND" or name == "WEAPONOFFHAND" or name == "SHIELD" or name == "HOLDABLE" then
return 16, 17;
elseif name == "RANGED" or name == "RANGEDRIGHT" or name == "RELIC" then
return 18;
end
end
function CEPGP_inOverride(itemName)
itemName = string.gsub(string.gsub(string.gsub(string.lower(itemName), " ", ""), "'", ""), ",", "");
for k, _ in pairs(OVERRIDE_INDEX) do
if itemName == string.gsub(string.gsub(string.gsub(string.lower(k), " ", ""), "'", ""), ",", "") then
return true;
end
end
return false;
end
function CEPGP_tContains(t, val, bool)
if not t then return; end
if bool == nil then
for _,value in pairs(t) do
if value == val then
return true;
end
end
elseif bool == true then
for index,_ in pairs(t) do
if index == val then
return true;
end
end
end
return false;
end
function CEPGP_isNumber(num)
return not (string.find(tostring(num), '[^-0-9.]+') or string.find(tostring(num), '[^-0-9.]+$'));
end
function CEPGP_isML()
local _, isML = GetLootMethod();
return isML;
end
function CEPGP_updateGuild()
if not IsInGuild() then
HideUIPanel(CEPGP_button_guild);
HideUIPanel(CEPGP_guild);
return;
else
ShowUIPanel(CEPGP_button_guild);
if CEPGP_ntgetn(STANDBYRANKS) > 0 then
for i = 1, 10 do
STANDBYRANKS[i][1] = GuildControlGetRankName(i);
end
end
end
GuildRoster();
end
function CEPGP_tSort(t, index)
if not t then return; end
local t2 = {};
table.insert(t2, t[1]);
table.remove(t, 1);
local tSize = table.getn(t);
if tSize > 0 then
for x = 1, tSize do
local t2Size = table.getn(t2);
for y = 1, t2Size do
if y < t2Size and t[1][index] ~= nil then
if CEPGP_critReverse then
if (t[1][index] >= t2[y][index]) then
table.insert(t2, y, t[1]);
table.remove(t, 1);
break;
elseif (t[1][index] < t2[y][index]) and (t[1][index] >= t2[(y + 1)][index]) then
table.insert(t2, (y + 1), t[1]);
table.remove(t, 1);
break;
end
else
if (t[1][index] <= t2[y][index]) then
table.insert(t2, y, t[1]);
table.remove(t, 1);
break;
elseif (t[1][index] > t2[y][index]) and (t[1][index] <= t2[(y + 1)][index]) then
table.insert(t2, (y + 1), t[1]);
table.remove(t, 1);
break;
end
end
elseif y == t2Size and t[1][index] ~= nil then
if CEPGP_critReverse then
if t[1][index] > t2[y][index] then
table.insert(t2, y, t[1]);
table.remove(t, 1);
else
table.insert(t2, t[1]);
table.remove(t, 1);
end
else
if t[1][index] < t2[y][index] then
table.insert(t2, y, t[1]);
table.remove(t, 1);
else
table.insert(t2, t[1]);
table.remove(t, 1);
end
end
end
end
end
end
return t2;
end
function CEPGP_ntgetn(tbl)
if tbl == nil then
return 0;
end
local n = 0;
for _,_ in pairs(tbl) do
n = n + 1;
end
return n;
end
function CEPGP_setCriteria(x, disp)
if CEPGP_criteria == x then
CEPGP_critReverse = not CEPGP_critReverse
end
CEPGP_criteria = x;
if disp == "Raid" then
CEPGP_UpdateRaidScrollBar();
elseif disp == "Guild" then
CEPGP_UpdateGuildScrollBar();
elseif disp == "Loot" then
CEPGP_UpdateLootScrollBar();
elseif disp == "Standby" then
CEPGP_UpdateStandbyScrollBar();
end
end
function CEPGP_toggleBossConfigFrame(fName)
for _, frame in pairs(CEPGP_boss_config_frames) do
if frame:GetName() ~= fName then
HideUIPanel(frame);
else
frame:Show();
end;
end
end
function CEPGP_button_options_OnClick()
CEPGP_updateGuild();
PlaySound(799);
CEPGP_toggleFrame("CEPGP_options");
CEPGP_mode = "options";
CEPGP_options_mod_edit:SetText(tostring(MOD));
CEPGP_options_coef_edit:SetText(tostring(COEF));
CEPGP_options_coef_2_edit:SetText(tostring(MOD_COEF));
CEPGP_options_gp_base_edit:SetText(tostring(BASEGP));
CEPGP_options_keyword_edit:SetText(tostring(CEPGP_keyword));
if STANDBYEP then
CEPGP_options_standby_ep_check:SetChecked(true);
else
CEPGP_options_standby_ep_check:SetChecked(false);
end
CEPGP_options_standby_ep_val:SetText(tostring(STANDBYPERCENT));
if CEPGP_standby_byrank then
CEPGP_toggleStandbyRanks(true);
else
CEPGP_toggleStandbyRanks(false);
end
if STANDBYEP then
_G["CEPGP_options_standby_ep_check"]:SetChecked(true);
else
_G["CEPGP_options_standby_ep_check"]:SetChecked(false);
end
if STANDBYOFFLINE then
_G["CEPGP_options_standby_ep_offline_check"]:SetChecked(true);
else
_G["CEPGP_options_standby_ep_offline_check"]:SetChecked(false);
end
CEPGP_options_standby_ep_val:SetText(tostring(STANDBYPERCENT));
if CEPGP_options_standby_ep_byrank_check:GetChecked() then
CEPGP_options_standby_ep_message_val:Hide();
CEPGP_options_standby_ep_whisper_message:Hide();
else
CEPGP_options_standby_ep_message_val:Show();
CEPGP_options_standby_ep_whisper_message:Show();
end;
if CEPGP_options_standby_ep_check:GetChecked() then
CEPGP_options_standby_ep_options:Show();
else
CEPGP_options_standby_ep_options:Hide();
end
for k, v in pairs(SLOTWEIGHTS) do
if k ~= "ROBE" and k ~= "WEAPON" and k ~= "EXCEPTION" then
_G["CEPGP_options_" .. k .. "_weight"]:SetText(tonumber(SLOTWEIGHTS[k]));
end
end
local rName = GuildControlGetRankName(CEPGP_force_sync_rank); --rank name
UIDropDownMenu_SetSelectedName(CEPGP_sync_rank, rName);
if ALLOW_FORCED_SYNC then
CEPGP_options_allow_forced_sync_check:SetChecked(true);
_G["CEPGP_sync_rank"]:Show();
_G["CEPGP_button_options_force_sync"]:Show();
else
CEPGP_options_allow_forced_sync_check:SetChecked(false);
_G["CEPGP_sync_rank"]:Hide();
_G["CEPGP_button_options_force_sync"]:Hide();
end
if CEPGP_loot_GUI then
_G["CEPGP_options_response_gui_checkbox"]:SetChecked(true);
_G["CEPGP_options_keyword"]:Hide();
_G["CEPGP_options_keyword_edit"]:Hide();
else
_G["CEPGP_options_response_gui_checkbox"]:SetChecked(false);
_G["CEPGP_options_keyword"]:Show();
_G["CEPGP_options_keyword_edit"]:Show();
end
CEPGP_populateFrame();
end
function CEPGP_UIDropDownMenu_Initialize(frame, initFunction, displayMode, level, menuList, search)
if ( not frame ) then
frame = self;
end
frame.menuList = menuList;