@ -14,15 +14,32 @@ local L = LibStub("AceLocale-3.0"):GetLocale("TradeSkillMaster_Crafting") -- loa
local next = next
local private = { shoppingItems = { } }
local function IsCrafterPlayer ( crafter )
if not crafter then return false end
local player = UnitName ( " player " )
if not player then return false end
if strlower ( crafter ) == strlower ( player ) then
return true
end
local baseName = strmatch ( crafter , " ^[^-]+ " )
return baseName and strlower ( baseName ) == strlower ( player ) or false
end
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
@ -31,12 +48,13 @@ end
function Gather : gatherItems ( source , task )
local items = TSM.db . realm.gathering . availableMats
local crafter = TSM.db . realm.gathering . crafter
if source == L [ " Vendor " ] then
Gather : BuyFromMerchant ( items )
elseif source == UnitName ( " player " ) and ( task == L [ " Visit Bank " ] or task == L [ " Visit Guild Bank " ] ) then
Gather : GatherBank ( items )
elseif source == UnitName ( " player " ) and task == L [ " Collect Mail " ] then
elseif source == UnitName ( " player " ) and ( task == L [ " Collect Mail " ] or ( task == L [ " Mail Items " ] and IsCrafterPlayer ( crafter ) ) ) then
TSMAPI : ModuleAPI ( " Mailing " , " collectItems " , items , Gather.PrintMsg )
elseif source == UnitName ( " player " ) and task == L [ " Mail Items " ] then
Gather : MailItems ( items )
@ -168,23 +186,23 @@ function Gather:ShoppingSearch(itemString, need, ignoreMaxQty)
TSMAPI : ModuleAPI ( " Shopping " , " runDestroySearch " , TSMAPI : GetSafeItemInfo ( itemString ) .. " /x " .. need , ShoppingCallback )
end
else
TSMAPI : ModuleAPI ( " Shopping " , " runSearch " , TSMAPI : GetSafeItemInfo ( itemString ) .. " /exact/x " .. need , ShoppingCallback )
TSMAPI : ModuleAPI ( " Shopping " , " runSearch " , TSMAPI : GetSafeItemInfo ( itemString ) .. " /exact/x " .. need , ShoppingCallback , true )
end
else
TSM.Inventory . gatherItem = nil
if ignoreMaxQty then
TSMAPI : ModuleAPI ( " Shopping " , " runSearch " , TSMAPI : GetSafeItemInfo ( itemString ) .. " /exact " , ShoppingCallback )
TSMAPI : ModuleAPI ( " Shopping " , " runSearch " , TSMAPI : GetSafeItemInfo ( itemString ) .. " /exact " , ShoppingCallback , true )
else
TSMAPI : ModuleAPI ( " Shopping " , " runSearch " , TSMAPI : GetSafeItemInfo ( itemString ) .. " /exact/x " .. need , ShoppingCallback )
TSMAPI : ModuleAPI ( " Shopping " , " runSearch " , TSMAPI : GetSafeItemInfo ( itemString ) .. " /exact/x " .. need , ShoppingCallback , true )
end
end
else
TSM.Inventory . gatherItem = nil
if ignoreMaxQty then
TSMAPI : ModuleAPI ( " Shopping " , " runSearch " , TSMAPI : GetSafeItemInfo ( itemString ) .. " /exact " , ShoppingCallback )
TSMAPI : ModuleAPI ( " Shopping " , " runSearch " , TSMAPI : GetSafeItemInfo ( itemString ) .. " /exact " , ShoppingCallback , true )
else
TSMAPI : ModuleAPI ( " Shopping " , " runSearch " , TSMAPI : GetSafeItemInfo ( itemString ) .. " /exact/x " .. need , ShoppingCallback )
TSMAPI : ModuleAPI ( " Shopping " , " runSearch " , TSMAPI : GetSafeItemInfo ( itemString ) .. " /exact/x " .. need , ShoppingCallback , true )
end
end
end