comparison Main.lua @ 496:3938b87cfcd3

Radically rewrote currency support for WoWDBProfiler. It now uses currencyIDs everywhere instead of texture paths.
author MMOSimca <mmosimca@gmail.com>
date Tue, 11 Oct 2016 06:13:22 -0400
parents 1d1bbcad6563
children c8a8231c2336
comparison
equal deleted inserted replaced
495:1d1bbcad6563 496:3938b87cfcd3
14 local select = _G.select 14 local select = _G.select
15 local type = _G.type 15 local type = _G.type
16 local unpack = _G.unpack 16 local unpack = _G.unpack
17 17
18 local C_Timer = _G.C_Timer 18 local C_Timer = _G.C_Timer
19 local GetCurrencyInfo = _G.GetCurrencyInfo
19 20
20 21
21 -- ADDON NAMESPACE ---------------------------------------------------- 22 -- ADDON NAMESPACE ----------------------------------------------------
22 23
23 local ADDON_NAME, private = ... 24 local ADDON_NAME, private = ...
314 return math.floor(copper_cost / modifier) 315 return math.floor(copper_cost / modifier)
315 end 316 end
316 end -- do-block 317 end -- do-block
317 318
318 319
320 local CurrencyInfoToID
321 local PopulateCurrencyInfoLookup
322 do
323 local MAX_CURRENCY_ID_GAP = 800
324
325 local currency_info_lookup = {}
326
327
328 function CurrencyInfoToID(name, texture)
329 return currency_info_lookup[("%s:%s"):format(name, texture)]
330 end
331
332
333 function PopulateCurrencyInfoLookup()
334 local currency_index = 1
335 local gap_since_last_currency = 0
336 repeat
337 -- Store ID by info (name and texture combined)
338 local name, _, texture = GetCurrencyInfo(currency_index)
339 currency_info_lookup[("%s:%s"):format(name, texture)] = currency_index
340
341 -- If we found nothing, increment gap
342 if not name or not texture or (name == "" and texture == "") then
343 gap_since_last_currency = gap_since_last_currency + 1
344 else
345 gap_since_last_currency = 0
346 end
347
348 -- Increment loop counter
349 currency_index = currency_index + 1
350
351 until (gap_since_last_currency > MAX_CURRENCY_ID_GAP)
352 end
353 end
354
355
319 local function InstanceDifficultyToken() 356 local function InstanceDifficultyToken()
320 -- Sometimes, instance information is returned when not in an instance. This check protects against that. 357 -- Sometimes, instance information is returned when not in an instance. This check protects against that.
321 if _G.IsInInstance() then 358 if _G.IsInInstance() then
322 local _, instance_type, instance_difficulty, _, _, _, is_dynamic = _G.GetInstanceInfo() 359 local _, instance_type, instance_difficulty, _, _, _, is_dynamic = _G.GetInstanceInfo()
323 360
470 return zone_data 507 return zone_data
471 end 508 end
472 end -- do-block 509 end -- do-block
473 510
474 511
475 local function CurrencyLinkToTexture(currency_link) 512 local function CurrencyLinkToID(currency_link)
476 if not currency_link then 513 if not currency_link then
477 return 514 return nil
478 end 515 end
479 local _, _, texture_path = _G.GetCurrencyInfo(tonumber(currency_link:match("currency:(%d+)"))) 516 return tonumber(currency_link:match("currency:(%d+)")) or 0
480 return texture_path:match("[^\\]+$"):lower() 517 --texture_path:match("[^\\]+$"):lower()
481 end 518 end
482 519
483 520
484 local function ItemLinkToID(item_link) 521 local function ItemLinkToID(item_link)
485 if not item_link then 522 if not item_link then
696 for item_id, quantity in pairs(loot_data) do 733 for item_id, quantity in pairs(loot_data) do
697 table.insert(loot_table, ("%d:%d"):format(item_id, quantity)) 734 table.insert(loot_table, ("%d:%d"):format(item_id, quantity))
698 end 735 end
699 else 736 else
700 for loot_token, quantity in pairs(loot_data) do 737 for loot_token, quantity in pairs(loot_data) do
701 local label, currency_texture = (":"):split(loot_token) 738 local label, currency_id = (":"):split(loot_token)
702 739
703 if label == "currency" and currency_texture then 740 if label == "currency" and currency_id then
704 table.insert(loot_table, ("currency:%d:%s"):format(quantity, currency_texture)) 741 -- Convert currency_id back into number from string
742 currency_id = tonumber(currency_id) or 0
743 if currency_id ~= 0 then
744 table.insert(loot_table, ("currency:%d:%d"):format(quantity, currency_id))
745 end
705 elseif loot_token == "money" then 746 elseif loot_token == "money" then
706 table.insert(loot_table, ("money:%d"):format(quantity)) 747 table.insert(loot_table, ("money:%d"):format(quantity))
707 else 748 else
708 table.insert(loot_table, ("%d:%d"):format(loot_token, quantity)) 749 table.insert(loot_table, ("%d:%d"):format(loot_token, quantity))
709 end 750 end
830 if entry then 871 if entry then
831 local loot_table = LootTable(entry, "contains") 872 local loot_table = LootTable(entry, "contains")
832 entry["contains_count"] = (entry["contains_count"] or 0) + 1 873 entry["contains_count"] = (entry["contains_count"] or 0) + 1
833 874
834 for loot_token, quantity in pairs(chat_loot_data.loot) do 875 for loot_token, quantity in pairs(chat_loot_data.loot) do
835 local label, currency_texture = (":"):split(loot_token) 876 local label, currency_id = (":"):split(loot_token)
836 877
837 if label == "currency" and currency_texture then 878 if label == "currency" and currency_id then
838 table.insert(loot_table, ("currency:%d:%s"):format(quantity, currency_texture)) 879 -- Convert currency_id back into number from string
880 currency_id = tonumber(currency_id) or 0
881 if currency_id ~= 0 then
882 table.insert(loot_table, ("currency:%d:%d"):format(quantity, currency_id))
883 end
839 elseif loot_token == "money" then 884 elseif loot_token == "money" then
840 table.insert(loot_table, ("money:%d"):format(quantity)) 885 table.insert(loot_table, ("money:%d"):format(quantity))
841 else 886 else
842 table.insert(loot_table, ("%d:%d"):format(loot_token, quantity)) 887 table.insert(loot_table, ("%d:%d"):format(loot_token, quantity))
843 end 888 end
911 else 956 else
912 self:RegisterEvent(event_name, (_G.type(mapping) ~= "boolean") and mapping or nil) 957 self:RegisterEvent(event_name, (_G.type(mapping) ~= "boolean") and mapping or nil)
913 end 958 end
914 end 959 end
915 960
961 -- Gather known languages
916 for index = 1, _G.GetNumLanguages() do 962 for index = 1, _G.GetNumLanguages() do
917 languages_known[_G.GetLanguageByIndex(index)] = true 963 languages_known[_G.GetLanguageByIndex(index)] = true
918 end 964 end
965
966 -- Populate currency data from known currency information
967 PopulateCurrencyInfoLookup()
919 968
920 -- These timers loop indefinitely using Lua's infinity constant 969 -- These timers loop indefinitely using Lua's infinity constant
921 item_process_timer_handle = C_Timer.NewTicker(DELAY_PROCESS_ITEMS, WDP.ProcessItems, math.huge) 970 item_process_timer_handle = C_Timer.NewTicker(DELAY_PROCESS_ITEMS, WDP.ProcessItems, math.huge)
922 target_location_timer_handle = C_Timer.NewTicker(DELAY_UPDATE_TARGET_LOCATION, WDP.UpdateTargetLocation, math.huge) 971 target_location_timer_handle = C_Timer.NewTicker(DELAY_UPDATE_TARGET_LOCATION, WDP.UpdateTargetLocation, math.huge)
923 world_quest_timer_handle = C_Timer.NewTicker(DELAY_PROCESS_WORLD_QUESTS, WDP.ProcessWorldQuests, math.huge) 972 world_quest_timer_handle = C_Timer.NewTicker(DELAY_PROCESS_WORLD_QUESTS, WDP.ProcessWorldQuests, math.huge)
974 entry["rewards"]["honor"] = tonumber(_G.GetQuestLogRewardHonor(quest_id)) or 0 1023 entry["rewards"]["honor"] = tonumber(_G.GetQuestLogRewardHonor(quest_id)) or 0
975 1024
976 -- Record currencies 1025 -- Record currencies
977 entry["rewards"]["currency_count"] = tonumber(_G.GetNumQuestLogRewardCurrencies(quest_id)) or 0 1026 entry["rewards"]["currency_count"] = tonumber(_G.GetNumQuestLogRewardCurrencies(quest_id)) or 0
978 1027
1028 -- Create currency rewards sub-table and fill
979 if entry["rewards"]["currency_count"] > 0 then 1029 if entry["rewards"]["currency_count"] > 0 then
980
981 -- Create currency rewards sub-table and fill
982 entry["rewards"]["currencies"] = {} 1030 entry["rewards"]["currencies"] = {}
983 for i = 1, entry["rewards"]["currency_count"] do 1031 for i = 1, entry["rewards"]["currency_count"] do
984 local name, texture_path, quantity = _G.GetQuestLogRewardCurrencyInfo(i, quest_id) 1032 local name, texture_path, quantity = _G.GetQuestLogRewardCurrencyInfo(i, quest_id)
985 local currency_texture = texture_path:match("[^\\]+$"):lower() 1033 local currency_id = CurrencyInfoToID(name, texture_path)
986 table.insert(entry["rewards"]["currencies"], ("%d:%s"):format(quantity, currency_texture)) 1034 table.insert(entry["rewards"]["currencies"], ("%d:%d"):format(quantity, currency_id))
987 end 1035 end
988 end 1036 end
989 1037
990 -- Record items 1038 -- Record items
991 entry["rewards"]["item_count"] = tonumber(_G.GetNumQuestLogRewards(quest_id)) or 0 1039 entry["rewards"]["item_count"] = tonumber(_G.GetNumQuestLogRewards(quest_id)) or 0
992 1040
1041 -- Create item rewards sub-table and fill
993 if entry["rewards"]["item_count"] > 0 then 1042 if entry["rewards"]["item_count"] > 0 then
994
995 -- Create item rewards sub-table and fill
996 entry["rewards"]["items"] = {} 1043 entry["rewards"]["items"] = {}
997 for i = 1, entry["rewards"]["item_count"] do 1044 for i = 1, entry["rewards"]["item_count"] do
998 local item_name, item_texture, quantity, quality, is_usable, item_id = _G.GetQuestLogRewardInfo(i, quest_id) 1045 local item_name, item_texture, quantity, quality, is_usable, item_id = _G.GetQuestLogRewardInfo(i, quest_id)
999 table.insert(entry["rewards"]["items"], ("%d:%d"):format(item_id, quantity)) 1046 table.insert(entry["rewards"]["items"], ("%d:%d"):format(item_id, quantity))
1000 end 1047 end
1170 "REVERED", 1217 "REVERED",
1171 "EXALTED", 1218 "EXALTED",
1172 } 1219 }
1173 1220
1174 1221
1222 -- We should just use IDs here someday; WoWDB site knows all about different power types
1175 local POWER_TYPE_NAMES = { 1223 local POWER_TYPE_NAMES = {
1176 ["0"] = "MANA", 1224 ["0"] = "MANA",
1177 ["1"] = "RAGE", 1225 ["1"] = "RAGE",
1178 ["2"] = "FOCUS", 1226 ["2"] = "FOCUS",
1179 ["3"] = "ENERGY", 1227 ["3"] = "ENERGY",
1210 level_data = {} 1258 level_data = {}
1211 encounter_data[npc_level] = level_data 1259 encounter_data[npc_level] = level_data
1212 end 1260 end
1213 level_data.max_health = level_data.max_health or _G.UnitHealthMax("target") 1261 level_data.max_health = level_data.max_health or _G.UnitHealthMax("target")
1214 1262
1263 -- May not capture as much data as it could, since the API changed in Legion to report multiple types of power
1215 if not level_data.power then 1264 if not level_data.power then
1216 local max_power = _G.UnitPowerMax("target") 1265 local max_power = _G.UnitPowerMax("target")
1217 1266
1218 if max_power > 0 then 1267 if max_power > 0 then
1219 local power_type = _G.UnitPowerType("target") 1268 local power_type = _G.UnitPowerType("target")
1383 if loot_source and (loot_source == LOOT_SOURCE_ID_GARRISON_CACHE) and last_garrison_cache_object_id then 1432 if loot_source and (loot_source == LOOT_SOURCE_ID_GARRISON_CACHE) and last_garrison_cache_object_id then
1384 -- Record location data for cache 1433 -- Record location data for cache
1385 UpdateDBEntryLocation("objects", ("OPENING:%d"):format(last_garrison_cache_object_id)) 1434 UpdateDBEntryLocation("objects", ("OPENING:%d"):format(last_garrison_cache_object_id))
1386 1435
1387 -- Add drop data 1436 -- Add drop data
1388 local currency_texture = CurrencyLinkToTexture(item_link) 1437 local currency_id = CurrencyLinkToID(item_link)
1389 if currency_texture and currency_texture ~= "" then 1438 if currency_id and currency_id ~= 0 then
1390 -- Check for top level object data 1439 -- Check for top level object data
1391 local object_entry = DBEntry("objects", ("OPENING:%d"):format(last_garrison_cache_object_id)) 1440 local object_entry = DBEntry("objects", ("OPENING:%d"):format(last_garrison_cache_object_id))
1392 local difficulty_token = InstanceDifficultyToken() 1441 local difficulty_token = InstanceDifficultyToken()
1393 if object_entry[difficulty_token] then 1442 if object_entry[difficulty_token] then
1394 -- Increment loot count 1443 -- Increment loot count
1395 object_entry[difficulty_token]["opening_count"] = (object_entry[difficulty_token]["opening_count"] or 0) + 1 1444 object_entry[difficulty_token]["opening_count"] = (object_entry[difficulty_token]["opening_count"] or 0) + 1
1396 1445
1397 Debug("%s: %s X %d", event_name, currency_texture, quantity) 1446 Debug("%s: %d X %d", event_name, currency_id, quantity)
1398 object_entry[difficulty_token]["opening"] = object_entry[difficulty_token]["opening"] or {} 1447 object_entry[difficulty_token]["opening"] = object_entry[difficulty_token]["opening"] or {}
1399 table.insert(object_entry[difficulty_token]["opening"], ("currency:%d:%s"):format(quantity, currency_texture)) 1448 table.insert(object_entry[difficulty_token]["opening"], ("currency:%d:%d"):format(quantity, currency_id))
1400 else 1449 else
1401 Debug("%s: When handling the Garrison cache, the top level loot data was missing for objectID %d.", event_name, last_garrison_cache_object_id) 1450 Debug("%s: When handling the Garrison cache, the top level loot data was missing for objectID %d.", event_name, last_garrison_cache_object_id)
1402 end 1451 end
1403 else 1452 else
1404 Debug("%s: Currency texture is nil, from currency link %s", event_name, item_link) 1453 Debug("%s: Currency ID is nil or 0, from currency link %s", event_name, item_link)
1405 end 1454 end
1406 1455
1407 -- Wipe object ID until future mouseover 1456 -- Wipe object ID until future mouseover
1408 last_garrison_cache_object_id = nil 1457 last_garrison_cache_object_id = nil
1409 elseif raid_boss_id then 1458 elseif raid_boss_id then
1426 end 1475 end
1427 elseif loot_type == "money" then 1476 elseif loot_type == "money" then
1428 Debug("%s: money X %d", event_name, quantity) 1477 Debug("%s: money X %d", event_name, quantity)
1429 table.insert(encounter_data[loot_label], ("money:%d"):format(quantity)) 1478 table.insert(encounter_data[loot_label], ("money:%d"):format(quantity))
1430 elseif loot_type == "currency" then 1479 elseif loot_type == "currency" then
1431 local currency_texture = CurrencyLinkToTexture(item_link) 1480 local currency_id = CurrencyLinkToID(item_link)
1432 if currency_texture and currency_texture ~= "" then 1481 if currency_id and currency_id ~= 0 then
1433 Debug("%s: %s X %d", event_name, currency_texture, quantity) 1482 Debug("%s: %d X %d", event_name, currency_id, quantity)
1434 table.insert(encounter_data[loot_label], ("currency:%d:%s"):format(quantity, currency_texture)) 1483 table.insert(encounter_data[loot_label], ("currency:%d:%d"):format(quantity, currency_id))
1435 else 1484 else
1436 Debug("%s: Currency texture is nil, from currency link %s", event_name, item_link) 1485 Debug("%s: Currency ID is nil or 0, from currency link %s", event_name, item_link)
1437 return 1486 return
1438 end 1487 end
1439 end 1488 end
1440 1489
1441 if not boss_loot_toasting[raid_boss_id] then 1490 if not boss_loot_toasting[raid_boss_id] then
1466 end 1515 end
1467 elseif loot_type == "money" then 1516 elseif loot_type == "money" then
1468 Debug("%s: money X %d", event_name, quantity) 1517 Debug("%s: money X %d", event_name, quantity)
1469 current_loot.sources[loot_toast_container_id]["money"] = (current_loot.sources[loot_toast_container_id]["money"] or 0) + quantity 1518 current_loot.sources[loot_toast_container_id]["money"] = (current_loot.sources[loot_toast_container_id]["money"] or 0) + quantity
1470 elseif loot_type == "currency" then 1519 elseif loot_type == "currency" then
1471 local currency_texture = CurrencyLinkToTexture(item_link) 1520 local currency_id = CurrencyLinkToID(item_link)
1472 if currency_texture and currency_texture ~= "" then 1521 if currency_id and currency_id ~= 0 then
1473 Debug("%s: %s X %d", event_name, currency_texture, quantity) 1522 Debug("%s: %d X %d", event_name, currency_id, quantity)
1474 local currency_token = ("currency:%s"):format(currency_texture) 1523 local currency_token = ("currency:%d"):format(currency_id)
1475 current_loot.sources[loot_toast_container_id][currency_token] = (current_loot.sources[loot_toast_container_id][currency_token] or 0) + quantity 1524 current_loot.sources[loot_toast_container_id][currency_token] = (current_loot.sources[loot_toast_container_id][currency_token] or 0) + quantity
1476 else 1525 else
1477 Debug("%s: Currency texture is nil, from currency link %s", event_name, item_link) 1526 Debug("%s: Currency ID is nil or 0, from currency link %s", event_name, item_link)
1478 current_loot = nil 1527 current_loot = nil
1479 return 1528 return
1480 end 1529 end
1481 end 1530 end
1482 1531
1484 current_loot = nil 1533 current_loot = nil
1485 container_loot_toasting = true -- Do not count further loots until timer expires or another container is opened 1534 container_loot_toasting = true -- Do not count further loots until timer expires or another container is opened
1486 elseif loot_source and (loot_source == LOOT_SOURCE_ID_REDUNDANT) and chat_loot_timer_handle then 1535 elseif loot_source and (loot_source == LOOT_SOURCE_ID_REDUNDANT) and chat_loot_timer_handle then
1487 -- Handle currency loot toasts for chat-based loot (we do this instead of reading currency chat messages because the chat messages are very delayed) 1536 -- Handle currency loot toasts for chat-based loot (we do this instead of reading currency chat messages because the chat messages are very delayed)
1488 if loot_type == "currency" then 1537 if loot_type == "currency" then
1489 local currency_texture = CurrencyLinkToTexture(item_link) 1538 local currency_id = CurrencyLinkToID(item_link)
1490 if currency_texture and currency_texture ~= "" then 1539 if currency_id and currency_id ~= 0 then
1491 -- Verify that we're still assigning data to the right items 1540 -- Verify that we're still assigning data to the right items
1492 if chat_loot_data.identifier and (private.CONTAINER_ITEM_ID_LIST[chat_loot_data.identifier] ~= nil) then 1541 if chat_loot_data.identifier and (private.CONTAINER_ITEM_ID_LIST[chat_loot_data.identifier] ~= nil) then
1493 local currency_token = ("currency:%s"):format(currency_texture) 1542 Debug("%s: Captured currency for chat-based loot recording. %d X %d", event_name, currency_id, quantity)
1494 Debug("%s: Captured currency for chat-based loot recording. %s X %d", event_name, currency_token, quantity) 1543 local currency_token = ("currency:%d"):format(currency_id)
1495 chat_loot_data.loot = chat_loot_data.loot or {} 1544 chat_loot_data.loot = chat_loot_data.loot or {}
1496 chat_loot_data.loot[currency_token] = (chat_loot_data.loot[currency_token] or 0) + quantity 1545 chat_loot_data.loot[currency_token] = (chat_loot_data.loot[currency_token] or 0) + quantity
1497 else -- If not, cancel the timer and wipe the loot table early 1546 else -- If not, cancel the timer and wipe the loot table early
1498 Debug("%s: Canceled chat-based loot recording because we would have assigned the wrong loot!", event_name) 1547 Debug("%s: Canceled chat-based loot recording because we would have assigned the wrong loot!", event_name)
1499 ClearChatLootData() 1548 ClearChatLootData()
1500 end 1549 end
1501 else 1550 else
1502 Debug("%s: Currency texture is nil, from currency link %s", event_name, item_link) 1551 Debug("%s: Currency ID is nil or 0, from currency link %s", event_name, item_link)
1503 end 1552 end
1504 -- Handle money loot toasts for chat-based loot (we do this instead of reading money chat messages because the chat messages are very delayed) 1553 -- Handle money loot toasts for chat-based loot (we do this instead of reading money chat messages because the chat messages are very delayed)
1505 elseif loot_type == "money" then 1554 elseif loot_type == "money" then
1506 -- Verify that we're still assigning data to the right items 1555 -- Verify that we're still assigning data to the right items
1507 if chat_loot_data.identifier and (private.CONTAINER_ITEM_ID_LIST[chat_loot_data.identifier] ~= nil) then 1556 if chat_loot_data.identifier and (private.CONTAINER_ITEM_ID_LIST[chat_loot_data.identifier] ~= nil) then
1529 end 1578 end
1530 1579
1531 1580
1532 do 1581 do
1533 local CHAT_MSG_CURRENCY_UPDATE_FUNCS = { 1582 local CHAT_MSG_CURRENCY_UPDATE_FUNCS = {
1534 [AF.NPC] = function(currency_texture, quantity) 1583 [AF.NPC] = function(currency_id, quantity)
1535 Debug("CHAT_MSG_CURRENCY: AF.NPC currency:%s (%d)", currency_texture, quantity) 1584 Debug("CHAT_MSG_CURRENCY: AF.NPC currency:%d (%d)", currency_id, quantity)
1536 end, 1585 end,
1537 [AF.ZONE] = function(currency_texture, quantity) 1586 [AF.ZONE] = function(currency_id, quantity)
1538 local currency_token = ("currency:%s"):format(currency_texture) 1587 Debug("CHAT_MSG_CURRENCY: AF.ZONE currency:%d (%d)", currency_id, quantity)
1539 Debug("CHAT_MSG_CURRENCY: AF.ZONE %s (%d)", currency_token, quantity)
1540 InitializeCurrentLoot() 1588 InitializeCurrentLoot()
1541 current_loot.list[1] = ("%s:%d"):format(currency_token, quantity) 1589 current_loot.list[1] = ("currency:%d:%d"):format(quantity, currency_id)
1542 GenericLootUpdate("zones") 1590 GenericLootUpdate("zones")
1543 current_loot = nil 1591 current_loot = nil
1544 end, 1592 end,
1545 } 1593 }
1546 1594
1550 1598
1551 local currency_link, quantity = deformat(message, _G.CURRENCY_GAINED_MULTIPLE) 1599 local currency_link, quantity = deformat(message, _G.CURRENCY_GAINED_MULTIPLE)
1552 if not currency_link then 1600 if not currency_link then
1553 quantity, currency_link = 1, deformat(message, _G.CURRENCY_GAINED) 1601 quantity, currency_link = 1, deformat(message, _G.CURRENCY_GAINED)
1554 end 1602 end
1555 local currency_texture = CurrencyLinkToTexture(currency_link) 1603 local currency_id = CurrencyLinkToID(currency_link)
1556 1604
1557 if not currency_texture or currency_texture == "" then 1605 if not currency_id or currency_id == 0 then
1558 return 1606 return
1559 end 1607 end
1560 1608
1561 -- Set update category 1609 -- Set update category
1562 if current_action.spell_label == "FISHING" then 1610 if current_action.spell_label == "FISHING" then
1568 -- Take action based on update category 1616 -- Take action based on update category
1569 local update_func = CHAT_MSG_CURRENCY_UPDATE_FUNCS[category] 1617 local update_func = CHAT_MSG_CURRENCY_UPDATE_FUNCS[category]
1570 if not category or not update_func then 1618 if not category or not update_func then
1571 return 1619 return
1572 end 1620 end
1573 update_func(currency_texture, quantity) 1621 update_func(currency_id, quantity)
1574 end 1622 end
1575 1623
1576 1624
1577 local BLACKLISTED_ITEMS = { 1625 local BLACKLISTED_ITEMS = {
1578 [114116] = true, 1626 [114116] = true,
1783 [213738] = true, -- Taste of Blood (applied by Fate and Fortune, Combat Rogue artifacts) 1831 [213738] = true, -- Taste of Blood (applied by Fate and Fortune, Combat Rogue artifacts)
1784 [213877] = true, -- Vampiric Aura (used by Nathrezim Invasion bosses and transformed players) 1832 [213877] = true, -- Vampiric Aura (used by Nathrezim Invasion bosses and transformed players)
1785 [215377] = true, -- The Maw Must Feed (applied by Maw of the Damned, Blood Death Knight artifact) 1833 [215377] = true, -- The Maw Must Feed (applied by Maw of the Damned, Blood Death Knight artifact)
1786 [224762] = true, -- Leyline Rift (summoned by players with Leyline Mastery in Suramar) 1834 [224762] = true, -- Leyline Rift (summoned by players with Leyline Mastery in Suramar)
1787 [225832] = true, -- Nightglow Wisp (cast by players using Wisp in a Bottle toy) 1835 [225832] = true, -- Nightglow Wisp (cast by players using Wisp in a Bottle toy)
1788
1789 } 1836 }
1790 1837
1791 local function RecordNPCSpell(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name) 1838 local function RecordNPCSpell(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name)
1792 if not spell_id or BLACKLISTED_SPELLS[spell_id] then 1839 if not spell_id or BLACKLISTED_SPELLS[spell_id] then
1793 return 1840 return
2066 encounter_data.loot_counts[loot_label] = (encounter_data.loot_counts[loot_label] or 0) + 1 2113 encounter_data.loot_counts[loot_label] = (encounter_data.loot_counts[loot_label] or 0) + 1
2067 source_list[source_guid] = true 2114 source_list[source_guid] = true
2068 end 2115 end
2069 2116
2070 for loot_token, quantity in pairs(loot_data) do 2117 for loot_token, quantity in pairs(loot_data) do
2071 local loot_type, currency_texture = (":"):split(loot_token) 2118 local loot_type, currency_id = (":"):split(loot_token)
2072 2119
2073 if loot_type == "currency" and currency_texture then 2120 if loot_type == "currency" and currency_id then
2074 table.insert(encounter_data[loot_label], ("currency:%d:%s"):format(quantity, currency_texture)) 2121 -- Convert currency_id back into number from string
2122 currency_id = tonumber(currency_id) or 0
2123 if currency_id ~= 0 then
2124 table.insert(encounter_data[loot_label], ("currency:%d:%d"):format(quantity, currency_id))
2125 end
2075 elseif loot_token == "money" then 2126 elseif loot_token == "money" then
2076 table.insert(encounter_data[loot_label], ("money:%d"):format(quantity)) 2127 table.insert(encounter_data[loot_label], ("money:%d"):format(quantity))
2077 else 2128 else
2078 table.insert(encounter_data[loot_label], ("%d:%d"):format(loot_token, quantity)) 2129 table.insert(encounter_data[loot_label], ("%d:%d"):format(loot_token, quantity))
2079 end 2130 end
2278 2329
2279 InitializeCurrentLoot() 2330 InitializeCurrentLoot()
2280 loot_guid_registry[current_loot.label] = loot_guid_registry[current_loot.label] or {} 2331 loot_guid_registry[current_loot.label] = loot_guid_registry[current_loot.label] or {}
2281 2332
2282 for loot_slot = 1, _G.GetNumLootItems() do 2333 for loot_slot = 1, _G.GetNumLootItems() do
2283 local texturefiledataID, item_text, slot_quantity, quality, locked = _G.GetLootSlotInfo(loot_slot) 2334 local texture_filedata_id, item_text, slot_quantity, quality, locked = _G.GetLootSlotInfo(loot_slot)
2284 local slot_type = _G.GetLootSlotType(loot_slot) 2335 local slot_type = _G.GetLootSlotType(loot_slot)
2285 local loot_info = { _G.GetLootSourceInfo(loot_slot) } 2336 local loot_info = { _G.GetLootSourceInfo(loot_slot) }
2286 local loot_link = _G.GetLootSlotLink(loot_slot) 2337 local loot_link = _G.GetLootSlotLink(loot_slot)
2287 2338
2288 -- Odd index is GUID, even is count. 2339 -- Odd index is GUID, even is count.
2320 guids_used[source_guid] = true 2371 guids_used[source_guid] = true
2321 end 2372 end
2322 elseif slot_type == LOOT_SLOT_CURRENCY then 2373 elseif slot_type == LOOT_SLOT_CURRENCY then
2323 -- Same bug with GetLootSlotInfo() will screw up currency when it happens, so we won't process this slot's loot. 2374 -- Same bug with GetLootSlotInfo() will screw up currency when it happens, so we won't process this slot's loot.
2324 if loot_link then 2375 if loot_link then
2325 local icon_texture = CurrencyLinkToTexture(loot_link) 2376 local currency_id = CurrencyLinkToID(loot_link)
2326 Debug("GUID: %s - Type:ID: %s - Currency: %s - Amount: %d (%d)", loot_info[loot_index], source_key, icon_texture, loot_info[loot_index + 1], slot_quantity) 2377 Debug("GUID: %s - Type:ID: %s - Currency: %d - Amount: %d (%d)", loot_info[loot_index], source_key, currency_id, loot_info[loot_index + 1], slot_quantity)
2327 if current_loot.target_type == AF.ZONE then 2378 if current_loot.target_type == AF.ZONE then
2328 table.insert(current_loot.list, ("currency:%d:%s"):format(loot_quantity, icon_texture)) 2379 table.insert(current_loot.list, ("currency:%d:%d"):format(loot_quantity, currency_id))
2329 else 2380 else
2330 local currency_token = ("currency:%s"):format(icon_texture) 2381 local currency_token = ("currency:%d"):format(currency_id)
2331 2382
2332 current_loot.sources[source_guid] = current_loot.sources[source_guid] or {} 2383 current_loot.sources[source_guid] = current_loot.sources[source_guid] or {}
2333 current_loot.sources[source_guid][currency_token] = (current_loot.sources[source_guid][currency_token] or 0) + loot_quantity 2384 current_loot.sources[source_guid][currency_token] = (current_loot.sources[source_guid][currency_token] or 0) + loot_quantity
2334 guids_used[source_guid] = true 2385 guids_used[source_guid] = true
2335 end 2386 end
2483 -- price_string = ("%s:%s:%s:%s"):format(price_string, battleground_rating, personal_rating, required_season_amount or 0) 2534 -- price_string = ("%s:%s:%s:%s"):format(price_string, battleground_rating, personal_rating, required_season_amount or 0)
2484 price_string = ("%s:%s:%s"):format(price_string, personal_rating, required_season_amount or 0) 2535 price_string = ("%s:%s:%s"):format(price_string, personal_rating, required_season_amount or 0)
2485 2536
2486 for cost_index = 1, item_count do 2537 for cost_index = 1, item_count do
2487 -- The third return (Blizz calls "currency_link") of GetMerchantItemCostItem only returns item links as of Patch 5.3.0. 2538 -- The third return (Blizz calls "currency_link") of GetMerchantItemCostItem only returns item links as of Patch 5.3.0.
2488 local icon_texture, amount_required, item_link = _G.GetMerchantItemCostItem(item_index, cost_index) 2539 local texture_path, amount_required, item_link, name = _G.GetMerchantItemCostItem(item_index, cost_index)
2489 local currency_identifier = item_link and ItemLinkToID(item_link) or nil 2540
2490 2541 -- Try to detect if this is actually a currency by looking for a nil item_link or item ID
2491 if (not currency_identifier or currency_identifier < 1) and icon_texture then 2542 local is_item = item_link and ItemLinkToID(item_link)
2492 currency_identifier = icon_texture:match("[^\\]+$"):lower() 2543
2493 end 2544 if not is_item then
2494 2545 local currency_id = CurrencyInfoToID(name, texture_path)
2495 if currency_identifier then 2546 currency_list[#currency_list + 1] = ("(%s:%d)"):format(amount_required, currency_id)
2496 currency_list[#currency_list + 1] = ("(%s:%s)"):format(amount_required, currency_identifier)
2497 end 2547 end
2498 end 2548 end
2499 2549
2500 for currency_index = 1, #currency_list do 2550 for currency_index = 1, #currency_list do
2501 price_string = ("%s:%s"):format(price_string, currency_list[currency_index]) 2551 price_string = ("%s:%s"):format(price_string, currency_list[currency_index])
2871 table.insert(encounter_data[loot_label], ("%d:%d"):format(item_id, quantity)) 2921 table.insert(encounter_data[loot_label], ("%d:%d"):format(item_id, quantity))
2872 elseif loot_type == "money" then 2922 elseif loot_type == "money" then
2873 Debug("%s: Assigned stored money loot data - money:%d", event_name, quantity) 2923 Debug("%s: Assigned stored money loot data - money:%d", event_name, quantity)
2874 table.insert(encounter_data[loot_label], ("money:%d"):format(quantity)) 2924 table.insert(encounter_data[loot_label], ("money:%d"):format(quantity))
2875 elseif loot_type == "currency" then 2925 elseif loot_type == "currency" then
2876 local currency_texture = CurrencyLinkToTexture(hyperlink) 2926 local currency_id = CurrencyLinkToID(hyperlink)
2877 Debug("%s: Assigned stored currency loot data - %s - currency:%d:%s", event_name, hyperlink, currency_texture, quantity) 2927 Debug("%s: Assigned stored currency loot data - %s - currency:%d (%d)", event_name, hyperlink, currency_id, quantity)
2878 table.insert(encounter_data[loot_label], ("currency:%d:%s"):format(quantity, currency_texture)) 2928 table.insert(encounter_data[loot_label], ("currency:%d:%d"):format(quantity, currency_id))
2879 end 2929 end
2880 end 2930 end
2881 2931
2882 if not boss_loot_toasting[raid_boss_id] then 2932 if not boss_loot_toasting[raid_boss_id] then
2883 encounter_data.loot_counts[loot_label] = (encounter_data.loot_counts[loot_label] or 0) + 1 2933 encounter_data.loot_counts[loot_label] = (encounter_data.loot_counts[loot_label] or 0) + 1