/GetSalesPriceTip.lua Secret
Last active
May 6, 2020 21:56
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function upgradeItemLink(itemLink) | |
local itemQuality = GetItemLinkQuality(itemLink) | |
if itemQuality == 2 then | |
return itemLink:gsub(':' .. '359' .. ':', ':' .. '362' .. ':') | |
end | |
if itemQuality == 3 then | |
return itemLink:gsub(':' .. '362' .. ':', ':' .. '363' .. ':') | |
end | |
if itemQuality == 4 then | |
return itemLink:gsub(':' .. '363' .. ':', ':' .. '364' .. ':') | |
end | |
return nil | |
end | |
local function countItemsListedSold(prices, saleType) | |
local result = '' | |
local countListed = 0 | |
if prices.countListed ~= nil then | |
countListed = prices.countListed | |
end | |
local countSold = 0 | |
if prices.countSold ~= nil then | |
countSold = prices.countSold | |
end | |
local itemCount = 0 | |
if prices.itemCount ~= nil then | |
itemCount = prices.itemCount | |
end | |
if saleType == 'list' and countListed > 0 then | |
if countListed >= 1000 then | |
result = result .. tostring(math.floor(countListed / 1000)) .. 'k listed' | |
else | |
result = result .. tostring(countListed) .. ' listed' | |
end | |
if countSold > 0 then | |
result = result .. ', ' | |
end | |
end | |
if saleType == 'sold' then | |
if countSold >= 1000 then | |
result = result .. tostring(math.floor(countSold / 1000)) .. 'k sold' | |
elseif countSold > 0 then | |
result = result .. tostring(countSold) .. ' sold' | |
end | |
end | |
if saleType == 'both' then | |
if itemCount > countSold + countListed then | |
if itemCount >= 1000000 then | |
result = result .. ', ' .. tostring(math.floor(itemCount / 1000000)) .. 'M items' | |
elseif itemCount >= 1000 then | |
result = result .. ', ' .. tostring(math.floor(itemCount / 1000)) .. 'k items' | |
else | |
result = result .. ', ' .. tostring(itemCount) .. ' items' | |
end | |
end | |
end | |
return result | |
end | |
function uespLog.GetSalesPriceTip(itemLink, isChat) | |
if (itemLink == nil) then | |
return '' | |
end | |
local itemQuality = GetItemLinkQuality(itemLink) | |
local prices = uespLog.FindSalesPrice(itemLink) | |
local newItemLink = itemLink:gsub('|H0:', '|H1:') | |
if prices == nil then | |
if (isChat) then | |
return 'UESP has no price data for ' .. tostring(newItemLink) | |
end | |
return '' | |
end | |
local price = prices.price | |
local countSold = prices.countSold | |
local countListed = prices.countListed | |
local itemCount = prices.items | |
local saleType = uespLog.GetSalesShowSaleType() | |
if (countSold + countListed == 0) then | |
if (isChat) then | |
return 'UESP has no price data for ' .. tostring(newItemLink) | |
else | |
return '' | |
end | |
end | |
local msg = 'UESP price' | |
local currentCount = countItemsListedSold(prices, saleType) | |
if itemQuality > 1 and itemQuality < 5 then | |
local superiorItemLink = '' | |
local epicItemLink = '' | |
local legendaryItemLink = '' | |
local superiorPrices | |
local epicPrices | |
local legendaryPrices | |
if itemQuality == 2 then | |
superiorItemLink = upgradeItemLink(itemLink) | |
superiorPrices = uespLog.FindSalesPrice(superiorItemLink) | |
epicItemLink = upgradeItemLink(superiorItemLink) | |
epicPrices = uespLog.FindSalesPrice(epicItemLink) | |
legendaryItemLink = upgradeItemLink(epicItemLink) | |
legendaryPrices = uespLog.FindSalesPrice(legendaryItemLink) | |
if saleType == 'list' then | |
msg = string.format('%s\nFine (%s): %s', msg, currentCount, price) | |
if superiorPrices ~= nil and superiorPrices.priceListed > 0 then | |
msg = string.format('%s\nSuperior (%s): %s', msg, countItemsListedSold(superiorPrices, saleType), superiorPrices.priceListed) | |
end | |
if epicPrices ~= nil and epicPrices.priceListed > 0 then | |
msg = string.format('%s\nEpic (%s): %s', msg, countItemsListedSold(epicPrices, saleType), epicPrices.priceListed) | |
end | |
if legendaryPrices ~= nil and legendaryPrices.priceListed > 0 then | |
msg = string.format('%s\nLegendary (%s): %s', msg, countItemsListedSold(legendaryPrices, saleType), legendaryPrices.priceListed) | |
end | |
elseif saleType == 'sold' then | |
msg = string.format('%s\nFine (%s): %s', msg, currentCount, price) | |
if superiorPrices ~= nil and superiorPrices.priceSold > 0 then | |
msg = string.format('%s\nSuperior (%s): %s', msg, countItemsListedSold(superiorPrices, saleType), superiorPrices.priceSold) | |
end | |
if epicPrices ~= nil and epicPrices.priceSold > 0 then | |
msg = string.format('%s\nEpic (%s): %s', msg, countItemsListedSold(epicPrices, saleType), epicPrices.priceSold) | |
end | |
if legendaryPrices ~= nil and legendaryPrices.priceSold > 0 then | |
msg = string.format('%s\nLegendary (%s): %s', msg, countItemsListedSold(legendaryPrices, saleType), legendaryPrices.priceSold) | |
end | |
end | |
elseif itemQuality == 3 then | |
epicItemLink = upgradeItemLink(itemLink) | |
epicPrices = uespLog.FindSalesPrice(epicItemLink) | |
legendaryItemLink = upgradeItemLink(epicItemLink) | |
legendaryPrices = uespLog.FindSalesPrice(legendaryItemLink) | |
if saleType == 'list' then | |
msg = string.format('%s\nSuperior (%s): %s', msg, currentCount, price) | |
if epicPrices ~= nil and epicPrices.priceListed > 0 then | |
msg = string.format('%s\nEpic (%s): %s', msg, countItemsListedSold(epicPrices, saleType), epicPrices.priceListed) | |
end | |
if legendaryPrices ~= nil and legendaryPrices.priceListed > 0 then | |
msg = string.format('%s\nLegendary (%s): %s', msg, countItemsListedSold(legendaryPrices, saleType), legendaryPrices.priceListed) | |
end | |
elseif saleType == 'sold' then | |
msg = string.format('%s\nSuperior (%s): %s', msg, currentCount, price) | |
if epicPrices ~= nil and epicPrices.priceSold > 0 then | |
msg = string.format('%s\nEpic (%s): %s', msg, countItemsListedSold(epicPrices, saleType), epicPrices.priceSold) | |
end | |
if legendaryPrices ~= nil and legendaryPrices.priceSold > 0 then | |
msg = string.format('%s\nLegendary (%s): %s', msg, countItemsListedSold(legendaryPrices, saleType), legendaryPrices.priceSold) | |
end | |
end | |
elseif itemQuality == 4 then | |
legendaryItemLink = upgradeItemLink(itemLink) | |
legendaryPrices = uespLog.FindSalesPrice(legendaryItemLink) | |
if saleType == 'list' then | |
msg = string.format('%s\nEpic (%s): %s', msg, currentCount, price) | |
if legendaryPrices ~= nil and legendaryPrices.priceListed > 0 then | |
msg = string.format('%s\nLegendary (%s): %s', msg, countItemsListedSold(legendaryPrices, saleType), legendaryPrices.priceListed) | |
end | |
elseif saleType == 'sold' then | |
msg = string.format('%s\nEpic (%s): %s', msg, currentCount, price) | |
if legendaryPrices ~= nil and legendaryPrices.priceSold > 0 then | |
msg = string.format('%s\nLegendary (%s): %s', msg, countItemsListedSold(legendaryPrices, saleType), legendaryPrices.priceSold) | |
end | |
end | |
end | |
else | |
msg = msg .. ' (' .. currentCount .. '): ' .. tostring(price) | |
end | |
if (isChat) then | |
msg = msg .. ' gp for ' .. tostring(newItemLink) | |
end | |
return msg | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment