|
|
|
|
@ -18,11 +18,17 @@ function Gather:BuyFromMerchant(neededMats)
|
|
|
|
|
for i = 1, GetMerchantNumItems() do |
|
|
|
|
local itemString = TSMAPI:GetItemString(GetMerchantItemLink(i)) |
|
|
|
|
if neededMats[itemString] then |
|
|
|
|
local _, _, _, quantity = GetMerchantItemInfo(i) |
|
|
|
|
local maxStack = GetMerchantItemMaxStack(i) |
|
|
|
|
quantity = max(quantity or 1, 1) |
|
|
|
|
local toBuy = neededMats[itemString] |
|
|
|
|
while toBuy > 0 do |
|
|
|
|
BuyMerchantItem(i, math.min(toBuy, maxStack)) |
|
|
|
|
toBuy = toBuy - maxStack |
|
|
|
|
local buyCount = math.ceil(toBuy / quantity) |
|
|
|
|
if maxStack and maxStack > 0 then |
|
|
|
|
buyCount = math.min(buyCount, maxStack) |
|
|
|
|
end |
|
|
|
|
BuyMerchantItem(i, buyCount) |
|
|
|
|
toBuy = toBuy - (buyCount * quantity) |
|
|
|
|
TSM.db.realm.gathering.gatheredMats = true |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|