@ -125,6 +125,8 @@ function TSM:RegisterModule()
TSM.priceSources = {
TSM.priceSources = {
{ key = " avgSell " , label = L [ " Avg Sell Price " ] , callback = " GetAvgSellPrice " } ,
{ key = " avgSell " , label = L [ " Avg Sell Price " ] , callback = " GetAvgSellPrice " } ,
{ key = " avgBuy " , label = L [ " Avg Buy Price " ] , callback = " GetAvgBuyPrice " } ,
{ key = " avgBuy " , label = L [ " Avg Buy Price " ] , callback = " GetAvgBuyPrice " } ,
{ key = " smartAvgBuy " , label = L [ " Smart Avg Buy Price " ] , callback = " GetSmartAvgBuyPrice " } ,
{ key = " lastBuy " , label = L [ " Last Buy Price " ] , callback = " GetLastBuyPrice " } ,
{ key = " maxSell " , label = L [ " Max Sell Price " ] , callback = " GetMaxSellPrice " } ,
{ key = " maxSell " , label = L [ " Max Sell Price " ] , callback = " GetMaxSellPrice " } ,
{ key = " maxBuy " , label = L [ " Max Buy Price " ] , callback = " GetMaxBuyPrice " } ,
{ key = " maxBuy " , label = L [ " Max Buy Price " ] , callback = " GetMaxBuyPrice " } ,
{ key = " minSell " , label = L [ " Min Sell Price " ] , callback = " GetMinSellPrice " } ,
{ key = " minSell " , label = L [ " Min Sell Price " ] , callback = " GetMinSellPrice " } ,
@ -187,6 +189,7 @@ function TSM:GetTooltip(itemString)
if TSM.db . realm.tooltip . purchase and TSM.items [ itemString ] and # TSM.items [ itemString ] . buys > 0 then
if TSM.db . realm.tooltip . purchase and TSM.items [ itemString ] and # TSM.items [ itemString ] . buys > 0 then
local lastPurchased = TSM.items [ itemString ] . buys [ # TSM.items [ itemString ] . buys ] . time
local lastPurchased = TSM.items [ itemString ] . buys [ # TSM.items [ itemString ] . buys ] . time
local lastBuyPrice = TSM : GetLastBuyPrice ( itemString )
local totalPrice , totalNum = 0 , 0
local totalPrice , totalNum = 0 , 0
for _ , record in ipairs ( TSM.items [ itemString ] . buys ) do
for _ , record in ipairs ( TSM.items [ itemString ] . buys ) do
totalNum = totalNum + record.quantity
totalNum = totalNum + record.quantity
@ -202,15 +205,30 @@ function TSM:GetTooltip(itemString)
else
else
local avgPrice = TSM : GetAvgBuyPrice ( itemString )
local avgPrice = TSM : GetAvgBuyPrice ( itemString )
local maxPrice = TSM : GetMaxBuyPrice ( itemString )
local maxPrice = TSM : GetMaxBuyPrice ( itemString )
local smartAvgPrice = TSM : GetSmartAvgBuyPrice ( itemString )
if moneyCoinsTooltip then
if moneyCoinsTooltip then
tinsert ( text , { left = " " .. L [ " Purchased (Avg/Max Price): " ] , right = format ( " %s (%s / %s) " , " |cffffffff " .. totalNum .. " |r " , ( TSMAPI : FormatTextMoneyIcon ( avgPrice , " |cffffffff " , true ) or ( " |cffffffff " .. " ? " ) ) , ( TSMAPI : FormatTextMoneyIcon ( maxPrice , " |cffffffff " , true ) or ( " |cffffffff " .. " ? " ) ) ) } )
tinsert ( text , { left = " " .. L [ " Purchased (Avg/Max Price): " ] , right = format ( " %s (%s / %s) " , " |cffffffff " .. totalNum .. " |r " , ( TSMAPI : FormatTextMoneyIcon ( avgPrice , " |cffffffff " , true ) or ( " |cffffffff " .. " ? " ) ) , ( TSMAPI : FormatTextMoneyIcon ( maxPrice , " |cffffffff " , true ) or ( " |cffffffff " .. " ? " ) ) ) } )
else
else
tinsert ( text , { left = " " .. L [ " Purchased (Avg/Max Price): " ] , right = format ( " %s (%s / %s) " , " |cffffffff " .. totalNum .. " |r " , ( TSMAPI : FormatTextMoney ( avgPrice , " |cffffffff " , true ) or ( " |cffffffff " .. " ? " ) ) , ( TSMAPI : FormatTextMoney ( maxPrice , " |cffffffff " , true ) or ( " |cffffffff " .. " ? " ) ) ) } )
tinsert ( text , { left = " " .. L [ " Purchased (Avg/Max Price): " ] , right = format ( " %s (%s / %s) " , " |cffffffff " .. totalNum .. " |r " , ( TSMAPI : FormatTextMoney ( avgPrice , " |cffffffff " , true ) or ( " |cffffffff " .. " ? " ) ) , ( TSMAPI : FormatTextMoney ( maxPrice , " |cffffffff " , true ) or ( " |cffffffff " .. " ? " ) ) ) } )
end
end
if smartAvgPrice then
if moneyCoinsTooltip then
tinsert ( text , { left = " " .. L [ " Smart Avg Buy Price: " ] , right = ( TSMAPI : FormatTextMoneyIcon ( smartAvgPrice , " |cffffffff " , true ) or ( " |cffffffff " .. " ? " ) ) } )
else
tinsert ( text , { left = " " .. L [ " Smart Avg Buy Price: " ] , right = ( TSMAPI : FormatTextMoney ( smartAvgPrice , " |cffffffff " , true ) or ( " |cffffffff " .. " ? " ) ) } )
end
end
end
end
if lastPurchased then
if lastPurchased then
local timeDiff = SecondsToTime ( time ( ) - lastPurchased )
local timeDiff = SecondsToTime ( time ( ) - lastPurchased )
tinsert ( text , { left = " " .. L [ " Last Purchased: " ] , right = " |cffffffff " .. format ( L [ " %s ago " ] , timeDiff ) } )
tinsert ( text , { left = " " .. L [ " Last Purchased: " ] , right = " |cffffffff " .. format ( L [ " %s ago " ] , timeDiff ) } )
if lastBuyPrice then
if moneyCoinsTooltip then
tinsert ( text , { left = " " .. L [ " Last Buy Price: " ] , right = ( TSMAPI : FormatTextMoneyIcon ( lastBuyPrice , " |cffffffff " , true ) or ( " |cffffffff " .. " ? " ) ) } )
else
tinsert ( text , { left = " " .. L [ " Last Buy Price: " ] , right = ( TSMAPI : FormatTextMoney ( lastBuyPrice , " |cffffffff " , true ) or ( " |cffffffff " .. " ? " ) ) } )
end
end
end
end
end
end
@ -424,12 +442,24 @@ function TSM:GetAvgSellPrice(itemString)
return TSM.cache [ itemString ] . avgSellPrice , TSM.cache [ itemString ] . avgSellNum
return TSM.cache [ itemString ] . avgSellPrice , TSM.cache [ itemString ] . avgSellNum
end
end
local function GetAvgerageBuyPrice ( itemString , noBaseItem )
local function GetSmartBuyItemCount ( itemString )
local player , alts = TSMAPI : ModuleAPI ( " ItemTracker " , " playertotal " , itemString )
if not player then
alts = nil
end
player = player or 0
alts = alts or 0
local guild = TSMAPI : ModuleAPI ( " ItemTracker " , " guildtotal " , itemString ) or 0
local auctions = TSMAPI : ModuleAPI ( " ItemTracker " , " auctionstotal " , itemString ) or 0
return player + alts + guild + auctions
end
local function GetAvgerageBuyPrice ( itemString , noBaseItem , useSmart )
if not noBaseItem and itemString and baseItemLookup [ itemString ] then
if not noBaseItem and itemString and baseItemLookup [ itemString ] then
local totalPrice , totalNum = 0 , 0
local totalPrice , totalNum = 0 , 0
for _ , item in ipairs ( baseItemLookup [ itemString ] ) do
for _ , item in ipairs ( baseItemLookup [ itemString ] ) do
if not baseItemLookup [ item ] then
if not baseItemLookup [ item ] then
local price , num = GetAvgerageBuyPrice ( item , true )
local price , num = GetAvgerageBuyPrice ( item , true , useSmart )
if price and num and num > 0 then
if price and num and num > 0 then
totalPrice = totalPrice + price
totalPrice = totalPrice + price
totalNum = totalNum + num
totalNum = totalNum + num
@ -443,16 +473,11 @@ local function GetAvgerageBuyPrice(itemString, noBaseItem)
if not ( TSM.items [ itemString ] and # TSM.items [ itemString ] . buys > 0 ) then return end
if not ( TSM.items [ itemString ] and # TSM.items [ itemString ] . buys > 0 ) then return end
local itemCount = 0
local itemCount = 0
if TSM.db . realm.smartBuyPrice then
if useSmart or TSM.db . realm.smartBuyPrice then
local player , alts = TSMAPI : ModuleAPI ( " ItemTracker " , " playertotal " , itemString )
itemCount = GetSmartBuyItemCount ( itemString )
if not player then
if useSmart and itemCount <= 0 then
alts = nil
return
end
end
player = player or 0
alts = alts or 0
local guild = TSMAPI : ModuleAPI ( " ItemTracker " , " guildtotal " , itemString ) or 0
local auctions = TSMAPI : ModuleAPI ( " ItemTracker " , " auctionstotal " , itemString ) or 0
itemCount = player + alts + guild + auctions
end
end
local num , totalPrice = 0 , 0
local num , totalPrice = 0 , 0
@ -482,6 +507,19 @@ function TSM:GetAvgBuyPrice(itemString)
return TSM.cache [ itemString ] . avgBuyPrice , TSM.cache [ itemString ] . avgBuyNum
return TSM.cache [ itemString ] . avgBuyPrice , TSM.cache [ itemString ] . avgBuyNum
end
end
function TSM : GetSmartAvgBuyPrice ( itemString )
itemString = TSMAPI : GetItemString ( select ( 2 , TSMAPI : GetSafeItemInfo ( itemString ) ) )
if not itemString then return end
TSM.cache [ itemString ] = TSM.cache [ itemString ] or { }
TSM : UpdateBaseItemLookup ( )
if not TSM.cache [ itemString ] . smartAvgBuyPrice then
local price , num = GetAvgerageBuyPrice ( itemString , nil , true )
TSM.cache [ itemString ] . smartAvgBuyPrice = price
TSM.cache [ itemString ] . smartAvgBuyNum = num
end
return TSM.cache [ itemString ] . smartAvgBuyPrice , TSM.cache [ itemString ] . smartAvgBuyNum
end
function TSM : GetMaxSellPrice ( itemString )
function TSM : GetMaxSellPrice ( itemString )
itemString = TSMAPI : GetItemString ( select ( 2 , TSMAPI : GetSafeItemInfo ( itemString ) ) )
itemString = TSMAPI : GetItemString ( select ( 2 , TSMAPI : GetSafeItemInfo ( itemString ) ) )
if not ( itemString and TSM.items [ itemString ] and # TSM.items [ itemString ] . sales > 0 ) then return end
if not ( itemString and TSM.items [ itemString ] and # TSM.items [ itemString ] . sales > 0 ) then return end
@ -546,6 +584,19 @@ function TSM:GetMinBuyPrice(itemString)
return TSM.cache [ itemString ] . minBuyPrice
return TSM.cache [ itemString ] . minBuyPrice
end
end
function TSM : GetLastBuyPrice ( itemString )
itemString = TSMAPI : GetItemString ( select ( 2 , TSMAPI : GetSafeItemInfo ( itemString ) ) )
if not ( itemString and TSM.items [ itemString ] and # TSM.items [ itemString ] . buys > 0 ) then return end
TSM.cache [ itemString ] = TSM.cache [ itemString ] or { }
if not TSM.cache [ itemString ] . lastBuyPrice then
local lastRecord = TSM.items [ itemString ] . buys [ # TSM.items [ itemString ] . buys ]
TSM.cache [ itemString ] . lastBuyPrice = lastRecord and lastRecord.copper or nil
end
return TSM.cache [ itemString ] . lastBuyPrice
end
function TSM : Round ( value , sig )
function TSM : Round ( value , sig )
sig = sig or 1
sig = sig or 1
local gold = value / sig
local gold = value / sig