comparison 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
comparison
equal deleted inserted replaced
74:06daf4cb1cf9 75:a034bfa8982b
379 end 379 end
380 end 380 end
381 end -- do-block 381 end -- do-block
382 382
383 383
384 local function GenericLootUpdate(data_type, top_field) 384 local GenericLootUpdate
385 local entry = DBEntry(data_type, action_data.identifier) 385 do
386 386 local function LootTable(entry, loot_type, loot_count, top_field)
387 if not entry then 387 if top_field then
388 return 388 entry[top_field] = entry[top_field] or {}
389 end 389 entry[top_field][loot_count] = (entry[top_field][loot_count] or 0) + 1
390 local loot_type = action_data.label or "drops" 390 entry[top_field][loot_type] = entry[top_field][loot_type] or {}
391 local loot_count = ("%s_count"):format(loot_type) 391 return entry[top_field][loot_type]
392 local loot_data 392 end
393
394 if top_field then
395 entry[top_field] = entry[top_field] or {}
396 entry[top_field][loot_count] = (entry[top_field][loot_count] or 0) + 1
397 entry[top_field][loot_type] = entry[top_field][loot_type] or {}
398 loot_data = entry[top_field][loot_type]
399 else
400 entry[loot_count] = (entry[loot_count] or 0) + 1 393 entry[loot_count] = (entry[loot_count] or 0) + 1
401 entry[loot_type] = entry[loot_type] or {} 394 entry[loot_type] = entry[loot_type] or {}
402 loot_data = entry[loot_type] 395 return entry[loot_type]
403 end 396 end
404 397
405 for index = 1, #action_data.loot_list do 398 function GenericLootUpdate(data_type, top_field)
406 table.insert(loot_data, action_data.loot_list[index]) 399 local loot_type = action_data.label or "drops"
407 end 400 local loot_count = ("%s_count"):format(loot_type)
408 end 401
409 402 for source_id, loot_data in pairs(action_data.loot_sources) do
403 local entry = DBEntry(data_type, source_id)
404
405 if entry then
406 local loot_table = LootTable(entry, loot_type, loot_count, top_field)
407 UpdateDBEntryLocation(data_type, source_id)
408
409 for item_id, quantity in pairs(loot_data) do
410 table.insert(loot_table, ("%d:%d"):format(item_id, quantity))
411 end
412 end
413 end
414 -- TODO: Remove this when GetLootSourceInfo() has values for money
415 local entry = DBEntry(data_type, action_data.identifier)
416
417 if not entry then
418 return
419 end
420 local loot_table = LootTable(entry, loot_type, loot_count, top_field)
421
422 for index = 1, #action_data.loot_list do
423 table.insert(loot_table, action_data.loot_list[index])
424 end
425 end
426 end -- do-block
410 427
411 ----------------------------------------------------------------------- 428 -----------------------------------------------------------------------
412 -- Methods. 429 -- Methods.
413 ----------------------------------------------------------------------- 430 -----------------------------------------------------------------------
414 function WDP:OnInitialize() 431 function WDP:OnInitialize()
521 end 538 end
522 end 539 end
523 end 540 end
524 541
525 542
526 function WDP:CHAT_MSG_LOOT(event, message) 543 function WDP:CHAT_MSG_LOOT(event_name, message)
527 if action_data.spell_label ~= "EXTRACT_GAS" then 544 if action_data.spell_label ~= "EXTRACT_GAS" then
528 return 545 return
529 end 546 end
530 local item_link, quantity = deformat(message, _G.LOOT_ITEM_PUSHED_SELF_MULTIPLE) 547 local item_link, quantity = deformat(message, _G.LOOT_ITEM_PUSHED_SELF_MULTIPLE)
531 548
804 local LOOT_UPDATE_FUNCS = { 821 local LOOT_UPDATE_FUNCS = {
805 [AF.ITEM] = function() 822 [AF.ITEM] = function()
806 GenericLootUpdate("items") 823 GenericLootUpdate("items")
807 end, 824 end,
808 [AF.NPC] = function() 825 [AF.NPC] = function()
826 local difficulty_token = InstanceDifficultyToken()
827 local loot_type = action_data.label or "drops"
828
829 for source_id, loot_data in pairs(action_data.loot_sources) do
830 local npc = NPCEntry(source_id)
831
832 if npc then
833 local encounter_data = npc.encounter_data[difficulty_token]
834 encounter_data.loot_counts = encounter_data.loot_counts or {}
835 encounter_data.loot_counts[loot_type] = (encounter_data.loot_counts[loot_type] or 0) + 1
836 encounter_data[loot_type] = encounter_data[loot_type] or {}
837
838 for item_id, quantity in pairs(loot_data) do
839 table.insert(encounter_data[loot_type], ("%d:%d"):format(item_id, quantity))
840 end
841 end
842 end
843
844 -- TODO: Remove this when GetLootSourceInfo() has values for money
809 local npc = NPCEntry(action_data.identifier) 845 local npc = NPCEntry(action_data.identifier)
810 846
811 if not npc then 847 if not npc then
812 return 848 return
813 end 849 end
814 local encounter_data = npc.encounter_data[InstanceDifficultyToken()] 850 local encounter_data = npc.encounter_data[difficulty_token]
815 local loot_type = action_data.label or "drops"
816 encounter_data.loot_counts = encounter_data.loot_counts or {} 851 encounter_data.loot_counts = encounter_data.loot_counts or {}
817 encounter_data.loot_counts[loot_type] = (encounter_data.loot_counts[loot_type] or 0) + 1 852 encounter_data.loot_counts[loot_type] = (encounter_data.loot_counts[loot_type] or 0) + 1
818 encounter_data[loot_type] = encounter_data[loot_type] or {} 853 encounter_data[loot_type] = encounter_data[loot_type] or {}
819 854
820 for index = 1, #action_data.loot_list do 855 for index = 1, #action_data.loot_list do
859 end 894 end
860 895
861 if _G.type(verify_func) == "function" and not verify_func() then 896 if _G.type(verify_func) == "function" and not verify_func() then
862 return 897 return
863 end 898 end
864 local loot_registry = {}
865 action_data.loot_list = {} 899 action_data.loot_list = {}
900 action_data.loot_sources = {}
866 action_data.looting = true 901 action_data.looting = true
867 902
868 for loot_slot = 1, _G.GetNumLootItems() do 903 for loot_slot = 1, _G.GetNumLootItems() do
869 local icon_texture, item_text, quantity, quality, locked = _G.GetLootSlotInfo(loot_slot) 904 local icon_texture, item_text, quantity, quality, locked = _G.GetLootSlotInfo(loot_slot)
870 local slot_type = _G.GetLootSlotType(loot_slot) 905 local slot_type = _G.GetLootSlotType(loot_slot)
871 906 local sources = {
872 if slot_type == _G.LOOT_SLOT_ITEM then 907 _G.GetLootSourceInfo(loot_slot)
873 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot)) 908 }
874 loot_registry[item_id] = (loot_registry[item_id]) or 0 + quantity 909
875 elseif slot_type == _G.LOOT_SLOT_MONEY then 910 -- TODO: Remove debugging
876 table.insert(action_data.loot_list, ("money:%d"):format(_toCopper(item_text))) 911 -- print(("Loot slot %d: Source count: %d"):format(loot_slot, floor((#sources / 2) + 0.5)))
877 elseif slot_type == _G.LOOT_SLOT_CURRENCY then 912
878 table.insert(action_data.loot_list, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower())) 913 -- Odd index is GUID, even is count.
879 end 914 for source_index = 1, #sources, 2 do
880 end 915 local source_type, source_id = ParseGUID(sources[source_index])
881 916 local source_count = sources[source_index + 1]
882 for item_id, quantity in pairs(loot_registry) do 917 local source_key = ("%s:%d"):format(private.UNIT_TYPE_NAMES[source_type + 1], source_id)
883 table.insert(action_data.loot_list, ("%d:%d"):format(item_id, quantity)) 918 -- TODO: Remove debugging
919 -- print(("GUID: %s - Type:ID: %s - Amount: %d"):format(sources[source_index], source_key, source_count))
920
921 -- Items return the player as the source, so we need to replace the nil ID with the item's ID (disenchant, milling, etc)
922 if not source_id then
923 source_id = action_data.identifier
924 end
925 action_data.loot_sources[source_id] = action_data.loot_sources[source_id] or {}
926
927 if slot_type == _G.LOOT_SLOT_ITEM then
928 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot))
929 action_data.loot_sources[source_id][item_id] = action_data.loot_sources[source_id][item_id] or 0 + source_count
930 elseif slot_type == _G.LOOT_SLOT_MONEY then
931 table.insert(action_data.loot_list, ("money:%d"):format(_toCopper(item_text)))
932 elseif slot_type == _G.LOOT_SLOT_CURRENCY then
933 table.insert(action_data.loot_list, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower()))
934 end
935 end
884 end 936 end
885 update_func() 937 update_func()
886 end 938 end
887 end -- do-block 939 end -- do-block
888 940
1264 1316
1265 if bit.band(spell_flags, AF.OBJECT) == AF.OBJECT then 1317 if bit.band(spell_flags, AF.OBJECT) == AF.OBJECT then
1266 if target_name == "" then 1318 if target_name == "" then
1267 return 1319 return
1268 end 1320 end
1269 local identifier = ("%s:%s"):format(spell_label, target_name)
1270 UpdateDBEntryLocation("objects", identifier)
1271
1272 action_data.type = AF.OBJECT 1321 action_data.type = AF.OBJECT
1273 action_data.identifier = identifier
1274 elseif bit.band(spell_flags, AF.ZONE) == AF.ZONE then 1322 elseif bit.band(spell_flags, AF.ZONE) == AF.ZONE then
1275 local identifier = ("%s:%s"):format(spell_label, _G["GameTooltipTextLeft1"]:GetText() or "NONE") -- Possible fishing pool name. 1323 local identifier = ("%s:%s"):format(spell_label, _G["GameTooltipTextLeft1"]:GetText() or "NONE") -- Possible fishing pool name.
1276 action_data.zone_data = UpdateDBEntryLocation("zones", identifier) 1324 action_data.zone_data = UpdateDBEntryLocation("zones", identifier)
1277 action_data.type = AF.ZONE 1325 action_data.type = AF.ZONE
1278 action_data.identifier = identifier 1326 action_data.identifier = identifier