gold2usd.lua

From Jimmy, 2 Years ago, written in Lua, viewed 656 times.
URL http://ifoo.bar/view/f7cc0f92 Shorturl http://youl.ink/4 Embed
Download Paste or View Raw
  1. --[[
  2.         Author: Jimmy from US-Anvilmar
  3.         4/9/2015
  4.         Attempt at adding a USD price feature using the current market price of the WoW Token
  5.         Inspiration: https://www.reddit.com/r/wow/comments/320gq2/we_need_an_addon_that_displays_real_world/
  6.         Resource: http://us.battle.net/wow/en/forum/topic/16953815587
  7. ]]--
  8.  
  9. local Frame = CreateFrame("Frame")
  10. Frame:RegisterEvent("AUCTION_ITEM_LIST_UPDATE")
  11.  
  12. local function AddPrice(self, price)
  13.         --TODO
  14.         GameTooltip:AddLine('$' .. price)
  15.         GameTooltip:Show()
  16. end
  17.  
  18. hooksecurefunc(GameTooltip, "Show", AddPrice)
  19.        
  20. local function Scan()
  21.         local data = {}
  22.         --TODO
  23.         -- maybe do like other auction addons and run a scan on all items when AUCTION_ITEM_LIST_UPDATE fires to populate a
  24.         -- data table with USD prices for each item, then do a lookup when an item is mousedover and add it to the tooltip?
  25.         -- or add a column to the default AuctionUI with the gold price... I dunno..
  26. end
  27.        
  28.  
  29. -- This is some hackery i was using to get the index of the auction i am currently moused over... there's definitely a more elegant way
  30. local function GetSelectedFrame()
  31.         return GetMouseFocus():GetName()
  32. end
  33.  
  34.  
  35. -- This function is horrible and I should figure out a better way to get an item's buyout/bid price from the auction UI...
  36. -- I should probably look at TSM, Auctioneer, or Auctionator to get a better idea.
  37. local function GetPrice(str)
  38.         local buy = 0
  39.         local bid = 0
  40.         local _, index = strfind(str, "BrowseButton")
  41.        
  42.         --type is a list, browsing auctions
  43.         if index ~= nil then
  44.                 buy, bid = select(10, GetAuctionItemInfo("list", index+1))
  45.         else
  46.                 _, index = strfind(str, "AuctionsButton")
  47.                 --type is owner, browsing my auctions
  48.                 if index ~= nil then
  49.                         buy, bid = select(10, GetAuctionItemInfo("owner", index+1))
  50.                 else
  51.                         --type is bidder, browsing my bids
  52.                         _, index = strfind(str, "BidButton")
  53.                         if index~= nil then
  54.                                 buy, bid = select(10, GetAuctionItemInfo("bidder", index+1))
  55.                         end
  56.                 end
  57.         end
  58.        
  59.         -- At this point, either buy or bid should have a price (in copper) returned by GetAuctionItemInfo
  60.         -- Send the greater of those values to GetMarketPrice to return a price in USD
  61.         return GetMarketPrice(math.max(buy, bid))
  62. end
  63.  
  64. local function GetMarketPrice(gold)
  65.         -- Update the market price.  This fires the event TOKEN_MARKET_PRICE_UPDATED
  66.         C_WowTokenPublic.UpdateMarketPrice()
  67.         -- Maybe we should wait for the above event to be fired before getting the price..
  68.         -- Grab the current market price and divide by 10000 to get a gold figure.  Could also use GetMoneyString(...)
  69.         local price, _ = C_WowTokenPublic.GetCurrentMarketPrice()/10000
  70.         -- Right now Token price in USD is fixed at $20, but who knows if it will change
  71.         local dollars = 20
  72.         -- Our exchange rate
  73.         local exchangeRate = dollars/price
  74.         -- Return a formatted floating point number in the form of x.xx
  75.         return math.floor(exchangeRate * gold * 100 + 0.5)/100
  76. end
  77.  

Reply to "gold2usd.lua"

Here you can reply to the paste above