First 2 functions added, sniper and adjust price to itemlevel

This commit is contained in:
Robin 2021-02-02 17:08:36 +01:00
commit 16bdc80e8f
2 changed files with 125 additions and 0 deletions

121
core.lua Normal file
View File

@ -0,0 +1,121 @@
local addonName, addon = ...
local events = events or CreateFrame("FRAME")
local prices, pricesIlvl
function events:ITEM_SEARCH_RESULTS_UPDATED(event, item)
local itemID = item['itemID']
-- print(itemID)
pricesIlvl[itemID] = pricesIlvl[itemID] or {}
-- 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)
if(pricesIlvl[itemID][itemlevel] == 0 or result.buyoutAmount<pricesIlvl[itemID][itemlevel]) then
pricesIlvl[itemID][itemlevel] = result.buyoutAmount
-- print("New price",itemlevel, result.buyoutAmount)
end
end
end
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
local function hookItem(self, ...)
local cItemLoc = AuctionHouseFrame.CommoditiesSellFrame.ItemDisplay.ItemButton:GetItemLocation()
local ItemLoc = AuctionHouseFrame.ItemSellFrame.ItemDisplay.ItemButton:GetItemLocation()
if(cItemLoc or ItemLoc) then
local il = cItemLoc or ItemLoc
if(il:IsValid() and il:IsBagAndSlot()) then
local bid = C_Item.GetItemID(il)
-- 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("Price", prices[bid])
else
local lvl = C_Item.GetCurrentItemLevel(il)
-- print(lvl)
-- print("Price",pricesIlvl[bid][lvl])
if(lvl and pricesIlvl[bid][lvl]) then
AuctionHouseFrame.ItemSellFrame.PriceInput:SetAmount(pricesIlvl[bid][lvl])
end
end
end
end
end
function events:AUCTION_HOUSE_SHOW(event)
self:UnregisterEvent(event)
AuctionHouseFrame.CommoditiesSellFrame.Overlay:HookScript("OnReceiveDrag", hookItem)
AuctionHouseFrame.ItemSellFrame.ItemDisplay.ItemButton:HookScript("OnReceiveDrag", 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)

4
zzAuctions.toc Normal file
View File

@ -0,0 +1,4 @@
## Interface: 90002
## Name: zzAuctions
## SavedVariables: zzAuctionsDB
core.lua