comparison Main.lua @ 501:f64b4ed77b77 7.0.3-7

Fixed currency ID support to properly handle nil currency names or currency textures when doing a lookup.
author MMOSimca <mmosimca@gmail.com>
date Thu, 13 Oct 2016 10:28:33 -0400
parents b177416f7888
children abc372f93293
comparison
equal deleted inserted replaced
500:26ee8074e5ba 501:f64b4ed77b77
324 324
325 local currency_info_lookup = {} 325 local currency_info_lookup = {}
326 326
327 327
328 function CurrencyInfoToID(name, texture) 328 function CurrencyInfoToID(name, texture)
329 if not name or not texture then return nil end
329 return currency_info_lookup[("%s:%s"):format(name, texture)] 330 return currency_info_lookup[("%s:%s"):format(name, texture)]
330 end 331 end
331 332
332 333
333 function PopulateCurrencyInfoLookup() 334 function PopulateCurrencyInfoLookup()
1042 if entry["rewards"]["currency_count"] > 0 then 1043 if entry["rewards"]["currency_count"] > 0 then
1043 entry["rewards"]["currencies"] = {} 1044 entry["rewards"]["currencies"] = {}
1044 for i = 1, entry["rewards"]["currency_count"] do 1045 for i = 1, entry["rewards"]["currency_count"] do
1045 local name, texture_path, quantity = _G.GetQuestLogRewardCurrencyInfo(i, quest_id) 1046 local name, texture_path, quantity = _G.GetQuestLogRewardCurrencyInfo(i, quest_id)
1046 local currency_id = CurrencyInfoToID(name, texture_path) 1047 local currency_id = CurrencyInfoToID(name, texture_path)
1047 table.insert(entry["rewards"]["currencies"], ("%d:%d"):format(quantity, currency_id)) 1048 if currency_id and currency_id ~= 0 then
1049 table.insert(entry["rewards"]["currencies"], ("%d:%d"):format(quantity, currency_id))
1050 end
1048 end 1051 end
1049 end 1052 end
1050 1053
1051 -- Record items 1054 -- Record items
1052 entry["rewards"]["item_count"] = tonumber(_G.GetNumQuestLogRewards(quest_id)) or 0 1055 entry["rewards"]["item_count"] = tonumber(_G.GetNumQuestLogRewards(quest_id)) or 0
2551 for cost_index = 1, item_count do 2554 for cost_index = 1, item_count do
2552 -- The third return (Blizz calls "currency_link") of GetMerchantItemCostItem only returns item links as of Patch 5.3.0. 2555 -- The third return (Blizz calls "currency_link") of GetMerchantItemCostItem only returns item links as of Patch 5.3.0.
2553 local texture_path, amount_required, item_link, name = _G.GetMerchantItemCostItem(item_index, cost_index) 2556 local texture_path, amount_required, item_link, name = _G.GetMerchantItemCostItem(item_index, cost_index)
2554 2557
2555 -- Try to detect if this is actually a currency by looking for a nil item_link or item ID 2558 -- Try to detect if this is actually a currency by looking for a nil item_link or item ID
2556 local is_item = item_link and ItemLinkToID(item_link) 2559 local is_currency = (not item_link) or (not ItemLinkToID(item_link))
2557 2560
2558 if not is_item then 2561 if is_currency then
2559 local currency_id = CurrencyInfoToID(name, texture_path) 2562 local currency_id = CurrencyInfoToID(name, texture_path)
2560 currency_list[#currency_list + 1] = ("(%s:%d)"):format(amount_required, currency_id) 2563 if currency_id and currency_id ~= 0 then
2564 currency_list[#currency_list + 1] = ("(%s:%d)"):format(amount_required, currency_id)
2565 end
2561 end 2566 end
2562 end 2567 end
2563 2568
2564 for currency_index = 1, #currency_list do 2569 for currency_index = 1, #currency_list do
2565 price_string = ("%s:%s"):format(price_string, currency_list[currency_index]) 2570 price_string = ("%s:%s"):format(price_string, currency_list[currency_index])