Mercurial > wow > wowdb-profiler
comparison Main.lua @ 312:de9d571df07f
More loot fixes.
| author | James D. Callahan III <jcallahan@curse.com> |
|---|---|
| date | Mon, 09 Sep 2013 16:05:55 -0500 |
| parents | 3b9c6d588e62 |
| children | 564deda095ec |
comparison
equal
deleted
inserted
replaced
| 311:183b6b967cc2 | 312:de9d571df07f |
|---|---|
| 1 -- LUA API ------------------------------------------------------------ | 1 -- LUA API ------------------------------------------------------------ |
| 2 | 2 |
| 3 local _G = getfenv(0) | 3 local _G = getfenv(0) |
| 4 | 4 |
| 5 local pairs = _G.pairs | 5 local pairs = _G.pairs |
| 6 local tostring = _G.tostring | |
| 6 local tonumber = _G.tonumber | 7 local tonumber = _G.tonumber |
| 7 | 8 |
| 8 local bit = _G.bit | 9 local bit = _G.bit |
| 9 local math = _G.math | 10 local math = _G.math |
| 10 local table = _G.table | 11 local table = _G.table |
| 143 local target_location_timer_handle | 144 local target_location_timer_handle |
| 144 local current_target_id | 145 local current_target_id |
| 145 local current_area_id | 146 local current_area_id |
| 146 local current_loot | 147 local current_loot |
| 147 | 148 |
| 149 | |
| 148 -- Data for our current action. Including possible values as a reference. | 150 -- Data for our current action. Including possible values as a reference. |
| 149 local current_action = { | 151 local current_action = { |
| 150 identifier = nil, | 152 identifier = nil, |
| 151 loot_label = nil, | 153 loot_label = nil, |
| 152 loot_list = nil, | 154 loot_list = nil, |
| 325 local _, instance_type, instance_difficulty, _, _, _, is_dynamic = _G.GetInstanceInfo() | 327 local _, instance_type, instance_difficulty, _, _, _, is_dynamic = _G.GetInstanceInfo() |
| 326 | 328 |
| 327 if not instance_type or instance_type == "" then | 329 if not instance_type or instance_type == "" then |
| 328 instance_type = "NONE" | 330 instance_type = "NONE" |
| 329 end | 331 end |
| 330 return ("%s:%d:%s"):format(instance_type:upper(), instance_difficulty, _G.tostring(is_dynamic)) | 332 return ("%s:%d:%s"):format(instance_type:upper(), instance_difficulty, tostring(is_dynamic)) |
| 331 end | 333 end |
| 332 | 334 |
| 333 | 335 |
| 334 local function DBEntry(data_type, unit_id) | 336 local function DBEntry(data_type, unit_id) |
| 335 if not data_type or not unit_id then | 337 if not data_type or not unit_id then |
| 413 | 415 |
| 414 if y % 2 ~= 0 then | 416 if y % 2 ~= 0 then |
| 415 y = y + 1 | 417 y = y + 1 |
| 416 end | 418 end |
| 417 return _G.GetRealZoneText(), current_area_id, x, y, map_level, InstanceDifficultyToken() | 419 return _G.GetRealZoneText(), current_area_id, x, y, map_level, InstanceDifficultyToken() |
| 420 end | |
| 421 | |
| 422 | |
| 423 local function CurrencyLinkToTexture(currency_link) | |
| 424 if not currency_link then | |
| 425 return | |
| 426 end | |
| 427 local _, _, texture_path = _G.GetCurrencyInfo(tonumber(currency_link:match("currency:(%d+)"))) | |
| 428 return texture_path:match("[^\\]+$"):lower() | |
| 418 end | 429 end |
| 419 | 430 |
| 420 | 431 |
| 421 local function ItemLinkToID(item_link) | 432 local function ItemLinkToID(item_link) |
| 422 if not item_link then | 433 if not item_link then |
| 554 break | 565 break |
| 555 end | 566 end |
| 556 | 567 |
| 557 if current_line:GetText() == _G.ITEM_OPENABLE then | 568 if current_line:GetText() == _G.ITEM_OPENABLE then |
| 558 table.wipe(current_action) | 569 table.wipe(current_action) |
| 570 current_loot = nil | |
| 571 | |
| 559 current_action.target_type = AF.ITEM | 572 current_action.target_type = AF.ITEM |
| 560 current_action.identifier = item_id | 573 current_action.identifier = item_id |
| 561 current_action.loot_label = "contains" | 574 current_action.loot_label = "contains" |
| 562 break | 575 break |
| 563 end | 576 end |
| 755 if map_area_id == current_area_id then | 768 if map_area_id == current_area_id then |
| 756 return | 769 return |
| 757 end | 770 end |
| 758 local world_map = _G.WorldMapFrame | 771 local world_map = _G.WorldMapFrame |
| 759 local map_visible = world_map:IsVisible() | 772 local map_visible = world_map:IsVisible() |
| 760 local sfx_value = _G.tonumber(_G.GetCVar("Sound_EnableSFX")) | 773 local sfx_value = tonumber(_G.GetCVar("Sound_EnableSFX")) |
| 761 | 774 |
| 762 if not map_visible then | 775 if not map_visible then |
| 763 _G.SetCVar("Sound_EnableSFX", 0) | 776 _G.SetCVar("Sound_EnableSFX", 0) |
| 764 world_map:Show() | 777 world_map:Show() |
| 765 end | 778 end |
| 822 end | 835 end |
| 823 end | 836 end |
| 824 raw_db.build_num = build_num | 837 raw_db.build_num = build_num |
| 825 raw_db.version = DB_VERSION | 838 raw_db.version = DB_VERSION |
| 826 | 839 |
| 827 if DEBUGGING then -- TODO: Remove this when comment subsystem is finished. | 840 private.InitializeCommentSystem() |
| 828 private.InitializeCommentSystem() | 841 self:RegisterChatCommand("comment", private.ProcessCommentCommand) |
| 829 self:RegisterChatCommand("comment", private.ProcessCommentCommand) | |
| 830 end | |
| 831 end | 842 end |
| 832 | 843 |
| 833 | 844 |
| 834 function WDP:EventDispatcher(...) | 845 function WDP:EventDispatcher(...) |
| 835 local event_name = ... | 846 local event_name = ... |
| 1054 if not level_data.power then | 1065 if not level_data.power then |
| 1055 local max_power = _G.UnitManaMax("target") | 1066 local max_power = _G.UnitManaMax("target") |
| 1056 | 1067 |
| 1057 if max_power > 0 then | 1068 if max_power > 0 then |
| 1058 local power_type = _G.UnitPowerType("target") | 1069 local power_type = _G.UnitPowerType("target") |
| 1059 level_data.power = ("%s:%d"):format(POWER_TYPE_NAMES[_G.tostring(power_type)] or power_type, max_power) | 1070 level_data.power = ("%s:%d"):format(POWER_TYPE_NAMES[tostring(power_type)] or power_type, max_power) |
| 1060 end | 1071 end |
| 1061 end | 1072 end |
| 1062 name_to_id_map[_G.UnitName("target")] = unit_idnum | 1073 name_to_id_map[_G.UnitName("target")] = unit_idnum |
| 1063 return npc, unit_idnum | 1074 return npc, unit_idnum |
| 1064 end | 1075 end |
| 1164 UpdateUnitPet(_G.UnitGUID(unit_id), unit_id) | 1175 UpdateUnitPet(_G.UnitGUID(unit_id), unit_id) |
| 1165 end | 1176 end |
| 1166 | 1177 |
| 1167 | 1178 |
| 1168 function WDP:SHOW_LOOT_TOAST(event_name, loot_type, item_link, quantity) | 1179 function WDP:SHOW_LOOT_TOAST(event_name, loot_type, item_link, quantity) |
| 1169 if not loot_type or (loot_type ~= "item" and loot_type ~= "money") then | 1180 if not loot_type or (loot_type ~= "item" and loot_type ~= "money" and loot_type ~= "currency") then |
| 1170 Debug("%s: loot_type is %s. Item link is %s, and quantity is %d.", event_name, loot_type, item_link, quantity) | 1181 Debug("%s: loot_type is %s. Item link is %s, and quantity is %d.", event_name, loot_type, item_link, quantity) |
| 1171 return | 1182 return |
| 1172 end | 1183 end |
| 1173 local container_id = private.loot_toast_container_id | 1184 local container_id = private.loot_toast_container_id |
| 1174 local item_id = ItemLinkToID(item_link) | |
| 1175 local npc = NPCEntry(private.raid_finder_boss_id or private.world_boss_id) | 1185 local npc = NPCEntry(private.raid_finder_boss_id or private.world_boss_id) |
| 1176 | 1186 |
| 1177 if npc then | 1187 if npc then |
| 1178 if loot_type == "item" and not item_id then | |
| 1179 Debug("%s: ItemID is nil, from item link %s", event_name, item_link) | |
| 1180 return | |
| 1181 end | |
| 1182 local loot_label = "drops" | 1188 local loot_label = "drops" |
| 1183 local encounter_data = npc:EncounterData(InstanceDifficultyToken()) | 1189 local encounter_data = npc:EncounterData(InstanceDifficultyToken()) |
| 1184 encounter_data[loot_label] = encounter_data[loot_label] or {} | 1190 encounter_data[loot_label] = encounter_data[loot_label] or {} |
| 1185 encounter_data.loot_counts = encounter_data.loot_counts or {} | 1191 encounter_data.loot_counts = encounter_data.loot_counts or {} |
| 1186 | 1192 |
| 1193 if loot_type == "item" then | |
| 1194 local item_id = ItemLinkToID(item_link) | |
| 1195 if item_id then | |
| 1196 Debug("%s: %s X %d (%d)", event_name, item_link, quantity, item_id) | |
| 1197 table.insert(encounter_data[loot_label], ("%d:%d"):format(item_id, quantity)) | |
| 1198 else | |
| 1199 Debug("%s: ItemID is nil, from item link %s", event_name, item_link) | |
| 1200 return | |
| 1201 end | |
| 1202 elseif loot_type == "money" then | |
| 1203 Debug("%s: money X %d", event_name, quantity) | |
| 1204 table.insert(encounter_data[loot_label], ("money:%d"):format(quantity)) | |
| 1205 elseif loot_type == "currency" then | |
| 1206 local currency_texture = CurrencyLinkToTexture(item_link) | |
| 1207 if currency_texture and currency_texture ~= "" then | |
| 1208 Debug("%s: %s X %d", event_name, currency_texture, quantity) | |
| 1209 table.insert(encounter_data[loot_label], ("currency:%d:%s"):format(quantity, currency_texture)) | |
| 1210 else | |
| 1211 Debug("%s: Currency texture is nil, from currency link %s", event_name, item_link) | |
| 1212 return | |
| 1213 end | |
| 1214 end | |
| 1215 | |
| 1187 if not private.boss_loot_toasting then | 1216 if not private.boss_loot_toasting then |
| 1188 encounter_data.loot_counts[loot_label] = (encounter_data.loot_counts[loot_label] or 0) + 1 | 1217 encounter_data.loot_counts[loot_label] = (encounter_data.loot_counts[loot_label] or 0) + 1 |
| 1189 end | 1218 end |
| 1190 | 1219 |
| 1191 if loot_type == "item" then | |
| 1192 Debug("%s: %sX%d (%d)", event_name, item_link, quantity, item_id) | |
| 1193 table.insert(encounter_data[loot_label], ("%d:%d"):format(item_id, quantity)) | |
| 1194 elseif loot_type == "money" then | |
| 1195 Debug("%s: money - %d", event_name, quantity) | |
| 1196 table.insert(encounter_data[loot_label], ("money:%d"):format(quantity)) | |
| 1197 end | |
| 1198 private.boss_loot_toasting = true -- Do not count further loots until timer expires or another boss is killed | 1220 private.boss_loot_toasting = true -- Do not count further loots until timer expires or another boss is killed |
| 1199 elseif container_id then | 1221 elseif container_id then |
| 1200 InitializeCurrentLoot() | 1222 InitializeCurrentLoot() |
| 1201 | 1223 |
| 1202 -- Fake the loot characteristics to match that of an actual container item | 1224 -- Fake the loot characteristics to match that of an actual container item |
| 1203 current_loot.identifier = container_id | 1225 current_loot.identifier = container_id |
| 1204 current_loot.label = "contains" | 1226 current_loot.label = "contains" |
| 1205 current_loot.target_type = AF.ITEM | 1227 current_loot.target_type = AF.ITEM |
| 1206 | 1228 |
| 1229 current_loot.sources[container_id] = current_loot.sources[container_id] or {} | |
| 1230 | |
| 1207 if loot_type == "item" then | 1231 if loot_type == "item" then |
| 1208 if not item_id then | 1232 local item_id = ItemLinkToID(item_link) |
| 1233 if item_id then | |
| 1234 Debug("%s: %s X %d (%d)", event_name, item_link, quantity, item_id) | |
| 1235 current_loot.sources[container_id][item_id] = current_loot.sources[container_id][item_id] or 0 + quantity | |
| 1236 else | |
| 1209 Debug("%s: ItemID is nil, from item link %s", event_name, item_link) | 1237 Debug("%s: ItemID is nil, from item link %s", event_name, item_link) |
| 1238 current_loot = nil | |
| 1210 return | 1239 return |
| 1211 end | 1240 end |
| 1212 current_loot.sources[container_id] = { | |
| 1213 [item_id] = quantity, | |
| 1214 } | |
| 1215 elseif loot_type == "money" then | 1241 elseif loot_type == "money" then |
| 1216 table.insert(current_loot.list, ("money:%d"):format(quantity)) | 1242 Debug("%s: money X %d", event_name, quantity) |
| 1217 end | 1243 current_loot.sources[container_id]["money"] = current_loot.sources[container_id]["money"] or 0 + quantity |
| 1244 elseif loot_type == "currency" then | |
| 1245 local currency_texture = CurrencyLinkToTexture(item_link) | |
| 1246 if currency_texture and currency_texture ~= "" then | |
| 1247 Debug("%s: %s X %d", event_name, currency_texture, quantity) | |
| 1248 local currency_token = ("currency:%s"):format(currency_texture) | |
| 1249 current_loot.sources[container_id][currency_token] = current_loot.sources[container_id][currency_token] or 0 + quantity | |
| 1250 else | |
| 1251 Debug("%s: Currency texture is nil, from currency link %s", event_name, item_link) | |
| 1252 current_loot = nil | |
| 1253 return | |
| 1254 end | |
| 1255 end | |
| 1256 | |
| 1218 GenericLootUpdate("items") | 1257 GenericLootUpdate("items") |
| 1219 current_loot = nil | 1258 current_loot = nil |
| 1220 private.container_loot_toasting = true -- Do not count further loots until timer expires or another container is opened | 1259 private.container_loot_toasting = true -- Do not count further loots until timer expires or another container is opened |
| 1221 else | 1260 else |
| 1222 if loot_type == "item" and not item_id then | |
| 1223 Debug("%s: ItemID is nil, from item link %s", event_name, item_link) | |
| 1224 return | |
| 1225 end | |
| 1226 Debug("%s: NPC and Container are nil, storing loot toast data for 5 seconds.", event_name) | 1261 Debug("%s: NPC and Container are nil, storing loot toast data for 5 seconds.", event_name) |
| 1227 | 1262 |
| 1228 loot_toast_data = loot_toast_data or {} | 1263 loot_toast_data = loot_toast_data or {} |
| 1229 loot_toast_data[#loot_toast_data + 1] = { loot_type, item_link, quantity, item_id } | 1264 loot_toast_data[#loot_toast_data + 1] = { loot_type, item_link, quantity } |
| 1230 | 1265 |
| 1231 loot_toast_data_timer_handle = WDP:ScheduleTimer(ClearLootToastData, 5) | 1266 loot_toast_data_timer_handle = WDP:ScheduleTimer(ClearLootToastData, 5) |
| 1232 end | 1267 end |
| 1233 end | 1268 end |
| 1234 | 1269 |
| 1237 local CHAT_MSG_LOOT_UPDATE_FUNCS = { | 1272 local CHAT_MSG_LOOT_UPDATE_FUNCS = { |
| 1238 [AF.NPC] = function(item_id, quantity) | 1273 [AF.NPC] = function(item_id, quantity) |
| 1239 Debug("CHAT_MSG_LOOT: %d (%d)", item_id, quantity) | 1274 Debug("CHAT_MSG_LOOT: %d (%d)", item_id, quantity) |
| 1240 end, | 1275 end, |
| 1241 [AF.ZONE] = function(item_id, quantity) | 1276 [AF.ZONE] = function(item_id, quantity) |
| 1242 current_loot = { | 1277 InitializeCurrentLoot() |
| 1243 list = { | 1278 current_loot.list[1] = ("%d:%d"):format(item_id, quantity) |
| 1244 ("%d:%d"):format(item_id, quantity) | |
| 1245 }, | |
| 1246 identifier = current_action.identifier, | |
| 1247 label = current_action.loot_label or "drops", | |
| 1248 map_level = current_action.map_level, | |
| 1249 object_name = current_action.object_name, | |
| 1250 spell_label = current_action.spell_label, | |
| 1251 target_type = current_action.target_type, | |
| 1252 x = current_action.x, | |
| 1253 y = current_action.y, | |
| 1254 zone_data = current_action.zone_data, | |
| 1255 } | |
| 1256 table.wipe(current_action) | |
| 1257 GenericLootUpdate("zones") | 1279 GenericLootUpdate("zones") |
| 1280 current_loot = nil | |
| 1258 end, | 1281 end, |
| 1259 } | 1282 } |
| 1260 | 1283 |
| 1261 | 1284 |
| 1262 function WDP:CHAT_MSG_LOOT(event_name, message) | 1285 function WDP:CHAT_MSG_LOOT(event_name, message) |
| 1283 return | 1306 return |
| 1284 end | 1307 end |
| 1285 update_func(item_id, quantity) | 1308 update_func(item_id, quantity) |
| 1286 end | 1309 end |
| 1287 end | 1310 end |
| 1311 | |
| 1288 | 1312 |
| 1289 function WDP:RecordQuote(event_name, message, source_name, language_name) | 1313 function WDP:RecordQuote(event_name, message, source_name, language_name) |
| 1290 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 | 1314 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 |
| 1291 return | 1315 return |
| 1292 end | 1316 end |
| 1409 local unit_type, unit_idnum = ParseGUID(dest_guid) | 1433 local unit_type, unit_idnum = ParseGUID(dest_guid) |
| 1410 | 1434 |
| 1411 if not unit_idnum or not UnitTypeIsNPC(unit_type) then | 1435 if not unit_idnum or not UnitTypeIsNPC(unit_type) then |
| 1412 Debug("%s: %s is not an NPC, or has no ID.", sub_event, dest_name or _G.UNKNOWN) | 1436 Debug("%s: %s is not an NPC, or has no ID.", sub_event, dest_name or _G.UNKNOWN) |
| 1413 ClearKilledNPC() | 1437 ClearKilledNPC() |
| 1414 ClearKilledBossID() | |
| 1415 private.harvesting = nil | 1438 private.harvesting = nil |
| 1416 return | 1439 return |
| 1417 end | 1440 end |
| 1418 | 1441 |
| 1419 if source_guid == "" then | 1442 if source_guid == "" then |
| 1421 end | 1444 end |
| 1422 local killer_guid = source_guid or previous_combat_event.source_guid | 1445 local killer_guid = source_guid or previous_combat_event.source_guid |
| 1423 local killer_name = source_name or previous_combat_event.source_name | 1446 local killer_name = source_name or previous_combat_event.source_name |
| 1424 | 1447 |
| 1425 if not previous_combat_event.party_damage then | 1448 if not previous_combat_event.party_damage then |
| 1426 Debug("%s: %s was killed by %s (not group member or pet).", sub_event, dest_name or _G.UNKNOWN, killer_name or _G.UNKNOWN) | 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 |
| 1427 table.wipe(previous_combat_event) | 1450 table.wipe(previous_combat_event) |
| 1428 ClearKilledNPC() | 1451 ClearKilledNPC() |
| 1429 else | 1452 else |
| 1430 Debug("%s: %s was killed by %s.", sub_event, dest_name or _G.UNKNOWN, killer_name or _G.UNKNOWN) | 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 |
| 1431 end | 1454 end |
| 1432 killed_npc_id = unit_idnum | 1455 killed_npc_id = unit_idnum |
| 1433 WDP:ScheduleTimer(ClearKilledNPC, 0.1) | 1456 WDP:ScheduleTimer(ClearKilledNPC, 0.1) |
| 1434 end, | 1457 end, |
| 1435 } | 1458 } |
| 1609 UpdateDBEntryLocation("objects", unit_idnum) | 1632 UpdateDBEntryLocation("objects", unit_idnum) |
| 1610 end | 1633 end |
| 1611 | 1634 |
| 1612 | 1635 |
| 1613 do | 1636 do |
| 1614 local RE_GOLD = _G.GOLD_AMOUNT:gsub("%%d", "(%%d+)") | |
| 1615 local RE_SILVER = _G.SILVER_AMOUNT:gsub("%%d", "(%%d+)") | |
| 1616 local RE_COPPER = _G.COPPER_AMOUNT:gsub("%%d", "(%%d+)") | |
| 1617 | |
| 1618 | |
| 1619 local function _moneyMatch(money, re) | |
| 1620 return money:match(re) or 0 | |
| 1621 end | |
| 1622 | |
| 1623 | |
| 1624 local function _toCopper(money) | |
| 1625 if not money then | |
| 1626 return 0 | |
| 1627 end | |
| 1628 return _moneyMatch(money, RE_GOLD) * 10000 + _moneyMatch(money, RE_SILVER) * 100 + _moneyMatch(money, RE_COPPER) | |
| 1629 end | |
| 1630 | |
| 1631 | |
| 1632 local LOOT_OPENED_VERIFY_FUNCS = { | 1637 local LOOT_OPENED_VERIFY_FUNCS = { |
| 1633 [AF.ITEM] = function() | 1638 [AF.ITEM] = function() |
| 1634 local locked_item_id | 1639 local locked_item_id |
| 1635 | 1640 |
| 1636 for bag_index = 0, _G.NUM_BAG_FRAMES do | 1641 for bag_index = 0, _G.NUM_BAG_FRAMES do |
| 1677 [AF.ITEM] = function() | 1682 [AF.ITEM] = function() |
| 1678 GenericLootUpdate("items") | 1683 GenericLootUpdate("items") |
| 1679 end, | 1684 end, |
| 1680 [AF.NPC] = function() | 1685 [AF.NPC] = function() |
| 1681 local difficulty_token = InstanceDifficultyToken() | 1686 local difficulty_token = InstanceDifficultyToken() |
| 1682 local loot_type = current_loot.label | 1687 local loot_label = current_loot.label |
| 1683 local source_list = {} | 1688 local source_list = {} |
| 1684 | 1689 |
| 1685 for source_guid, loot_data in pairs(current_loot.sources) do | 1690 for source_guid, loot_data in pairs(current_loot.sources) do |
| 1686 local source_id = select(2, ParseGUID(source_guid)) | 1691 local source_id = select(2, ParseGUID(source_guid)) |
| 1687 local npc = NPCEntry(source_id) | 1692 local npc = NPCEntry(source_id) |
| 1688 | 1693 |
| 1689 if npc then | 1694 if npc then |
| 1690 local encounter_data = npc:EncounterData(difficulty_token) | 1695 local encounter_data = npc:EncounterData(difficulty_token) |
| 1691 encounter_data[loot_type] = encounter_data[loot_type] or {} | 1696 encounter_data[loot_label] = encounter_data[loot_label] or {} |
| 1692 | 1697 |
| 1693 if not source_list[source_guid] then | 1698 if not source_list[source_guid] then |
| 1694 encounter_data.loot_counts = encounter_data.loot_counts or {} | 1699 encounter_data.loot_counts = encounter_data.loot_counts or {} |
| 1695 encounter_data.loot_counts[loot_type] = (encounter_data.loot_counts[loot_type] or 0) + 1 | 1700 encounter_data.loot_counts[loot_label] = (encounter_data.loot_counts[loot_label] or 0) + 1 |
| 1696 source_list[source_id] = true | 1701 source_list[source_guid] = true |
| 1697 end | 1702 end |
| 1698 | 1703 |
| 1699 for loot_token, quantity in pairs(loot_data) do | 1704 for loot_token, quantity in pairs(loot_data) do |
| 1700 local label, currency_texture = (":"):split(loot_token) | 1705 local loot_type, currency_texture = (":"):split(loot_token) |
| 1701 | 1706 |
| 1702 if label == "currency" and currency_texture then | 1707 if loot_type == "currency" and currency_texture then |
| 1703 table.insert(encounter_data[loot_type], ("currency:%d:%s"):format(quantity, currency_texture)) | 1708 table.insert(encounter_data[loot_label], ("currency:%d:%s"):format(quantity, currency_texture)) |
| 1704 elseif loot_token == "money" then | 1709 elseif loot_token == "money" then |
| 1705 table.insert(encounter_data[loot_type], ("money:%d"):format(quantity)) | 1710 table.insert(encounter_data[loot_label], ("money:%d"):format(quantity)) |
| 1706 else | 1711 else |
| 1707 table.insert(encounter_data[loot_type], ("%d:%d"):format(loot_token, quantity)) | 1712 table.insert(encounter_data[loot_label], ("%d:%d"):format(loot_token, quantity)) |
| 1708 end | 1713 end |
| 1709 end | 1714 end |
| 1710 end | 1715 end |
| 1711 end | 1716 end |
| 1712 end, | 1717 end, |
| 1753 end | 1758 end |
| 1754 | 1759 |
| 1755 | 1760 |
| 1756 function WDP:LOOT_OPENED(event_name) | 1761 function WDP:LOOT_OPENED(event_name) |
| 1757 if current_loot then | 1762 if current_loot then |
| 1763 Debug("%s: Previous loot did not process.", event_name) | |
| 1758 return | 1764 return |
| 1759 end | 1765 end |
| 1760 | 1766 |
| 1761 if not current_action.target_type then | 1767 if not current_action.target_type then |
| 1768 Debug("%s: No target type found.", event_name) | |
| 1762 return | 1769 return |
| 1763 end | 1770 end |
| 1764 local verify_func = LOOT_OPENED_VERIFY_FUNCS[current_action.target_type] | 1771 local verify_func = LOOT_OPENED_VERIFY_FUNCS[current_action.target_type] |
| 1765 local update_func = LOOT_OPENED_UPDATE_FUNCS[current_action.target_type] | 1772 local update_func = LOOT_OPENED_UPDATE_FUNCS[current_action.target_type] |
| 1766 | 1773 |
| 1792 if #loot_info == 2 and slot_quantity > loot_quantity then | 1799 if #loot_info == 2 and slot_quantity > loot_quantity then |
| 1793 loot_quantity = slot_quantity | 1800 loot_quantity = slot_quantity |
| 1794 end | 1801 end |
| 1795 local source_type, source_id = ParseGUID(source_guid) | 1802 local source_type, source_id = ParseGUID(source_guid) |
| 1796 local source_key = ("%s:%d"):format(private.UNIT_TYPE_NAMES[source_type + 1], source_id) | 1803 local source_key = ("%s:%d"):format(private.UNIT_TYPE_NAMES[source_type + 1], source_id) |
| 1797 Debug("GUID: %s - Type:ID: %s - Amount: %d (%d)", loot_info[loot_index], source_key, loot_info[loot_index + 1], slot_quantity) | |
| 1798 | 1804 |
| 1799 if slot_type == _G.LOOT_SLOT_ITEM then | 1805 if slot_type == _G.LOOT_SLOT_ITEM then |
| 1800 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot)) | 1806 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot)) |
| 1807 Debug("GUID: %s - Type:ID: %s - ItemID: %d - Amount: %d (%d)", loot_info[loot_index], source_key, item_id, loot_info[loot_index + 1], slot_quantity) | |
| 1801 current_loot.sources[source_guid] = current_loot.sources[source_guid] or {} | 1808 current_loot.sources[source_guid] = current_loot.sources[source_guid] or {} |
| 1802 current_loot.sources[source_guid][item_id] = current_loot.sources[source_guid][item_id] or 0 + loot_quantity | 1809 current_loot.sources[source_guid][item_id] = current_loot.sources[source_guid][item_id] or 0 + loot_quantity |
| 1803 guids_used[source_guid] = true | 1810 guids_used[source_guid] = true |
| 1804 elseif slot_type == _G.LOOT_SLOT_MONEY then | 1811 elseif slot_type == _G.LOOT_SLOT_MONEY then |
| 1805 Debug("money:%d", loot_quantity) | 1812 Debug("GUID: %s - Type:ID: %s - Money - Amount: %d (%d)", loot_info[loot_index], source_key, loot_info[loot_index + 1], slot_quantity) |
| 1806 if current_loot.target_type == AF.ZONE then | 1813 if current_loot.target_type == AF.ZONE then |
| 1807 table.insert(current_loot.list, ("money:%d"):format(_toCopper(item_text))) | 1814 table.insert(current_loot.list, ("money:%d"):format(loot_quantity)) |
| 1808 else | 1815 else |
| 1809 current_loot.sources[source_guid] = current_loot.sources[source_guid] or {} | 1816 current_loot.sources[source_guid] = current_loot.sources[source_guid] or {} |
| 1810 current_loot.sources[source_guid]["money"] = current_loot.sources[source_guid]["money"] or 0 + loot_quantity | 1817 current_loot.sources[source_guid]["money"] = current_loot.sources[source_guid]["money"] or 0 + loot_quantity |
| 1811 guids_used[source_guid] = true | 1818 guids_used[source_guid] = true |
| 1812 end | 1819 end |
| 1813 elseif slot_type == _G.LOOT_SLOT_CURRENCY then | 1820 elseif slot_type == _G.LOOT_SLOT_CURRENCY then |
| 1814 Debug("Found currency - %s:%d", icon_texture, loot_quantity) | 1821 Debug("GUID: %s - Type:ID: %s - Currency: %s - Amount: %d (%d)", loot_info[loot_index], source_key, icon_texture, loot_info[loot_index + 1], slot_quantity) |
| 1815 if current_loot.target_type == AF.ZONE then | 1822 if current_loot.target_type == AF.ZONE then |
| 1816 table.insert(current_loot.list, ("currency:%d:%s"):format(slot_quantity, icon_texture:match("[^\\]+$"):lower())) | 1823 table.insert(current_loot.list, ("currency:%d:%s"):format(loot_quantity, icon_texture:match("[^\\]+$"):lower())) |
| 1817 else | 1824 else |
| 1818 local currency_token = ("currency:%s"):format(icon_texture:match("[^\\]+$"):lower()) | 1825 local currency_token = ("currency:%s"):format(icon_texture:match("[^\\]+$"):lower()) |
| 1819 | 1826 |
| 1820 current_loot.sources[source_guid] = current_loot.sources[source_guid] or {} | 1827 current_loot.sources[source_guid] = current_loot.sources[source_guid] or {} |
| 1821 current_loot.sources[source_guid][currency_token] = current_loot.sources[source_guid][currency_token] or 0 + loot_quantity | 1828 current_loot.sources[source_guid][currency_token] = current_loot.sources[source_guid][currency_token] or 0 + loot_quantity |
| 1953 -- Keeping this around in case Blizzard makes the two points diverge at some point. | 1960 -- Keeping this around in case Blizzard makes the two points diverge at some point. |
| 1954 -- price_string = ("%s:%s:%s:%s"):format(price_string, battleground_rating, personal_rating, required_season_amount or 0) | 1961 -- price_string = ("%s:%s:%s:%s"):format(price_string, battleground_rating, personal_rating, required_season_amount or 0) |
| 1955 price_string = ("%s:%s:%s"):format(price_string, personal_rating, required_season_amount or 0) | 1962 price_string = ("%s:%s:%s"):format(price_string, personal_rating, required_season_amount or 0) |
| 1956 | 1963 |
| 1957 for cost_index = 1, item_count do | 1964 for cost_index = 1, item_count do |
| 1958 local icon_texture, amount_required, currency_link = _G.GetMerchantItemCostItem(item_index, cost_index) | 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) |
| 1959 local currency_id = currency_link and ItemLinkToID(currency_link) or nil | 1966 -- the third return ("currency_link") of GetMerchantItemCostItem is broken as of Patch 5.4.0 |
| 1960 | 1967 local currency_texture, amount_required = _G.GetMerchantItemCostItem(item_index, cost_index) |
| 1961 if (not currency_id or currency_id < 1) and icon_texture then | 1968 |
| 1962 currency_id = icon_texture:match("[^\\]+$"):lower() | 1969 if currency_texture then |
| 1963 end | 1970 currency_list[#currency_list + 1] = ("(%s:%s)"):format(amount_required, currency_texture:match("[^\\]+$"):lower()) |
| 1964 | |
| 1965 if currency_id then | |
| 1966 currency_list[#currency_list + 1] = ("(%s:%s)"):format(amount_required, currency_id) | |
| 1967 end | 1971 end |
| 1968 end | 1972 end |
| 1969 | 1973 |
| 1970 for currency_index = 1, #currency_list do | 1974 for currency_index = 1, #currency_list do |
| 1971 price_string = ("%s:%s"):format(price_string, currency_list[currency_index]) | 1975 price_string = ("%s:%s"):format(price_string, currency_list[currency_index]) |
| 2296 end | 2300 end |
| 2297 private.tracked_line = spell_line | 2301 private.tracked_line = spell_line |
| 2298 end | 2302 end |
| 2299 | 2303 |
| 2300 | 2304 |
| 2301 function WDP:SPELL_CONFIRMATION_PROMPT(event_name, spell_id, confirm_type, text, duration, currency_id) | 2305 function WDP:SPELL_CONFIRMATION_PROMPT(event_name, spell_id, confirm_type, text, duration, currency_id_cost) |
| 2302 if private.RAID_BOSS_BONUS_SPELL_ID_TO_NPC_ID_MAP[spell_id] then | 2306 if private.RAID_BOSS_BONUS_SPELL_ID_TO_NPC_ID_MAP[spell_id] then |
| 2303 ClearKilledBossID() | 2307 ClearKilledBossID() |
| 2304 ClearLootToastContainerID() | 2308 ClearLootToastContainerID() |
| 2305 private.raid_finder_boss_id = private.RAID_BOSS_BONUS_SPELL_ID_TO_NPC_ID_MAP[spell_id] | 2309 private.raid_finder_boss_id = private.RAID_BOSS_BONUS_SPELL_ID_TO_NPC_ID_MAP[spell_id] |
| 2306 elseif private.WORLD_BOSS_BONUS_SPELL_ID_TO_NPC_ID_MAP[spell_id] then | 2310 elseif private.WORLD_BOSS_BONUS_SPELL_ID_TO_NPC_ID_MAP[spell_id] then |
| 2325 encounter_data.loot_counts[loot_label] = (encounter_data.loot_counts[loot_label] or 0) + 1 | 2329 encounter_data.loot_counts[loot_label] = (encounter_data.loot_counts[loot_label] or 0) + 1 |
| 2326 | 2330 |
| 2327 for index = 1, #loot_toast_data do | 2331 for index = 1, #loot_toast_data do |
| 2328 local data = loot_toast_data[index] | 2332 local data = loot_toast_data[index] |
| 2329 local loot_type = data[1] | 2333 local loot_type = data[1] |
| 2334 local hyperlink = data[2] | |
| 2330 local quantity = data[3] | 2335 local quantity = data[3] |
| 2331 | 2336 |
| 2332 if loot_type == "item" then | 2337 if loot_type == "item" then |
| 2333 local item_id = data[4] | 2338 local item_id = ItemLinkToID(hyperlink) |
| 2334 | 2339 Debug("%s: Assigned stored item loot data - %s - %d:%d", event_name, hyperlink, item_id, quantity) |
| 2335 Debug("%s: Stored loot data - %sX%d (%d)", event_name, data[2], quantity, item_id) | |
| 2336 table.insert(encounter_data[loot_label], ("%d:%d"):format(item_id, quantity)) | 2340 table.insert(encounter_data[loot_label], ("%d:%d"):format(item_id, quantity)) |
| 2337 elseif loot_type == "money" then | 2341 elseif loot_type == "money" then |
| 2338 Debug("%s: Stored loot data - money - %d", event_name, quantity) | 2342 Debug("%s: Assigned stored money loot data - money:%d", event_name, quantity) |
| 2339 table.insert(encounter_data[loot_label], ("money:%d"):format(quantity)) | 2343 table.insert(encounter_data[loot_label], ("money:%d"):format(quantity)) |
| 2344 elseif loot_type == "currency" then | |
| 2345 local currency_texture = CurrencyLinkToTexture(hyperlink) | |
| 2346 Debug("%s: Assigned stored currency loot data - %s - currency:%d:%s", event_name, hyperlink, currency_texture, quantity) | |
| 2347 table.insert(encounter_data[loot_label], ("currency:%d:%s"):format(quantity, currency_texture)) | |
| 2340 end | 2348 end |
| 2341 end | 2349 end |
| 2342 private.boss_loot_toasting = true | 2350 private.boss_loot_toasting = true |
| 2343 else | 2351 else |
| 2344 Debug("%s: NPC is nil, but we have stored loot data...", event_name) | 2352 Debug("%s: NPC is nil, but we have stored loot data...", event_name) |
