Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- suffixes = {
- Whale = 1,
- Tiger = 1,
- Gorilla = 1,
- Falcon = 1,
- Owl = 1,
- Wolf = 1,
- Boar = 1,
- Defense = 1,
- Strength = 1,
- Intellect = 1,
- Spirit = 1,
- Healing = 1,
- ["Arcane Protection"] = 1,
- ["Arcane Resistance"] = 1,
- ["Arcane Wrath"] = 1,
- }
- firstAid = {
- [4306] = 6451
- }
- print("")
- function GetItemPrice(itemId, customPriceStr)
- local _, link = GetItemInfo(itemId)
- local itemString = TSM_API.ToItemString(link)
- if not TSM_API.IsCustomPriceValid(customPriceStr) then
- source = "dbmarket"
- end
- return TSM_API.GetCustomPriceValue(customPriceStr, itemString), link
- end
- local totalPrice = 0
- local itemList = {}
- function ItemDestroyInfo(item)
- local typeDestroy = "Misc"
- local price = nil
- local itemRarity = select(3,GetItemInfo(item))
- local id = tonumber(item:match("item:(%d+):"))
- local count = GetItemCount(item)
- if firstAid[id] then
- typeDestroy = "First Aid"
- _, link = GetItemInfo(firstAid[id])
- local vendorPrice = GetItemPrice(item,"VendorSell")
- local marketPrice = GetItemPrice(item,"DBMarket")
- if not count or count <= 0 then count = 1 end
- price = marketPrice
- if vendorPrice < price then
- typeDestroy = typeDestroy .. " <Auction House>"
- else
- price = vendorPrice
- typeDestroy = typeDestroy .. " <Vendor>"
- end
- price = price * count
- else
- if itemRarity >= 2 then
- typeDestroy = "Disenchant"
- else
- return price, typeDestroy
- end
- local destroyPrice = GetItemPrice(item, "Destroy")
- local vendorPrice = GetItemPrice(item,"VendorSell")
- local marketPrice = GetItemPrice(item,"DBMinBuyout")
- price = vendorPrice
- local skipMarket = nil
- if not price then
- price = marketPrice
- destroyType = "Market"
- skipMarket = true
- end
- if price and destroyPrice and destroyPrice < price then
- price = vendorPrice
- typeDestroy = "Vendor"
- end
- if not skipMarket and marketPrice and price < marketPrice then
- typeDestroy = "Market"
- price = marketPrice
- end
- end
- -- print(item, price, typeDestroy, count)
- return price, typeDestroy, count
- end
- function AddItem(item, bag, slot, suffix)
- local name, link, itemRarity = GetItemInfo(item)
- local price, typeDestroy, count = ItemDestroyInfo(item)
- local itemBindType = select(14, GetItemInfo(item))
- if price then
- if not itemList[typeDestroy] then
- itemList[typeDestroy] = { totalPrice = 0 }
- end
- if not itemList[typeDestroy][name] then
- -- print(price, item, bag, slot, suffix)
- itemList[typeDestroy].totalPrice = itemList[typeDestroy].totalPrice + price
- itemList[typeDestroy].Price = count * price
- itemList[typeDestroy][name] = {
- name = name, link = item, price = price, rarity = itemRarity,
- bindtype = itemBindType,
- suffix = suffix,
- destroyType = typeDestroy,
- count = count
- }
- itemList[typeDestroy][name].slotInfo = {}
- table.insert(itemList[typeDestroy][name].slotInfo, { bag = bag, slot = slot })
- else
- itemList[typeDestroy][name].price = itemList[typeDestroy][name].price + price
- itemList[typeDestroy][name].suffix = suffix
- itemList[typeDestroy][name].destroyType = typeDestroy
- table.insert(itemList[typeDestroy][name].slotInfo, { bag = bag, slot = slot })
- end
- end
- end
- function SellFarmingItems_Init()
- wipe(itemList)
- for bag=0,4 do
- for slot=1,GetContainerNumSlots(bag) do
- local item=GetContainerItemLink(bag,slot)
- if item then
- local name,_,itemRarity, itemLevel, itemMinLevel, itemType, itemSubType = GetItemInfo(item)
- local itemBindType = select(14, GetItemInfo(item))
- _,suffix = name:match("(.*) of the (.*)")
- if not suffix then
- _,suffix = name:match("(.*) of (.*)")
- end
- if (itemRarity == 2 and itemBindType == 2) or itemRarity == 1 then
- AddItem(item, bag, slot, suffixes[suffix])
- end
- end
- end
- end
- end
- function SellFarmingItems()
- SellFarmingItems_Init()
- local count = 0
- for k,v in pairs(itemList) do
- if type(v) == "table" then
- count = count + 1
- end
- end
- if count > 0 then
- for k,v in pairs(itemList) do
- if currentTable and currentTable ~= k then
- print("")
- end
- currentTable = k
- print("|cffff0000"..currentTable.."|r" .. " TOTAL: ".. TSM_API.FormatMoneyString(v.totalPrice))
- for x,y in pairs(v) do
- if type(y) == "table" then
- local priceStr = TSM_API.FormatMoneyString(y.price)
- print(y.link,priceStr)
- if #y.slotInfo >= 1 then
- for _,info in pairs(y.slotInfo) do
- if MerchantFrame:IsVisible() and y and (y.destroyType == "Vendor" or y.suffix) then
- --ShowMerchantSellCursor(1)
- UseContainerItem(info.bag, info.slot)
- end
- end
- end
- end
- end
- end
- end
- end
- SellFarmingItems()
- function SellFarmingItemsEx()
- SellFarmingItems()
- end
- local f = CreateFrame("Frame")
- f:RegisterEvent("MERCHANT_SHOW")
- f:SetScript("OnEvent", SellFarmingItemsEx)
Advertisement
Add Comment
Please, Sign In to add comment