diff Main.lua @ 317:8a2e619cced5

Loot and merchant currency fixes.
author James D. Callahan III <jcallahan@curse.com>
date Sun, 15 Sep 2013 19:01:58 -0500
parents 564deda095ec
children 4f2d5a082b6d
line wrap: on
line diff
--- a/Main.lua	Tue Sep 10 10:40:56 2013 -0500
+++ b/Main.lua	Sun Sep 15 19:01:58 2013 -0500
@@ -135,6 +135,7 @@
 local faction_standings = {}
 local forge_spell_ids = {}
 local languages_known = {}
+local boss_loot_toasting = {}
 local loot_toast_container_timer_handle
 local loot_toast_data
 local loot_toast_data_timer_handle
@@ -285,6 +286,12 @@
 end -- do-block
 
 
+-- constant for duplicate boss data; a dirty hack to get around world bosses that cannot be identified individually and cannot be linked on wowdb because they are not in a raid
+local DUPLICATE_WORLD_BOSS_IDS = {
+    [71952] = { 71953, 71954, 71955, },
+}
+
+
 -- Called on a timer
 local function ClearKilledNPC()
     killed_npc_id = nil
@@ -295,7 +302,7 @@
     if killed_boss_id_timer_handle then
         WDP:CancelTimer(killed_boss_id_timer_handle)
     end
-    private.boss_loot_toasting = false
+    table.wipe(boss_loot_toasting)
     private.raid_finder_boss_id = nil
     private.world_boss_id = nil
     killed_boss_id_timer_handle = nil
@@ -1182,42 +1189,61 @@
         return
     end
     local container_id = private.loot_toast_container_id
-    local npc = NPCEntry(private.raid_finder_boss_id or private.world_boss_id)
-
-    if npc then
-        local loot_label = "drops"
-        local encounter_data = npc:EncounterData(InstanceDifficultyToken())
-        encounter_data[loot_label] = encounter_data[loot_label] or {}
-        encounter_data.loot_counts = encounter_data.loot_counts or {}
-
-        if loot_type == "item" then
-            local item_id = ItemLinkToID(item_link)
-            if item_id then
-                Debug("%s: %s X %d (%d)", event_name, item_link, quantity, item_id)
-                table.insert(encounter_data[loot_label], ("%d:%d"):format(item_id, quantity))
-            else
-                Debug("%s: ItemID is nil, from item link %s", event_name, item_link)
-                return
+    local npc_id = private.raid_finder_boss_id or private.world_boss_id
+
+    if npc_id then
+        -- slightly messy hack to workaround duplicate world bosses
+        local upper_limit = 0
+        if DUPLICATE_WORLD_BOSS_IDS[npc_id] then
+            upper_limit = #DUPLICATE_WORLD_BOSS_IDS[npc_id]
+        end
+        for i = 0, upper_limit do
+            local temp_npc_id = npc_id
+
+            if i > 0 then
+                temp_npc_id = DUPLICATE_WORLD_BOSS_IDS[npc_id][i]
             end
