comparison Main.lua @ 79:376d3e03d632

Ignore loot_list if empty. Hold NPC GUIDs in a loot registry to avoid recording the same NPC loot multiple times.
author James D. Callahan III <jcallahan@curse.com>
date Wed, 22 Aug 2012 13:20:21 -0500
parents 7179e2938324
children fffa5af4c6ce
comparison
equal deleted inserted replaced
78:7179e2938324 79:376d3e03d632
432 table.insert(loot_table, ("%d:%d"):format(item_id, quantity)) 432 table.insert(loot_table, ("%d:%d"):format(item_id, quantity))
433 end 433 end
434 end 434 end
435 end 435 end
436 -- TODO: Remove this when GetLootSourceInfo() has values for money 436 -- TODO: Remove this when GetLootSourceInfo() has values for money
437 if action_data.type == AF.OBJECT then 437 if #action_data.loot_list <= 0 or action_data.type == AF.OBJECT then
438 -- Unfortunately, this means we can't record money from chests... 438 -- Unfortunately, this means we can't record money from chests...
439 return 439 return
440 end 440 end
441 local entry = DBEntry(data_type, action_data.identifier) 441 local entry = DBEntry(data_type, action_data.identifier)
442 442
880 end 880 end
881 end 881 end
882 end 882 end
883 883
884 -- TODO: Remove this when GetLootSourceInfo() has values for money 884 -- TODO: Remove this when GetLootSourceInfo() has values for money
885 if #action_data.loot_list <= 0 then
886 return
887 end
885 local npc = NPCEntry(action_data.identifier) 888 local npc = NPCEntry(action_data.identifier)
886 889
887 if not npc then 890 if not npc then
888 return 891 return
889 end 892 end
918 table.insert(action_data.zone_data[location_token].drops, action_data.loot_list[index]) 921 table.insert(action_data.zone_data[location_token].drops, action_data.loot_list[index])
919 end 922 end
920 end, 923 end,
921 } 924 }
922 925
926 -- Prevent opening the same loot window multiple times from recording data multiple times.
927 local loot_guid_registry = {}
923 928
924 function WDP:LOOT_OPENED() 929 function WDP:LOOT_OPENED()
925 if action_data.looting then 930 if action_data.looting then
926 return 931 return
927 end 932 end
957 -- print(("Loot slot %d: Source count: %d"):format(loot_slot, floor((#sources / 2) + 0.5))) 962 -- print(("Loot slot %d: Source count: %d"):format(loot_slot, floor((#sources / 2) + 0.5)))
958 963
959 -- Odd index is GUID, even is count. 964 -- Odd index is GUID, even is count.
960 for loot_index = 1, #loot_info, 2 do 965 for loot_index = 1, #loot_info, 2 do
961 local source_guid = loot_info[loot_index] 966 local source_guid = loot_info[loot_index]
962 local loot_quantity = loot_info[loot_index + 1] 967
963 local source_type, source_id = ParseGUID(source_guid) 968 if not loot_guid_registry[source_guid] then
964 -- TODO: Remove debugging 969 local loot_quantity = loot_info[loot_index + 1]
965 -- local source_key = ("%s:%d"):format(private.UNIT_TYPE_NAMES[source_type + 1], source_id) 970 local source_type, source_id = ParseGUID(source_guid)
966 -- print(("GUID: %s - Type:ID: %s - Amount: %d"):format(loot_info[loot_index], source_key, loot_quantity)) 971 -- TODO: Remove debugging
967 972 -- local source_key = ("%s:%d"):format(private.UNIT_TYPE_NAMES[source_type + 1], source_id)
968 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot)) 973 -- print(("GUID: %s - Type:ID: %s - Amount: %d"):format(loot_info[loot_index], source_key, loot_quantity))
969 action_data.loot_sources[source_guid] = action_data.loot_sources[source_guid] or {} 974
970 action_data.loot_sources[source_guid][item_id] = action_data.loot_sources[source_guid][item_id] or 0 + loot_quantity 975 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot))
976 action_data.loot_sources[source_guid] = action_data.loot_sources[source_guid] or {}
977 action_data.loot_sources[source_guid][item_id] = action_data.loot_sources[source_guid][item_id] or 0 + loot_quantity
978 loot_guid_registry[source_guid] = true
979 end
971 end 980 end
972 elseif slot_type == _G.LOOT_SLOT_MONEY then 981 elseif slot_type == _G.LOOT_SLOT_MONEY then
973 table.insert(action_data.loot_list, ("money:%d"):format(_toCopper(item_text))) 982 table.insert(action_data.loot_list, ("money:%d"):format(_toCopper(item_text)))
974 elseif slot_type == _G.LOOT_SLOT_CURRENCY then 983 elseif slot_type == _G.LOOT_SLOT_CURRENCY then
975 table.insert(action_data.loot_list, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower())) 984 table.insert(action_data.loot_list, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower()))