-
Notifications
You must be signed in to change notification settings - Fork 1
/
Merchant.lua
executable file
·69 lines (56 loc) · 1.89 KB
/
Merchant.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
local addonName, ATOM = ...
local Module = ATOM:NewModule('Merchant')
local RepairItems, SellGreyItems
function Module:OnEnable()
self:RegisterEvent('MERCHANT_SHOW')
end
function Module:OnDisable()
self:UnregisterEvent('MERCHANT_SHOW')
end
function Module:MERCHANT_SHOW()
RepairItems()
if not _G['ZygorGuidesViewer'] --[[ and not select(4, GetAddOnInfo('TradeSkillMaster_Vendoring')) ]] then
SellGreyItems()
end
end
function RepairItems()
if CanMerchantRepair() then
local repairAllCost, canRepair = GetRepairAllCost()
if canRepair and repairAllCost <= GetMoney() then
RepairAllItems()
ATOM:Print('|cff80ff80REPAIRS COMPLETED FOR |cffffff80%s|r', GetMoneyString(repairAllCost))
end
end
end
function SellGreyItems()
local bag, slot
local totalprofit = 0
for bag = BACKPACK_CONTAINER, NUM_BAG_SLOTS do
for slot = 1, C_Container.GetContainerNumSlots(bag) do
local item = C_Container.GetContainerItemInfo(bag, slot)
if item and item.hyperlink and item.quality == 0 then
local vendorPrice = select(11, GetItemInfo(item.hyperlink))
if vendorPrice > 0 then
totalprofit = totalprofit + vendorPrice * item.stackCount
C_Container.UseContainerItem(bag, slot)
end
end
end
end
if totalprofit > 0 then
ATOM:Print('|cff80ff80TOTAL PROFIT OF |cffffff80%s|cff80ff80 ON SOLD GREYS|r', GetMoneyString(totalprofit))
end
end
--[[
Buy a stack of items from a vendor. This will by pass the
purchase confirmation given by some merchants.
--]]
function ATOM:BuyItem(name, quantity)
local slot
for slot = 1, GetMerchantNumItems() do
if name == GetMerchantItemInfo(slot) then
BuyMerchantItem(slot, quantity or 1)
break
end
end
end