changeset 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
files Comments.lua Constants.lua Main.lua
diffstat 3 files changed, 74 insertions(+), 62 deletions(-) [+]
line wrap: on
line diff
--- a/Comments.lua	Wed Aug 06 04:31:49 2014 -0400
+++ b/Comments.lua	Wed Aug 06 04:39:26 2014 -0400
@@ -115,7 +115,7 @@
         WDP:Printf("Unable to determine unit from '%s'", unit_id)
         return
     end
-    local type_name = private.UNIT_TYPE_NAMES[unit_type + 1]
+    local type_name = private.UNIT_TYPE_NAMES[unit_type]
     local unit_name = is_command and _G.UnitName(unit_id) or comment_units[unit_id].name
 
     table.wipe(comment_units)
--- a/Constants.lua	Wed Aug 06 04:31:49 2014 -0400
+++ b/Constants.lua	Wed Aug 06 04:39:26 2014 -0400
@@ -18,25 +18,25 @@
 private.wow_version, private.build_num = _G.GetBuildInfo()
 
 private.UNIT_TYPES = {
-    PLAYER = 0,
-    OBJECT = 1,
-    UNKNOWN = 2,
-    NPC = 3,
-    PET = 4,
-    VEHICLE = 5,
+    PLAYER = "Player",
+    OBJECT = "GameObject",
+    UNKNOWN = "Unknown",
+    NPC = "Creature",
+    PET = "Pet",
+    VEHICLE = "Vehicle",
+    ITEM = "Item",
 }
 
-
 private.UNIT_TYPE_NAMES = {
-    "PLAYER",
-    "OBJECT",
-    "UNKNOWN",
-    "NPC",
-    "PET",
-    "VEHICLE",
+    ["Player"] = "PLAYER",
+    ["GameObject"] = "OBJECT",
+    ["Unknown"] = "UNKNOWN",
+    ["Creature"] = "NPC",
+    ["Pet"] = "PET",
+    ["Vehicle"] = "VEHICLE",
+    ["Item"] = "ITEM",
 }
 
-
 private.ACTION_TYPE_FLAGS = {
     ITEM = 0x00000001,
     NPC = 0x00000002,
@@ -44,14 +44,12 @@
     ZONE = 0x00000008,
 }
 
-
 private.ACTION_TYPE_NAMES = {}
 
 for name, bit in _G.pairs(private.ACTION_TYPE_FLAGS) do
     private.ACTION_TYPE_NAMES[bit] = name
 end
 
-
 private.EXTRAPOLATION_BANNED_SPELL_IDS = {
     [13262] = "DISENCHANT",
     [4036] = "ENGINEERING",
@@ -67,7 +65,6 @@
     [8613] = "SKINNING",
 }
 
-
 private.SPELL_LABELS_BY_NAME = {
     [_G.GetSpellInfo(13262)] = "DISENCHANT",
     [_G.GetSpellInfo(4036)] = "ENGINEERING",
@@ -84,12 +81,10 @@
     [_G.GetSpellInfo(8613)] = "SKINNING",
 }
 
-
 private.NON_LOOT_SPELL_LABELS = {
     MIND_CONTROL = true,
 }
 
-
 local AF = private.ACTION_TYPE_FLAGS
 
 private.SPELL_FLAGS_BY_LABEL = {
@@ -108,7 +103,6 @@
     SKINNING = AF.NPC,
 }
 
-
 private.LOOT_SPELL_ID_TO_ITEM_ID_MAP = {
     [142397] = 98134, -- Heroic Cache of Treasures
     [143506] = 98095, -- Brawler's Pet Supplies
@@ -124,7 +118,6 @@
     [149223] = 105912, -- Oversized Pouch of Enduring Wisdom
 }
 
-
 private.RAID_FINDER_BOSS_IDS = {
     -----------------------------------------------------------------------
     -- Mogu'shan Vaults
@@ -216,7 +209,6 @@
     [71865] = true, -- Garrosh Hellscream
 }
 
-
 private.WORLD_BOSS_IDS = {
     [60491] = true, -- Sha of Anger
     [62346] = true, -- Galleon
@@ -229,7 +221,6 @@
     [72057] = true, -- Ordos
 }
 
