Mercurial > wow > wowdb-profiler
comparison Main.lua @ 317:8a2e619cced5
Loot and merchant currency fixes.
| author | James D. Callahan III <jcallahan@curse.com> |
|---|---|
| date | Sun, 15 Sep 2013 19:01:58 -0500 |
| parents | 564deda095ec |
| children | 4f2d5a082b6d |
comparison
equal
deleted
inserted
replaced
| 316:9fe19fd62142 | 317:8a2e619cced5 |
|---|---|
| 133 local in_instance | 133 local in_instance |
| 134 local item_process_timer_handle | 134 local item_process_timer_handle |
| 135 local faction_standings = {} | 135 local faction_standings = {} |
| 136 local forge_spell_ids = {} | 136 local forge_spell_ids = {} |
| 137 local languages_known = {} | 137 local languages_known = {} |
| 138 local boss_loot_toasting = {} | |
| 138 local loot_toast_container_timer_handle | 139 local loot_toast_container_timer_handle |
| 139 local loot_toast_data | 140 local loot_toast_data |
| 140 local loot_toast_data_timer_handle | 141 local loot_toast_data_timer_handle |
| 141 local name_to_id_map = {} | 142 local name_to_id_map = {} |
| 142 local killed_boss_id_timer_handle | 143 local killed_boss_id_timer_handle |
| 283 return math.floor(copper_cost / modifier) | 284 return math.floor(copper_cost / modifier) |
| 284 end | 285 end |
| 285 end -- do-block | 286 end -- do-block |
| 286 | 287 |
| 287 | 288 |
| 289 -- constant for duplicate boss data; a dirty hack to get around world bosses that cannot be identified individually and cannot be linked on wowdb because they are not in a raid | |
| 290 local DUPLICATE_WORLD_BOSS_IDS = { | |
| 291 [71952] = { 71953, 71954, 71955, }, | |
| 292 } | |
| 293 | |
| 294 | |
| 288 -- Called on a timer | 295 -- Called on a timer |
| 289 local function ClearKilledNPC() | 296 local function ClearKilledNPC() |
| 290 killed_npc_id = nil | 297 killed_npc_id = nil |
| 291 end | 298 end |
| 292 | 299 |
| 293 | 300 |
| 294 local function ClearKilledBossID() | 301 local function ClearKilledBossID() |
| 295 if killed_boss_id_timer_handle then | 302 if killed_boss_id_timer_handle then |
| 296 WDP:CancelTimer(killed_boss_id_timer_handle) | 303 WDP:CancelTimer(killed_boss_id_timer_handle) |
| 297 end | 304 end |
| 298 private.boss_loot_toasting = false | 305 table.wipe(boss_loot_toasting) |
| 299 private.raid_finder_boss_id = nil | 306 private.raid_finder_boss_id = nil |
| 300 private.world_boss_id = nil | 307 private.world_boss_id = nil |
| 301 killed_boss_id_timer_handle = nil | 308 killed_boss_id_timer_handle = nil |
| 302 end | 309 end |
| 303 | 310 |
| 1180 if not loot_type or (loot_type ~= "item" and loot_type ~= "money" and loot_type ~= "currency") then | 1187 if not loot_type or (loot_type ~= "item" and loot_type ~= "money" and loot_type ~= "currency") then |
| 1181 Debug("%s: loot_type is %s. Item link is %s, and quantity is %d.", event_name, loot_type, item_link, quantity) | 1188 Debug("%s: loot_type is %s. Item link is %s, and quantity is %d.", event_name, loot_type, item_link, quantity) |
| 1182 return | 1189 return |
| 1183 end | 1190 end |
| 1184 local container_id = private.loot_toast_container_id | 1191 local container_id = private.loot_toast_container_id |
| 1185 local npc = NPCEntry(private.raid_finder_boss_id or private.world_boss_id) | 1192 local npc_id = private.raid_finder_boss_id or private.world_boss_id |
| 1186 | 1193 |
| 1187 if npc then | 1194 if npc_id then |
| 1188 local loot_label = "drops" | 1195 -- slightly messy hack to workaround duplicate world bosses |
| 1189 local encounter_data = npc:EncounterData(InstanceDifficultyToken()) | 1196 local upper_limit = 0 |
| 1190 encounter_data[loot_label] = encounter_data[loot_label] or {} | 1197 if DUPLICATE_WORLD_BOSS_IDS[npc_id] then |
| 1191 encounter_data.loot_counts = encounter_data.loot_counts or {} | 1198 upper_limit = #DUPLICATE_WORLD_BOSS_IDS[npc_id] |
| 1192 | 1199 end |
| 1193 if loot_type == "item" then | 1200 for i = 0, upper_limit do |
| 1194 local item_id = ItemLinkToID(item_link) | 1201 local temp_npc_id = npc_id |
| 1195 if item_id then | 1202 |
| 1196 Debug("%s: %s X %d (%d)", event_name, item_link, quantity, item_id) | 1203 if i > 0 then |
| 1197 table.insert(encounter_data[loot_label], ("%d:%d"):format(item_id, quantity)) | 1204 temp_npc_id = DUPLICATE_WORLD_BOSS_IDS[npc_id][i] |
| 1198 else | 1205 end |
| 1199 Debug("%s: ItemID is nil, from item link %s", event_name, item_link) | 1206 |
| 1200 return | 1207 local npc = NPCEntry(temp_npc_id) |
| 1201 end | 1208 if npc then |
| 1202 elseif loot_type == "money" then | 1209 local loot_label = "drops" |
| 1203 Debug("%s: money X %d", event_name, quantity) | 1210 local encounter_data = npc:EncounterData(InstanceDifficultyToken()) |
| 1204 table.insert(encounter_data[loot_label], ("money:%d"):format(quantity)) | 1211 encounter_data[loot_label] = encounter_data[loot_label] or {} |
| 1205 elseif loot_type == "currency" then | 1212 encounter_data.loot_counts = encounter_data.loot_counts or {} |
| 1206 local currency_texture = CurrencyLinkToTexture(item_link) | 1213 |
| 1207 if currency_texture and currency_texture ~= "" then | 1214 if loot_type == "item" then |
| 1208 Debug("%s: %s X %d", event_name, currency_texture, quantity) | 1215 local item_id = ItemLinkToID(item_link) |
| 1209 table.insert(encounter_data[loot_label], ("currency:%d:%s"):format(quantity, currency_texture)) | 1216 if item_id then |
| 1210 else | 1217 Debug("%s: %s X %d (%d)", event_name, item_link, quantity, item_id) |
| 1211 Debug("%s: Currency texture is nil, from currency link %s", event_name, item_link) | 1218 table.insert(encounter_data[loot_label], ("%d:%d"):format(item_id, quantity)) |
| 1212 return | 1219 else |
| 1213 end | 1220 Debug("%s: ItemID is nil, from item link %s", event_name, item_link) |
| 1214 end | 1221 return |
| 1215 | 1222 end |
| 1216 if not private.boss_loot_toasting then | 1223 elseif loot_type == "money" then |
| 1217 encounter_data.loot_counts[loot_label] = (encounter_data.loot_counts[loot_label] or 0) + 1 | 1224 Debug("%s: money X %d", event_name, quantity) |
| 1218 end | 1225 table.insert(encounter_data[loot_label], ("money:%d"):format(quantity)) |
| 1219 | 1226 elseif loot_type == "currency" then |
| 1220 private.boss_loot_toasting = true -- Do not count further loots until timer expires or another boss is killed | 1227 local currency_texture = CurrencyLinkToTexture(item_link) |
| 1228 if currency_texture and currency_texture ~= "" then | |
| 1229 Debug("%s: %s X %d", event_name, currency_texture, quantity) | |
| 1230 -- workaround for Patch 5.4.0 bug with Flexible raid Siege of Orgrimmar bosses and Valor Points | |
| 1231 if quantity > 1000 and currency_texture == "pvecurrency-valor" then | |
| 1232 quantity = math.floor(quantity / 100) | |
| 1233 end | |
| 1234 table.insert(encounter_data[loot_label], ("currency:%d:%s"):format(quantity, currency_texture)) | |
| 1235 else | |
| 1236 Debug("%s: Currency texture is nil, from currency link %s", event_name, item_link) | |
| 1237 return | |
| 1238 end | |
| 1239 end | |
| 1240 | |
| 1241 if not boss_loot_toasting[temp_npc_id] then | |
| 1242 encounter_data.loot_counts[loot_label] = (encounter_data.loot_counts[loot_label] or 0) + 1 | |
| 1243 boss_loot_toasting[temp_npc_id] = true -- Do not count further loots until timer expires or another boss is killed | |
| 1244 end | |
| 1245 end | |
| 1246 end | |
| 1221 elseif container_id then | 1247 elseif container_id then |
| 1222 InitializeCurrentLoot() | 1248 InitializeCurrentLoot() |
| 1223 | 1249 |
| 1224 -- Fake the loot characteristics to match that of an actual container item | 1250 -- Fake the loot characteristics to match that of an actual container item |
| 1225 current_loot.identifier = container_id | 1251 current_loot.identifier = container_id |
| 1448 if not previous_combat_event.party_damage then | 1474 if not previous_combat_event.party_damage then |
| 1449 --Debug("%s: %s was killed by %s (not group member or pet).", sub_event, dest_name or _G.UNKNOWN, killer_name or _G.UNKNOWN) -- broken in Patch 5.4 | 1475 --Debug("%s: %s was killed by %s (not group member or pet).", sub_event, dest_name or _G.UNKNOWN, killer_name or _G.UNKNOWN) -- broken in Patch 5.4 |
| 1450 table.wipe(previous_combat_event) | 1476 table.wipe(previous_combat_event) |
| 1451 ClearKilledNPC() | 1477 ClearKilledNPC() |
| 1452 else | 1478 else |
| 1453 --Debug("%s: %s was killed by %s.", sub_event, dest_name or _G.UNKNOWN, killer_name or _G.UNKNOWN) -- broken in Patch 5.4 | 1479 --Debug("%s: %s was killed by %s.", sub_event, dest_name or _G.UNKNOWN, killer_name or _G.UNKNOWN) -- broken in Patch 5.4 |
| 1454 end | 1480 end |
| 1455 killed_npc_id = unit_idnum | 1481 killed_npc_id = unit_idnum |
| 1456 WDP:ScheduleTimer(ClearKilledNPC, 0.1) | 1482 WDP:ScheduleTimer(ClearKilledNPC, 0.1) |
| 1457 end, | 1483 end, |
| 1458 } | 1484 } |
| 1960 -- Keeping this around in case Blizzard makes the two points diverge at some point. | 1986 -- Keeping this around in case Blizzard makes the two points diverge at some point. |
| 1961 -- price_string = ("%s:%s:%s:%s"):format(price_string, battleground_rating, personal_rating, required_season_amount or 0) | 1987 -- price_string = ("%s:%s:%s:%s"):format(price_string, battleground_rating, personal_rating, required_season_amount or 0) |
| 1962 price_string = ("%s:%s:%s"):format(price_string, personal_rating, required_season_amount or 0) | 1988 price_string = ("%s:%s:%s"):format(price_string, personal_rating, required_season_amount or 0) |
| 1963 | 1989 |
| 1964 for cost_index = 1, item_count do | 1990 for cost_index = 1, item_count do |
| 1965 -- (after some testing, the DB/Parser doesn't even support currency_ids -at all-, so vendor data submitted with the correct format will ironically be destroyed. that's why I removed the code here for currency_ids) | 1991 -- the third return (Blizz calls "currency_link") of GetMerchantItemCostItem only returns item links as of Patch 5.3.0 |
| 1966 -- the third return ("currency_link") of GetMerchantItemCostItem is broken as of Patch 5.4.0 | 1992 local icon_texture, amount_required, item_link = _G.GetMerchantItemCostItem(item_index, cost_index) |
| 1967 local currency_texture, amount_required = _G.GetMerchantItemCostItem(item_index, cost_index) | 1993 local currency_identifier = item_link and ItemLinkToID(item_link) or nil |
| 1968 | 1994 |
| 1969 if currency_texture then | 1995 if (not currency_identifier or currency_identifier < 1) and icon_texture then |
| 1970 currency_list[#currency_list + 1] = ("(%s:%s)"):format(amount_required, currency_texture:match("[^\\]+$"):lower()) | 1996 currency_identifier = icon_texture:match("[^\\]+$"):lower() |
| 1997 end | |
| 1998 | |
| 1999 if currency_identifier then | |
| 2000 currency_list[#currency_list + 1] = ("(%s:%s)"):format(amount_required, currency_identifier) | |
| 1971 end | 2001 end |
| 1972 end | 2002 end |
| 1973 | 2003 |
| 1974 for currency_index = 1, #currency_list do | 2004 for currency_index = 1, #currency_list do |
| 1975 price_string = ("%s:%s"):format(price_string, currency_list[currency_index]) | 2005 price_string = ("%s:%s"):format(price_string, currency_list[currency_index]) |
| 2316 return | 2346 return |
| 2317 end | 2347 end |
| 2318 | 2348 |
| 2319 -- assign existing loot data to boss if it exists | 2349 -- assign existing loot data to boss if it exists |
| 2320 if loot_toast_data then | 2350 if loot_toast_data then |
| 2321 local npc = NPCEntry(private.raid_finder_boss_id or private.world_boss_id) | 2351 local npc_id = private.raid_finder_boss_id or private.world_boss_id |
| 2322 | 2352 |
| 2323 if npc then | 2353 -- slightly messy hack to workaround duplicate world bosses |
| 2324 -- create needed npc fields if required | 2354 local upper_limit = 0 |
| 2325 local loot_label = "drops" | 2355 if DUPLICATE_WORLD_BOSS_IDS[npc_id] then |
| 2326 local encounter_data = npc:EncounterData(InstanceDifficultyToken()) | 2356 upper_limit = #DUPLICATE_WORLD_BOSS_IDS[npc_id] |
| 2327 encounter_data[loot_label] = encounter_data[loot_label] or {} | 2357 end |
| 2328 encounter_data.loot_counts = encounter_data.loot_counts or {} | 2358 |
| 2329 encounter_data.loot_counts[loot_label] = (encounter_data.loot_counts[loot_label] or 0) + 1 | 2359 for i = 0, upper_limit do |
| 2330 | 2360 local temp_npc_id = npc_id |
| 2331 for index = 1, #loot_toast_data do | 2361 |
| 2332 local data = loot_toast_data[index] | 2362 if i > 0 then |
| 2333 local loot_type = data[1] | 2363 temp_npc_id = DUPLICATE_WORLD_BOSS_IDS[npc_id][i] |
| 2334 local hyperlink = data[2] | 2364 end |
| 2335 local quantity = data[3] | 2365 |
| 2336 | 2366 local npc = NPCEntry(temp_npc_id) |
| 2337 if loot_type == "item" then | 2367 if npc then |
| 2338 local item_id = ItemLinkToID(hyperlink) | 2368 -- create needed npc fields if required |
| 2339 Debug("%s: Assigned stored item loot data - %s - %d:%d", event_name, hyperlink, item_id, quantity) | 2369 local loot_label = "drops" |
| 2340 table.insert(encounter_data[loot_label], ("%d:%d"):format(item_id, quantity)) | 2370 local encounter_data = npc:EncounterData(InstanceDifficultyToken()) |
| 2341 elseif loot_type == "money" then | 2371 encounter_data[loot_label] = encounter_data[loot_label] or {} |
| 2342 Debug("%s: Assigned stored money loot data - money:%d", event_name, quantity) | 2372 encounter_data.loot_counts = encounter_data.loot_counts or {} |
| 2343 table.insert(encounter_data[loot_label], ("money:%d"):format(quantity)) | 2373 |
| 2344 elseif loot_type == "currency" then | 2374 for index = 1, #loot_toast_data do |
| 2345 local currency_texture = CurrencyLinkToTexture(hyperlink) | 2375 local data = loot_toast_data[index] |
| 2346 Debug("%s: Assigned stored currency loot data - %s - currency:%d:%s", event_name, hyperlink, currency_texture, quantity) | 2376 local loot_type = data[1] |
| 2347 table.insert(encounter_data[loot_label], ("currency:%d:%s"):format(quantity, currency_texture)) | 2377 local hyperlink = data[2] |
| 2378 local quantity = data[3] | |
| 2379 | |
| 2380 if loot_type == "item" then | |
| 2381 local item_id = ItemLinkToID(hyperlink) | |
| 2382 Debug("%s: Assigned stored item loot data - %s - %d:%d", event_name, hyperlink, item_id, quantity) | |
| 2383 table.insert(encounter_data[loot_label], ("%d:%d"):format(item_id, quantity)) | |
| 2384 elseif loot_type == "money" then | |
| 2385 Debug("%s: Assigned stored money loot data - money:%d", event_name, quantity) | |
| 2386 table.insert(encounter_data[loot_label], ("money:%d"):format(quantity)) | |
| 2387 elseif loot_type == "currency" then | |
| 2388 local currency_texture = CurrencyLinkToTexture(hyperlink) | |
| 2389 Debug("%s: Assigned stored currency loot data - %s - currency:%d:%s", event_name, hyperlink, currency_texture, quantity) | |
| 2390 -- workaround for Patch 5.4.0 bug with Flexible raid Siege of Orgrimmar bosses and Valor Points | |
| 2391 if quantity > 1000 and currency_texture == "pvecurrency-valor" then | |
| 2392 quantity = math.floor(quantity / 100) | |
| 2393 end | |
| 2394 table.insert(encounter_data[loot_label], ("currency:%d:%s"):format(quantity, currency_texture)) | |
| 2395 end | |
| 2348 end | 2396 end |
| 2349 end | 2397 |
| 2350 private.boss_loot_toasting = true | 2398 if not boss_loot_toasting[temp_npc_id] then |
| 2351 else | 2399 encounter_data.loot_counts[loot_label] = (encounter_data.loot_counts[loot_label] or 0) + 1 |
| 2352 Debug("%s: NPC is nil, but we have stored loot data...", event_name) | 2400 boss_loot_toasting[temp_npc_id] = true -- Do not count further loots until timer expires or another boss is killed |
| 2401 end | |
| 2402 else | |
| 2403 Debug("%s: NPC is nil, but we have stored loot data...", event_name) | |
| 2404 end | |
| 2353 end | 2405 end |
| 2354 end | 2406 end |
| 2355 | 2407 |
| 2356 ClearLootToastData() | 2408 ClearLootToastData() |
| 2357 | 2409 |
