Mercurial > wow > wowdb-profiler
comparison Main.lua @ 387:b4a0a56ab3ae
Assorted code cleanup and reorganization as preparation for new data collection methods.
| author | MMOSimca <MMOSimca@gmail.com> |
|---|---|
| date | Tue, 16 Dec 2014 20:46:14 -0500 |
| parents | bc1b8234c659 |
| children | 1c6098b69ec9 |
comparison
equal
deleted
inserted
replaced
| 386:bc1b8234c659 | 387:b4a0a56ab3ae |
|---|---|
| 162 local item_process_timer_handle | 162 local item_process_timer_handle |
| 163 local faction_standings = {} | 163 local faction_standings = {} |
| 164 local forge_spell_ids = {} | 164 local forge_spell_ids = {} |
| 165 local languages_known = {} | 165 local languages_known = {} |
| 166 local boss_loot_toasting = {} | 166 local boss_loot_toasting = {} |
| 167 local container_loot_toasting | |
| 168 local loot_toast_container_id | |
| 169 local raid_boss_id | |
| 167 local loot_toast_container_timer_handle | 170 local loot_toast_container_timer_handle |
| 168 local loot_toast_data | 171 local loot_toast_data |
| 169 local loot_toast_data_timer_handle | 172 local loot_toast_data_timer_handle |
| 170 local name_to_id_map = {} | 173 local name_to_id_map = {} |
| 171 local killed_boss_id_timer_handle | 174 local killed_boss_id_timer_handle |
| 682 local loot_table = LootTable(entry, loot_type, top_field) | 685 local loot_table = LootTable(entry, loot_type, top_field) |
| 683 | 686 |
| 684 if not source_list[source_id] then | 687 if not source_list[source_id] then |
| 685 if top_field then | 688 if top_field then |
| 686 entry[top_field][loot_count] = (entry[top_field][loot_count] or 0) + 1 | 689 entry[top_field][loot_count] = (entry[top_field][loot_count] or 0) + 1 |
| 687 elseif not private.container_loot_toasting then | 690 elseif not container_loot_toasting then |
| 688 entry[loot_count] = (entry[loot_count] or 0) + 1 | 691 entry[loot_count] = (entry[loot_count] or 0) + 1 |
| 689 end | 692 end |
| 690 source_list[source_id] = true | 693 source_list[source_id] = true |
| 691 end | 694 end |
| 692 UpdateDBEntryLocation(data_type, source_id) | 695 UpdateDBEntryLocation(data_type, source_id) |
| 854 killed_boss_id_timer_handle:Cancel() | 857 killed_boss_id_timer_handle:Cancel() |
| 855 killed_boss_id_timer_handle = nil | 858 killed_boss_id_timer_handle = nil |
| 856 end | 859 end |
| 857 | 860 |
| 858 table.wipe(boss_loot_toasting) | 861 table.wipe(boss_loot_toasting) |
| 859 private.raid_boss_id = nil | 862 raid_boss_id = nil |
| 860 end | 863 end |
| 861 | 864 |
| 862 | 865 |
| 863 local function ClearLootToastContainerID() | 866 local function ClearLootToastContainerID() |
| 864 if loot_toast_container_timer_handle then | 867 if loot_toast_container_timer_handle then |
| 865 loot_toast_container_timer_handle:Cancel() | 868 loot_toast_container_timer_handle:Cancel() |
| 866 loot_toast_container_timer_handle = nil | 869 loot_toast_container_timer_handle = nil |
| 867 end | 870 end |
| 868 | 871 |
| 869 private.container_loot_toasting = false | 872 container_loot_toasting = false |
| 870 private.loot_toast_container_id = nil | 873 loot_toast_container_id = nil |
| 871 end | 874 end |
| 872 | 875 |
| 873 | 876 |
| 874 local function ClearLootToastData() | 877 local function ClearLootToastData() |
| 875 if loot_toast_data_timer_handle then | 878 if loot_toast_data_timer_handle then |
| 881 table.wipe(loot_toast_data) | 884 table.wipe(loot_toast_data) |
| 882 end | 885 end |
| 883 end | 886 end |
| 884 | 887 |
| 885 | 888 |
| 886 local function ClearTimeBasedLootData() | 889 local function ClearChatLootData() |
| 887 Debug("ClearTimeBasedLootData: Ending salvage loot timer.") | 890 Debug("ClearChatLootData: Ending chat-based loot timer.") |
| 888 if chat_loot_timer_handle then | 891 if chat_loot_timer_handle then |
| 889 chat_loot_timer_handle:Cancel() | 892 chat_loot_timer_handle:Cancel() |
| 890 chat_loot_timer_handle = nil | 893 chat_loot_timer_handle = nil |
| 891 end | 894 end |
| 892 | 895 |
| 1316 function WDP:SHOW_LOOT_TOAST(event_name, loot_type, item_link, quantity, spec_ID, sex_ID, is_personal, loot_source) | 1319 function WDP:SHOW_LOOT_TOAST(event_name, loot_type, item_link, quantity, spec_ID, sex_ID, is_personal, loot_source) |
| 1317 if not loot_type or (loot_type ~= "item" and loot_type ~= "money" and loot_type ~= "currency") then | 1320 if not loot_type or (loot_type ~= "item" and loot_type ~= "money" and loot_type ~= "currency") then |
| 1318 Debug("%s: loot_type is %s. Item link is %s, and quantity is %d.", event_name, loot_type, item_link, quantity) | 1321 Debug("%s: loot_type is %s. Item link is %s, and quantity is %d.", event_name, loot_type, item_link, quantity) |
| 1319 return | 1322 return |
| 1320 end | 1323 end |
| 1321 local container_id = private.loot_toast_container_id | |
| 1322 local npc_id = private.raid_boss_id | |
| 1323 | 1324 |
| 1324 -- Need information on the most recent args, so using this complete debug statement for now | 1325 -- Need information on the most recent args, so using this complete debug statement for now |
| 1325 Debug("%s: loot_type: %s, item_link: %s, quantity: %s, spec_ID: %s, sex_ID: %s, is_personal: %s, loot_source: %s", event_name, loot_type, item_link, quantity, spec_ID, sex_ID, is_personal, loot_source) | 1326 Debug("%s: loot_type: %s, item_link: %s, quantity: %s, spec_ID: %s, sex_ID: %s, is_personal: %s, loot_source: %s", event_name, loot_type, item_link, quantity, spec_ID, sex_ID, is_personal, loot_source) |
| 1326 | 1327 |
| 1327 -- Handle Garrison cache specially | 1328 -- Handle Garrison cache specially |
| 1346 Debug("%s: When handling the Garrison cache, the top level loot data was missing for objectID %d.", event_name, last_garrison_cache_object_id) | 1347 Debug("%s: When handling the Garrison cache, the top level loot data was missing for objectID %d.", event_name, last_garrison_cache_object_id) |
| 1347 end | 1348 end |
| 1348 else | 1349 else |
| 1349 Debug("%s: Currency texture is nil, from currency link %s", event_name, item_link) | 1350 Debug("%s: Currency texture is nil, from currency link %s", event_name, item_link) |
| 1350 end | 1351 end |
| 1351 elseif npc_id then | 1352 elseif raid_boss_id then |
| 1352 -- Slightly messy hack to workaround duplicate world bosses | 1353 -- Slightly messy hack to workaround duplicate world bosses |
| 1353 local upper_limit = 0 | 1354 local upper_limit = 0 |
| 1354 if DUPLICATE_WORLD_BOSS_IDS[npc_id] then | 1355 if DUPLICATE_WORLD_BOSS_IDS[raid_boss_id] then |
| 1355 upper_limit = #DUPLICATE_WORLD_BOSS_IDS[npc_id] | 1356 upper_limit = #DUPLICATE_WORLD_BOSS_IDS[raid_boss_id] |
| 1356 end | 1357 end |
| 1357 for i = 0, upper_limit do | 1358 for i = 0, upper_limit do |
| 1358 local temp_npc_id = npc_id | 1359 local temp_npc_id = raid_boss_id |
| 1359 | 1360 |
| 1360 if i > 0 then | 1361 if i > 0 then |
| 1361 temp_npc_id = DUPLICATE_WORLD_BOSS_IDS[npc_id][i] | 1362 temp_npc_id = DUPLICATE_WORLD_BOSS_IDS[raid_boss_id][i] |
| 1362 end | 1363 end |
| 1363 | 1364 |
| 1364 local npc = NPCEntry(temp_npc_id) | 1365 local npc = NPCEntry(temp_npc_id) |
| 1365 if npc then | 1366 if npc then |
| 1366 local loot_label = "drops" | 1367 local loot_label = "drops" |
| 1396 encounter_data.loot_counts[loot_label] = (encounter_data.loot_counts[loot_label] or 0) + 1 | 1397 encounter_data.loot_counts[loot_label] = (encounter_data.loot_counts[loot_label] or 0) + 1 |
| 1397 boss_loot_toasting[temp_npc_id] = true -- Do not count further loots until timer expires or another boss is killed | 1398 boss_loot_toasting[temp_npc_id] = true -- Do not count further loots until timer expires or another boss is killed |
| 1398 end | 1399 end |
| 1399 end | 1400 end |
| 1400 end | 1401 end |
| 1401 elseif container_id then | 1402 elseif loot_toast_container_id then |
| 1402 InitializeCurrentLoot() | 1403 InitializeCurrentLoot() |
| 1403 | 1404 |
| 1404 -- Fake the loot characteristics to match that of an actual container item | 1405 -- Fake the loot characteristics to match that of an actual container item |
| 1405 current_loot.identifier = container_id | 1406 current_loot.identifier = loot_toast_container_id |
| 1406 current_loot.label = "contains" | 1407 current_loot.label = "contains" |
| 1407 current_loot.target_type = AF.ITEM | 1408 current_loot.target_type = AF.ITEM |
| 1408 | 1409 |
| 1409 current_loot.sources[container_id] = current_loot.sources[container_id] or {} | 1410 current_loot.sources[loot_toast_container_id] = current_loot.sources[loot_toast_container_id] or {} |
| 1410 | 1411 |
| 1411 if loot_type == "item" then | 1412 if loot_type == "item" then |
| 1412 local item_id = ItemLinkToID(item_link) | 1413 local item_id = ItemLinkToID(item_link) |
| 1413 if item_id then | 1414 if item_id then |
| 1414 Debug("%s: %s X %d (%d)", event_name, item_link, quantity, item_id) | 1415 Debug("%s: %s X %d (%d)", event_name, item_link, quantity, item_id) |
| 1415 RecordItemData(item_id, item_link, true) | 1416 RecordItemData(item_id, item_link, true) |
| 1416 current_loot.sources[container_id][item_id] = (current_loot.sources[container_id][item_id] or 0) + quantity | 1417 current_loot.sources[loot_toast_container_id][item_id] = (current_loot.sources[loot_toast_container_id][item_id] or 0) + quantity |
| 1417 else | 1418 else |
| 1418 Debug("%s: ItemID is nil, from item link %s", event_name, item_link) | 1419 Debug("%s: ItemID is nil, from item link %s", event_name, item_link) |
| 1419 current_loot = nil | 1420 current_loot = nil |
| 1420 return | 1421 return |
| 1421 end | 1422 end |
| 1422 elseif loot_type == "money" then | 1423 elseif loot_type == "money" then |
| 1423 Debug("%s: money X %d", event_name, quantity) | 1424 Debug("%s: money X %d", event_name, quantity) |
| 1424 current_loot.sources[container_id]["money"] = (current_loot.sources[container_id]["money"] or 0) + quantity | 1425 current_loot.sources[loot_toast_container_id]["money"] = (current_loot.sources[loot_toast_container_id]["money"] or 0) + quantity |
| 1425 elseif loot_type == "currency" then | 1426 elseif loot_type == "currency" then |
| 1426 local currency_texture = CurrencyLinkToTexture(item_link) | 1427 local currency_texture = CurrencyLinkToTexture(item_link) |
| 1427 if currency_texture and currency_texture ~= "" then | 1428 if currency_texture and currency_texture ~= "" then |
| 1428 Debug("%s: %s X %d", event_name, currency_texture, quantity) | 1429 Debug("%s: %s X %d", event_name, currency_texture, quantity) |
| 1429 local currency_token = ("currency:%s"):format(currency_texture) | 1430 local currency_token = ("currency:%s"):format(currency_texture) |
| 1430 current_loot.sources[container_id][currency_token] = (current_loot.sources[container_id][currency_token] or 0) + quantity | 1431 current_loot.sources[loot_toast_container_id][currency_token] = (current_loot.sources[loot_toast_container_id][currency_token] or 0) + quantity |
| 1431 else | 1432 else |
| 1432 Debug("%s: Currency texture is nil, from currency link %s", event_name, item_link) | 1433 Debug("%s: Currency texture is nil, from currency link %s", event_name, item_link) |
| 1433 current_loot = nil | 1434 current_loot = nil |
| 1434 return | 1435 return |
| 1435 end | 1436 end |
| 1436 end | 1437 end |
| 1437 | 1438 |
| 1438 GenericLootUpdate("items") | 1439 GenericLootUpdate("items") |
| 1439 current_loot = nil | 1440 current_loot = nil |
| 1440 private.container_loot_toasting = true -- Do not count further loots until timer expires or another container is opened | 1441 container_loot_toasting = true -- Do not count further loots until timer expires or another container is opened |
| 1441 else | 1442 else |
| 1442 Debug("%s: NPC and Container are nil, storing loot toast data for 5 seconds.", event_name) | 1443 Debug("%s: NPC and Container are nil, storing loot toast data for 5 seconds.", event_name) |
| 1443 | 1444 |
| 1444 loot_toast_data = loot_toast_data or {} | 1445 loot_toast_data = loot_toast_data or {} |
| 1445 loot_toast_data[#loot_toast_data + 1] = { loot_type, item_link, quantity } | 1446 loot_toast_data[#loot_toast_data + 1] = { loot_type, item_link, quantity } |
| 1462 if container_id and (container_id == BAG_OF_SALVAGE_ITEM_ID or container_id == CRATE_OF_SALVAGE_ITEM_ID or container_id == BIG_CRATE_OF_SALVAGE_ITEM_ID) then | 1463 if container_id and (container_id == BAG_OF_SALVAGE_ITEM_ID or container_id == CRATE_OF_SALVAGE_ITEM_ID or container_id == BIG_CRATE_OF_SALVAGE_ITEM_ID) then |
| 1463 Debug("CHAT_MSG_LOOT: AF.ITEM %d (%d)", item_id, quantity) | 1464 Debug("CHAT_MSG_LOOT: AF.ITEM %d (%d)", item_id, quantity) |
| 1464 current_loot.sources[container_id] = current_loot.sources[container_id] or {} | 1465 current_loot.sources[container_id] = current_loot.sources[container_id] or {} |
| 1465 current_loot.sources[container_id][item_id] = (current_loot.sources[container_id][item_id] or 0) + quantity | 1466 current_loot.sources[container_id][item_id] = (current_loot.sources[container_id][item_id] or 0) + quantity |
| 1466 else -- If not, cancel the timer and wipe the loot table early | 1467 else -- If not, cancel the timer and wipe the loot table early |
| 1467 Debug("CHAT_MSG_LOOT: We would have assigned the wrong loot to salvage crates!") | 1468 Debug("CHAT_MSG_LOOT: We would have assigned the wrong loot!") |
| 1468 ClearTimeBasedLootData() | 1469 ClearChatLootData() |
| 1469 end | 1470 end |
| 1470 end, | 1471 end, |
| 1471 [AF.NPC] = function(item_id, quantity) | 1472 [AF.NPC] = function(item_id, quantity) |
| 1472 Debug("CHAT_MSG_LOOT: AF.NPC %d (%d)", item_id, quantity) | 1473 Debug("CHAT_MSG_LOOT: AF.NPC %d (%d)", item_id, quantity) |
| 1473 end, | 1474 end, |
| 1495 current_loot = nil | 1496 current_loot = nil |
| 1496 end, | 1497 end, |
| 1497 } | 1498 } |
| 1498 | 1499 |
| 1499 | 1500 |
| 1500 function WDP:CHAT_MSG_LOOT(event_name, message) | 1501 function WDP:CHAT_MSG_CURRENCY(event_name, message) |
| 1501 local category | 1502 local category |
| 1502 | 1503 |
| 1503 local item_link, quantity = deformat(message, _G.LOOT_ITEM_PUSHED_SELF_MULTIPLE) | 1504 local item_link, quantity = deformat(message, _G.LOOT_ITEM_PUSHED_SELF_MULTIPLE) |
| 1504 if not item_link then | 1505 if not item_link then |
| 1505 quantity, item_link = 1, deformat(message, _G.LOOT_ITEM_PUSHED_SELF) | 1506 quantity, item_link = 1, deformat(message, _G.LOOT_ITEM_PUSHED_SELF) |
| 2058 return true | 2059 return true |
| 2059 end | 2060 end |
| 2060 | 2061 |
| 2061 | 2062 |
| 2062 function WDP:LOOT_OPENED(event_name) | 2063 function WDP:LOOT_OPENED(event_name) |
| 2064 if chat_loot_timer_handle then | |
| 2065 ClearChatLootData() | |
| 2066 end | |
| 2067 | |
| 2063 if current_loot then | 2068 if current_loot then |
| 2064 current_loot = nil | 2069 current_loot = nil |
| 2065 Debug("%s: Previous loot did not process in time for this event. Attempting to extrapolate current_action from loot data.", event_name) | 2070 Debug("%s: Previous loot did not process in time for this event. Attempting to extrapolate current_action from loot data.", event_name) |
| 2066 | 2071 |
| 2067 if not ExtrapolatedCurrentActionFromLootData(event_name) then | 2072 if not ExtrapolatedCurrentActionFromLootData(event_name) then |
| 2648 | 2653 |
| 2649 function WDP:SPELL_CONFIRMATION_PROMPT(event_name, spell_id, confirm_type, text, duration, currency_id_cost) | 2654 function WDP:SPELL_CONFIRMATION_PROMPT(event_name, spell_id, confirm_type, text, duration, currency_id_cost) |
| 2650 if private.RAID_BOSS_BONUS_SPELL_ID_TO_NPC_ID_MAP[spell_id] then | 2655 if private.RAID_BOSS_BONUS_SPELL_ID_TO_NPC_ID_MAP[spell_id] then |
| 2651 ClearKilledBossID() | 2656 ClearKilledBossID() |
| 2652 ClearLootToastContainerID() | 2657 ClearLootToastContainerID() |
| 2653 private.raid_boss_id = private.RAID_BOSS_BONUS_SPELL_ID_TO_NPC_ID_MAP[spell_id] | 2658 raid_boss_id = private.RAID_BOSS_BONUS_SPELL_ID_TO_NPC_ID_MAP[spell_id] |
| 2654 else | 2659 else |
| 2655 Debug("%s: Spell ID %d is not a known raid boss 'Bonus' spell.", event_name, spell_id) | 2660 Debug("%s: Spell ID %d is not a known raid boss 'Bonus' spell.", event_name, spell_id) |
| 2656 return | 2661 return |
| 2657 end | 2662 end |
| 2658 | 2663 |
| 2659 -- Assign existing loot data to boss if it exists | 2664 -- Assign existing loot data to boss if it exists |
| 2660 if loot_toast_data then | 2665 if loot_toast_data then |
| 2661 local npc_id = private.raid_boss_id | 2666 local npc_id = raid_boss_id |
| 2662 | 2667 |
| 2663 -- Slightly messy hack to workaround duplicate world bosses | 2668 -- Slightly messy hack to workaround duplicate world bosses |
| 2664 local upper_limit = 0 | 2669 local upper_limit = 0 |
| 2665 if DUPLICATE_WORLD_BOSS_IDS[npc_id] then | 2670 if DUPLICATE_WORLD_BOSS_IDS[npc_id] then |
| 2666 upper_limit = #DUPLICATE_WORLD_BOSS_IDS[npc_id] | 2671 upper_limit = #DUPLICATE_WORLD_BOSS_IDS[npc_id] |
| 2735 if private.LOOT_TOAST_CONTAINER_SPELL_ID_TO_ITEM_ID_MAP[spell_id] then | 2740 if private.LOOT_TOAST_CONTAINER_SPELL_ID_TO_ITEM_ID_MAP[spell_id] then |
| 2736 ClearKilledBossID() | 2741 ClearKilledBossID() |
| 2737 ClearLootToastContainerID() | 2742 ClearLootToastContainerID() |
| 2738 ClearLootToastData() | 2743 ClearLootToastData() |
| 2739 | 2744 |
| 2740 private.loot_toast_container_id = private.LOOT_TOAST_CONTAINER_SPELL_ID_TO_ITEM_ID_MAP[spell_id] | 2745 loot_toast_container_id = private.LOOT_TOAST_CONTAINER_SPELL_ID_TO_ITEM_ID_MAP[spell_id] |
| 2741 loot_toast_container_timer_handle = C_Timer.NewTimer(1, ClearLootToastContainerID) -- we need to assign a handle here to cancel it later | 2746 loot_toast_container_timer_handle = C_Timer.NewTimer(1, ClearLootToastContainerID) -- we need to assign a handle here to cancel it later |
| 2742 return | 2747 return |
| 2743 end | 2748 end |
| 2744 | 2749 |
| 2745 -- For Crates of Salvage (and potentially other items based on spell casts in the future which need manual handling) | 2750 -- For Crates of Salvage (and potentially other items based on spell casts in the future which need manual handling) |
| 2746 if private.DELAYED_CONTAINER_SPELL_ID_TO_ITEM_ID_MAP[spell_id] then | 2751 if private.DELAYED_CONTAINER_SPELL_ID_TO_ITEM_ID_MAP[spell_id] then |
| 2747 -- Set up timer | 2752 -- Set up timer |
| 2748 Debug("%s: Beginning Salvage loot timer for spellID %d", event_name, spell_id) | 2753 Debug("%s: Beginning Salvage loot timer for spellID %d", event_name, spell_id) |
| 2749 chat_loot_timer_handle = C_Timer.NewTimer(1, ClearTimeBasedLootData) | 2754 chat_loot_timer_handle = C_Timer.NewTimer(1, ClearChatLootData) |
| 2750 | 2755 |
| 2751 -- Standard item handling setup | 2756 -- Standard item handling setup |
| 2752 table.wipe(current_action) | 2757 table.wipe(current_action) |
| 2753 current_loot = nil | 2758 current_loot = nil |
| 2754 current_action.target_type = AF.ITEM | 2759 current_action.target_type = AF.ITEM |
