forked from sadsfae/CEPGP-Retail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Loot.lua
265 lines (245 loc) · 9.42 KB
/
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
function CEPGP_LootFrame_Update()
local items = {};
local count = 0;
if CEPGP_ElvUI then
local numLootItems = GetNumLootItems();
local texture, item, quantity, quality;
for index = 1, numLootItems do
if ( index <= numLootItems ) then
texture, item, quantity, _, quality = GetLootSlotInfo(index);
if (tostring(GetLootSlotLink(index)) ~= "nil" or CEPGP_inOverride(item)) and item ~= nil then
items[index-count] = {};
items[index-count][1] = texture;
items[index-count][2] = item;
items[index-count][3] = quality;
items[index-count][4] = GetLootSlotLink(index);
local link = GetLootSlotLink(index);
local itemString = string.find(link, "item[%-?%d:]+");
itemString = strsub(link, itemString, string.len(link)-string.len(item)-6);
items[index-count][5] = itemString;
items[index-count][6] = index;
items[index-count][7] = quantity;
else
count = count + 1;
end
end
end
else
local numLootItems = LootFrame.numLootItems;
local texture, item, quantity, quality;
for index = 1, numLootItems do
local slot = index;
if ( slot <= numLootItems ) then
if (LootSlotHasItem(slot)) then
texture, item, quantity, _, quality = GetLootSlotInfo(slot);
if tostring(GetLootSlotLink(slot)) ~= "nil" or CEPGP_inOverride(item) then
items[index-count] = {};
items[index-count][1] = texture;
items[index-count][2] = item;
items[index-count][3] = quality;
items[index-count][4] = GetLootSlotLink(slot);
local link = GetLootSlotLink(index);
local itemString = string.find(link, "item[%-?%d:]+");
itemString = strsub(link, itemString, string.len(link)-string.len(item)-6);
items[index-count][5] = itemString;
items[index-count][6] = slot;
items[index-count][7] = quantity;
else
count = count + 1;
end
end
end
end
end
for k, v in pairs(items) do -- k = loot slot number, v is the table result
if (UnitInRaid("player") or CEPGP_Info.Debug) and (v[3] >= CEPGP.Loot.MinThreshold) or (CEPGP_inOverride(v[2]) or CEPGP_inOverride(v[4])) then
if CEPGP_isML() == 0 then
CEPGP_frame:Show();
CEPGP_mode = "loot";
CEPGP_toggleFrame("CEPGP_loot");
end
break;
end
end
CEPGP_populateFrame(items);
end
function CEPGP_announce(link, x, slotNum, quantity)
if (GetLootMethod() == "master" and CEPGP_isML() == 0) or CEPGP_Info.Debug then
local iString = CEPGP_getItemString(link);
local name, _, _, _, _, _, _, _, slot, tex = GetItemInfo(iString);
local id = CEPGP_getItemID(iString);
CEPGP_Info.LootGUID = id .. "-" .. GetTime(); -- Note: This is a custom GUID and is not the standard format provided by the client
for i = 1, 4 do
CEPGP_Info.LootSchema[i] = CEPGP_response_buttons[i][2];
end
CEPGP_Info.LootSchema[5] = "";
CEPGP_Info.LootSchema[6] = "Pass";
CEPGP_Info.LootRespondants = 0;
local temp = {};
for label, v in pairs(CEPGP.Loot.ExtraKeywords.Keywords) do
for _, disc in pairs(v) do
local entry = {[1] = label, [2] = disc};
table.insert(temp, entry);
end
end
temp = CEPGP_tSort(temp, 2, true);
for index, t in ipairs(temp) do
CEPGP_Info.LootSchema[index+6] = t[1];
end
local schema = "lootschema";
local temp = {}; -- Only used if schema needs to be separated due to length
for index, response in ipairs(CEPGP_Info.LootSchema) do
if #(schema .. index .. ";" .. response) > 249 then
table.insert(temp, schema);
schema = "lootschema;" .. index .. ";" .. response;
else
schema = schema .. ";" .. index .. ";" .. response;
end
end
table.insert(temp, schema);
for _, schema in ipairs(temp) do
if CEPGP.Loot.RaidVisibility[2] then
CEPGP_SendAddonMsg(schema, "RAID");
elseif CEPGP.Loot.RaidVisibility[1] then
CEPGP_messageGroup(schema, "assists");
end
end
CEPGP_distributing = true;
CEPGP_toggleGPEdit(false);
CEPGP_itemsTable = {};
CEPGP_distItemLink = link;
CEPGP_DistID = id;
CEPGP_SendAddonMsg("CEPGP_setDistID;" .. id, "RAID");
CEPGP_SendAddonMsg("CEPGP_setLootGUID;" .. CEPGP_Info.LootGUID, "RAID");
CEPGP_distSlot = slot;
gp = _G[CEPGP_mode..'itemGP'..x]:GetText();
CEPGP_lootSlot = slotNum;
CEPGP_responses = {};
CEPGP_UpdateLootScrollBar();
_G["CEPGP_respond_texture"]:SetTexture(tex);
_G["CEPGP_respond_texture_frame"]:SetScript('OnEnter', function()
GameTooltip:SetOwner(_G["CEPGP_respond_texture_frame"], "ANCHOR_TOPLEFT")
GameTooltip:SetHyperlink(iString);
GameTooltip:Show();
end);
_G["CEPGP_respond_texture_frame"]:SetScript('OnLeave', function()
GameTooltip:Hide();
end);
_G["CEPGP_respond_item_name_frame"]:SetScript('OnClick', function() SetItemRef(iString, name); end);
_G["CEPGP_respond_item_name"]:SetText(link);
local rank = 0;
for i = 1, GetNumGroupMembers() do
if UnitName("player") == GetRaidRosterInfo(i) then
_, rank = GetRaidRosterInfo(i);
end
end
-- Messages are much faster when sent via the WHISPER channel, so a delay is needed so the distribution ID can be set in time
C_Timer.After(1, function()
if CEPGP.Loot.RaidVisibility[2] then
CEPGP_SendAddonMsg("RaidAssistLootDist;"..link..";"..gp..";true", "RAID");
elseif CEPGP.Loot.RaidVisibility[1] then
CEPGP_messageGroup("RaidAssistLootDist;"..link..";"..gp..";true", "assists");
end
end);
SendChatMessage("--------------------------", "RAID", CEPGP_LANGUAGE);
if rank > 0 then
if quantity > 1 then
if CEPGP.Loot.RaidWarning then
SendChatMessage("NOW DISTRIBUTING: x" .. quantity .. " " .. link, "RAID_WARNING", CEPGP_LANGUAGE);
else
SendChatMessage("NOW DISTRIBUTING: x" .. quantity .. " " .. link, "RAID", CEPGP_LANGUAGE);
end
else
if CEPGP.Loot.RaidWarning then
SendChatMessage("NOW DISTRIBUTING: " .. link, "RAID_WARNING", CEPGP_LANGUAGE);
else
SendChatMessage("NOW DISTRIBUTING: " .. link, "RAID", CEPGP_LANGUAGE);
end
end
else
if quantity > 1 then
SendChatMessage("NOW DISTRIBUTING: x" .. quantity .. " " .. link, "RAID", CEPGP_LANGUAGE);
else
SendChatMessage("NOW DISTRIBUTING: " .. link, "RAID", CEPGP_LANGUAGE);
end
end
if quantity > 1 then
SendChatMessage("GP Value: " .. gp .. " (~" .. math.floor(gp/quantity) .. "GP per unit)", "RAID", CEPGP_LANGUAGE);
else
SendChatMessage("GP Value: " .. gp, "RAID", CEPGP_LANGUAGE);
end
if CEPGP.Loot.GUI.Timer > 0 then
SendChatMessage("Time to respond: " .. CEPGP.Loot.GUI.Timer .. (CEPGP.Loot.GUI.Timer > 1 and " seconds" or " second"), "RAID", CEPGP_LANGUAGE);
end
SendChatMessage(CEPGP.Loot.Announcement, "RAID", CEPGP_LANGUAGE);
if not CEPGP.Loot.HideKeyphrases then
SendChatMessage(CEPGP_response_buttons[1][4] .. " : " .. CEPGP_response_buttons[1][2], "RAID", CEPGP_LANGUAGE);
if CEPGP_response_buttons[2][1] then
SendChatMessage(CEPGP_response_buttons[2][4] .. " : " .. CEPGP_response_buttons[2][2], "RAID", CEPGP_LANGUAGE);
end
if CEPGP_response_buttons[3][1] then
SendChatMessage(CEPGP_response_buttons[3][4] .. " : " .. CEPGP_response_buttons[3][2], "RAID", CEPGP_LANGUAGE);
end
if CEPGP_response_buttons[4][1] then
SendChatMessage(CEPGP_response_buttons[4][4] .. " : " .. CEPGP_response_buttons[4][2], "RAID", CEPGP_LANGUAGE);
end
end
local keywords = {};
for label, v in pairs(CEPGP.Loot.ExtraKeywords.Keywords) do
local entry = {};
for key, disc in pairs(v) do
entry = {[1] = label, [2] = key, [3] = disc};
end
table.insert(keywords, entry);
end
keywords = CEPGP_tSort(keywords, 3, true);
for k, v in ipairs(keywords) do
SendChatMessage(v[2] .. " : " .. v[1], "RAID", CEPGP_LANGUAGE);
end
SendChatMessage("--------------------------", "RAID", CEPGP_LANGUAGE);
local call = "CallItem;"..id..";"..gp;
local buttons = {};
if CEPGP_response_buttons[1][1] then
call = call .. ";" .. CEPGP_response_buttons[1][2];
buttons[1] = CEPGP_response_buttons[1][2];
else
call = call .. ";";
end
if CEPGP_response_buttons[2][1] then
call = call .. ";" .. CEPGP_response_buttons[2][2];
buttons[2] = CEPGP_response_buttons[2][2];
else
call = call .. ";";
end
if CEPGP_response_buttons[3][1] then
call = call .. ";" .. CEPGP_response_buttons[3][2];
buttons[3] = CEPGP_response_buttons[3][2];
else
call = call .. ";";
end
if CEPGP_response_buttons[4][1] then
call = call .. ";" .. CEPGP_response_buttons[4][2];
buttons[4] = CEPGP_response_buttons[4][2];
else
call = call .. ";";
end
call = call .. ";" .. tostring(CEPGP.Loot.GUI.Timer);
CEPGP_callItem(id, gp, buttons, CEPGP.Loot.GUI.Timer);
CEPGP_SendAddonMsg(call, "RAID");
CEPGP_distribute:Show();
CEPGP_loot:Hide();
_G["CEPGP_distribute_item_name"]:SetText(link);
_G["CEPGP_distribute_item_name_frame"]:SetScript('OnClick', function() SetItemRef(iString, name) end);
_G["CEPGP_distribute_item_tex"]:SetScript('OnEnter', function() GameTooltip:SetOwner(_G["CEPGP_distribute_item_tex"], "ANCHOR_TOPLEFT") GameTooltip:SetHyperlink(iString) GameTooltip:Show() end);
_G["CEPGP_distribute_item_texture"]:SetTexture(tex);
_G["CEPGP_distribute_item_tex"]:SetScript('OnLeave', function() GameTooltip:Hide() end);
_G["CEPGP_distribute_GP_value"]:SetText(gp);
elseif GetLootMethod() == "master" then
CEPGP_print("You are not the Loot Master.", 1);
return;
elseif GetLootMethod() ~= "master" then
CEPGP_print("The loot method is not Master Looter", 1);
end
end
function CEPGP_announceFromBag()
end