-
 private.RAID_BOSS_BONUS_SPELL_ID_TO_NPC_ID_MAP = {
     -----------------------------------------------------------------------
     -- Mogu'shan Vaults
--- a/Main.lua	Wed Aug 06 04:31:49 2014 -0400
+++ b/Main.lua	Wed Aug 06 04:39:26 2014 -0400
@@ -92,7 +92,7 @@
     ITEM_TEXT_BEGIN = true,
     ITEM_UPGRADE_MASTER_OPENED = true,
     LOOT_CLOSED = true,
-    LOOT_OPENED = true,
+    LOOT_READY = true,
     MAIL_SHOW = true,
     MERCHANT_CLOSED = true,
     MERCHANT_SHOW = "UpdateMerchantItems",
@@ -463,26 +463,37 @@
 local ParseGUID
 do
     local UNIT_TYPES = private.UNIT_TYPES
-    local UNIT_TYPE_BITMASK = 0x007
 
     local NPC_ID_MAPPING = {
         [62164] = 63191, -- Garalon
     }
 
 
+    function MatchUnitTypes(unit_type_name)
+        if not unit_type_name then
+            return UNIT_TYPES.UNKNOWN
+        end
+
+        for def, text in next, UNIT_TYPES do
+            if unit_type_name == text then
+                return UNIT_TYPES[def]
+            end
+        end
+        return UNIT_TYPES.UNKNOWN
+    end
+
+
     function ParseGUID(guid)
         if not guid then
             return
         end
-        local bitfield = tonumber(guid:sub(1, 5))
-
-        if not bitfield then
-            return UNIT_TYPES.UNKNOWN
-        end
-        local unit_type = _G.bit.band(bitfield, UNIT_TYPE_BITMASK)
-
-        if unit_type ~= UNIT_TYPES.PLAYER and unit_type ~= UNIT_TYPES.PET then
-            local unit_idnum = tonumber(guid:sub(6, 10), 16)
+
+        -- We might want to use some of this new information later, but leaving the returns alone for now
+        local unit_type_name, unk_id1, server_id, instance_id, unk_id2, unit_idnum, spawn_id = (":"):split(guid)
+
+        unit_type = MatchUnitTypes(unit_type_name)
+        if unit_type ~= UNIT_TYPES.PLAYER and unit_type ~= UNIT_TYPES.PET and unit_type ~= UNIT_TYPES.ITEM then
+
             local id_mapping = NPC_ID_MAPPING[unit_idnum]
 
             if id_mapping and UnitTypeIsNPC(unit_type) then
@@ -597,7 +608,6 @@
             return
         end
     end
-
     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)
 end
 
@@ -949,14 +959,6 @@
             local amount, stat = left_text:match("+(.-) (.*)")
 
             if amount and stat then
-                if reforge_id and reforge_id ~= 0 then
-                    local reforge_string = stat:find("Reforged")
-
-                    if reforge_string then
-                        stat = stat:sub(0, reforge_string - 3)
-                        intermediary.reforge_id = reforge_id
-                    end
-                end
                 create_entry = true
                 intermediary[stat:lower():gsub(" ", "_"):gsub("|r", "")] = tonumber((amount:gsub(",", "")))
             end
@@ -984,19 +986,41 @@
     local item
 
     if item_string then
-        local _, _, _, _, _, _, _, suffix_id, unique_id, _, reforge_id, upgrade_id = (":"):split(item_string)
-        suffix_id = tonumber(suffix_id)
+        local _, _, _, _, _, _, _, suffix_id, unique_id, _, upgrade_id, instance_difficulty_id, num_bonus_ids = (":"):split(item_string)
+        local bonus_ids = {select(14, (":"):split(item_string))}
         upgrade_id = tonumber(upgrade_id)
-
-        if suffix_id and suffix_id ~= 0 then
+        instance_difficulty_id = tonumber(instance_difficulty_id)
+        num_bonus_ids = tonumber(num_bonus_ids)
+        if (not num_bonus_ids) or (num_bonus_ids == 0) then
+            if (suffix_id and suffix_id ~= 0) or (instance_difficulty_id and instance_difficulty_id ~= 0) then
+                item = DBEntry("items", item_id)
+                item.unique_id = bit.band(unique_id, 0xFFFF)
+                if (suffix_id and suffix_id ~= 0) then
+                    item.suffix_id = suffix_id
+                end
+                if (instance_difficulty_id and instance_difficulty_id ~= 0) then
+                    item.instance_difficulty_id = instance_difficulty_id
+                end
+            end
+        elseif num_bonus_ids > 0 then
             item = DBEntry("items", item_id)
