diff --git a/Changelog b/Changelog index 62546ca..56596fd 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,9 @@ Changelog +v1.7 + - Indexing items by itemId rather than name + - Using item level as a sub-index + v1.6 - Improved search algorithm to avoid trading house error messages - Properly changing guilds between searches to avoid error messages diff --git a/PriceTracker.lua b/PriceTracker.lua index dd681e1..108d105 100644 --- a/PriceTracker.lua +++ b/PriceTracker.lua @@ -5,7 +5,7 @@ PriceTracker = { queryDelay = 3000, isSearching = false, - settingsVersion = 0.2, + settingsVersion = 0.3, icons = { gold = "EsoUI/Art/currency/currency_gold.dds" }, @@ -98,11 +98,17 @@ end -- This method makes sure the item list is intact and parsable, in order to avoid exceptions later on function PriceTracker:Housekeeping() - if not self.settings.itemList then return end + if not self.settings.itemList then + self.settings.itemList = {} + end + for k, v in pairs(self.settings.itemList) do -- Remove any empty items - for p, q in pairs(v) do - if not q.purchasePrice or not q.stackCount then v[p] = nil end + for level, item in pairs(v) do + for p, q in pairs(item) do + if not q.purchasePrice or not q.stackCount then v[p] = nil end + end + if not next(item) then self.settings.itemList[k][level] = nil end end if not next(v) then self.settings.itemList[k] = nil end end @@ -115,7 +121,21 @@ function PriceTracker:OnUpdateTooltip(item, tooltip) local stackCount = item.dataEntry.data.stackCount or item.dataEntry.data.stack if not stackCount then return end - local matches = self:GetMatches(item.dataEntry.data.name) + -- Attempt to find the item ID and level + local itemId = item.dataEntry.data.itemId + local level = item.dataEntry.data.level + if not item.dataEntry.data.itemId then + if item.dataEntry.data.searchData then + -- Must be a bag or bank item + _, _, _, itemId, _, level = ZO_LinkHandler_ParseLink(GetItemLink(item.dataEntry.data.searchData.bagId, item.dataEntry.data.searchData.slotIndex, item.dataEntry.data.searchData.type)) + end + if item.dataEntry.data.itemIndex then + -- Must be a store item + _, _, _, itemId, _, level = ZO_LinkHandler_ParseLink(GetTradingHouseSearchResultItemLink(item.dataEntry.data.itemIndex)) + end + end + + local matches = self:GetMatches(itemId, level) if not matches then return end local item = self:SuggestPrice(matches) @@ -166,7 +186,7 @@ function PriceTracker:OnSearchResultsReceived(eventId, guildId, numItemsOnPage, if not self.isSearching then return end for i = 1, numItemsOnPage do - self:AddItem(GetTradingHouseSearchResultItemInfo(i)) + self:AddItem(i) end self.currentPage = currentPage @@ -189,6 +209,8 @@ function PriceTracker:OnSearchResultsReceived(eventId, guildId, numItemsOnPage, end function PriceTracker:OnSearchResultsError(eventCode, errorCode) + if not self.isSearching then return end + self:OnSearchResultsReceived(eventCode, self.currentGuild, 0, self.currentPage, false) zo_callLater(function() ExecuteTradingHouseSearch(self.currentPage, TRADING_HOUSE_SORT_SALE_PRICE, true) end, GetTradingHouseCooldownRemaining() + 1000) end @@ -202,41 +224,58 @@ function PriceTracker:OnLinkClicked(rawLink, mouseButton, linkText, color, linkT if linkType ~= "item" then return end local _, sellPrice, _, _, _ = GetItemLinkInfo(rawLink) + local _, _, _, _, level = ZO_LinkHandler_ParseLink(rawLink) local item = { dataEntry = { data = { name = self:NormalizeName(string.sub(linkText, 2, #linkText - 1)), stackCount = 1, - purchasePrice = sellPrice + purchasePrice = sellPrice, + itemId = itemId, + level = level } } } self.clickedItem = item end -function PriceTracker:AddItem(icon, itemName, quality, stackCount, sellerName, timeRemaining, purchasePrice) +function PriceTracker:AddItem(index) + local icon, itemName, quality, stackCount, sellerName, timeRemaining, purchasePrice = GetTradingHouseSearchResultItemInfo(index) + local _, _, _, itemId, _, level, enchantmentType, enchantmentStrength1, enchantmentStrength2, _, _, _, _, _, _, _, _, _, style, crafted, _, charge = ZO_LinkHandler_ParseLink(GetTradingHouseSearchResultItemLink(index)) + if not purchasePrice or not stackCount then return end - local item = {} - item.expiry = timeRemaining + GetTimeStamp() - item.icon = icon - item.name = itemName - item.normalizedName = self:NormalizeName(itemName) - item.quality = quality - item.stackCount = stackCount - item.sellerName = sellerName - item.purchasePrice = purchasePrice - item.eachPrice = purchasePrice / stackCount - item.guildId = self.currentGuild - item.guildName = GetGuildName(item.guildId) - - if not self.settings.itemList[item.normalizedName] then - self.settings.itemList[item.normalizedName] = {} + local item = { + expiry = timeRemaining + GetTimeStamp(), + icon = icon, + name = itemName, + normalizedName = self:NormalizeName(itemName), + quality = quality, + stackCount = stackCount, + sellerName = sellerName, + purchasePrice = purchasePrice, + eachPrice = purchasePrice / stackCount, + guildId = self.currentGuild, + guildName = GetGuildName(self.currentGuild), + enchantmentType = enchantmentType, + enchantmentStrength1 = enchantmentStrength1, + enchantmentStrength2 = enchantmentStrength2, + style = style, + crafted = (crafted == 1), + charge = charge + } + + if not self.settings.itemList[itemId] then + self.settings.itemList[itemId] = {} + end + + if not self.settings.itemList[itemId][level] then + self.settings.itemList[itemId][level] = {} end -- Do not add items that are already in the database - if not self.settings.itemList[item.normalizedName][item.expiry] then - self.settings.itemList[item.normalizedName][item.expiry] = item + if not self.settings.itemList[itemId][level][item.expiry] then + self.settings.itemList[itemId][level][item.expiry] = item end end @@ -251,20 +290,26 @@ function PriceTracker:CleanItemList() end end -function PriceTracker:GetMatches(itemName) - local normalizedName = self:NormalizeName(itemName) - if not self.settings.itemList or not self.settings.itemList[normalizedName] then +function PriceTracker:GetMatches(itemId, itemLevel) + if not self.settings.itemList or not self.settings.itemList[itemId] then return nil end local limitToGuild = self.settings.limitToGuild or 1 local matches = {} - for k, v in pairs(self.settings.itemList[normalizedName]) do - if limitToGuild == 1 or v.guildId == GetGuildId(limitToGuild - 1) then - table.insert(matches, v) + for level, items in pairs(self.settings.itemList[itemId]) do + if (not itemLevel or itemLevel == level) then + local index = next(items) + while index do + if limitToGuild == 1 or items[index].guildId == GetGuildId(limitToGuild - 1) then + table.insert(matches, items[index]) + end + index = next(items, index) + end end end + if #matches == 0 then return nil end return matches end diff --git a/PriceTracker.txt b/PriceTracker.txt index 99edc24..da2dbf3 100644 --- a/PriceTracker.txt +++ b/PriceTracker.txt @@ -1,6 +1,6 @@ ## Title: PriceTracker ## Author: Barvazon -## Version: 1.6 +## Version: 1.7 ## SavedVariables: PriceTrackerSettings ## APIVersion: 100007 ## OptionalDependsOn: LibAddonMenu-2.0 diff --git a/PriceTrackerEnchantingTable.lua b/PriceTrackerEnchantingTable.lua index 5948002..31bd8ce 100644 --- a/PriceTrackerEnchantingTable.lua +++ b/PriceTrackerEnchantingTable.lua @@ -47,12 +47,18 @@ function PriceTrackerEnchantingTable:UpdateEnchantingTooltip() GetEnchantingResultingItemInfo(self.enchantingRunes.potency.bagId, self.enchantingRunes.potency.itemIndex, self.enchantingRunes.essence.bagId, self.enchantingRunes.essence.itemIndex, self.enchantingRunes.aspect.bagId, self.enchantingRunes.aspect.itemIndex) + local _, _, _, itemId, level = + ZO_LinkHandler_ParseLink(GetEnchantingResultingItemLink(self.enchantingRunes.potency.bagId, self.enchantingRunes.potency.itemIndex, + self.enchantingRunes.essence.bagId, self.enchantingRunes.essence.itemIndex, + self.enchantingRunes.aspect.bagId, self.enchantingRunes.aspect.itemIndex)) local item = { dataEntry = { data = { name = PriceTracker:NormalizeName(name), stackCount = 1, - purchasePrice = sellPrice + purchasePrice = sellPrice, + itemId = itemId, + level = level } } }