From 6c8cc1147e32a2f013c9a84491d6f3503867f2f7 Mon Sep 17 00:00:00 2001 From: shagu Date: Thu, 25 Jun 2020 10:05:19 +0200 Subject: [PATCH] autovendor: always scan for next and clear cursor --- modules/autovendor.lua | 66 +++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/modules/autovendor.lua b/modules/autovendor.lua index 325f4a67..3f6847e8 100644 --- a/modules/autovendor.lua +++ b/modules/autovendor.lua @@ -1,8 +1,7 @@ pfUI:RegisterModule("autovendor", "vanilla:tbc", function () local rawborder, border = GetBorderSize() local bpad = rawborder > 1 and border - GetPerfectPixel() or GetPerfectPixel() - - local scanlist = {} + local processed = {} local function RepairItems() local cost, possible = GetRepairAllCost() @@ -12,34 +11,35 @@ pfUI:RegisterModule("autovendor", "vanilla:tbc", function () end end - local function ScanGreyItems() - scanlist = {} + local function HasGreyItems() for bag = 0, 4, 1 do for slot = 1, GetContainerNumSlots(bag), 1 do local name = GetContainerItemLink(bag,slot) - if name and string.find(name,"ff9d9d9d") then - table.insert(scanlist, { bag, slot }) - end + if name and string.find(name,"ff9d9d9d") then return true end end end + return nil end local function GetNextGreyItem() - if scanlist[1] then - local bag, slot = scanlist[1][1], scanlist[1][2] - table.remove(scanlist, 1) - - return bag, slot - else - return nil, nil + for bag = 0, 4, 1 do + for slot = 1, GetContainerNumSlots(bag), 1 do + local name = GetContainerItemLink(bag,slot) + if name and string.find(name,"ff9d9d9d") and not processed[bag.."x"..slot] then + processed[bag.."x"..slot] = true + return bag, slot + end + end end + + return nil, nil end local autovendor = CreateFrame("Frame", "pfMoneyUpdate", nil) autovendor:Hide() autovendor:SetScript("OnShow", function() - ScanGreyItems() + processed = {} this.count = 0 this.price = 0 end) @@ -48,27 +48,31 @@ pfUI:RegisterModule("autovendor", "vanilla:tbc", function () -- throttle to to one item per .1 second if ( this.tick or 1) > GetTime() then return else this.tick = GetTime() + .1 end + -- scan for the next grey item local bag, slot = GetNextGreyItem() - if not bag or not slot then this:Hide() return end - local name = GetContainerItemLink(bag,slot) - -- double check to only sell grey - if name and string.find(name,"ff9d9d9d") then - -- get value - local _, icount = GetContainerItemInfo(bag, slot) - local _, _, id = string.find(GetContainerItemLink(bag, slot), "item:(%d+):%d+:%d+:%d+") - if pfSellData[tonumber(id)] then - local _, _, sell, buy = strfind(pfSellData[tonumber(id)], "(.*),(.*)") - this.price = this.price + ( sell * ( icount or 1 ) ) - this.count = this.count + 1 - end - UseContainerItem(bag, slot) + local name = GetContainerItemLink(bag,slot) + if not name or not string.find(name,"ff9d9d9d") then + return end + + -- get value + local _, icount = GetContainerItemInfo(bag, slot) + local _, _, id = string.find(GetContainerItemLink(bag, slot), "item:(%d+):%d+:%d+:%d+") + if pfSellData[tonumber(id)] then + local _, _, sell, buy = strfind(pfSellData[tonumber(id)], "(.*),(.*)") + this.price = this.price + ( sell * ( icount or 1 ) ) + this.count = this.count + 1 + end + + -- clear cursor and sell the item + ClearCursor() + UseContainerItem(bag, slot) end) autovendor:SetScript("OnHide", function() @@ -128,17 +132,13 @@ pfUI:RegisterModule("autovendor", "vanilla:tbc", function () autovendor.button.Update = function() if not autovendor:IsVisible() then - - ScanGreyItems() - - if scanlist[1] then + if HasGreyItems() then autovendor.button:Enable() autovendor.button.icon:SetDesaturated(false) else autovendor.button:Disable() autovendor.button.icon:SetDesaturated(true) end - else autovendor.button:Disable() autovendor.button.icon:SetDesaturated(true)