-            item.suffix_id = suffix_id
+
             item.unique_id = bit.band(unique_id, 0xFFFF)
+            item.instance_difficulty_id = instance_difficulty_id
+            
+            if not item.bonus_ids then
+                item.bonus_ids = {}
+            end
+            
+            for bonus_index = 1, num_bonus_ids do
+                item.bonus_ids[bonus_ids[bonus_index]] = true
+            end
+        else
+            Debug("RecordItemData: Item_system is supposed to be 0 or positive, instead it was %s.", item_system)
         end
-
         if upgrade_id and upgrade_id ~= 0 then
             DatamineTT:SetHyperlink(item_link)
-            ScrapeItemUpgradeStats(item_id, upgrade_id, reforge_id)
+            ScrapeItemUpgradeStats(item_id, upgrade_id)
         end
     end
 
@@ -1686,7 +1710,7 @@
 
 
 do
-    local LOOT_OPENED_VERIFY_FUNCS = {
+    local LOOT_READY_VERIFY_FUNCS = {
         -- 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.
         [AF.ITEM] = function()
             local locked_item_id
@@ -1721,7 +1745,7 @@
     }
 
 
-    local LOOT_OPENED_UPDATE_FUNCS = {
+    local LOOT_READY_UPDATE_FUNCS = {
         [AF.ITEM] = function()
             GenericLootUpdate("items")
         end,
@@ -1838,7 +1862,6 @@
             Debug("%s: No GUIDs found in loot. Blank loot window?", log_source)
             return false
         end
-
         if private.previous_spell_id and private.EXTRAPOLATION_BANNED_SPELL_IDS[private.previous_spell_id] then
             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)
             return false
@@ -1898,7 +1921,7 @@
     end
 
 
-    function WDP:LOOT_OPENED(event_name)
+    function WDP:LOOT_READY(event_name)
         if current_loot then
             current_loot = nil
             Debug("%s: Previous loot did not process in time for this event. Attempting to extrapolate current_action from loot data.", event_name)
@@ -1917,8 +1940,8 @@
                 return
             end
         end
-        local verify_func = LOOT_OPENED_VERIFY_FUNCS[current_action.target_type]
-        local update_func = LOOT_OPENED_UPDATE_FUNCS[current_action.target_type]
+        local verify_func = LOOT_READY_VERIFY_FUNCS[current_action.target_type]
+        local update_func = LOOT_READY_UPDATE_FUNCS[current_action.target_type]
 
         if not verify_func or not update_func then
             Debug("%s: The current action's target type is unsupported or nil.", event_name)
@@ -1947,16 +1970,14 @@
 
                 if not loot_guid_registry[current_loot.label][source_guid] then
                     local loot_quantity = loot_info[loot_index + 1]
-
                     -- There is a new bug in 5.4.0 that causes GetLootSlotInfo() to (rarely) return nil values for slot_quantity.
                     if slot_quantity then
                         -- We need slot_quantity to account for an old bug where loot_quantity is sometimes '1' for stacks of items, such as cloth.
                         if slot_quantity > loot_quantity then
                             loot_quantity = slot_quantity
                         end
-
                         local source_type, source_id = ParseGUID(source_guid)
-                        local source_key = ("%s:%d"):format(private.UNIT_TYPE_NAMES[source_type + 1], source_id)
+                        local source_key = ("%s:%d"):format(source_type, source_id)
 
                         if slot_type == _G.LOOT_SLOT_ITEM then
                             local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot))
@@ -2251,7 +2272,7 @@
         end
         local quest = DBEntry("quests", _G.GetQuestID())
         quest[point] = quest[point] or {}
-        quest[point][("%s:%d"):format(private.UNIT_TYPE_NAMES[unit_type + 1], unit_id)] = true
+        quest[point][("%s:%d"):format(private.UNIT_TYPE_NAMES[unit_type], unit_id)] = true
 
         return quest
     end
@@ -2289,7 +2310,7 @@
     local _, num_quests = _G.GetNumQuestLogEntries()
 
     while processed_quests <= num_quests do
-        local _, _, _, _, is_header, _, _, _, quest_id = _G.GetQuestLogTitle(entry_index)
+        local _, _, _, is_header, _, _, _, quest_id = _G.GetQuestLogTitle(entry_index)
 
         if quest_id == 0 then
             processed_quests = processed_quests + 1