-        elseif loot_type == "money" then
-            Debug("%s: money X %d", event_name, quantity)
-            table.insert(encounter_data[loot_label], ("money:%d"):format(quantity))
-        elseif loot_type == "currency" then
-            local currency_texture = CurrencyLinkToTexture(item_link)
-            if currency_texture and currency_texture ~= "" then
-                Debug("%s: %s X %d", event_name, currency_texture, quantity)
-                table.insert(encounter_data[loot_label], ("currency:%d:%s"):format(quantity, currency_texture))
-            else
-                Debug("%s: Currency texture is nil, from currency link %s", event_name, item_link)
-                return
+
+            local npc = NPCEntry(temp_npc_id)
+            if npc then
+                local loot_label = "drops"
+                local encounter_data = npc:EncounterData(InstanceDifficultyToken())
+                encounter_data[loot_label] = encounter_data[loot_label] or {}
+                encounter_data.loot_counts = encounter_data.loot_counts or {}
+
+                if loot_type == "item" then
+                    local item_id = ItemLinkToID(item_link)
+                    if item_id then
+                        Debug("%s: %s X %d (%d)", event_name, item_link, quantity, item_id)
+                        table.insert(encounter_data[loot_label], ("%d:%d"):format(item_id, quantity))
+                    else
+                        Debug("%s: ItemID is nil, from item link %s", event_name, item_link)
+                        return
+                    end
+                elseif loot_type == "money" then
+                    Debug("%s: money X %d", event_name, quantity)
+                    table.insert(encounter_data[loot_label], ("money:%d"):format(quantity))
+                elseif loot_type == "currency" then
+                    local currency_texture = CurrencyLinkToTexture(item_link)
+                    if currency_texture and currency_texture ~= "" then
+                        Debug("%s: %s X %d", event_name, currency_texture, quantity)
+                        -- workaround for Patch 5.4.0 bug with Flexible raid Siege of Orgrimmar bosses and Valor Points
+                        if quantity > 1000 and currency_texture == "pvecurrency-valor" then
+                            quantity = math.floor(quantity / 100)
+                        end
+                        table.insert(encounter_data[loot_label], ("currency:%d:%s"):format(quantity, currency_texture))
+                    else
+                        Debug("%s: Currency texture is nil, from currency link %s", event_name, item_link)
+                        return
+                    end
+                end
+
+                if not boss_loot_toasting[temp_npc_id] then
+                    encounter_data.loot_counts[loot_label] = (encounter_data.loot_counts[loot_label] or 0) + 1
+                    boss_loot_toasting[temp_npc_id] = true -- Do not count further loots until timer expires or another boss is killed
+                end
             end
         end
-
-        if not private.boss_loot_toasting then
-            encounter_data.loot_counts[loot_label] = (encounter_data.loot_counts[loot_label] or 0) + 1
-        end
-
-        private.boss_loot_toasting = true -- Do not count further loots until timer expires or another boss is killed
     elseif container_id then
         InitializeCurrentLoot()
 
@@ -1450,7 +1476,7 @@
                 table.wipe(previous_combat_event)
                 ClearKilledNPC()
             else
-               --Debug("%s: %s was killed by %s.", sub_event, dest_name or _G.UNKNOWN, killer_name or _G.UNKNOWN) -- broken in Patch 5.4
+                --Debug("%s: %s was killed by %s.", sub_event, dest_name or _G.UNKNOWN, killer_name or _G.UNKNOWN) -- broken in Patch 5.4
             end
             killed_npc_id = unit_idnum
             WDP:ScheduleTimer(ClearKilledNPC, 0.1)
@@ -1962,12 +1988,16 @@
                     price_string = ("%s:%s:%s"):format(price_string, personal_rating, required_season_amount or 0)
 
                     for cost_index = 1, item_count do
