comparison Main.lua @ 414:d97e37b1e239

Redesigned CHAT_LOOT_x timer system to no longer use current_loot (except for fishing).
author MMOSimca <MMOSimca@gmail.com>
date Sun, 04 Jan 2015 13:16:29 -0500
parents e2f7f33cf5f7
children 837a3a525a76
comparison
equal deleted inserted replaced
413:d45238345b6e 414:d97e37b1e239
170 local killed_boss_id_timer_handle 170 local killed_boss_id_timer_handle
171 local killed_npc_id 171 local killed_npc_id
172 local target_location_timer_handle 172 local target_location_timer_handle
173 local last_timber_spell_id 173 local last_timber_spell_id
174 local last_garrison_cache_object_id 174 local last_garrison_cache_object_id
175 local chat_loot_data
175 local chat_loot_timer_handle 176 local chat_loot_timer_handle
176 local current_target_id 177 local current_target_id
177 local current_area_id 178 local current_area_id
178 local current_loot 179 local current_loot
179 180
591 if private.CONTAINER_ITEM_ID_LIST[item_id] ~= nil then 592 if private.CONTAINER_ITEM_ID_LIST[item_id] ~= nil then
592 any_loot = true 593 any_loot = true
593 end 594 end
594 595
595 if any_loot then 596 if any_loot then
596 table.wipe(current_action) 597 -- For item containers that open instantly with no spell cast
597 current_loot = nil
598 current_action.target_type = AF.ITEM
599 current_action.identifier = item_id
600 current_action.loot_label = "contains"
601
602 -- For items that open instantly with no spell cast
603 if (private.CONTAINER_ITEM_ID_LIST[item_id] == true) and ((not _G.GetNumLootItems()) or (_G.GetNumLootItems() == 0)) then 598 if (private.CONTAINER_ITEM_ID_LIST[item_id] == true) and ((not _G.GetNumLootItems()) or (_G.GetNumLootItems() == 0)) then
604 ClearChatLootData() 599 ClearChatLootData()
605 Debug("HandleItemUse: Beginning chat-based loot timer for item with ID %d.", item_id) 600 Debug("HandleItemUse: Beginning chat-based loot timer for item with ID %d.", item_id)
606 chat_loot_timer_handle = C_Timer.NewTimer(1, ClearChatLootData) 601 chat_loot_timer_handle = C_Timer.NewTimer(1, ClearChatLootData)
607 InitializeCurrentLoot() 602 chat_loot_data = chat_loot_data or {}
603 chat_loot_data.identifier = item_id
604 chat_loot_data.sources = {}
605 -- For normal item containers
606 else
607 table.wipe(current_action)
608 current_loot = nil
609 current_action.target_type = AF.ITEM
610 current_action.identifier = item_id
611 current_action.loot_label = "contains"
608 end 612 end
609 end 613 end
610 end 614 end
611 615
612 616
887 end 891 end
888 Debug("ClearChatLootData: Ending chat-based loot timer.") 892 Debug("ClearChatLootData: Ending chat-based loot timer.")
889 chat_loot_timer_handle:Cancel() 893 chat_loot_timer_handle:Cancel()
890 chat_loot_timer_handle = nil 894 chat_loot_timer_handle = nil
891 895
892 if current_loot and current_loot.identifier and (private.CONTAINER_ITEM_ID_LIST[current_loot.identifier] ~= nil) then 896 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 GenericLootUpdate("items") 897 -- A slimmed down (and more importantly, separate) version of GenericLootUpdate, specifically for AF.ITEM and chat_loot_data
894 end 898 local entry = DBEntry("items", chat_loot_data.identifier)
895 current_loot = nil 899
900 if entry then
901 local loot_table = LootTable(entry, "contains")
902 entry["contains_count"] = (entry["contains_count"] or 0) + 1
903
904 for loot_token, quantity in pairs(chat_loot_data.sources[chat_loot_data.identifier]) do
905 local label, currency_texture = (":"):split(loot_token)
906
907 if label == "currency" and currency_texture then
908 table.insert(loot_table, ("currency:%d:%s"):format(quantity, currency_texture))
909 elseif loot_token == "money" then
910 table.insert(loot_table, ("money:%d"):format(quantity))
911 else
912 table.insert(loot_table, ("%d:%d"):format(loot_token, quantity))
913 end
914 end
915 end
916 end
917 if chat_loot_data then
918 table.wipe(chat_loot_data)
919 end
896 end 920 end
897 921
898 922
899 -- METHODS ------------------------------------------------------------ 923 -- METHODS ------------------------------------------------------------
900 924
1466 1490
1467 1491
1468 do 1492 do
1469 local CHAT_MSG_CURRENCY_UPDATE_FUNCS = { 1493 local CHAT_MSG_CURRENCY_UPDATE_FUNCS = {
1470 [AF.ITEM] = function(currency_texture, quantity) 1494 [AF.ITEM] = function(currency_texture, quantity)
1471 local currency_token = ("currency:%s"):format(currency_texture) 1495 local container_id = chat_loot_data.identifier -- For faster access, since this is going to be called 9 times in the next 3 lines
1472 local container_id = current_loot.identifier -- For faster access, since this is going to be called 9 times in the next 3 lines
1473 -- Verify that we're still assigning data to the right items 1496 -- Verify that we're still assigning data to the right items
1474 if container_id and (private.CONTAINER_ITEM_ID_LIST[container_id] ~= nil) then 1497 if container_id and (private.CONTAINER_ITEM_ID_LIST[container_id] ~= nil) then
1475 Debug("CHAT_MSG_CURRENCY: AF.ITEM %s (%d)", currency_token, quantity) 1498 Debug("CHAT_MSG_CURRENCY: AF.ITEM %s (%d)", currency_token, quantity)
1476 current_loot.sources[container_id] = current_loot.sources[container_id] or {} 1499 local currency_token = ("currency:%s"):format(currency_texture:match("[^\\]+$"):lower())
1477 current_loot.sources[container_id][currency_token] = (current_loot.sources[container_id][currency_token] or 0) + quantity 1500 chat_loot_data.sources[container_id] = chat_loot_data.sources[container_id] or {}
1501 chat_loot_data.sources[container_id][currency_token] = (chat_loot_data.sources[container_id][currency_token] or 0) + quantity
1478 else -- If not, cancel the timer and wipe the loot table early 1502 else -- If not, cancel the timer and wipe the loot table early
1479 Debug("CHAT_MSG_CURRENCY: We would have assigned the wrong loot!") 1503 Debug("CHAT_MSG_CURRENCY: We would have assigned the wrong loot!")
1480 ClearChatLootData() 1504 ClearChatLootData()
1481 end 1505 end
1482 end, 1506 end,
2856 if private.DELAYED_CONTAINER_SPELL_ID_TO_ITEM_ID_MAP[spell_id] then 2880 if private.DELAYED_CONTAINER_SPELL_ID_TO_ITEM_ID_MAP[spell_id] then
2857 -- Set up timer 2881 -- Set up timer
2858 ClearChatLootData() 2882 ClearChatLootData()
2859 Debug("%s: Beginning chat-based loot timer for spellID %d", event_name, spell_id) 2883 Debug("%s: Beginning chat-based loot timer for spellID %d", event_name, spell_id)
2860 chat_loot_timer_handle = C_Timer.NewTimer(1.5, ClearChatLootData) 2884 chat_loot_timer_handle = C_Timer.NewTimer(1.5, ClearChatLootData)
2861 2885 chat_loot_data = chat_loot_data or {}
2862 -- Standard item handling setup 2886 chat_loot_data.identifier = private.DELAYED_CONTAINER_SPELL_ID_TO_ITEM_ID_MAP[spell_id]
2863 table.wipe(current_action) 2887 chat_loot_data.sources = {}
2864 current_loot = nil
2865 current_action.target_type = AF.ITEM
2866 current_action.identifier = private.DELAYED_CONTAINER_SPELL_ID_TO_ITEM_ID_MAP[spell_id]
2867 current_action.loot_label = "contains"
2868 InitializeCurrentLoot()
2869 return 2888 return
2870 end 2889 end
2871 2890
2872 if anvil_spell_ids[spell_id] then 2891 if anvil_spell_ids[spell_id] then
2873 UpdateDBEntryLocation("objects", OBJECT_ID_ANVIL) 2892 UpdateDBEntryLocation("objects", OBJECT_ID_ANVIL)