comparison Main.lua @ 435:b220bc8dd3a8

Chat-based loot variables simplified a bit. Fixed a major conditional bug preventing recording for chat-based loot.
author MMOSimca <MMOSimca@gmail.com>
date Wed, 25 Feb 2015 15:55:07 -0500
parents 3f038cb19197
children 05a4002dd924
comparison
equal deleted inserted replaced
434:98e3947c180d 435:b220bc8dd3a8
168 local killed_boss_id_timer_handle 168 local killed_boss_id_timer_handle
169 local killed_npc_id 169 local killed_npc_id
170 local target_location_timer_handle 170 local target_location_timer_handle
171 local last_timber_spell_id 171 local last_timber_spell_id
172 local last_garrison_cache_object_id 172 local last_garrison_cache_object_id
173 local chat_loot_data 173 local chat_loot_data = {}
174 local chat_loot_timer_handle 174 local chat_loot_timer_handle
175 local current_target_id 175 local current_target_id
176 local current_area_id 176 local current_area_id
177 local current_loot 177 local current_loot
178 178
595 -- For item containers that open instantly with no spell cast 595 -- For item containers that open instantly with no spell cast
596 if (private.CONTAINER_ITEM_ID_LIST[item_id] == true) and ((not _G.GetNumLootItems()) or (_G.GetNumLootItems() == 0)) then 596 if (private.CONTAINER_ITEM_ID_LIST[item_id] == true) and ((not _G.GetNumLootItems()) or (_G.GetNumLootItems() == 0)) then
597 ClearChatLootData() 597 ClearChatLootData()
598 Debug("HandleItemUse: Beginning chat-based loot timer for item with ID %d.", item_id) 598 Debug("HandleItemUse: Beginning chat-based loot timer for item with ID %d.", item_id)
599 chat_loot_timer_handle = C_Timer.NewTimer(1.5, ClearChatLootData) 599 chat_loot_timer_handle = C_Timer.NewTimer(1.5, ClearChatLootData)
600 chat_loot_data = chat_loot_data or {}
601 chat_loot_data.identifier = item_id 600 chat_loot_data.identifier = item_id
602 chat_loot_data.sources = {}
603 -- For normal item containers 601 -- For normal item containers
604 else 602 else
605 table.wipe(current_action) 603 table.wipe(current_action)
606 current_loot = nil 604 current_loot = nil
607 current_action.target_type = AF.ITEM 605 current_action.target_type = AF.ITEM
883 end 881 end
884 882
885 883
886 function ClearChatLootData() 884 function ClearChatLootData()
887 if not chat_loot_timer_handle then 885 if not chat_loot_timer_handle then
886 table.wipe(chat_loot_data)
888 return 887 return
889 end 888 end
890 Debug("ClearChatLootData: Ending chat-based loot timer.") 889 Debug("ClearChatLootData: Ending chat-based loot timer.")
891 chat_loot_timer_handle:Cancel() 890 chat_loot_timer_handle:Cancel()
892 chat_loot_timer_handle = nil 891 chat_loot_timer_handle = nil
893 892
894 if chat_loot_data and chat_loot_data.identifier and (private.CONTAINER_ITEM_ID_LIST[chat_loot_data.identifier] ~= nil) and chat_loot_data.sources and (#chat_loot_data.sources > 0) then 893 if chat_loot_data.identifier and (private.CONTAINER_ITEM_ID_LIST[chat_loot_data.identifier] ~= nil) and chat_loot_data.loot then
895 -- A slimmed down (and more importantly, separate) version of GenericLootUpdate, specifically for AF.ITEM and chat_loot_data 894 -- A slimmed down (and more importantly, separate) version of GenericLootUpdate, specifically for AF.ITEM and chat_loot_data
896 local entry = DBEntry("items", chat_loot_data.identifier) 895 local entry = DBEntry("items", chat_loot_data.identifier)
897 896
898 if entry then 897 if entry then
899 local loot_table = LootTable(entry, "contains") 898 local loot_table = LootTable(entry, "contains")
900 entry["contains_count"] = (entry["contains_count"] or 0) + 1 899 entry["contains_count"] = (entry["contains_count"] or 0) + 1
901 900
902 for loot_token, quantity in pairs(chat_loot_data.sources[chat_loot_data.identifier]) do 901 for loot_token, quantity in pairs(chat_loot_data.loot) do
903 local label, currency_texture = (":"):split(loot_token) 902 local label, currency_texture = (":"):split(loot_token)
904 903
905 if label == "currency" and currency_texture then 904 if label == "currency" and currency_texture then
906 table.insert(loot_table, ("currency:%d:%s"):format(quantity, currency_texture)) 905 table.insert(loot_table, ("currency:%d:%s"):format(quantity, currency_texture))
907 elseif loot_token == "money" then 906 elseif loot_token == "money" then
910 table.insert(loot_table, ("%d:%d"):format(loot_token, quantity)) 909 table.insert(loot_table, ("%d:%d"):format(loot_token, quantity))
911 end 910 end
912 end 911 end
913 end 912 end
914 end 913 end
915 if chat_loot_data then 914 table.wipe(chat_loot_data)
916 table.wipe(chat_loot_data)
917 end
918 end 915 end
919 916
920 917
921 -- METHODS ------------------------------------------------------------ 918 -- METHODS ------------------------------------------------------------
922 919
1462 current_loot = nil 1459 current_loot = nil
1463 container_loot_toasting = true -- Do not count further loots until timer expires or another container is opened 1460 container_loot_toasting = true -- Do not count further loots until timer expires or another container is opened
1464 elseif loot_source and (loot_source == LOOT_SOURCE_ID_REDUNDANT) and chat_loot_timer_handle and loot_type == "currency" then 1461 elseif loot_source and (loot_source == LOOT_SOURCE_ID_REDUNDANT) and chat_loot_timer_handle and loot_type == "currency" then
1465 local currency_texture = CurrencyLinkToTexture(item_link) 1462 local currency_texture = CurrencyLinkToTexture(item_link)
1466 if currency_texture and currency_texture ~= "" then 1463 if currency_texture and currency_texture ~= "" then
1467 local container_id = chat_loot_data.identifier -- For faster access, since this is going to be called 9 times in the next 3 lines
1468 -- Verify that we're still assigning data to the right items 1464 -- Verify that we're still assigning data to the right items
1469 if container_id and (private.CONTAINER_ITEM_ID_LIST[container_id] ~= nil) then 1465 if chat_loot_data.identifier and (private.CONTAINER_ITEM_ID_LIST[chat_loot_data.identifier] ~= nil) then
1470 local currency_token = ("currency:%s"):format(currency_texture) 1466 local currency_token = ("currency:%s"):format(currency_texture)
1471 Debug("%s: Captured currency for chat-based loot recording. %s X %d", event_name, currency_token, quantity) 1467 Debug("%s: Captured currency for chat-based loot recording. %s X %d", event_name, currency_token, quantity)
1472 chat_loot_data.sources[container_id] = chat_loot_data.sources[container_id] or {} 1468 chat_loot_data.loot = chat_loot_data.loot or {}
1473 chat_loot_data.sources[container_id][currency_token] = (chat_loot_data.sources[container_id][currency_token] or 0) + quantity 1469 chat_loot_data.loot[currency_token] = (chat_loot_data.loot[currency_token] or 0) + quantity
1474 else -- If not, cancel the timer and wipe the loot table early 1470 else -- If not, cancel the timer and wipe the loot table early
1475 Debug("%s: Canceled chat-based loot recording because we would have assigned the wrong loot!", event_name) 1471 Debug("%s: Canceled chat-based loot recording because we would have assigned the wrong loot!", event_name)
1476 ClearChatLootData() 1472 ClearChatLootData()
1477 end 1473 end
1478 else 1474 else
1549 } 1545 }
1550 1546
1551 1547
1552 local CHAT_MSG_LOOT_UPDATE_FUNCS = { 1548 local CHAT_MSG_LOOT_UPDATE_FUNCS = {
1553 [AF.ITEM] = function(item_id, quantity) 1549 [AF.ITEM] = function(item_id, quantity)
1554 local container_id = chat_loot_data.identifier -- For faster access, since this is going to be called 9 times in the next 3 lines
1555 -- Verify that we're still assigning data to the right items 1550 -- Verify that we're still assigning data to the right items
1556 if container_id and (private.CONTAINER_ITEM_ID_LIST[container_id] ~= nil) then 1551 if chat_loot_data.identifier and (private.CONTAINER_ITEM_ID_LIST[chat_loot_data.identifier] ~= nil) then
1557 Debug("CHAT_MSG_LOOT: AF.ITEM %d (%d)", item_id, quantity) 1552 Debug("CHAT_MSG_LOOT: AF.ITEM %d (%d)", item_id, quantity)
1558 chat_loot_data.sources[container_id] = chat_loot_data.sources[container_id] or {} 1553 chat_loot_data.loot = chat_loot_data.loot or {}
1559 chat_loot_data.sources[container_id][item_id] = (chat_loot_data.sources[container_id][item_id] or 0) + quantity 1554 chat_loot_data.loot[item_id] = (chat_loot_data.loot[item_id] or 0) + quantity
1560 else -- If not, cancel the timer and wipe the loot table early 1555 else -- If not, cancel the timer and wipe the loot table early
1561 Debug("CHAT_MSG_LOOT: We would have assigned the wrong loot!") 1556 Debug("CHAT_MSG_LOOT: We would have assigned the wrong loot!")
1562 ClearChatLootData() 1557 ClearChatLootData()
1563 end 1558 end
1564 end, 1559 end,
2861 if private.DELAYED_CONTAINER_SPELL_ID_TO_ITEM_ID_MAP[spell_id] then 2856 if private.DELAYED_CONTAINER_SPELL_ID_TO_ITEM_ID_MAP[spell_id] then
2862 -- Set up timer 2857 -- Set up timer
2863 ClearChatLootData() 2858 ClearChatLootData()
2864 Debug("%s: Beginning chat-based loot timer for spellID %d", event_name, spell_id) 2859 Debug("%s: Beginning chat-based loot timer for spellID %d", event_name, spell_id)
2865 chat_loot_timer_handle = C_Timer.NewTimer(1.5, ClearChatLootData) 2860 chat_loot_timer_handle = C_Timer.NewTimer(1.5, ClearChatLootData)
2866 chat_loot_data = chat_loot_data or {}
2867 chat_loot_data.identifier = private.DELAYED_CONTAINER_SPELL_ID_TO_ITEM_ID_MAP[spell_id] 2861 chat_loot_data.identifier = private.DELAYED_CONTAINER_SPELL_ID_TO_ITEM_ID_MAP[spell_id]
2868 chat_loot_data.sources = {}
2869 return 2862 return
2870 end 2863 end
2871 2864
2872 if anvil_spell_ids[spell_id] then 2865 if anvil_spell_ids[spell_id] then
2873 UpdateDBEntryLocation("objects", OBJECT_ID_ANVIL) 2866 UpdateDBEntryLocation("objects", OBJECT_ID_ANVIL)