initial commit
This commit is contained in:
71
Core/Service/Sniper/BidSearch.lua
Normal file
71
Core/Service/Sniper/BidSearch.lua
Normal file
@@ -0,0 +1,71 @@
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
-- TradeSkillMaster --
|
||||
-- https://tradeskillmaster.com --
|
||||
-- All Rights Reserved - Detailed license information included with addon. --
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
|
||||
local _, TSM = ...
|
||||
local BidSearch = TSM.Sniper:NewPackage("BidSearch")
|
||||
local Threading = TSM.Include("Service.Threading")
|
||||
local private = {
|
||||
scanThreadId = nil,
|
||||
searchContext = nil,
|
||||
}
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Module Functions
|
||||
-- ============================================================================
|
||||
|
||||
function BidSearch.OnInitialize()
|
||||
private.scanThreadId = Threading.New("SNIPER_BID_SEARCH", private.ScanThread)
|
||||
private.searchContext = TSM.Sniper.SniperSearchContext(private.scanThreadId, private.MarketValueFunction, "BID")
|
||||
end
|
||||
|
||||
function BidSearch.GetSearchContext()
|
||||
assert(TSM.IsWowClassic())
|
||||
return private.searchContext
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Scan Thread
|
||||
-- ============================================================================
|
||||
|
||||
function private.ScanThread(auctionScan)
|
||||
assert(TSM.IsWowClassic())
|
||||
local numQueries = auctionScan:GetNumQueries()
|
||||
if numQueries == 0 then
|
||||
auctionScan:NewQuery()
|
||||
:AddCustomFilter(private.QueryFilter)
|
||||
:SetPage("FIRST")
|
||||
else
|
||||
assert(numQueries == 1)
|
||||
end
|
||||
-- don't care if the scan fails for sniper since it's rerun constantly
|
||||
auctionScan:ScanQueriesThreaded()
|
||||
return true
|
||||
end
|
||||
|
||||
function private.QueryFilter(_, subRow)
|
||||
local itemString = subRow:GetItemString()
|
||||
if not itemString or not subRow:IsSubRow() or not subRow:HasRawData() then
|
||||
-- can only filter complete subRows
|
||||
return false
|
||||
end
|
||||
local maxPrice = TSM.Operations.Sniper.GetBelowPrice(itemString) or nil
|
||||
if not maxPrice then
|
||||
-- no Shopping operation applies to this item, so filter it out
|
||||
return true
|
||||
end
|
||||
|
||||
local _, itemDisplayedBid = subRow:GetDisplayedBids()
|
||||
return itemDisplayedBid > maxPrice
|
||||
end
|
||||
|
||||
function private.MarketValueFunction(row)
|
||||
local itemString = row:GetItemString()
|
||||
return itemString and TSM.Operations.Sniper.GetBelowPrice(itemString) or nil
|
||||
end
|
||||
111
Core/Service/Sniper/BuyoutSearch.lua
Normal file
111
Core/Service/Sniper/BuyoutSearch.lua
Normal file
@@ -0,0 +1,111 @@
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
-- TradeSkillMaster --
|
||||
-- https://tradeskillmaster.com --
|
||||
-- All Rights Reserved - Detailed license information included with addon. --
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
|
||||
local _, TSM = ...
|
||||
local BuyoutSearch = TSM.Sniper:NewPackage("BuyoutSearch")
|
||||
local L = TSM.Include("Locale").GetTable()
|
||||
local Log = TSM.Include("Util.Log")
|
||||
local Threading = TSM.Include("Service.Threading")
|
||||
local ItemInfo = TSM.Include("Service.ItemInfo")
|
||||
local private = {
|
||||
scanThreadId = nil,
|
||||
searchContext = nil,
|
||||
itemList = {},
|
||||
}
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Module Functions
|
||||
-- ============================================================================
|
||||
|
||||
function BuyoutSearch.OnInitialize()
|
||||
private.scanThreadId = Threading.New("SNIPER_BUYOUT_SEARCH", private.ScanThread)
|
||||
private.searchContext = TSM.Sniper.SniperSearchContext(private.scanThreadId, private.MarketValueFunction, "BUYOUT")
|
||||
end
|
||||
|
||||
function BuyoutSearch.GetSearchContext()
|
||||
return private.searchContext
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Scan Thread
|
||||
-- ============================================================================
|
||||
|
||||
function private.ScanThread(auctionScan)
|
||||
local numQueries = auctionScan:GetNumQueries()
|
||||
if numQueries == 0 then
|
||||
if TSM.IsWowClassic() then
|
||||
auctionScan:NewQuery()
|
||||
:AddCustomFilter(private.QueryFilter)
|
||||
:SetPage("LAST")
|
||||
else
|
||||
wipe(private.itemList)
|
||||
if not TSM.Sniper.PopulateItemList(private.itemList) then
|
||||
-- scan the entire AH
|
||||
auctionScan:NewQuery()
|
||||
:AddCustomFilter(private.QueryFilter)
|
||||
elseif #private.itemList == 0 then
|
||||
Log.PrintUser(L["Failed to start sniper. No groups have a Sniper operation applied."])
|
||||
return false
|
||||
else
|
||||
-- scan for the list of items
|
||||
auctionScan:AddItemListQueriesThreaded(private.itemList)
|
||||
for _, query in auctionScan:QueryIterator() do
|
||||
query:AddCustomFilter(private.QueryFilter)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
-- don't care if the scan fails for sniper since it's rerun constantly
|
||||
auctionScan:ScanQueriesThreaded()
|
||||
return true
|
||||
end
|
||||
|
||||
function private.QueryFilter(_, subRow)
|
||||
local baseItemString = subRow:GetBaseItemString()
|
||||
local itemString = subRow:GetItemString()
|
||||
local maxPrice = itemString and TSM.Operations.Sniper.GetBelowPrice(itemString) or nil
|
||||
if itemString and not maxPrice then
|
||||
-- no Shopping operation applies to this item, so filter it out
|
||||
return true
|
||||
end
|
||||
local auctionBuyout, itemBuyout, minItemBuyout = subRow:GetBuyouts()
|
||||
itemBuyout = itemBuyout or minItemBuyout
|
||||
if not itemBuyout then
|
||||
-- don't have buyout info yet, so don't filter
|
||||
return false
|
||||
elseif auctionBuyout == 0 then
|
||||
-- no buyout, so filter it out
|
||||
return true
|
||||
elseif itemString then
|
||||
-- filter if the buyout is too high
|
||||
return itemBuyout > maxPrice
|
||||
elseif not ItemInfo.CanHaveVariations(baseItemString) then
|
||||
-- check the buyout against the base item
|
||||
return itemBuyout > (TSM.Operations.Sniper.GetBelowPrice(baseItemString) or 0)
|
||||
end
|
||||
|
||||
-- check if any variant of this item is in a group and could potentially be worth scnaning
|
||||
local hasPotentialItem = false
|
||||
for _, groupItemString in TSM.Groups.ItemByBaseItemStringIterator(baseItemString) do
|
||||
hasPotentialItem = hasPotentialItem or itemBuyout < (TSM.Operations.Sniper.GetBelowPrice(groupItemString) or 0)
|
||||
end
|
||||
if hasPotentialItem then
|
||||
return false
|
||||
elseif not TSM.Operations.Sniper.HasOperation(baseItemString) then
|
||||
-- no potential other variants we care about
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function private.MarketValueFunction(row)
|
||||
local itemString = row:GetItemString()
|
||||
return itemString and TSM.Operations.Sniper.GetBelowPrice(itemString) or nil
|
||||
end
|
||||
77
Core/Service/Sniper/Core.lua
Normal file
77
Core/Service/Sniper/Core.lua
Normal file
@@ -0,0 +1,77 @@
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
-- TradeSkillMaster --
|
||||
-- https://tradeskillmaster.com --
|
||||
-- All Rights Reserved - Detailed license information included with addon. --
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
|
||||
local _, TSM = ...
|
||||
local Sniper = TSM:NewPackage("Sniper")
|
||||
local Threading = TSM.Include("Service.Threading")
|
||||
local SniperSearchContext = TSM.Include("LibTSMClass").DefineClass("SniperSearchContext")
|
||||
TSM.Sniper.SniperSearchContext = SniperSearchContext
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Module Methods
|
||||
-- ============================================================================
|
||||
|
||||
function Sniper.PopulateItemList(itemList)
|
||||
local baseHasOperation = false
|
||||
for _ in TSM.Operations.GroupOperationIterator("Sniper", TSM.CONST.ROOT_GROUP_PATH) do
|
||||
baseHasOperation = true
|
||||
end
|
||||
if baseHasOperation and TSM.IsWowClassic() then
|
||||
return false
|
||||
end
|
||||
|
||||
-- add all the items from groups with Sniper operations
|
||||
for _, groupPath in TSM.Groups.GroupIterator() do
|
||||
local hasOperations = false
|
||||
for _ in TSM.Operations.GroupOperationIterator("Sniper", groupPath) do
|
||||
hasOperations = true
|
||||
end
|
||||
if hasOperations then
|
||||
for _, itemString in TSM.Groups.ItemIterator(groupPath) do
|
||||
if TSM.Operations.Sniper.IsOperationValid(itemString) then
|
||||
tinsert(itemList, itemString)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- SniperSearchContext - Public Class Methods
|
||||
-- ============================================================================
|
||||
|
||||
function SniperSearchContext.__init(self, threadId, marketValueFunc, scanType)
|
||||
assert(threadId and marketValueFunc and (scanType == "BUYOUT" or scanType == "BID"))
|
||||
self._threadId = threadId
|
||||
self._marketValueFunc = marketValueFunc
|
||||
self._scanType = scanType
|
||||
end
|
||||
|
||||
function SniperSearchContext.StartThread(self, callback, auctionScan)
|
||||
Threading.SetCallback(self._threadId, callback)
|
||||
Threading.Start(self._threadId, auctionScan)
|
||||
end
|
||||
|
||||
function SniperSearchContext.KillThread(self)
|
||||
Threading.Kill(self._threadId)
|
||||
end
|
||||
|
||||
function SniperSearchContext.GetMarketValueFunc(self)
|
||||
return self._marketValueFunc
|
||||
end
|
||||
|
||||
function SniperSearchContext.IsBuyoutScan(self)
|
||||
return self._scanType == "BUYOUT"
|
||||
end
|
||||
|
||||
function SniperSearchContext.IsBidScan(self)
|
||||
return self._scanType == "BID"
|
||||
end
|
||||
Reference in New Issue
Block a user