-                        -- (after some testing, the DB/Parser doesn't even support currency_ids -at all-, so vendor data submitted with the correct format will ironically be destroyed. that's why I removed the code here for currency_ids)
-                        -- the third return ("currency_link") of GetMerchantItemCostItem is broken as of Patch 5.4.0
-                        local currency_texture, amount_required = _G.GetMerchantItemCostItem(item_index, cost_index)
-
-                        if currency_texture then
-                            currency_list[#currency_list + 1] = ("(%s:%s)"):format(amount_required, currency_texture:match("[^\\]+$"):lower())
+                        -- the third return (Blizz calls "currency_link") of GetMerchantItemCostItem only returns item links as of Patch 5.3.0
+                        local icon_texture, amount_required, item_link = _G.GetMerchantItemCostItem(item_index, cost_index)
+                        local currency_identifier = item_link and ItemLinkToID(item_link) or nil
+
+                        if (not currency_identifier or currency_identifier < 1) and icon_texture then
+                            currency_identifier = icon_texture:match("[^\\]+$"):lower()
+                        end
+
+                        if currency_identifier then
+                            currency_list[#currency_list + 1] = ("(%s:%s)"):format(amount_required, currency_identifier)
                         end
                     end
 
@@ -2318,38 +2348,60 @@
 
     -- assign existing loot data to boss if it exists
     if loot_toast_data then
-        local npc = NPCEntry(private.raid_finder_boss_id or private.world_boss_id)
-
-        if npc then
-            -- create needed npc fields if required
-            local loot_label = "drops"
-            local encounter_data = npc:EncounterData(InstanceDifficultyToken())
-            encounter_data[loot_label] = encounter_data[loot_label] or {}
-            encounter_data.loot_counts = encounter_data.loot_counts or {}
-            encounter_data.loot_counts[loot_label] = (encounter_data.loot_counts[loot_label] or 0) + 1
-
-            for index = 1, #loot_toast_data do
-                local data = loot_toast_data[index]
-                local loot_type = data[1]
-                local hyperlink = data[2]
-                local quantity = data[3]
-
-                if loot_type == "item" then
-                    local item_id = ItemLinkToID(hyperlink)
-                    Debug("%s: Assigned stored item loot data - %s - %d:%d", event_name, hyperlink, item_id, quantity)
-                    table.insert(encounter_data[loot_label], ("%d:%d"):format(item_id, quantity))
-                elseif loot_type == "money" then
-                    Debug("%s: Assigned stored money loot data - money:%d", event_name, quantity)
-                    table.insert(encounter_data[loot_label], ("money:%d"):format(quantity))
-                elseif loot_type == "currency" then
-                    local currency_texture = CurrencyLinkToTexture(hyperlink)
-                    Debug("%s: Assigned stored currency loot data - %s - currency:%d:%s", event_name, hyperlink, currency_texture, quantity)
-                    table.insert(encounter_data[loot_label], ("currency:%d:%s"):format(quantity, currency_texture))
+        local npc_id = private.raid_finder_boss_id or private.world_boss_id
+
+        -- slightly messy hack to workaround duplicate world bosses
+        local upper_limit = 0
+        if DUPLICATE_WORLD_BOSS_IDS[npc_id] then
+            upper_limit = #DUPLICATE_WORLD_BOSS_IDS[npc_id]
+        end
+
+        for i = 0, upper_limit do
+            local temp_npc_id = npc_id
+
+            if i > 0 then
+                temp_npc_id = DUPLICATE_WORLD_BOSS_IDS[npc_id][i]
+            end
+
+            local npc = NPCEntry(temp_npc_id)
+            if npc then
+                -- create needed npc fields if required
+                local loot_label = "drops"
+                local encounter_data = npc:EncounterData(InstanceDifficultyToken())
+                encounter_data[loot_label] = encounter_data[loot_label] or {}
+                encounter_data.loot_counts = encounter_data.loot_counts or {}
+
+                for index = 1, #loot_toast_data do
+                    local data = loot_toast_data[index]
+                    local loot_type = data[1]
+                    local hyperlink = data[2]
+                    local quantity = data[3]
+
+                    if loot_type == "item" then
+                        local item_id = ItemLinkToID(hyperlink)
+                        Debug("%s: Assigned stored item loot data - %s - %d:%d", event_name, hyperlink, item_id, quantity)
+                        table.insert(encounter_data[loot_label], ("%d:%d"):format(item_id, quantity))
+                    elseif loot_type == "money" then
+                        Debug("%s: Assigned stored money loot data - money:%d", event_name, quantity)
+                        table.insert(encounter_data[loot_label], ("money:%d"):format(quantity))
+                    elseif loot_type == "currency" then
+                        local currency_texture = CurrencyLinkToTexture(hyperlink)
+                        Debug("%s: Assigned stored currency loot data - %s - currency:%d:%s", event_name, hyperlink, currency_texture, quantity)
+                        -- workaround for Patch 5.4.0 bug with Flexible raid Siege of Orgrimmar bosses and Valor Points
+                        if quantity > 1000 and currency_texture == "pvecurrency-valor" then
+                            quantity = math.floor(quantity / 100)
+                        end
+                        table.insert(encounter_data[loot_label], ("currency:%d:%s"):format(quantity, currency_texture))
+                    end
                 end
+
+                if not boss_loot_toasting[temp_npc_id] then
+                    encounter_data.loot_counts[loot_label] = (encounter_data.loot_counts[loot_label] or 0) + 1
+                    boss_loot_toasting[temp_npc_id] = true -- Do not count further loots until timer expires or another boss is killed
+                end
+            else
+                Debug("%s: NPC is nil, but we have stored loot data...", event_name)
             end
-            private.boss_loot_toasting = true
-        else
-            Debug("%s: NPC is nil, but we have stored loot data...", event_name)
         end
     end