-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuickVendor.lua
463 lines (414 loc) · 21.4 KB
/
QuickVendor.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
local L = LibStub("AceLocale-3.0"):GetLocale("ExtVendor", true);
local SELL_ITEM_GROUP_SIZE = 1;
local REFRESH_CURRENT_BAG = 0;
local REFRESH_CURRENT_SLOT = 1;
local REFRESH_SLOTS_IN_BAG = 0;
local NUM_BLACKLISTED_JUNK = 0;
-- This table defines the levels at which the player "outlevels" gear from
-- a given expac (outdated gear filter). Syntax per entry is as follows:
-- [expac_id] = <min player level for expac's gear to be considered outdated>
local GEAR_OUTLEVEL_TABLE = {
[0] = 70, -- vanilla gear uses a different check, this is here just because
[1] = 90, -- BC gear is outdated when player reaches level 90
[2] = 90, -- wotlk gear is also outdated when player reaches level 90
[3] = 100, -- cata gear is outdated when player reaches level 100
[4] = 100, -- pandaria gear is also outdated when player reaches level 100
[5] = 110, -- draenor gear is outdated when player reaches level 110
[6] = 120, -- legion gear is outdated when player reaches level 120
[7] = 130, -- BFA gear is outdated when player reaches level 130
[8] = 130, -- ...
[9] = 130,
[10] = 130,
};
--========================================
-- Gets a list of junk items in the
-- player's bags
--========================================
function ExtVendor_StartQuickVendorRefresh()
if (EXTVENDOR.RefreshingQuickVendorList) then return false; end
ExtVendor_SetJunkButtonState(false);
if (EXTVENDOR.QuickVendor.Processing) then return false; end
REFRESH_CURRENT_BAG = 0;
REFRESH_CURRENT_SLOT = 1;
NUM_BLACKLISTED_JUNK = 0;
REFRESH_SLOTS_IN_BAG = C_Container.GetContainerNumSlots(REFRESH_CURRENT_BAG);
EXTVENDOR.QuickVendor.CurrentJunkList = {};
EXTVENDOR.QuickVendor.InventoryDetail = {};
EXTVENDOR.RefreshingQuickVendorList = true;
return true;
end
function ExtVendor_DoQuickVendorRefresh()
local processed = 0;
local __, count, isJunk, junkInfo, detail;
while true do
if (processed >= 20) then break; end
if (REFRESH_CURRENT_SLOT <= REFRESH_SLOTS_IN_BAG) then
__, count = C_Container.GetContainerItemInfo(REFRESH_CURRENT_BAG, REFRESH_CURRENT_SLOT);
if (count) then
isJunk, junkInfo, isBlacklisted, detail = ExtVendor_IsContainerItemJunk(REFRESH_CURRENT_BAG, REFRESH_CURRENT_SLOT);
if (isJunk) then
table.insert(EXTVENDOR.QuickVendor.CurrentJunkList, junkInfo);
else
if (isBlacklisted) then
NUM_BLACKLISTED_JUNK = NUM_BLACKLISTED_JUNK + 1;
end
end
if (detail) then
table.insert(EXTVENDOR.QuickVendor.InventoryDetail, detail);
end
processed = processed + 1;
end
end
REFRESH_CURRENT_SLOT = REFRESH_CURRENT_SLOT + 1;
if (REFRESH_CURRENT_SLOT > REFRESH_SLOTS_IN_BAG) then
REFRESH_CURRENT_SLOT = 1;
REFRESH_CURRENT_BAG = REFRESH_CURRENT_BAG + 1;
REFRESH_SLOTS_IN_BAG = C_Container.GetContainerNumSlots(REFRESH_CURRENT_BAG);
end
if (REFRESH_CURRENT_BAG > 4) then
ExtVendor_StopQuickVendorRefresh();
break;
end
end
end
function ExtVendor_StopQuickVendorRefresh()
EXTVENDOR.RefreshingQuickVendorList = false;
if (#EXTVENDOR.QuickVendor.CurrentJunkList > 0) then
ExtVendor_SetJunkButtonState(true);
else
ExtVendor_SetJunkButtonState(false);
end
end
--========================================
-- Show confirmation for selling all
-- junk items
--========================================
function ExtVendor_StartQuickVendor(self)
--local junk, numBlacklisted = ExtVendor_GetQuickVendorList();
if (#EXTVENDOR.QuickVendor.CurrentJunkList > 0) then
table.sort(EXTVENDOR.QuickVendor.CurrentJunkList, function(a, b) return (a.stackPrice < b.stackPrice); end);
ExtVendor_ShowJunkPopup(EXTVENDOR.QuickVendor.CurrentJunkList, NUM_BLACKLISTED_JUNK);
end
end
function ExtVendor_IsContainerItemJunk(bag, slot)
local __, count = C_Container.GetContainerItemInfo(bag, slot);
local iDetail;
if (count) then
local link = C_Container.GetContainerItemLink(bag, slot);
if (link) then
local isKnown, reqClasses, itemId, isAccountBound, isFoodOrDrink = ExtVendor_GetExtendedItemInfo(link);
local itemName, __, itemQuality, itemLevel, itemReqLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture, sellPrice, classID, subclassID, bindType, expacID, setID, isCraftingReagent = GetItemInfo(item)
--local name, __, itemQuality, itemLevel, itemReqLevel, itemType, itemSubType, maxStack, itemEquipLoc, __, price, itemClassId, itemSubClassId, bindType, expacID = GetItemInfo(link);
-- make sure the item has a vendor price
if ((price or 0) > 0) then
local isJunk, reason, detail = ExtVendor_IsItemQuickVendor(bag, slot, link, itemQuality, itemLevel, itemReqLevel, bindType, isKnown, classId, subClassId, itemEquipLoc, reqClasses, isAccountBound, expacID, isFoodOrDrink);
if (detail) then
iDetail = { link = link, isJunk = isJunk, reason = detail };
else
iDetail = { link = link, isJunk = isJunk, reason = "No information" };
end
if ((not isJunk) and (reason == 100)) then
return false, nil, true, iDetail;
end
-- if the item meets requirements, add it to the list
if (isJunk) then
return isJunk, {id = itemId, name = name, quality = quality, count = count, maxStack = maxStack, stackPrice = count * price, reason = reason}, false, iDetail;
end
return false, nil, false, iDetail;
else
return false, nil, false, { link = link, isJunk = false, reason = "No vendor price" };
end
end
end
return nil;
end
--========================================
-- Returns whether an item should
-- quick-vendor based on quality, type,
-- if it is already known, soulbound
--========================================
function ExtVendor_IsItemQuickVendor(bag, bagSlot, link, quality, itemLevel, itemReqLevel, bindType, alreadyKnown, itemClassId, itemSubClassId, equipSlot, requiredClasses, isAccountBound, expacID, isFoodOrDrink)
local itemID = ExtVendor_GetItemID(link);
local idx, id;
for idx, id in pairs(EXTVENDOR_INTERNAL_BLACKLIST) do
if (id == itemID) then
return false, nil, "Blacklisted internally";
end
end
local playerLevel = UnitLevel("player");
-- don't vendor blacklisted items
if (ExtVendor_IsBlacklisted(itemID)) then
return false, 100, "Blacklisted";
end
-- always vendor whitelisted items
if (ExtVendor_IsWhitelisted(itemID)) then
return true, L["QUICKVENDOR_REASON_WHITELISTED"], "Whitelisted";
end
-- never attempt to sell account-bound items (unless they're whitelisted)
if (isAccountBound) then
return false, nil, "Account-bound";
end
-- NEVER quick-vendor legendary or heirloom items. EVER. Ever. ever.
if (quality > 4) then
return false, nil, "Quality too high";
end
-- don't vendor equipment if it's part of an equipment set
if ((itemClassId == Enum.ItemClass.Armor) or (itemClassId == Enum.ItemClass.Weapon)) then
if (ExtVendor_IsItemInEquipmentSet(bag, bagSlot)) then return false, nil, "Part of equipment set"; end
end
-- *** Poor (grey) items ***
if (quality == 0) then
return true, L["QUICKVENDOR_REASON_POORQUALITY"], "Poor quality";
end
-- *** Common (white) gear ***
if (EXTVENDOR_DATA['config']['quickvendor_whitegear']) then
if (quality == 1) then
if (itemClassId == Enum.ItemClass.Armor) then
if ((itemSubClassId == Enum.ItemArmorSubclass.Cloth) or (itemSubClassId == Enum.ItemArmorSubclass.Leather) or (itemSubClassId == Enum.ItemArmorSubclass.Mail) or (itemSubClassId == Enum.ItemArmorSubclass.Plate)) then
if ((equipSlot ~= "INVTYPE_TABARD") and (equipSlot ~= "INVTYPE_SHIRT")) then
return true, L["QUICKVENDOR_REASON_WHITEGEAR"], "Common (white) armor";
end
end
elseif (itemClassId == Enum.ItemClass.Weapon) then
if ((itemSubClassId ~= Enum.ItemWeaponSubclass.Generic) and (itemSubClassId ~= Enum.ItemWeaponSubclass.Fishingpole)) then
return true, L["QUICKVENDOR_REASON_WHITEGEAR"], "Common (white) weapon";
end
end
end
end
if (EXTVENDOR_DATA['config']['quickvendor_oldfood']) then
if (isFoodOrDrink) then
if (ExtVendor_IsOutdatedItemLevel(itemLevel, playerLevel)) then
return true, L["QUICKVENDOR_REASON_OUTDATED_FOOD"], "Outdated food";
end
end
end
-- Soulbound stuff
if (bindType == 1) then
-- *** "Already Known" ***
if (EXTVENDOR_DATA['config']['quickvendor_alreadyknown']) then
if (alreadyKnown) then
return true, L["QUICKVENDOR_REASON_ALREADYKNOWN"], "Already known";
end
end
-- *** Unusable (class-restricted, unusable armor/weapon types) ***
if (EXTVENDOR_DATA['config']['quickvendor_unusable']) then
if (not ExtVendor_ClassIsAllowed(UnitClass("player"), requiredClasses)) then
return true, L["QUICKVENDOR_REASON_CLASSRESTRICTED"], "Class restricted";
end
if (not ExtVendor_IsUsableArmorType(itemClassId, itemSubClassId, equipSlot)) then
return true, L["QUICKVENDOR_REASON_UNUSABLEARMOR"], "Unusable armor";
end
if (not ExtVendor_IsUsableWeaponType(itemClassId, itemSubClassId, equipSlot)) then
return true, L["QUICKVENDOR_REASON_UNUSABLEWEAPON"], "Unusable weapon";
end
end
-- *** Sub-optimal armor ***
if (EXTVENDOR_DATA['config']['quickvendor_suboptimal']) then
if (not ExtVendor_IsOptimalArmor(itemClassId, itemSubClassId, equipSlot)) then
return true, L["QUICKVENDOR_REASON_SUBOPTIMAL"], "Sub-optimal armor";
end
end
-- *** Outdated gear ***
if (((quality == 3) or (quality == 4)) and ((itemClassId == Enum.ItemClass.Armor) or (itemClassId == Enum.ItemClass.Weapon)) and (equipSlot ~= "")) then
if (EXTVENDOR_DATA['config']['quickvendor_oldgear']) then
-- always ignore items from the account's expansion level (or higher)
if (expacID < GetAccountExpansionLevel()) then
-- ignore items with a minimum level requirement within 10 levels of the player, regardless of item level or expac (timewarped fix)
if (itemReqLevel < (playerLevel - 10)) then
if ((playerLevel >= (GEAR_OUTLEVEL_TABLE[expacID] or 999)) or ((expacID == 0) and (playerLevel >= (itemLevel + 12)))) then
return true, L["QUICKVENDOR_REASON_OUTDATED_GEAR"], "Outdated rare/epic equipment";
end
end
end
end
end
end
-- nothing matched = do not quickvendor
return false, nil, "No matching criteria";
end
--========================================
-- Performs quick-vendor
--========================================
function ExtVendor_ConfirmQuickVendor()
local link, count, itemName, color, itemQuality, itemLevel, itemMinLevel, sellPrice, itemStackCount, quantity, bindType, expacID, itemType, itemSubType, classId, subClassId, itemEquipLoc, itemTexture, setID, isCraftingReagent, __;
local isKnown, reqClasses, itemId, isAccountBound, isFoodOrDrink;
local bag, slot;
local totalPrice = 0;
local itemsOnLine = 0;
local numItemsSold = 0;
local itemsSold = "";
local soldPref = L["SOLD"];
if (not MerchantFrame:IsShown()) then return; end
EXTVENDOR.QuickVendor.ProcessJunkList = EXTVENDOR.QuickVendor.CurrentJunkList; --ExtVendor_GetQuickVendorList();
if (not EXTVENDOR.QuickVendor.ProcessJunkList) then return; end
if (table.maxn(EXTVENDOR.QuickVendor.ProcessJunkList) < 1) then return; end
-- use the progress window if the junk item list is bigger than 10 items
if (table.maxn(EXTVENDOR.QuickVendor.ProcessJunkList) > SELL_ITEM_GROUP_SIZE) then
ExtVendor_StartProcessQuickVendor();
return;
end
-- otherwise just do it the old way
for bag = 0, 4, 1 do
if (GetContainerNumSlots(bag)) then
for slot = 1, C_Container.GetContainerNumSlots(bag), 1 do
__, count = C_Container.GetContainerItemInfo(bag, slot);
link = C_Container.GetContainerItemLink(bag, slot);
if (link and count) then
itemName, __, itemQuality, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture, sellPrice, classID, subclassID, bindType, expacID, setID, isCraftingReagent = GetItemInfo(item)
--name, __, quality, itemLevel, itemReqLevel, itemType, itemSubType, maxStack, itemEquipLoc, __, price, itemClassId, subClassId, bindType, expacID = GetItemInfo(link)
isKnown, reqClasses, itemId, isAccountBound, isFoodOrDrink = ExtVendor_GetExtendedItemInfo(link);
if ((sellPrice or 0) > 0) then
if (ExtVendor_IsItemQuickVendor(bag, slot, link, itemQ, itemLevel, itemMinLevel, bindType, isKnown, classId, subClassId, itemEquipLoc, reqClasses, isAccountBound, expacID, isFoodOrDrink)) then
C_Container.PickupContainerItem(bag, slot);
C_Container.PickupMerchantItem(0);
__, __, __, color = GetItemQualityColor(itemQ);
if (itemsOnLine > 0) then
itemsSold = itemsSold .. ", ";
end
if (itemStackCount > 1) then
quantity = "x" .. count;
else
quantity = "";
end
itemsSold = itemsSold .. "|c" .. color .. "[" .. name .. "]|r" .. quantity;
itemsOnLine = itemsOnLine + 1;
if (itemsOnLine == 12) then
DEFAULT_CHAT_FRAME:AddMessage(soldPref .. " " .. itemsSold, ChatTypeInfo["SYSTEM"].r, ChatTypeInfo["SYSTEM"].g, ChatTypeInfo["SYSTEM"].b, GetChatTypeIndex("SYSTEM"));
soldPref = " ";
itemsSold = "";
itemsOnLine = 0;
end
totalPrice = totalPrice + (sellPrice * count);
numItemsSold = numItemsSold + 1;
end
end
end
end
end
end
if (numItemsSold > 0) then
DEFAULT_CHAT_FRAME:AddMessage(ExtVendor_FormatString(L["SOLD_COMPACT"], { ["count"] = numItemsSold, ["sellPrice"] = "|cffffffff" .. ExtVendor_FormatMoneyString(totalPrice) }), ChatTypeInfo["SYSTEM"].r, ChatTypeInfo["SYSTEM"].g, ChatTypeInfo["SYSTEM"].b, GetChatTypeIndex("SYSTEM"));
end
end
function ExtVendor_StartProcessQuickVendor()
if (EXTVENDOR.QuickVendor.Processing) then return; end
EXTVENDOR.QuickVendor.Processing = true;
EXTVENDOR.QuickVendor.TotalSellPrice = 0;
EXTVENDOR.QuickVendor.TotalItemsSold = 0;
ExtVendor_ShowProgressPopup();
ExtVendor_ProgressQuickVendor();
end
function ExtVendor_ProgressQuickVendor()
if (not EXTVENDOR.QuickVendor.Processing) then return nil; end
-- cancel the process if the vendor window is no longer shown
if (not MerchantFrame:IsShown()) then
ExtVendor_StopProcessQuickVendor();
return nil;
end
local link, count, itemName, color, itemQuality, itemLevel, itemMinLevel, sellPrice, itemStackCount, quantity, bindType, expacID, itemType, itemSubType, itemEquipLoc, classId, subClassId, itemTexture, setID, isCraftingReagent, __;
local isKnown, reqClasses, itemId, isAccountBound, isFoodOrDrink;
local bag, slot;
local totalPrice = 0;
local itemsOnLine = 0;
local numItemsSold = 0;
local itemsSold = "";
local soldPref = L["SOLD"];
local CANCEL = false;
for bag = 0, 4, 1 do
if (C_Container.GetContainerNumSlots(bag)) then
for slot = 1, C_Container.GetContainerNumSlots(bag), 1 do
if (not CANCEL) then
__, itemCount, locked = C_Container.GetContainerItemInfo(bag, slot);
if (not locked) then
link = GetContainerItemLink(bag, slot);
if (link and count) then
itemName, __, itemQuality, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture, sellPrice, classID, subclassID, bindType, expacID, setID, isCraftingReagent = GetItemInfo(item)
--name, __, quality, itemLevel, itemReqLevel, itemType, itemSubType, maxStack, itemEquipLoc, __, price, itemClassId, itemSubClassId, bindType, expacID = C_Container.GetItemInfo(link);
isKnown, reqClasses, itemId, isAccountBound, isFoodOrDrink = ExtVendor_GetExtendedItemInfo(link);
if ((sellPrice or 0) > 0) then
if (ExtVendor_IsItemQuickVendor(bag, slot, link, itemQuality, itemLevel, itemMinLevel, bindType, isKnown, classId, subClassId, itemEquipLoc, reqClasses, isAccountBound, expacID, isFoodOrDrink)) then
C_Container.PickupContainerItem(bag, slot);
PickupMerchantItem(0);
__, __, __, color = GetItemQualityColor(itemQuality);
if (itemsOnLine > 0) then
itemsSold = itemsSold .. ", ";
end
if (itemStackCount > 1) then
quantity = "x" .. count;
else
quantity = "";
end
itemsSold = itemsSold .. "|c" .. color .. "[" .. itemName .. "]|r" .. quantity;
itemsOnLine = itemsOnLine + 1;
totalPrice = totalPrice + (sellPrice * count);
numItemsSold = numItemsSold + 1;
if (numItemsSold >= SELL_ITEM_GROUP_SIZE) then CANCEL = true; end
end
end
end
end
end
end
end
end
EXTVENDOR.QuickVendor.TotalItemsSold = EXTVENDOR.QuickVendor.TotalItemsSold + numItemsSold;
EXTVENDOR.QuickVendor.TotalSellPrice = EXTVENDOR.QuickVendor.TotalSellPrice + totalPrice;
if (EXTVENDOR.QuickVendor.TotalItemsSold >= #EXTVENDOR.QuickVendor.ProcessJunkList) then
ExtVendor_StopProcessQuickVendor();
end
return numItemsSold, totalPrice, EXTVENDOR.QuickVendor.TotalItemsSold, EXTVENDOR.QuickVendor.TotalSellPrice;
end
function ExtVendor_StopProcessQuickVendor()
if (EXTVENDOR.QuickVendor.Processing) then
EXTVENDOR.QuickVendor.Processing = false;
if (EXTVENDOR.QuickVendor.TotalItemsSold > 0) then
DEFAULT_CHAT_FRAME:AddMessage(ExtVendor_FormatString(L["SOLD_COMPACT"], { ["count"] = EXTVENDOR.QuickVendor.TotalItemsSold, ["price"] = "|cffffffff" .. ExtVendor_FormatMoneyString(EXTVENDOR.QuickVendor.TotalSellPrice) }), ChatTypeInfo["SYSTEM"].r, ChatTypeInfo["SYSTEM"].g, ChatTypeInfo["SYSTEM"].b, GetChatTypeIndex("SYSTEM"));
end
end
ExtVendor_SellJunkProgressPopup:Hide();
ExtVendor_UpdateDisplay();
ExtVendor_OnQuickVendorStop();
end
--========================================
-- Returns whether or not the specified
-- item ID is blacklisted
--========================================
function ExtVendor_IsBlacklisted(itemId)
for idx, id in pairs(EXTVENDOR_DATA['quickvendor_blacklist']) do
if (id == itemId) then
return true;
end
end
return false;
end
--========================================
-- Returns whether or not the specified
-- item ID is whitelisted
--========================================
function ExtVendor_IsWhitelisted(itemId, globalOnly)
for idx, id in pairs(EXTVENDOR_DATA['quickvendor_whitelist']) do
if (id == itemId) then
return true;
end
end
if (not globalOnly) then
for idx, id in pairs(EXTVENDOR_DATA[EXTVENDOR.Profile]['quickvendor_whitelist']) do
if (id == itemId) then
return true;
end
end
end
return false;
end
--========================================
-- Shows or hides the quick vendor button
-- depending on configuration
--========================================
function ExtVendor_UpdateQuickVendorButtonVisibility()
if (EXTVENDOR_DATA['config']['enable_quickvendor']) then
MerchantFrameSellJunkButton:Show();
else
MerchantFrameSellJunkButton:Hide();
end
end