136 lines
5.0 KiB
Lua
Executable File
136 lines
5.0 KiB
Lua
Executable File
local addonName, addon = ...
|
|
local events = addon['events'] or CreateFrame("FRAME")
|
|
local prices, pricesIlvl
|
|
local function getItem()
|
|
return AuctionHouseFrame.CommoditiesSellFrame.ItemDisplay.ItemButton:GetItemLocation() or AuctionHouseFrame.ItemSellFrame.ItemDisplay.ItemButton:GetItemLocation()
|
|
end
|
|
local function hookItem(self, ...)
|
|
-- print('hook')
|
|
local il = getItem()
|
|
if(il) then
|
|
if(il:IsValid() and il:IsBagAndSlot()) then
|
|
local bid = C_Item.GetItemID(il)
|
|
if(bid) then
|
|
-- print("hook",self:GetName(), ...)
|
|
-- print(AuctionHouseFrame.CommoditiesSellFrame.ItemDisplay.ItemButton:GetItemLocation())
|
|
-- print(AuctionHouseFrame.ItemSellFrame.ItemDisplay.ItemButton:GetItemLocation())
|
|
if(C_AuctionHouse.GetItemCommodityStatus(il) and prices[bid]) then
|
|
-- print("CPrice", prices[bid])
|
|
else
|
|
local lvl = C_Item.GetCurrentItemLevel(il)
|
|
-- print(lvl)
|
|
-- print("Price",lvl,pricesIlvl[bid][lvl])
|
|
if(lvl and pricesIlvl[bid] and pricesIlvl[bid][lvl]) then
|
|
AuctionHouseFrame.ItemSellFrame.PriceInput:SetAmount(pricesIlvl[bid][lvl])
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
function events:ITEM_SEARCH_RESULTS_UPDATED(event, item)
|
|
local itemID = item['itemID']
|
|
-- print("id",itemID)
|
|
if(itemID) then
|
|
pricesIlvl[itemID] = {}
|
|
end
|
|
-- pricesIlvl[item['itemID']][item['itemLevel']] = 0
|
|
for i = 1, C_AuctionHouse.GetNumItemSearchResults(item) do
|
|
local result = C_AuctionHouse.GetItemSearchResultInfo(item, i)
|
|
|
|
if(result and result.buyoutAmount) then
|
|
local itemKey = result['itemKey']
|
|
local itemlevel = itemKey.itemLevel
|
|
if(itemlevel and not pricesIlvl[itemID][itemlevel]) then
|
|
pricesIlvl[itemID][itemlevel] = 0
|
|
end
|
|
-- print(itemlevel, pricesIlvl[itemID][itemlevel], result.buyoutAmount,result.buyoutAmount<pricesIlvl[itemID][itemlevel])
|
|
if(pricesIlvl[itemID][itemlevel] == 0 or result.buyoutAmount<pricesIlvl[itemID][itemlevel]) then
|
|
pricesIlvl[itemID][itemlevel] = result.buyoutAmount
|
|
-- print("New price",itemlevel, result.buyoutAmount)
|
|
end
|
|
else
|
|
-- print("nr", result, result.buyoutAmount)
|
|
end
|
|
end
|
|
hookItem()
|
|
end
|
|
function events:COMMODITY_SEARCH_RESULTS_UPDATED(event, itemID)
|
|
prices[itemID] = 0
|
|
for i = 1, C_AuctionHouse.GetNumCommoditySearchResults(itemID) do
|
|
local result = C_AuctionHouse.GetCommoditySearchResultInfo(itemID, 1)
|
|
-- print(unpack(result))
|
|
if(prices[itemID] == 0 or result.unitPrice<prices[itemID]) then
|
|
prices[itemID] = result.unitPrice
|
|
-- print("New price", result.unitPrice)
|
|
end
|
|
end
|
|
end
|
|
|
|
function events:AUCTION_HOUSE_SHOW(event)
|
|
self:UnregisterEvent(event)
|
|
for k,v in pairs(AuctionHouseFrame.ItemSellFrame.ItemDisplay.ItemButton) do
|
|
-- print("-- ",k,v)
|
|
end
|
|
-- hooksecurefunc(AuctionHouseFrame.ItemSellFrame.ItemDisplay.ItemButton, "SwitchItemWithCursor", function(...) print("sil",...) end)
|
|
-- AuctionHouseFrame.CommoditiesSellFrame.Overlay:HookScript("OnReceiveDrag", hookItem)
|
|
-- AuctionHouseFrame.ItemSellFrame.ItemDisplay.ItemButton:HookScript("OnReceiveDrag", hookItem)
|
|
-- AuctionHouseFrame.ItemSellFrame.ItemDisplay.ItemButton:HookScript("OnClick", hookItem)
|
|
AuctionHouseFrameAuctionsFrame.ItemDisplay.ItemButton:HookScript("OnClick", function(self, button, ...)
|
|
if(button == "LeftButton") then
|
|
local itemid = self:GetParent().item
|
|
local itemKey = self:GetParent().itemKey
|
|
local itemlevel = itemKey.itemLevel
|
|
|
|
for bag=0,4 do
|
|
for slot=1,GetContainerNumSlots(bag) do
|
|
local bagitem = ItemLocation:CreateFromBagAndSlot(bag, slot)
|
|
if(bagitem:IsValid()) then
|
|
local bid = C_Item.GetItemID(bagitem)
|
|
local lvl = C_Item.GetCurrentItemLevel(bagitem)
|
|
if(bid == itemid) then
|
|
if(C_AuctionHouse.GetItemCommodityStatus(bagitem) and prices[bid]) then
|
|
-- print('isCommodity / Handwerksware', prices[bid])
|
|
C_AuctionHouse.PostCommodity(bagitem, 1, 1, prices[bid])
|
|
-- C_AuctionHouse.SendSearchQuery(itemKey, {}, false)
|
|
return
|
|
else
|
|
-- print(self:GetParent().itemLink,self:GetParent().itemLevel)
|
|
if(lvl == itemlevel) then
|
|
-- print('noCommodity / Singleitem')
|
|
C_AuctionHouse.PostItem(bagitem, 1, 1, nil, pricesIlvl[bid][lvl])
|
|
-- C_AuctionHouse.SendSearchQuery(itemKey, {}, false)
|
|
return
|
|
end
|
|
end
|
|
-- local itemKey = C_AuctionHouse.MakeItemKey(bid)
|
|
-- C_AuctionHouse.SendSearchQuery(itemKey, {}, false)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end)
|
|
end
|
|
|
|
function events:ADDON_LOADED(event, arg1)
|
|
-- print(event, arg1, addonName, arg1==addonName)
|
|
if(arg1 == addonName) then
|
|
-- print(addonName)
|
|
zzAuctionsDB = zzAuctionsDB or {
|
|
['prices'] = {},
|
|
['pricesIlvl'] = {}
|
|
}
|
|
prices = zzAuctionsDB['prices']
|
|
pricesIlvl = zzAuctionsDB['pricesIlvl']
|
|
self:UnregisterEvent(event)
|
|
end
|
|
end
|
|
for event, func in pairs(events) do
|
|
if(type(func) == 'function') then
|
|
events:RegisterEvent(event)
|
|
end
|
|
end
|
|
events:SetScript("OnEvent", function(self, event, ...)
|
|
self[event](self, event, ...)
|
|
end) |