zz_AltMail/stock.lua

80 lines
2.5 KiB
Lua

local addonName, addon = ...
local stock = CreateFrame("FRAME")
local keepStock = {
["Rilgana-Tirion"] = {
[173060] = 2000, -- Wasser
[180732] = 2000, -- Phiole
[180817] = 1,
[175886] = 500 -- Pergament
},
["Rilgany-Tirion"] = {
[180817] = 1,
}
}
function stock:BAG_UPDATE_DELAYED()
if(not MerchantFrame or not MerchantFrame:IsVisible()) then return end
local bag = 0
local earnedMoney = 0
while(bag<=NUM_BAG_SLOTS) do
local slot = 1
while(slot<=GetContainerNumSlots(bag)) do
if(C_NewItems.IsNewItem(bag, slot)) then
local item = ItemLocation:CreateFromBagAndSlot(bag, slot)
local itemLink = C_Item.GetItemLink(item)
local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture, itemSellPrice, itemClassID, itemSubClassID, bindType, expacID, itemSetID, isCraftingReagent = GetItemInfo(itemLink)
-- print(itemName, itemType, itemSubType, itemClassID, itemSubClassID)
if(itemClassID ~= 7) then -- dont sell crafting reagents
UseContainerItem(bag, slot)
end
end
slot = slot + 1
end
bag = bag + 1
end
end
function stock:MERCHANT_SHOW(event, ...)
-- print(event, ...)
-- self:BAG_UPDATE_DELAYED()
if(keepStock[addon:GetUName()]) then
for i = 1, GetMerchantNumItems() do
local name, texture, price, quantity, numAvailable, isPurchasable, isUsable, extendedCost = GetMerchantItemInfo(i)
if(name and isPurchasable) then
local itemID, itemType, itemSubType, itemEquipLoc, icon, itemClassID, itemSubClassID = GetItemInfoInstant(name)
if(keepStock[addon:GetUName()][itemID]) then
local count = GetItemCount(itemID, true)
if(count < keepStock[addon:GetUName()][itemID]) then
-- print(name, itemID, quantity, numAvailable, count)
local buy = keepStock[addon:GetUName()][itemID] - count
if(buy > 0) then
local maxStack = GetMerchantItemMaxStack(i)
if(buy >= maxStack) then
for b = 1, floor(buy / maxStack) do
BuyMerchantItem(i, maxStack)
buy = buy - maxStack
end
end
if(buy > quantity) then
BuyMerchantItem(i, buy)
end
-- print("buy", name, buy, buyStacks)
end
end
end
else
-- print(i, name, isPurchasable)
end
end
end
end
stock:RegisterEvent("MERCHANT_SHOW")
-- stock:RegisterEvent("BAG_UPDATE_DELAYED")
stock:SetScript("OnEvent", function(self, event, ...)
if(type(self[event]) == 'function') then
self[event](self, event, ...)
else
print("NO IDEA", event, ...)
end
end)