comparison Main.lua @ 131:35da36cc87f0

Decoupled loot data from current_action. Fixed recording of Fishing data.
author James D. Callahan III <jcallahan@curse.com>
date Fri, 21 Sep 2012 11:19:36 -0500
parents e0550c57972d
children 05b77c08b211
comparison
equal deleted inserted replaced
130:fbac5f643f04 131:35da36cc87f0
128 local name_to_id_map = {} 128 local name_to_id_map = {}
129 local reputation_npc_id 129 local reputation_npc_id
130 local target_location_timer_handle 130 local target_location_timer_handle
131 local current_target_id 131 local current_target_id
132 local current_area_id 132 local current_area_id
133 local current_loot
133 134
134 ----------------------------------------------------------------------- 135 -----------------------------------------------------------------------
135 -- Data for our current action. Including possible values as a reference. 136 -- Data for our current action. Including possible values as a reference.
136 ----------------------------------------------------------------------- 137 -----------------------------------------------------------------------
137 local current_action = { 138 local current_action = {
438 entry[loot_type] = entry[loot_type] or {} 439 entry[loot_type] = entry[loot_type] or {}
439 return entry[loot_type] 440 return entry[loot_type]
440 end 441 end
441 442
442 function GenericLootUpdate(data_type, top_field) 443 function GenericLootUpdate(data_type, top_field)
443 local loot_type = current_action.loot_label or "drops" 444 local loot_type = current_loot.label or "drops"
444 local loot_count = ("%s_count"):format(loot_type) 445 local loot_count = ("%s_count"):format(loot_type)
445 local source_list = {} 446 local source_list = {}
446 447
447 if current_action.loot_sources then 448 if current_loot.sources then
448 for source_guid, loot_data in pairs(current_action.loot_sources) do 449 for source_guid, loot_data in pairs(current_loot.sources) do
449 local entry, source_id 450 local entry, source_id
450 451
451 if current_action.target_type == AF.ITEM then 452 if current_loot.target_type == AF.ITEM then
452 -- Items return the player as the source, so we need to use the item's ID (disenchant, milling, etc) 453 -- Items return the player as the source, so we need to use the item's ID (disenchant, milling, etc)
453 source_id = current_action.identifier 454 source_id = current_loot.identifier
454 entry = DBEntry(data_type, source_id) 455 entry = DBEntry(data_type, source_id)
455 elseif current_action.target_type == AF.OBJECT then 456 elseif current_loot.target_type == AF.OBJECT then
456 source_id = ("%s:%s"):format(current_action.spell_label, select(2, ParseGUID(source_guid))) 457 source_id = ("%s:%s"):format(current_loot.spell_label, select(2, ParseGUID(source_guid)))
457 entry = DBEntry(data_type, source_id) 458 entry = DBEntry(data_type, source_id)
458 else 459 else
459 source_id = select(2, ParseGUID(source_guid)) 460 source_id = select(2, ParseGUID(source_guid))
460 entry = DBEntry(data_type, source_id) 461 entry = DBEntry(data_type, source_id)
461 end 462 end
479 end 480 end
480 end 481 end
481 end 482 end
482 483
483 -- This is used for Gas Extractions. 484 -- This is used for Gas Extractions.
484 if #current_action.loot_list <= 0 then 485 if #current_loot.list <= 0 then
485 return 486 return
486 end 487 end
487 local entry 488 local entry
488 489
489 -- At this point we only have a name if it's an object. 490 -- At this point we only have a name if it's an object.
490 if current_action.target_type == AF.OBJECT then 491 if current_loot.target_type == AF.OBJECT then
491 entry = DBEntry(data_type, ("%s:%s"):format(current_action.spell_label, current_action.object_name)) 492 entry = DBEntry(data_type, ("%s:%s"):format(current_loot.spell_label, current_loot.object_name))
492 else 493 else
493 entry = DBEntry(data_type, current_action.identifier) 494 entry = DBEntry(data_type, current_loot.identifier)
494 end 495 end
495 496
496 if not entry then 497 if not entry then
497 return 498 return
498 end 499 end
499 local loot_table = LootTable(entry, loot_type, top_field) 500 local loot_table = LootTable(entry, loot_type, top_field)
500 501
501 if not source_list[current_action.identifier] then 502 if not source_list[current_loot.identifier] then
502 if top_field then 503 if top_field then
503 entry[top_field][loot_count] = (entry[top_field][loot_count] or 0) + 1 504 entry[top_field][loot_count] = (entry[top_field][loot_count] or 0) + 1
504 else 505 else
505 entry[loot_count] = (entry[loot_count] or 0) + 1 506 entry[loot_count] = (entry[loot_count] or 0) + 1
506 end 507 end
507 end 508 end
508 509
509 for index = 1, #current_action.loot_list do 510 for index = 1, #current_loot.list do
510 table.insert(loot_table, current_action.loot_list[index]) 511 table.insert(loot_table, current_loot.list[index])
511 end 512 end
512 end 513 end
513 end -- do-block 514 end -- do-block
514 515
515 516
703 encounter_data[npc_level].power = ("%s:%d"):format(POWER_TYPE_NAMES[_G.tostring(power_type)] or power_type, max_power) 704 encounter_data[npc_level].power = ("%s:%d"):format(POWER_TYPE_NAMES[_G.tostring(power_type)] or power_type, max_power)
704 end 705 end
705 end 706 end
706 name_to_id_map[_G.UnitName("target")] = unit_idnum 707 name_to_id_map[_G.UnitName("target")] = unit_idnum
707 708
708 table.wipe(current_action)
709 current_action.target_type = AF.NPC 709 current_action.target_type = AF.NPC
710 current_action.identifier = unit_idnum 710 current_action.identifier = unit_idnum
711 return npc, unit_idnum 711 return npc, unit_idnum
712 end 712 end
713 end -- do-block 713 end -- do-block
788 local item_id = ItemLinkToID(item_link) 788 local item_id = ItemLinkToID(item_link)
789 789
790 if not item_id then 790 if not item_id then
791 return 791 return
792 end 792 end
793 current_action.loot_list = { 793 current_loot = {
794 ("%d:%d"):format(item_id, quantity) 794 list = {
795 ("%d:%d"):format(item_id, quantity)
796 },
797 identifier = current_action.identifier,
798 label = current_action.loot_label,
799 map_level = current_action.map_level,
800 object_name = current_action.object_name,
801 spell_label = current_action.spell_label,
802 target_type = current_action.target_type,
803 x = current_action.x,
804 y = current_action.y,
805 zone_data = current_action.zone_data,
795 } 806 }
807 table.wipe(current_action)
796 GenericLootUpdate("zones") 808 GenericLootUpdate("zones")
797 table.wipe(current_action)
798 end 809 end
799 810
800 811
801 function WDP:RecordQuote(event_name, message, source_name, language_name) 812 function WDP:RecordQuote(event_name, message, source_name, language_name)
802 if not ALLOWED_LOCALES[CLIENT_LOCALE] or not source_name or not name_to_id_map[source_name] or (language_name ~= "" and not languages_known[language_name]) then 813 if not ALLOWED_LOCALES[CLIENT_LOCALE] or not source_name or not name_to_id_map[source_name] or (language_name ~= "" and not languages_known[language_name]) then
1081 [AF.ITEM] = function() 1092 [AF.ITEM] = function()
1082 GenericLootUpdate("items") 1093 GenericLootUpdate("items")
1083 end, 1094 end,
1084 [AF.NPC] = function() 1095 [AF.NPC] = function()
1085 local difficulty_token = InstanceDifficultyToken() 1096 local difficulty_token = InstanceDifficultyToken()
1086 local loot_type = current_action.loot_label or "drops" 1097 local loot_type = current_loot.label or "drops"
1087 local source_list = {} 1098 local source_list = {}
1088 1099
1089 for source_guid, loot_data in pairs(current_action.loot_sources) do 1100 for source_guid, loot_data in pairs(current_loot.sources) do
1090 local source_id = select(2, ParseGUID(source_guid)) 1101 local source_id = select(2, ParseGUID(source_guid))
1091 local npc = NPCEntry(source_id) 1102 local npc = NPCEntry(source_id)
1092 1103
1093 if npc then 1104 if npc then
1094 local encounter_data = npc.encounter_data[difficulty_token] 1105 local encounter_data = npc.encounter_data[difficulty_token]
1105 end 1116 end
1106 end 1117 end
1107 end 1118 end
1108 1119
1109 -- TODO: Remove this when GetLootSourceInfo() has values for money 1120 -- TODO: Remove this when GetLootSourceInfo() has values for money
1110 if #current_action.loot_list <= 0 then 1121 if #current_loot.list <= 0 then
1111 return 1122 return
1112 end 1123 end
1113 local npc = NPCEntry(current_action.identifier) 1124 local npc = NPCEntry(current_loot.identifier)
1114 1125
1115 if not npc then 1126 if not npc then
1116 return 1127 return
1117 end 1128 end
1118 local encounter_data = npc.encounter_data[difficulty_token] 1129 local encounter_data = npc.encounter_data[difficulty_token]
1119 encounter_data[loot_type] = encounter_data[loot_type] or {} 1130 encounter_data[loot_type] = encounter_data[loot_type] or {}
1120 1131
1121 if not source_list[current_action.identifier] then 1132 if not source_list[current_loot.identifier] then
1122 encounter_data.loot_counts = encounter_data.loot_counts or {} 1133 encounter_data.loot_counts = encounter_data.loot_counts or {}
1123 encounter_data.loot_counts[loot_type] = (encounter_data.loot_counts[loot_type] or 0) + 1 1134 encounter_data.loot_counts[loot_type] = (encounter_data.loot_counts[loot_type] or 0) + 1
1124 end 1135 end
1125 1136
1126 for index = 1, #current_action.loot_list do 1137 for index = 1, #current_loot.list do
1127 table.insert(encounter_data[loot_type], current_action.loot_list[index]) 1138 table.insert(encounter_data[loot_type], current_loot.list[index])
1128 end 1139 end
1129 end, 1140 end,
1130 [AF.OBJECT] = function() 1141 [AF.OBJECT] = function()
1131 GenericLootUpdate("objects", InstanceDifficultyToken()) 1142 GenericLootUpdate("objects", InstanceDifficultyToken())
1132 end, 1143 end,
1133 [AF.ZONE] = function() 1144 [AF.ZONE] = function()
1134 local location_token = ("%s:%s:%s"):format(current_action.map_level, current_action.x, current_action.y) 1145 local location_token = ("%s:%s:%s"):format(current_loot.map_level, current_loot.x, current_loot.y)
1135 1146
1136 -- This will start life as a boolean true. 1147 -- This will start life as a boolean true.
1137 if _G.type(current_action.zone_data[location_token]) ~= "table" then 1148 if _G.type(current_loot.zone_data[location_token]) ~= "table" then
1138 current_action.zone_data[location_token] = { 1149 current_loot.zone_data[location_token] = {
1139 drops = {} 1150 drops = {}
1140 } 1151 }
1141 end 1152 end
1142 local loot_count = ("%s_count"):format(current_action.loot_label or "drops") 1153 local loot_count = ("%s_count"):format(current_loot.label or "drops")
1143 current_action.zone_data[location_token][loot_count] = (current_action.zone_data[location_token][loot_count] or 0) + 1 1154 current_loot.zone_data[location_token][loot_count] = (current_loot.zone_data[location_token][loot_count] or 0) + 1
1144 1155
1145 for index = 1, #current_action.loot_list do 1156 if current_loot.sources then
1146 table.insert(current_action.zone_data[location_token].drops, current_action.loot_list[index]) 1157 for source_guid, loot_data in pairs(current_loot.sources) do
1158 for item_id, quantity in pairs(loot_data) do
1159 table.insert(current_loot.zone_data[location_token].drops, ("%d:%d"):format(item_id, quantity))
1160 end
1161 end
1162 end
1163
1164 if #current_loot.list <= 0 then
1165 return
1166 end
1167
1168 for index = 1, #current_loot.list do
1169 table.insert(current_loot.zone_data[location_token].drops, current_loot.loot_list[index])
1147 end 1170 end
1148 end, 1171 end,
1149 } 1172 }
1150 1173
1151 -- Prevent opening the same loot window multiple times from recording data multiple times. 1174 -- Prevent opening the same loot window multiple times from recording data multiple times.
1152 local loot_guid_registry = {} 1175 local loot_guid_registry = {}
1153 local currently_looting
1154 1176
1155 1177
1156 function WDP:LOOT_CLOSED(event_name) 1178 function WDP:LOOT_CLOSED(event_name)
1157 currently_looting = nil 1179 current_loot = nil
1180 table.wipe(current_action)
1158 end 1181 end
1159 1182
1160 1183
1161 function WDP:LOOT_OPENED(event_name) 1184 function WDP:LOOT_OPENED(event_name)
1162 if currently_looting or not current_action.target_type then 1185 if current_loot or not current_action.target_type then
1163 return 1186 return
1164 end 1187 end
1165 local verify_func = LOOT_VERIFY_FUNCS[current_action.target_type] 1188 local verify_func = LOOT_VERIFY_FUNCS[current_action.target_type]
1166 local update_func = LOOT_UPDATE_FUNCS[current_action.target_type] 1189 local update_func = LOOT_UPDATE_FUNCS[current_action.target_type]
1167 1190
1171 1194
1172 if _G.type(verify_func) == "function" and not verify_func() then 1195 if _G.type(verify_func) == "function" and not verify_func() then
1173 return 1196 return
1174 end 1197 end
1175 local guids_used = {} 1198 local guids_used = {}
1176 current_action.loot_list = {} 1199 current_loot = {
1177 current_action.loot_sources = {} 1200 list = {},
1178 currently_looting = true 1201 sources = {},
1202 identifier = current_action.identifier,
1203 label = current_action.loot_label,
1204 map_level = current_action.map_level,
1205 object_name = current_action.object_name,
1206 spell_label = current_action.spell_label,
1207 target_type = current_action.target_type,
1208 x = current_action.x,
1209 y = current_action.y,
1210 zone_data = current_action.zone_data,
1211 }
1212 table.wipe(current_action)
1179 1213
1180 for loot_slot = 1, _G.GetNumLootItems() do 1214 for loot_slot = 1, _G.GetNumLootItems() do
1181 local icon_texture, item_text, quantity, quality, locked = _G.GetLootSlotInfo(loot_slot) 1215 local icon_texture, item_text, quantity, quality, locked = _G.GetLootSlotInfo(loot_slot)
1182 local slot_type = _G.GetLootSlotType(loot_slot) 1216 local slot_type = _G.GetLootSlotType(loot_slot)
1183 1217
1185 if slot_type == _G.LOOT_SLOT_ITEM then 1219 if slot_type == _G.LOOT_SLOT_ITEM then
1186 local loot_info = { 1220 local loot_info = {
1187 _G.GetLootSourceInfo(loot_slot) 1221 _G.GetLootSourceInfo(loot_slot)
1188 } 1222 }
1189 1223
1190 -- TODO: Remove debugging
1191 -- print(("Loot slot %d: Source count: %d"):format(loot_slot, floor((#sources / 2) + 0.5)))
1192
1193 -- Odd index is GUID, even is count. 1224 -- Odd index is GUID, even is count.
1194 for loot_index = 1, #loot_info, 2 do 1225 for loot_index = 1, #loot_info, 2 do
1195 local source_guid = loot_info[loot_index] 1226 local source_guid = loot_info[loot_index]
1196 1227
1197 if not loot_guid_registry[source_guid] then 1228 if not loot_guid_registry[source_guid] then
1198 local loot_quantity = loot_info[loot_index + 1] 1229 local loot_quantity = loot_info[loot_index + 1]
1199 local source_type, source_id = ParseGUID(source_guid) 1230 local source_type, source_id = ParseGUID(source_guid)
1200 -- TODO: Remove debugging 1231 -- TODO: Remove debugging
1201 -- local source_key = ("%s:%d"):format(private.UNIT_TYPE_NAMES[source_type + 1], source_id) 1232 -- local source_key = ("%s:%d"):format(private.UNIT_TYPE_NAMES[source_type + 1], source_id)
1202 -- print(("GUID: %s - Type:ID: %s - Amount: %d"):format(loot_info[loot_index], source_key, loot_quantity)) 1233 -- print(("GUID: %s - Type:ID: %s - Amount: %d"):format(loot_info[loot_index], source_key, loot_quantity))
1203 1234
1204 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot)) 1235 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot))
1205 current_action.loot_sources[source_guid] = current_action.loot_sources[source_guid] or {} 1236 current_loot.sources[source_guid] = current_loot.sources[source_guid] or {}
1206 current_action.loot_sources[source_guid][item_id] = current_action.loot_sources[source_guid][item_id] or 0 + loot_quantity 1237 current_loot.sources[source_guid][item_id] = current_loot.sources[source_guid][item_id] or 0 + loot_quantity
1207 guids_used[source_guid] = true 1238 guids_used[source_guid] = true
1208 end 1239 end
1209 end 1240 end
1210 -- elseif slot_type == _G.LOOT_SLOT_MONEY then 1241 -- elseif slot_type == _G.LOOT_SLOT_MONEY then
1211 -- table.insert(current_action.loot_list, ("money:%d"):format(_toCopper(item_text))) 1242 -- table.insert(current_action.loot_list, ("money:%d"):format(_toCopper(item_text)))
1212 elseif slot_type == _G.LOOT_SLOT_CURRENCY then 1243 elseif slot_type == _G.LOOT_SLOT_CURRENCY then
1213 table.insert(current_action.loot_list, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower())) 1244 table.insert(current_loot.list, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower()))
1214 end 1245 end
1215 end 1246 end
1216 1247
1217 for guid in pairs(guids_used) do 1248 for guid in pairs(guids_used) do
1218 loot_guid_registry[guid] = true 1249 loot_guid_registry[guid] = true
1219 end 1250 end
1220 update_func() 1251 update_func()
1221 table.wipe(current_action)
1222 end 1252 end
1223 end -- do-block 1253 end -- do-block
1224 1254
1225 1255
1226 function WDP:MAIL_SHOW(event_name) 1256 function WDP:MAIL_SHOW(event_name)