Mercurial > wow > wowdb-profiler
diff Main.lua @ 75:a034bfa8982b
Handle recording of loot from specific sources.
author | James D. Callahan III <jcallahan@curse.com> |
---|---|
date | Tue, 21 Aug 2012 15:29:15 -0500 |
parents | 06daf4cb1cf9 |
children | 5c42e26ae1fc |
line wrap: on
line diff
--- a/Main.lua Mon Aug 20 11:39:46 2012 -0500 +++ b/Main.lua Tue Aug 21 15:29:15 2012 -0500 @@ -381,32 +381,49 @@ end -- do-block -local function GenericLootUpdate(data_type, top_field) - local entry = DBEntry(data_type, action_data.identifier) - - if not entry then - return - end - local loot_type = action_data.label or "drops" - local loot_count = ("%s_count"):format(loot_type) - local loot_data - - if top_field then - entry[top_field] = entry[top_field] or {} - entry[top_field][loot_count] = (entry[top_field][loot_count] or 0) + 1 - entry[top_field][loot_type] = entry[top_field][loot_type] or {} - loot_data = entry[top_field][loot_type] - else +local GenericLootUpdate +do + local function LootTable(entry, loot_type, loot_count, top_field) + if top_field then + entry[top_field] = entry[top_field] or {} + entry[top_field][loot_count] = (entry[top_field][loot_count] or 0) + 1 + entry[top_field][loot_type] = entry[top_field][loot_type] or {} + return entry[top_field][loot_type] + end entry[loot_count] = (entry[loot_count] or 0) + 1 entry[loot_type] = entry[loot_type] or {} - loot_data = entry[loot_type] + return entry[loot_type] end - for index = 1, #action_data.loot_list do - table.insert(loot_data, action_data.loot_list[index]) + function GenericLootUpdate(data_type, top_field) + local loot_type = action_data.label or "drops" + local loot_count = ("%s_count"):format(loot_type) + + for source_id, loot_data in pairs(action_data.loot_sources) do + local entry = DBEntry(data_type, source_id) + + if entry then + local loot_table = LootTable(entry, loot_type, loot_count, top_field) + UpdateDBEntryLocation(data_type, source_id) + + for item_id, quantity in pairs(loot_data) do + table.insert(loot_table, ("%d:%d"):format(item_id, quantity)) + end + end + end + -- TODO: Remove this when GetLootSourceInfo() has values for money + local entry = DBEntry(data_type, action_data.identifier) + + if not entry then + return + end + local loot_table = LootTable(entry, loot_type, loot_count, top_field) + + for index = 1, #action_data.loot_list do + table.insert(loot_table, action_data.loot_list[index]) + end end -end - +end -- do-block ----------------------------------------------------------------------- -- Methods. @@ -523,7 +540,7 @@ end -function WDP:CHAT_MSG_LOOT(event, message) +function WDP:CHAT_MSG_LOOT(event_name, message) if action_data.spell_label ~= "EXTRACT_GAS" then return end @@ -806,13 +823,31 @@ GenericLootUpdate("items") end, [AF.NPC] = function() + local difficulty_token = InstanceDifficultyToken() + local loot_type = action_data.label or "drops" + + for source_id, loot_data in pairs(action_data.loot_sources) do + local npc = NPCEntry(source_id) + + if npc then + local encounter_data = npc.encounter_data[difficulty_token] + encounter_data.loot_counts = encounter_data.loot_counts or {} + encounter_data.loot_counts[loot_type] = (encounter_data.loot_counts[loot_type] or 0) + 1 + encounter_data[loot_type] = encounter_data[loot_type] or {} + + for item_id, quantity in pairs(loot_data) do + table.insert(encounter_data[loot_type], ("%d:%d"):format(item_id, quantity)) + end + end + end + + -- TODO: Remove this when GetLootSourceInfo() has values for money local npc = NPCEntry(action_data.identifier) if not npc then return end - local encounter_data = npc.encounter_data[InstanceDifficultyToken()] - local loot_type = action_data.label or "drops" + local encounter_data = npc.encounter_data[difficulty_token] encounter_data.loot_counts = encounter_data.loot_counts or {} encounter_data.loot_counts[loot_type] = (encounter_data.loot_counts[loot_type] or 0) + 1 encounter_data[loot_type] = encounter_data[loot_type] or {} @@ -861,27 +896,44 @@ if _G.type(verify_func) == "function" and not verify_func() then return end - local loot_registry = {} action_data.loot_list = {} + action_data.loot_sources = {} action_data.looting = true for loot_slot = 1, _G.GetNumLootItems() do local icon_texture, item_text, quantity, quality, locked = _G.GetLootSlotInfo(loot_slot) local slot_type = _G.GetLootSlotType(loot_slot) + local sources = { + _G.GetLootSourceInfo(loot_slot) + } - if slot_type == _G.LOOT_SLOT_ITEM then - local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot)) - loot_registry[item_id] = (loot_registry[item_id]) or 0 + quantity - elseif slot_type == _G.LOOT_SLOT_MONEY then - table.insert(action_data.loot_list, ("money:%d"):format(_toCopper(item_text))) - elseif slot_type == _G.LOOT_SLOT_CURRENCY then - table.insert(action_data.loot_list, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower())) + -- TODO: Remove debugging + -- print(("Loot slot %d: Source count: %d"):format(loot_slot, floor((#sources / 2) + 0.5))) + + -- Odd index is GUID, even is count. + for source_index = 1, #sources, 2 do + local source_type, source_id = ParseGUID(sources[source_index]) + local source_count = sources[source_index + 1] + local source_key = ("%s:%d"):format(private.UNIT_TYPE_NAMES[source_type + 1], source_id) + -- TODO: Remove debugging + -- print(("GUID: %s - Type:ID: %s - Amount: %d"):format(sources[source_index], source_key, source_count)) + + -- Items return the player as the source, so we need to replace the nil ID with the item's ID (disenchant, milling, etc) + if not source_id then + source_id = action_data.identifier + end + action_data.loot_sources[source_id] = action_data.loot_sources[source_id] or {} + + if slot_type == _G.LOOT_SLOT_ITEM then + local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot)) + action_data.loot_sources[source_id][item_id] = action_data.loot_sources[source_id][item_id] or 0 + source_count + elseif slot_type == _G.LOOT_SLOT_MONEY then + table.insert(action_data.loot_list, ("money:%d"):format(_toCopper(item_text))) + elseif slot_type == _G.LOOT_SLOT_CURRENCY then + table.insert(action_data.loot_list, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower())) + end end end - - for item_id, quantity in pairs(loot_registry) do - table.insert(action_data.loot_list, ("%d:%d"):format(item_id, quantity)) - end update_func() end end -- do-block @@ -1266,11 +1318,7 @@ if target_name == "" then return end - local identifier = ("%s:%s"):format(spell_label, target_name) - UpdateDBEntryLocation("objects", identifier) - action_data.type = AF.OBJECT - action_data.identifier = identifier elseif bit.band(spell_flags, AF.ZONE) == AF.ZONE then local identifier = ("%s:%s"):format(spell_label, _G["GameTooltipTextLeft1"]:GetText() or "NONE") -- Possible fishing pool name. action_data.zone_data = UpdateDBEntryLocation("zones", identifier)