comparison Main.lua @ 329:84817627cb22 WoD

Many changes for WoD, including support for Itembonuses, the new GUID format, and LOOT_READY.
author MMOSimca <MMOSimca@gmail.com>
date Wed, 06 Aug 2014 04:39:26 -0400
parents 3487529df8e5
children 267e7100407c 998f3264b482
comparison
equal deleted inserted replaced
328:3487529df8e5 329:84817627cb22
90 GROUP_ROSTER_UPDATE = true, 90 GROUP_ROSTER_UPDATE = true,
91 GUILDBANKFRAME_OPENED = true, 91 GUILDBANKFRAME_OPENED = true,
92 ITEM_TEXT_BEGIN = true, 92 ITEM_TEXT_BEGIN = true,
93 ITEM_UPGRADE_MASTER_OPENED = true, 93 ITEM_UPGRADE_MASTER_OPENED = true,
94 LOOT_CLOSED = true, 94 LOOT_CLOSED = true,
95 LOOT_OPENED = true, 95 LOOT_READY = true,
96 MAIL_SHOW = true, 96 MAIL_SHOW = true,
97 MERCHANT_CLOSED = true, 97 MERCHANT_CLOSED = true,
98 MERCHANT_SHOW = "UpdateMerchantItems", 98 MERCHANT_SHOW = "UpdateMerchantItems",
99 MERCHANT_UPDATE = "UpdateMerchantItems", 99 MERCHANT_UPDATE = "UpdateMerchantItems",
100 PET_BAR_UPDATE = true, 100 PET_BAR_UPDATE = true,
461 461
462 462
463 local ParseGUID 463 local ParseGUID
464 do 464 do
465 local UNIT_TYPES = private.UNIT_TYPES 465 local UNIT_TYPES = private.UNIT_TYPES
466 local UNIT_TYPE_BITMASK = 0x007
467 466
468 local NPC_ID_MAPPING = { 467 local NPC_ID_MAPPING = {
469 [62164] = 63191, -- Garalon 468 [62164] = 63191, -- Garalon
470 } 469 }
471 470
472 471
472 function MatchUnitTypes(unit_type_name)
473 if not unit_type_name then
474 return UNIT_TYPES.UNKNOWN
475 end
476
477 for def, text in next, UNIT_TYPES do
478 if unit_type_name == text then
479 return UNIT_TYPES[def]
480 end
481 end
482 return UNIT_TYPES.UNKNOWN
483 end
484
485
473 function ParseGUID(guid) 486 function ParseGUID(guid)
474 if not guid then 487 if not guid then
475 return 488 return
476 end 489 end
477 local bitfield = tonumber(guid:sub(1, 5)) 490
478 491 -- We might want to use some of this new information later, but leaving the returns alone for now
479 if not bitfield then 492 local unit_type_name, unk_id1, server_id, instance_id, unk_id2, unit_idnum, spawn_id = (":"):split(guid)
480 return UNIT_TYPES.UNKNOWN 493
481 end 494 unit_type = MatchUnitTypes(unit_type_name)
482 local unit_type = _G.bit.band(bitfield, UNIT_TYPE_BITMASK) 495 if unit_type ~= UNIT_TYPES.PLAYER and unit_type ~= UNIT_TYPES.PET and unit_type ~= UNIT_TYPES.ITEM then
483 496
484 if unit_type ~= UNIT_TYPES.PLAYER and unit_type ~= UNIT_TYPES.PET then
485 local unit_idnum = tonumber(guid:sub(6, 10), 16)
486 local id_mapping = NPC_ID_MAPPING[unit_idnum] 497 local id_mapping = NPC_ID_MAPPING[unit_idnum]
487 498
488 if id_mapping and UnitTypeIsNPC(unit_type) then 499 if id_mapping and UnitTypeIsNPC(unit_type) then
489 unit_idnum = id_mapping 500 unit_idnum = id_mapping
490 end 501 end
595 current_action.identifier = item_id 606 current_action.identifier = item_id
596 current_action.loot_label = "contains" 607 current_action.loot_label = "contains"
597 return 608 return
598 end 609 end
599 end 610 end
600
601 Debug("HandleItemUse: Item with ID %d and link %s did not have a tooltip that contained the string %s.", item_id, item_link, _G.ITEM_OPENABLE) 611 Debug("HandleItemUse: Item with ID %d and link %s did not have a tooltip that contained the string %s.", item_id, item_link, _G.ITEM_OPENABLE)
602 end 612 end
603 613
604 614
605 local UnitFactionStanding 615 local UnitFactionStanding
947 break 957 break
948 end 958 end
949 local amount, stat = left_text:match("+(.-) (.*)") 959 local amount, stat = left_text:match("+(.-) (.*)")
950 960
951 if amount and stat then 961 if amount and stat then
952 if reforge_id and reforge_id ~= 0 then
953 local reforge_string = stat:find("Reforged")
954
955 if reforge_string then
956 stat = stat:sub(0, reforge_string - 3)
957 intermediary.reforge_id = reforge_id
958 end
959 end
960 create_entry = true 962 create_entry = true
961 intermediary[stat:lower():gsub(" ", "_"):gsub("|r", "")] = tonumber((amount:gsub(",", ""))) 963 intermediary[stat:lower():gsub(" ", "_"):gsub("|r", "")] = tonumber((amount:gsub(",", "")))
962 end 964 end
963 end 965 end
964 966
982 local function RecordItemData(item_id, item_link, durability) 984 local function RecordItemData(item_id, item_link, durability)
983 local item_string = select(3, item_link:find("^|%x+|H(.+)|h%[.+%]")) 985 local item_string = select(3, item_link:find("^|%x+|H(.+)|h%[.+%]"))
984 local item 986 local item
985 987
986 if item_string then 988 if item_string then
987 local _, _, _, _, _, _, _, suffix_id, unique_id, _, reforge_id, upgrade_id = (":"):split(item_string) 989 local _, _, _, _, _, _, _, suffix_id, unique_id, _, upgrade_id, instance_difficulty_id, num_bonus_ids = (":"):split(item_string)
988 suffix_id = tonumber(suffix_id) 990 local bonus_ids = {select(14, (":"):split(item_string))}
989 upgrade_id = tonumber(upgrade_id) 991 upgrade_id = tonumber(upgrade_id)
990 992 instance_difficulty_id = tonumber(instance_difficulty_id)
991 if suffix_id and suffix_id ~= 0 then 993 num_bonus_ids = tonumber(num_bonus_ids)
994 if (not num_bonus_ids) or (num_bonus_ids == 0) then
995 if (suffix_id and suffix_id ~= 0) or (instance_difficulty_id and instance_difficulty_id ~= 0) then
996 item = DBEntry("items", item_id)
997 item.unique_id = bit.band(unique_id, 0xFFFF)
998 if (suffix_id and suffix_id ~= 0) then
999 item.suffix_id = suffix_id
1000 end
1001 if (instance_difficulty_id and instance_difficulty_id ~= 0) then
1002 item.instance_difficulty_id = instance_difficulty_id
1003 end
1004 end
1005 elseif num_bonus_ids > 0 then
992 item = DBEntry("items", item_id) 1006 item = DBEntry("items", item_id)
993 item.suffix_id = suffix_id 1007
994 item.unique_id = bit.band(unique_id, 0xFFFF) 1008 item.unique_id = bit.band(unique_id, 0xFFFF)
995 end 1009 item.instance_difficulty_id = instance_difficulty_id
996 1010
1011 if not item.bonus_ids then
1012 item.bonus_ids = {}
1013 end
1014
1015 for bonus_index = 1, num_bonus_ids do
1016 item.bonus_ids[bonus_ids[bonus_index]] = true
1017 end
1018 else
1019 Debug("RecordItemData: Item_system is supposed to be 0 or positive, instead it was %s.", item_system)
1020 end
997 if upgrade_id and upgrade_id ~= 0 then 1021 if upgrade_id and upgrade_id ~= 0 then
998 DatamineTT:SetHyperlink(item_link) 1022 DatamineTT:SetHyperlink(item_link)
999 ScrapeItemUpgradeStats(item_id, upgrade_id, reforge_id) 1023 ScrapeItemUpgradeStats(item_id, upgrade_id)
1000 end 1024 end
1001 end 1025 end
1002 1026
1003 if durability and durability > 0 then 1027 if durability and durability > 0 then
1004 item = item or DBEntry("items", item_id) 1028 item = item or DBEntry("items", item_id)
1684 UpdateDBEntryLocation("objects", unit_idnum) 1708 UpdateDBEntryLocation("objects", unit_idnum)
1685 end 1709 end
1686 1710
1687 1711
1688 do 1712 do
1689 local LOOT_OPENED_VERIFY_FUNCS = { 1713 local LOOT_READY_VERIFY_FUNCS = {
1690 -- Item containers can be AOE-looted in Patch 5.4.2 if the user clicks fast enough, but this verification still works as long as they both have loot. 1714 -- Item containers can be AOE-looted in Patch 5.4.2 if the user clicks fast enough, but this verification still works as long as they both have loot.
1691 [AF.ITEM] = function() 1715 [AF.ITEM] = function()
1692 local locked_item_id 1716 local locked_item_id
1693 1717
1694 for bag_index = 0, _G.NUM_BAG_FRAMES do 1718 for bag_index = 0, _G.NUM_BAG_FRAMES do
1719 return _G.IsFishingLoot() 1743 return _G.IsFishingLoot()
1720 end, 1744 end,
1721 } 1745 }
1722 1746
1723 1747
1724 local LOOT_OPENED_UPDATE_FUNCS = { 1748 local LOOT_READY_UPDATE_FUNCS = {
1725 [AF.ITEM] = function() 1749 [AF.ITEM] = function()
1726 GenericLootUpdate("items") 1750 GenericLootUpdate("items")
1727 end, 1751 end,
1728 [AF.NPC] = function() 1752 [AF.NPC] = function()
1729 local difficulty_token = InstanceDifficultyToken() 1753 local difficulty_token = InstanceDifficultyToken()
1836 1860
1837 if num_guids == 0 then 1861 if num_guids == 0 then
1838 Debug("%s: No GUIDs found in loot. Blank loot window?", log_source) 1862 Debug("%s: No GUIDs found in loot. Blank loot window?", log_source)
1839 return false 1863 return false
1840 end 1864 end
1841
1842 if private.previous_spell_id and private.EXTRAPOLATION_BANNED_SPELL_IDS[private.previous_spell_id] then 1865 if private.previous_spell_id and private.EXTRAPOLATION_BANNED_SPELL_IDS[private.previous_spell_id] then
1843 Debug("%s: Problematic spell id %s found. Loot extrapolation for this set of loot would have run an increased risk of introducing bad data into the system.", log_source, private.previous_spell_id) 1866 Debug("%s: Problematic spell id %s found. Loot extrapolation for this set of loot would have run an increased risk of introducing bad data into the system.", log_source, private.previous_spell_id)
1844 return false 1867 return false
1845 end 1868 end
1846 1869
1896 Debug("%s: Successfully extrapolated information for current_action.", log_source) 1919 Debug("%s: Successfully extrapolated information for current_action.", log_source)
1897 return true 1920 return true
1898 end 1921 end
1899 1922
1900 1923
1901 function WDP:LOOT_OPENED(event_name) 1924 function WDP:LOOT_READY(event_name)
1902 if current_loot then 1925 if current_loot then
1903 current_loot = nil 1926 current_loot = nil
1904 Debug("%s: Previous loot did not process in time for this event. Attempting to extrapolate current_action from loot data.", event_name) 1927 Debug("%s: Previous loot did not process in time for this event. Attempting to extrapolate current_action from loot data.", event_name)
1905 1928
1906 if not ExtrapolatedCurrentActionFromLootData(event_name) then 1929 if not ExtrapolatedCurrentActionFromLootData(event_name) then
1915 if not ExtrapolatedCurrentActionFromLootData(event_name) then 1938 if not ExtrapolatedCurrentActionFromLootData(event_name) then
1916 Debug("%s: Unable to extrapolate current_action. Aborting attempts to handle loot for now.", event_name) 1939 Debug("%s: Unable to extrapolate current_action. Aborting attempts to handle loot for now.", event_name)
1917 return 1940 return
1918 end 1941 end
1919 end 1942 end
1920 local verify_func = LOOT_OPENED_VERIFY_FUNCS[current_action.target_type] 1943 local verify_func = LOOT_READY_VERIFY_FUNCS[current_action.target_type]
1921 local update_func = LOOT_OPENED_UPDATE_FUNCS[current_action.target_type] 1944 local update_func = LOOT_READY_UPDATE_FUNCS[current_action.target_type]
1922 1945
1923 if not verify_func or not update_func then 1946 if not verify_func or not update_func then
1924 Debug("%s: The current action's target type is unsupported or nil.", event_name) 1947 Debug("%s: The current action's target type is unsupported or nil.", event_name)
1925 return 1948 return
1926 end 1949 end
1945 for loot_index = 1, #loot_info, 2 do 1968 for loot_index = 1, #loot_info, 2 do
1946 local source_guid = loot_info[loot_index] 1969 local source_guid = loot_info[loot_index]
1947 1970
1948 if not loot_guid_registry[current_loot.label][source_guid] then 1971 if not loot_guid_registry[current_loot.label][source_guid] then
1949 local loot_quantity = loot_info[loot_index + 1] 1972 local loot_quantity = loot_info[loot_index + 1]
1950
1951 -- There is a new bug in 5.4.0 that causes GetLootSlotInfo() to (rarely) return nil values for slot_quantity. 1973 -- There is a new bug in 5.4.0 that causes GetLootSlotInfo() to (rarely) return nil values for slot_quantity.
1952 if slot_quantity then 1974 if slot_quantity then
1953 -- We need slot_quantity to account for an old bug where loot_quantity is sometimes '1' for stacks of items, such as cloth. 1975 -- We need slot_quantity to account for an old bug where loot_quantity is sometimes '1' for stacks of items, such as cloth.
1954 if slot_quantity > loot_quantity then 1976 if slot_quantity > loot_quantity then
1955 loot_quantity = slot_quantity 1977 loot_quantity = slot_quantity
1956 end 1978 end
1957
1958 local source_type, source_id = ParseGUID(source_guid) 1979 local source_type, source_id = ParseGUID(source_guid)
1959 local source_key = ("%s:%d"):format(private.UNIT_TYPE_NAMES[source_type + 1], source_id) 1980 local source_key = ("%s:%d"):format(source_type, source_id)
1960 1981
1961 if slot_type == _G.LOOT_SLOT_ITEM then 1982 if slot_type == _G.LOOT_SLOT_ITEM then
1962 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot)) 1983 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot))
1963 Debug("GUID: %s - Type:ID: %s - ItemID: %d - Amount: %d (%d)", loot_info[loot_index], source_key, item_id, loot_info[loot_index + 1], slot_quantity) 1984 Debug("GUID: %s - Type:ID: %s - ItemID: %d - Amount: %d (%d)", loot_info[loot_index], source_key, item_id, loot_info[loot_index + 1], slot_quantity)
1964 current_loot.sources[source_guid] = current_loot.sources[source_guid] or {} 1985 current_loot.sources[source_guid] = current_loot.sources[source_guid] or {}
2249 if unit_type == private.UNIT_TYPES.OBJECT then 2270 if unit_type == private.UNIT_TYPES.OBJECT then
2250 UpdateDBEntryLocation("objects", unit_id) 2271 UpdateDBEntryLocation("objects", unit_id)
2251 end 2272 end
2252 local quest = DBEntry("quests", _G.GetQuestID()) 2273 local quest = DBEntry("quests", _G.GetQuestID())
2253 quest[point] = quest[point] or {} 2274 quest[point] = quest[point] or {}
2254 quest[point][("%s:%d"):format(private.UNIT_TYPE_NAMES[unit_type + 1], unit_id)] = true 2275 quest[point][("%s:%d"):format(private.UNIT_TYPE_NAMES[unit_type], unit_id)] = true
2255 2276
2256 return quest 2277 return quest
2257 end 2278 end
2258 2279
2259 2280
2287 local selected_quest = _G.GetQuestLogSelection() -- Save current selection to be restored when we're done. 2308 local selected_quest = _G.GetQuestLogSelection() -- Save current selection to be restored when we're done.
2288 local entry_index, processed_quests = 1, 0 2309 local entry_index, processed_quests = 1, 0
2289 local _, num_quests = _G.GetNumQuestLogEntries() 2310 local _, num_quests = _G.GetNumQuestLogEntries()
2290 2311
2291 while processed_quests <= num_quests do 2312 while processed_quests <= num_quests do
2292 local _, _, _, _, is_header, _, _, _, quest_id = _G.GetQuestLogTitle(entry_index) 2313 local _, _, _, is_header, _, _, _, quest_id = _G.GetQuestLogTitle(entry_index)
2293 2314
2294 if quest_id == 0 then 2315 if quest_id == 0 then
2295 processed_quests = processed_quests + 1 2316 processed_quests = processed_quests + 1
2296 elseif not is_header then 2317 elseif not is_header then
2297 _G.SelectQuestLogEntry(entry_index); 2318 _G.SelectQuestLogEntry(entry_index);