-- minimum amount of time between two LootLink scans of the auction house (1 hour = 3600 seconds) LOOTLINK_TIME_BETWEEN_AUCTION_SCANS = 3600; -- prevents the user from seeing what the LootLink does at the Auction House LootLink_Auction_Browsing = false; -- whether we're done getting links with the current page (perhaps not necessary, but I don't know if OnUpdate is ran in its own thread...) LootLink_Auction_DoneWithCurrentPage = true; LootLink_Auction_CurrentPage = 0; LootLink_Auction_TimeSinceLastScan = 0; LootLink_Saved_AuctionFrame_OnShow = nil; LootLink_Saved_AuctionFrameBrowse_OnEvent = nil; LootLink_Saved_CanSendAuctionQuery = nil; function LootLink_Auction_StartScan() LootLink_Auction_TimeSinceLastScan = GetTime(); LootLink_Auction_DoneWithCurrentPage = true; LootLink_GetAllAuctionItems(); end function LootLink_AuctionFrame_HookFunctions() if ( not LootLink_Saved_AuctionFrame_OnShow ) then LootLink_Saved_AuctionFrame_OnShow = AuctionFrame_OnShow; AuctionFrame_OnShow = LootLink_AuctionFrame_OnShow; end if ( not LootLink_Saved_AuctionFrameBrowse_OnEvent ) then LootLink_Saved_AuctionFrameBrowse_OnEvent = AuctionFrameBrowse_OnEvent; AuctionFrameBrowse_OnEvent = LootLink_AuctionFrameBrowse_OnEvent; end if ( not LootLink_Saved_CanSendAuctionQuery ) then LootLink_Saved_CanSendAuctionQuery = CanSendAuctionQuery; CanSendAuctionQuery = LootLink_CanSendAuctionQuery; end end -- this is called in the BrowseSearchButton:OnUpdate handler which is why it works function LootLink_CanSendAuctionQuery() local value = LootLink_Saved_CanSendAuctionQuery(); if ( LootLink_Auction_Browsing ) then if ( (value) and ( LootLink_Auction_DoneWithCurrentPage ) ) then LootLink_GetNextAuctionPage(); end return false; else return value; end end -- hides the search results while scanning is going on function LootLink_AuctionFrameBrowse_OnEvent() LootLink_GetAllCurrentBrowsedItems(); if ( not LootLink_Auction_Browsing ) then LootLink_Saved_AuctionFrameBrowse_OnEvent(); end end function LootLink_GetAllCurrentBrowsedItems() local numBatchAuctions, totalAuctions = GetNumAuctionItems("list"); local link = nil; for i = 1, numBatchAuctions do link = GetAuctionItemLink("list", i); if ( link ) then LootLink_ProcessLinks(link); end end LootLink_Auction_DoneWithCurrentPage = true; end function LootLink_GetNextAuctionPage() if ( LootLink_Auction_Browsing ) then if ( not AuctionFrame:IsVisible() ) then LootLink_Auction_Browsing = false; return; end local numBatchAuctions, totalAuctions = GetNumAuctionItems("list"); local numberOfPages = floor(totalAuctions / NUM_AUCTION_ITEMS_PER_PAGE); if ( LootLink_Auction_CurrentPage < numberOfPages ) then LootLink_Auction_CurrentPage = LootLink_Auction_CurrentPage + 1; LootLink_Auction_DoneWithCurrentPage = true; QueryAuctionItems("", "", "", nil, nil, nil, LootLink_Auction_CurrentPage, false, nil); if ( LootLink_Auction_CurrentPage == 0 ) then BrowseNoResultsText:SetText("LootLink is searching for new items in the auction house, please be patient."); else BrowseNoResultsText:SetText(format("LootLink is currently searching page %d/%d, please be patient.", LootLink_Auction_CurrentPage+1, numberOfPages+1)); end LootLink_Auction_DoneWithCurrentPage = false; else BrowseNoResultsText:SetText("LootLink has finished searching - thank you for your patience."); LootLink_Auction_Browsing = false; end else LootLink_Auction_DoneWithCurrentPage = true; end end function LootLink_GetAllAuctionItems() LootLink_Auction_Browsing = true; LootLink_Auction_CurrentPage = -1; end function LootLink_AuctionFrame_OnShow() local curTime = GetTime(); if ( ( LootLink_Auction_TimeSinceLastScan == 0 ) or ( ( LootLink_Auction_TimeSinceLastScan + LOOTLINK_TIME_BETWEEN_AUCTION_SCANS ) < curTime ) ) then LootLink_Auction_StartScan(); end LootLink_Saved_AuctionFrame_OnShow(); end