PROXiCiDE

WoW Classic - TSM - Farm Vendor

Feb 3rd, 2020
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.78 KB | None | 0 0
  1. suffixes = {
  2.    Whale = 1,
  3.    Tiger = 1,
  4.    Gorilla = 1,
  5.    Falcon = 1,
  6.    Owl = 1,
  7.    Wolf = 1,
  8.    Boar = 1,
  9.    Defense = 1,
  10.    
  11.    Strength = 1,
  12.    Intellect = 1,
  13.    Spirit = 1,
  14.    
  15.    Healing = 1,
  16.    ["Arcane Protection"] = 1,
  17.    ["Arcane Resistance"] = 1,
  18.    
  19.    ["Arcane Wrath"] = 1,
  20.    
  21. }
  22.  
  23. firstAid = {
  24.    [4306] = 6451
  25. }
  26.  
  27. print("")
  28.  
  29. function GetItemPrice(itemId, customPriceStr)
  30.    local _, link = GetItemInfo(itemId)
  31.    local itemString = TSM_API.ToItemString(link)
  32.    
  33.    if not TSM_API.IsCustomPriceValid(customPriceStr) then
  34.       source = "dbmarket"
  35.    end
  36.    
  37.    return TSM_API.GetCustomPriceValue(customPriceStr, itemString), link
  38. end
  39.  
  40. local totalPrice = 0
  41. local itemList = {}
  42.  
  43. function ItemDestroyInfo(item)
  44.    
  45.    local typeDestroy = "Misc"
  46.    
  47.    local price = nil
  48.    local itemRarity = select(3,GetItemInfo(item))
  49.    
  50.    local id = tonumber(item:match("item:(%d+):"))
  51.    
  52.    local count = GetItemCount(item)
  53.    
  54.    if firstAid[id] then
  55.       typeDestroy = "First Aid"
  56.       _, link = GetItemInfo(firstAid[id])
  57.       local vendorPrice = GetItemPrice(item,"VendorSell")
  58.       local marketPrice = GetItemPrice(item,"DBMarket")
  59.       if not count or count <= 0 then count = 1 end
  60.      
  61.       price = marketPrice
  62.       if vendorPrice < price then
  63.          typeDestroy = typeDestroy .. " <Auction House>"
  64.       else
  65.          price = vendorPrice
  66.          typeDestroy = typeDestroy .. " <Vendor>"
  67.       end
  68.       price = price * count
  69.    else
  70.       if itemRarity >= 2 then
  71.          typeDestroy = "Disenchant"
  72.       else
  73.          return price, typeDestroy
  74.       end
  75.      
  76.       local destroyPrice = GetItemPrice(item, "Destroy")
  77.       local vendorPrice = GetItemPrice(item,"VendorSell")
  78.       local marketPrice = GetItemPrice(item,"DBMinBuyout")
  79.      
  80.       price = vendorPrice
  81.       local skipMarket = nil
  82.       if not price then
  83.          price = marketPrice
  84.          destroyType = "Market"
  85.          skipMarket = true
  86.       end
  87.      
  88.       if price and destroyPrice and destroyPrice < price then
  89.          price = vendorPrice
  90.          typeDestroy = "Vendor"
  91.       end
  92.      
  93.       if not skipMarket and marketPrice and price < marketPrice then
  94.          typeDestroy = "Market"
  95.          price = marketPrice
  96.       end
  97.      
  98.    end
  99.    
  100.    -- print(item, price, typeDestroy, count)
  101.    return price, typeDestroy, count
  102. end
  103.  
  104. function AddItem(item, bag, slot, suffix)
  105.    local name, link, itemRarity = GetItemInfo(item)
  106.    local price, typeDestroy, count = ItemDestroyInfo(item)
  107.    local itemBindType = select(14, GetItemInfo(item))
  108.    
  109.    if price then
  110.       if not itemList[typeDestroy] then
  111.          itemList[typeDestroy] = { totalPrice = 0 }
  112.       end
  113.      
  114.       if not itemList[typeDestroy][name] then    
  115.          -- print(price, item, bag, slot, suffix)
  116.          
  117.          itemList[typeDestroy].totalPrice = itemList[typeDestroy].totalPrice + price
  118.          itemList[typeDestroy].Price = count * price
  119.          
  120.          itemList[typeDestroy][name] = {
  121.             name = name, link = item, price =  price, rarity = itemRarity,
  122.             bindtype = itemBindType,
  123.             suffix = suffix,
  124.             destroyType = typeDestroy,
  125.             count = count
  126.          }
  127.          itemList[typeDestroy][name].slotInfo = {}
  128.          table.insert(itemList[typeDestroy][name].slotInfo, { bag = bag, slot = slot })
  129.       else      
  130.          itemList[typeDestroy][name].price = itemList[typeDestroy][name].price + price
  131.          itemList[typeDestroy][name].suffix = suffix
  132.          itemList[typeDestroy][name].destroyType = typeDestroy
  133.          table.insert(itemList[typeDestroy][name].slotInfo, { bag = bag, slot = slot })
  134.       end
  135.    end
  136.    
  137. end
  138.  
  139. function SellFarmingItems_Init()
  140.    wipe(itemList)
  141.    for bag=0,4 do
  142.       for slot=1,GetContainerNumSlots(bag) do
  143.          local item=GetContainerItemLink(bag,slot)
  144.          if item then
  145.             local name,_,itemRarity, itemLevel, itemMinLevel, itemType, itemSubType = GetItemInfo(item)
  146.             local itemBindType = select(14, GetItemInfo(item))
  147.             _,suffix = name:match("(.*) of the (.*)")
  148.             if not suffix then
  149.                _,suffix = name:match("(.*) of (.*)")
  150.             end
  151.            
  152.             if (itemRarity == 2 and itemBindType == 2) or itemRarity == 1 then
  153.                AddItem(item, bag, slot, suffixes[suffix])
  154.             end
  155.            
  156.          end
  157.       end
  158.    end
  159. end
  160.  
  161.  
  162.  
  163. function SellFarmingItems()
  164.    SellFarmingItems_Init()
  165.    
  166.    local count = 0
  167.    for k,v in pairs(itemList) do
  168.       if type(v) == "table" then
  169.          count = count + 1
  170.       end
  171.    end
  172.    
  173.    
  174.    if count > 0 then
  175.       for k,v in pairs(itemList) do
  176.          
  177.          if currentTable and currentTable ~= k then
  178.             print("")
  179.          end
  180.          
  181.          currentTable = k
  182.          print("|cffff0000"..currentTable.."|r" .. " TOTAL: ".. TSM_API.FormatMoneyString(v.totalPrice))
  183.          
  184.          for x,y in pairs(v) do
  185.             if type(y) == "table" then
  186.                local priceStr = TSM_API.FormatMoneyString(y.price)
  187.                print(y.link,priceStr)
  188.                
  189.                if #y.slotInfo >= 1 then
  190.                   for _,info in pairs(y.slotInfo) do
  191.                      if MerchantFrame:IsVisible() and y and (y.destroyType == "Vendor" or y.suffix) then
  192.                         --ShowMerchantSellCursor(1)
  193.                         UseContainerItem(info.bag, info.slot)
  194.                      end
  195.                   end
  196.                end
  197.             end
  198.          end
  199.       end
  200.      
  201.      
  202.    end
  203. end
  204.  
  205. SellFarmingItems()
  206.  
  207. function SellFarmingItemsEx()
  208.    SellFarmingItems()
  209. end
  210.  
  211.  
  212. local f = CreateFrame("Frame")
  213. f:RegisterEvent("MERCHANT_SHOW")
  214. f:SetScript("OnEvent", SellFarmingItemsEx)
Advertisement
Add Comment
Please, Sign In to add comment