Mercurial > wow > wowdb-profiler
comparison Main.lua @ 306:7feb687b1b22
Fixes
author | James D. Callahan III <jcallahan@curse.com> |
---|---|
date | Tue, 23 Jul 2013 18:07:07 -0500 |
parents | 4986ef8a338a |
children | c33ab3413737 |
comparison
equal
deleted
inserted
replaced
305:4986ef8a338a | 306:7feb687b1b22 |
---|---|
8 local bit = _G.bit | 8 local bit = _G.bit |
9 local math = _G.math | 9 local math = _G.math |
10 local table = _G.table | 10 local table = _G.table |
11 | 11 |
12 local select = _G.select | 12 local select = _G.select |
13 local unpack = _G.unpack | |
13 | 14 |
14 | 15 |
15 -- ADDON NAMESPACE ---------------------------------------------------- | 16 -- ADDON NAMESPACE ---------------------------------------------------- |
16 | 17 |
17 local ADDON_NAME, private = ... | 18 local ADDON_NAME, private = ... |
97 QUEST_COMPLETE = true, | 98 QUEST_COMPLETE = true, |
98 QUEST_DETAIL = true, | 99 QUEST_DETAIL = true, |
99 QUEST_LOG_UPDATE = true, | 100 QUEST_LOG_UPDATE = true, |
100 QUEST_PROGRESS = true, | 101 QUEST_PROGRESS = true, |
101 SHOW_LOOT_TOAST = true, | 102 SHOW_LOOT_TOAST = true, |
103 SPELL_CONFIRMATION_PROMPT = true, | |
102 TAXIMAP_OPENED = true, | 104 TAXIMAP_OPENED = true, |
103 TRADE_SKILL_SHOW = true, | 105 TRADE_SKILL_SHOW = true, |
104 TRAINER_CLOSED = true, | 106 TRAINER_CLOSED = true, |
105 TRAINER_SHOW = true, | 107 TRAINER_SHOW = true, |
106 TRANSMOGRIFY_OPEN = true, | 108 TRANSMOGRIFY_OPEN = true, |
130 local in_instance | 132 local in_instance |
131 local item_process_timer_handle | 133 local item_process_timer_handle |
132 local faction_standings = {} | 134 local faction_standings = {} |
133 local forge_spell_ids = {} | 135 local forge_spell_ids = {} |
134 local languages_known = {} | 136 local languages_known = {} |
137 local loot_toast_container_timer_handle | |
135 local name_to_id_map = {} | 138 local name_to_id_map = {} |
139 local killed_boss_id_timer_handle | |
136 local killed_npc_id | 140 local killed_npc_id |
137 local target_location_timer_handle | 141 local target_location_timer_handle |
138 local current_target_id | 142 local current_target_id |
139 local current_area_id | 143 local current_area_id |
140 local current_loot | 144 local current_loot |
155 | 159 |
156 | 160 |
157 -- HELPERS ------------------------------------------------------------ | 161 -- HELPERS ------------------------------------------------------------ |
158 | 162 |
159 local function Debug(message, ...) | 163 local function Debug(message, ...) |
160 if not DEBUGGING then | 164 if not DEBUGGING or not message or not ... then |
161 return | 165 return |
162 end | 166 end |
163 _G.print(message:format(...)) | 167 local args = { ... } |
168 | |
169 for index = 1, #args do | |
170 if args[index] == nil then | |
171 args[index] = "nil" | |
172 end | |
173 end | |
174 _G.print(message:format(unpack(args))) | |
164 end | 175 end |
165 | 176 |
166 | 177 |
167 local TradeSkillExecutePer | 178 local TradeSkillExecutePer |
168 do | 179 do |
169 local header_list = {} | 180 local header_list = {} |
170 | 181 |
171 -- iter_func returns true to indicate that the loop should be broken | |
172 function TradeSkillExecutePer(iter_func) | 182 function TradeSkillExecutePer(iter_func) |
173 if not _G.TradeSkillFrame or not _G.TradeSkillFrame:IsVisible() then | 183 if not _G.TradeSkillFrame or not _G.TradeSkillFrame:IsVisible() then |
174 return | 184 return |
175 end | 185 end |
176 -- Clear the search box focus so the scan will have correct results. | 186 -- Clear the search box focus so the scan will have correct results. |
276 killed_npc_id = nil | 286 killed_npc_id = nil |
277 end | 287 end |
278 | 288 |
279 | 289 |
280 local function ClearKilledBossID() | 290 local function ClearKilledBossID() |
291 if killed_boss_id_timer_handle then | |
292 WDP:CancelTimer(killed_boss_id_timer_handle) | |
293 end | |
294 private.boss_loot_toasting = false | |
281 private.raid_finder_boss_id = nil | 295 private.raid_finder_boss_id = nil |
282 private.world_boss_id = nil | 296 private.world_boss_id = nil |
297 killed_boss_id_timer_handle = nil | |
298 end | |
299 | |
300 | |
301 local function ClearLootToastContainerID() | |
302 if loot_toast_container_timer_handle then | |
303 WDP:CancelTimer(loot_toast_container_timer_handle) | |
304 end | |
305 private.container_loot_toasting = false | |
306 private.loot_toast_container_id = nil | |
307 loot_toast_container_timer_handle = nil | |
283 end | 308 end |
284 | 309 |
285 | 310 |
286 local function InstanceDifficultyToken() | 311 local function InstanceDifficultyToken() |
287 local _, instance_type, instance_difficulty, _, _, _, is_dynamic = _G.GetInstanceInfo() | 312 local _, instance_type, instance_difficulty, _, _, _, is_dynamic = _G.GetInstanceInfo() |
513 local current_line = _G["WDPDatamineTTTextLeft" .. line_index] | 538 local current_line = _G["WDPDatamineTTTextLeft" .. line_index] |
514 | 539 |
515 if not current_line then | 540 if not current_line then |
516 break | 541 break |
517 end | 542 end |
518 local is_ptr = select(4, _G.GetBuildInfo()) ~= 50100 | 543 |
519 | 544 if current_line:GetText() == _G.ITEM_OPENABLE then |
520 if is_ptr or current_line:GetText() == _G.ITEM_OPENABLE then | |
521 table.wipe(current_action) | 545 table.wipe(current_action) |
522 current_action.target_type = AF.ITEM | 546 current_action.target_type = AF.ITEM |
523 current_action.identifier = item_id | 547 current_action.identifier = item_id |
524 current_action.loot_label = "contains" | 548 current_action.loot_label = "contains" |
525 break | 549 break |
610 local loot_table = LootTable(entry, loot_type, top_field) | 634 local loot_table = LootTable(entry, loot_type, top_field) |
611 | 635 |
612 if not source_list[source_id] then | 636 if not source_list[source_id] then |
613 if top_field then | 637 if top_field then |
614 entry[top_field][loot_count] = (entry[top_field][loot_count] or 0) + 1 | 638 entry[top_field][loot_count] = (entry[top_field][loot_count] or 0) + 1 |
615 else | 639 elseif not private.container_loot_toasting then |
616 entry[loot_count] = (entry[loot_count] or 0) + 1 | 640 entry[loot_count] = (entry[loot_count] or 0) + 1 |
617 end | 641 end |
618 source_list[source_id] = true | 642 source_list[source_id] = true |
619 end | 643 end |
620 UpdateDBEntryLocation(data_type, source_id) | 644 UpdateDBEntryLocation(data_type, source_id) |
1111 UpdateUnitPet(_G.UnitGUID(unit_id), unit_id) | 1135 UpdateUnitPet(_G.UnitGUID(unit_id), unit_id) |
1112 end | 1136 end |
1113 | 1137 |
1114 | 1138 |
1115 function WDP:SHOW_LOOT_TOAST(event_name, loot_type, item_link, quantity) | 1139 function WDP:SHOW_LOOT_TOAST(event_name, loot_type, item_link, quantity) |
1140 if not loot_type or (loot_type ~= "item" and loot_type ~= "money") then | |
1141 Debug("%s: loot_type is %s. Item link is %s, and quantity is %d.", event_name, loot_type, item_link, quantity) | |
1142 return | |
1143 end | |
1116 local container_id = private.loot_toast_container_id | 1144 local container_id = private.loot_toast_container_id |
1117 local item_id = ItemLinkToID(item_link) | 1145 local item_id = ItemLinkToID(item_link) |
1118 local npc = NPCEntry(private.raid_finder_boss_id or private.world_boss_id) | 1146 local npc = NPCEntry(private.raid_finder_boss_id or private.world_boss_id) |
1119 ClearKilledBossID() | |
1120 | 1147 |
1121 if npc then | 1148 if npc then |
1122 if not item_id then | 1149 if not item_id then |
1123 Debug("%s: ItemID is nil, from item link %s", event_name, item_link) | 1150 Debug("%s: ItemID is nil, from item link %s", event_name, item_link) |
1124 return | 1151 return |
1125 end | 1152 end |
1126 local loot_type = "drops" | 1153 local loot_label = "drops" |
1127 local encounter_data = npc:EncounterData(InstanceDifficultyToken()) | 1154 local encounter_data = npc:EncounterData(InstanceDifficultyToken()) |
1128 encounter_data[loot_type] = encounter_data[loot_type] or {} | 1155 encounter_data[loot_label] = encounter_data[loot_label] or {} |
1129 encounter_data.loot_counts = encounter_data.loot_counts or {} | 1156 encounter_data.loot_counts = encounter_data.loot_counts or {} |
1130 encounter_data.loot_counts[loot_type] = (encounter_data.loot_counts[loot_type] or 0) + 1 | 1157 |
1131 | 1158 if not private.boss_loot_toasting then |
1132 table.insert(encounter_data[loot_type], ("%d:%d"):format(item_id, quantity)) | 1159 encounter_data.loot_counts[loot_label] = (encounter_data.loot_counts[loot_label] or 0) + 1 |
1133 Debug("%s: %sX%d (%d)", event_name, item_link, quantity, item_id) | 1160 end |
1161 | |
1162 if loot_type == "item" then | |
1163 Debug("%s: %sX%d (%d)", event_name, item_link, quantity, item_id) | |
1164 table.insert(encounter_data[loot_label], ("%d:%d"):format(item_id, quantity)) | |
1165 elseif loot_type == "money" then | |
1166 Debug("%s: money - %d", event_name, quantity) | |
1167 table.insert(encounter_data[loot_label], ("money:%d"):format(quantity)) | |
1168 end | |
1169 private.boss_loot_toasting = true -- Do not count further loots until timer expires or another boss is killed | |
1134 elseif container_id then | 1170 elseif container_id then |
1135 private.loot_toast_container_id = nil | |
1136 | |
1137 InitializeCurrentLoot() | 1171 InitializeCurrentLoot() |
1172 | |
1173 -- Fake the loot characteristics to match that of an actual container item | |
1174 current_loot.identifier = container_id | |
1175 current_loot.label = "contains" | |
1176 current_loot.target_type = AF.ITEM | |
1138 | 1177 |
1139 if loot_type == "item" then | 1178 if loot_type == "item" then |
1140 if not item_id then | 1179 if not item_id then |
1141 Debug("%s: ItemID is nil, from item link %s", event_name, item_link) | 1180 Debug("%s: ItemID is nil, from item link %s", event_name, item_link) |
1142 return | 1181 return |
1147 elseif loot_type == "money" then | 1186 elseif loot_type == "money" then |
1148 table.insert(current_loot.list, ("money:%d"):format(quantity)) | 1187 table.insert(current_loot.list, ("money:%d"):format(quantity)) |
1149 end | 1188 end |
1150 GenericLootUpdate("items") | 1189 GenericLootUpdate("items") |
1151 current_loot = nil | 1190 current_loot = nil |
1191 private.container_loot_toasting = true -- do not count further loots until timer expires or another container is opened | |
1152 else | 1192 else |
1153 Debug("%s: NPC and Container are nil.", event_name) | 1193 Debug("%s: NPC and Container are nil.", event_name) |
1154 end | 1194 end |
1155 end | 1195 end |
1156 | 1196 |
1347 | 1387 |
1348 if not previous_combat_event.party_damage then | 1388 if not previous_combat_event.party_damage then |
1349 Debug("%s: %s was killed by %s (not group member or pet).", sub_event, dest_name or _G.UNKNOWN, killer_name or _G.UNKNOWN) | 1389 Debug("%s: %s was killed by %s (not group member or pet).", sub_event, dest_name or _G.UNKNOWN, killer_name or _G.UNKNOWN) |
1350 table.wipe(previous_combat_event) | 1390 table.wipe(previous_combat_event) |
1351 ClearKilledNPC() | 1391 ClearKilledNPC() |
1352 ClearKilledBossID() | 1392 else |
1353 return | 1393 Debug("%s: %s was killed by %s.", sub_event, dest_name or _G.UNKNOWN, killer_name or _G.UNKNOWN) |
1354 end | |
1355 Debug("%s: %s was killed by %s.", sub_event, dest_name or _G.UNKNOWN, killer_name or _G.UNKNOWN) | |
1356 | |
1357 if private.RAID_FINDER_BOSS_IDS[unit_idnum] then | |
1358 Debug("%s: Matching boss %s.", sub_event, dest_name) | |
1359 ClearKilledBossID() | |
1360 private.raid_finder_boss_id = unit_idnum | |
1361 elseif private.WORLD_BOSS_IDS[unit_idnum] then | |
1362 Debug("%s: Matching world boss %s.", sub_event, dest_name) | |
1363 ClearKilledBossID() | |
1364 private.world_boss_id = unit_idnum | |
1365 end | 1394 end |
1366 killed_npc_id = unit_idnum | 1395 killed_npc_id = unit_idnum |
1367 WDP:ScheduleTimer(ClearKilledNPC, 0.1) | 1396 WDP:ScheduleTimer(ClearKilledNPC, 0.1) |
1368 WDP:ScheduleTimer(ClearKilledBossID, 1) | |
1369 end, | 1397 end, |
1370 } | 1398 } |
1371 | 1399 |
1372 | 1400 |
1373 local NON_DAMAGE_EVENTS = { | 1401 local NON_DAMAGE_EVENTS = { |
2169 local spell_label = private.SPELL_LABELS_BY_NAME[spell_name] | 2197 local spell_label = private.SPELL_LABELS_BY_NAME[spell_name] |
2170 | 2198 |
2171 if not spell_label then | 2199 if not spell_label then |
2172 return | 2200 return |
2173 end | 2201 end |
2202 | |
2174 local item_name, item_link = _G.GameTooltip:GetItem() | 2203 local item_name, item_link = _G.GameTooltip:GetItem() |
2175 local unit_name, unit_id = _G.GameTooltip:GetUnit() | 2204 local unit_name, unit_id = _G.GameTooltip:GetUnit() |
2176 | 2205 |
2177 if not unit_name and _G.UnitName("target") == target_name then | 2206 if not unit_name and _G.UnitName("target") == target_name then |
2178 unit_name = target_name | 2207 unit_name = target_name |
2221 end | 2250 end |
2222 private.tracked_line = spell_line | 2251 private.tracked_line = spell_line |
2223 end | 2252 end |
2224 | 2253 |
2225 | 2254 |
2226 do | 2255 function WDP:SPELL_CONFIRMATION_PROMPT(event_name, spell_id, confirm_type, text, duration, currency_id) |
2227 local LOOT_SPELL_ID_TO_ITEM_ID_MAP = { | 2256 if private.RAID_BOSS_BONUS_SPELL_ID_TO_NPC_ID_MAP[spell_id] then |
2228 [142397] = 98134, -- Heroic Cache of Treasures | 2257 ClearKilledBossID() |
2229 [143506] = 98095, -- Brawler's Pet Supplies | 2258 ClearLootToastContainerID() |
2230 [143507] = 94207, -- Fabled Pandaren Pet Supplies | 2259 private.raid_finder_boss_id = private.RAID_BOSS_BONUS_SPELL_ID_TO_NPC_ID_MAP[spell_id] |
2231 [143512] = 93148, -- Pandaren Spirit Pet Supplies | 2260 elseif private.WORLD_BOSS_BONUS_SPELL_ID_TO_NPC_ID_MAP[spell_id] then |
2232 [143511] = 93149, -- Pandaren Spirit Pet Supplies | 2261 ClearKilledBossID() |
2233 [143510] = 93147, -- Pandaren Spirit Pet Supplies | 2262 ClearLootToastContainerID() |
2234 [143509] = 93146, -- Pandaren Spirit Pet Supplies | 2263 private.world_boss_id = private.WORLD_BOSS_BONUS_SPELL_ID_TO_NPC_ID_MAP[spell_id] |
2235 [143508] = 89125, -- Sack of Pet Supplies | 2264 else |
2236 } | 2265 Debug("%s: Spell ID %d is not a known raid or world boss 'Bonus' spell.", event_name, spell_id) |
2237 | 2266 return |
2238 function WDP:UNIT_SPELLCAST_SUCCEEDED(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id) | 2267 end |
2239 if unit_id ~= "player" then | 2268 |
2240 return | 2269 killed_boss_id_timer_handle = WDP:ScheduleTimer(ClearKilledBossID, 1) -- we need to assign a handle here to cancel it later |
2241 end | 2270 end |
2242 private.tracked_line = nil | 2271 |
2243 private.previous_spell_id = spell_id | 2272 |
2244 private.loot_toast_container_id = LOOT_SPELL_ID_TO_ITEM_ID_MAP[spell_id] | 2273 function WDP:UNIT_SPELLCAST_SUCCEEDED(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id) |
2245 | 2274 if unit_id ~= "player" then |
2246 if anvil_spell_ids[spell_id] then | 2275 return |
2247 UpdateDBEntryLocation("objects", OBJECT_ID_ANVIL) | 2276 end |
2248 elseif forge_spell_ids[spell_id] then | 2277 private.tracked_line = nil |
2249 UpdateDBEntryLocation("objects", OBJECT_ID_FORGE) | 2278 private.previous_spell_id = spell_id |
2250 elseif spell_name:match("^Harvest.+") then | 2279 |
2251 killed_npc_id = current_target_id | 2280 if private.LOOT_SPELL_ID_TO_ITEM_ID_MAP[spell_id] then |
2252 private.harvesting = true | 2281 ClearKilledBossID() |
2253 end | 2282 ClearLootToastContainerID() |
2254 end | 2283 |
2255 end -- do-block | 2284 private.loot_toast_container_id = private.LOOT_SPELL_ID_TO_ITEM_ID_MAP[spell_id] |
2285 loot_toast_container_timer_handle = WDP:ScheduleTimer(ClearLootToastContainerID, 1) -- we need to assign a handle here to cancel it later | |
2286 end | |
2287 | |
2288 if anvil_spell_ids[spell_id] then | |
2289 UpdateDBEntryLocation("objects", OBJECT_ID_ANVIL) | |
2290 elseif forge_spell_ids[spell_id] then | |
2291 UpdateDBEntryLocation("objects", OBJECT_ID_FORGE) | |
2292 elseif spell_name:match("^Harvest.+") then | |
2293 killed_npc_id = current_target_id | |
2294 private.harvesting = true | |
2295 end | |
2296 end | |
2256 | 2297 |
2257 | 2298 |
2258 function WDP:HandleSpellFailure(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id) | 2299 function WDP:HandleSpellFailure(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id) |
2259 if unit_id ~= "player" then | 2300 if unit_id ~= "player" then |
2260 return | 2301 return |