comparison Main.lua @ 77:c483513c7299

Only count loot sources once per loot event. Actually record money.
author James D. Callahan III <jcallahan@curse.com>
date Tue, 21 Aug 2012 22:57:34 -0500
parents 5c42e26ae1fc
children 7179e2938324
comparison
equal deleted inserted replaced
76:5c42e26ae1fc 77:c483513c7299
381 end -- do-block 381 end -- do-block
382 382
383 383
384 local GenericLootUpdate 384 local GenericLootUpdate
385 do 385 do
386 local function LootTable(entry, loot_type, loot_count, top_field) 386 local function LootTable(entry, loot_type, top_field)
387 if top_field then 387 if top_field then
388 entry[top_field] = entry[top_field] or {} 388 entry[top_field] = entry[top_field] or {}
389 entry[top_field][loot_count] = (entry[top_field][loot_count] or 0) + 1
390 entry[top_field][loot_type] = entry[top_field][loot_type] or {} 389 entry[top_field][loot_type] = entry[top_field][loot_type] or {}
391 return entry[top_field][loot_type] 390 return entry[top_field][loot_type]
392 end 391 end
393 entry[loot_count] = (entry[loot_count] or 0) + 1
394 entry[loot_type] = entry[loot_type] or {} 392 entry[loot_type] = entry[loot_type] or {}
395 return entry[loot_type] 393 return entry[loot_type]
396 end 394 end
397 395
398 function GenericLootUpdate(data_type, top_field) 396 function GenericLootUpdate(data_type, top_field)
399 local loot_type = action_data.label or "drops" 397 local loot_type = action_data.label or "drops"
400 local loot_count = ("%s_count"):format(loot_type) 398 local loot_count = ("%s_count"):format(loot_type)
399 local source_list = {}
401 400
402 for source_id, loot_data in pairs(action_data.loot_sources) do 401 for source_id, loot_data in pairs(action_data.loot_sources) do
403 local entry = DBEntry(data_type, source_id) 402 local entry = DBEntry(data_type, source_id)
404 403
405 if entry then 404 if entry then
406 local loot_table = LootTable(entry, loot_type, loot_count, top_field) 405 local loot_table = LootTable(entry, loot_type, top_field)
406
407 if not source_list[source_id] then
408 if top_field then
409 entry[top_field][loot_count] = (entry[top_field][loot_count] or 0) + 1
410 else
411 entry[loot_count] = (entry[loot_count] or 0) + 1
412 end
413 source_list[source_id] = true
414 end
407 UpdateDBEntryLocation(data_type, source_id) 415 UpdateDBEntryLocation(data_type, source_id)
408 416
409 for item_id, quantity in pairs(loot_data) do 417 for item_id, quantity in pairs(loot_data) do
410 table.insert(loot_table, ("%d:%d"):format(item_id, quantity)) 418 table.insert(loot_table, ("%d:%d"):format(item_id, quantity))
411 end 419 end
415 local entry = DBEntry(data_type, action_data.identifier) 423 local entry = DBEntry(data_type, action_data.identifier)
416 424
417 if not entry then 425 if not entry then
418 return 426 return
419 end 427 end
420 local loot_table = LootTable(entry, loot_type, loot_count, top_field) 428 local loot_table = LootTable(entry, loot_type, top_field)
429
430 if not source_list[action_data.identifier] then
431 if top_field then
432 entry[top_field][loot_count] = (entry[top_field][loot_count] or 0) + 1
433 else
434 entry[loot_count] = (entry[loot_count] or 0) + 1
435 end
436 end
421 437
422 for index = 1, #action_data.loot_list do 438 for index = 1, #action_data.loot_list do
423 table.insert(loot_table, action_data.loot_list[index]) 439 table.insert(loot_table, action_data.loot_list[index])
424 end 440 end
425 end 441 end
823 GenericLootUpdate("items") 839 GenericLootUpdate("items")
824 end, 840 end,
825 [AF.NPC] = function() 841 [AF.NPC] = function()
826 local difficulty_token = InstanceDifficultyToken() 842 local difficulty_token = InstanceDifficultyToken()
827 local loot_type = action_data.label or "drops" 843 local loot_type = action_data.label or "drops"
844 local source_list = {}
828 845
829 for source_id, loot_data in pairs(action_data.loot_sources) do 846 for source_id, loot_data in pairs(action_data.loot_sources) do
830 local npc = NPCEntry(source_id) 847 local npc = NPCEntry(source_id)
831 848
832 if npc then 849 if npc then
833 local encounter_data = npc.encounter_data[difficulty_token] 850 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 {} 851 encounter_data[loot_type] = encounter_data[loot_type] or {}
852
853 if not source_list[source_id] then
854 encounter_data.loot_counts = encounter_data.loot_counts or {}
855 encounter_data.loot_counts[loot_type] = (encounter_data.loot_counts[loot_type] or 0) + 1
856 source_list[source_id] = true
857 end
837 858
838 for item_id, quantity in pairs(loot_data) do 859 for item_id, quantity in pairs(loot_data) do
839 table.insert(encounter_data[loot_type], ("%d:%d"):format(item_id, quantity)) 860 table.insert(encounter_data[loot_type], ("%d:%d"):format(item_id, quantity))
840 end 861 end
841 end 862 end
846 867
847 if not npc then 868 if not npc then
848 return 869 return
849 end 870 end
850 local encounter_data = npc.encounter_data[difficulty_token] 871 local encounter_data = npc.encounter_data[difficulty_token]
851 encounter_data.loot_counts = encounter_data.loot_counts or {}
852 encounter_data.loot_counts[loot_type] = (encounter_data.loot_counts[loot_type] or 0) + 1
853 encounter_data[loot_type] = encounter_data[loot_type] or {} 872 encounter_data[loot_type] = encounter_data[loot_type] or {}
873
874 if not source_list[action_data.identifier] then
875 encounter_data.loot_counts = encounter_data.loot_counts or {}
876 encounter_data.loot_counts[loot_type] = (encounter_data.loot_counts[loot_type] or 0) + 1
877 end
854 878
855 for index = 1, #action_data.loot_list do 879 for index = 1, #action_data.loot_list do
856 table.insert(encounter_data[loot_type], action_data.loot_list[index]) 880 table.insert(encounter_data[loot_type], action_data.loot_list[index])
857 end 881 end
858 end, 882 end,
901 action_data.looting = true 925 action_data.looting = true
902 926
903 for loot_slot = 1, _G.GetNumLootItems() do 927 for loot_slot = 1, _G.GetNumLootItems() do
904 local icon_texture, item_text, quantity, quality, locked = _G.GetLootSlotInfo(loot_slot) 928 local icon_texture, item_text, quantity, quality, locked = _G.GetLootSlotInfo(loot_slot)
905 local slot_type = _G.GetLootSlotType(loot_slot) 929 local slot_type = _G.GetLootSlotType(loot_slot)
906 local sources = { 930
907 _G.GetLootSourceInfo(loot_slot) 931 -- TODO: Move LOOT_SLOT_X checks within loop when money is detectable via GetLootSourceInfo
908 } 932 if slot_type == _G.LOOT_SLOT_ITEM then
909 933 local sources = {
910 -- TODO: Remove debugging 934 _G.GetLootSourceInfo(loot_slot)
911 -- print(("Loot slot %d: Source count: %d"):format(loot_slot, floor((#sources / 2) + 0.5))) 935 }
912 936
913 -- Odd index is GUID, even is count.
914 for source_index = 1, #sources, 2 do
915 local source_type, source_id = ParseGUID(sources[source_index])
916 local source_count = sources[source_index + 1]
917 local source_key = ("%s:%d"):format(private.UNIT_TYPE_NAMES[source_type + 1], source_id)
918 -- TODO: Remove debugging 937 -- TODO: Remove debugging
919 -- print(("GUID: %s - Type:ID: %s - Amount: %d"):format(sources[source_index], source_key, source_count)) 938 -- print(("Loot slot %d: Source count: %d"):format(loot_slot, floor((#sources / 2) + 0.5)))
920 939
921 -- Items return the player as the source, so we need to replace the nil ID with the item's ID (disenchant, milling, etc) 940 -- Odd index is GUID, even is count.
922 if not source_id then 941 for source_index = 1, #sources, 2 do
923 source_id = action_data.identifier 942 local source_type, source_id = ParseGUID(sources[source_index])
924 elseif action_data.type == AF.OBJECT then 943 local source_count = sources[source_index + 1]
925 source_id = ("%s:%s"):format(action_data.spell_label, source_id) 944 local source_key = ("%s:%d"):format(private.UNIT_TYPE_NAMES[source_type + 1], source_id)
945 -- TODO: Remove debugging
946 -- print(("GUID: %s - Type:ID: %s - Amount: %d"):format(sources[source_index], source_key, source_count))
947
948 -- Items return the player as the source, so we need to replace the nil ID with the item's ID (disenchant, milling, etc)
949 if not source_id then
950 source_id = action_data.identifier
951 elseif action_data.type == AF.OBJECT then
952 source_id = ("%s:%s"):format(action_data.spell_label, source_id)
953 end
954 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot))
955 action_data.loot_sources[source_id] = action_data.loot_sources[source_id] or {}
956 action_data.loot_sources[source_id][item_id] = action_data.loot_sources[source_id][item_id] or 0 + source_count
926 end 957 end
927 action_data.loot_sources[source_id] = action_data.loot_sources[source_id] or {} 958 elseif slot_type == _G.LOOT_SLOT_MONEY then
928 959 table.insert(action_data.loot_list, ("money:%d"):format(_toCopper(item_text)))
929 if slot_type == _G.LOOT_SLOT_ITEM then 960 elseif slot_type == _G.LOOT_SLOT_CURRENCY then
930 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot)) 961 table.insert(action_data.loot_list, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower()))
931 action_data.loot_sources[source_id][item_id] = action_data.loot_sources[source_id][item_id] or 0 + source_count
932 elseif slot_type == _G.LOOT_SLOT_MONEY then
933 table.insert(action_data.loot_list, ("money:%d"):format(_toCopper(item_text)))
934 elseif slot_type == _G.LOOT_SLOT_CURRENCY then
935 table.insert(action_data.loot_list, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower()))
936 end
937 end 962 end
938 end 963 end
939 update_func() 964 update_func()
940 end 965 end
941 end -- do-block 966 end -- do-block