Mercurial > wow > wowdb-profiler
comparison Main.lua @ 245:9b1faccbccc8
Reworked Debug() to do all string formatting inline, so non-DEBUGGING users won't be hit with potential nil errors.
author | James D. Callahan III <jcallahan@curse.com> |
---|---|
date | Mon, 11 Mar 2013 09:25:52 -0500 |
parents | d7ed64be54b8 |
children | f506c09d75a9 |
comparison
equal
deleted
inserted
replaced
244:3b4716142d2f | 245:9b1faccbccc8 |
---|---|
31 | 31 |
32 ----------------------------------------------------------------------- | 32 ----------------------------------------------------------------------- |
33 -- Local constants. | 33 -- Local constants. |
34 ----------------------------------------------------------------------- | 34 ----------------------------------------------------------------------- |
35 local DB_VERSION = 16 | 35 local DB_VERSION = 16 |
36 local DEBUGGING = false | 36 local DEBUGGING = true |
37 local EVENT_DEBUG = false | 37 local EVENT_DEBUG = false |
38 | 38 |
39 | 39 |
40 local DATABASE_DEFAULTS = { | 40 local DATABASE_DEFAULTS = { |
41 char = {}, | 41 char = {}, |
160 } | 160 } |
161 | 161 |
162 ----------------------------------------------------------------------- | 162 ----------------------------------------------------------------------- |
163 -- Helper Functions. | 163 -- Helper Functions. |
164 ----------------------------------------------------------------------- | 164 ----------------------------------------------------------------------- |
165 local function Debug(...) | 165 local function Debug(message, ...) |
166 if not DEBUGGING then | 166 if not DEBUGGING then |
167 return | 167 return |
168 end | 168 end |
169 _G.print(...) | 169 _G.print(message:format(...)) |
170 end | 170 end |
171 | 171 |
172 | 172 |
173 local TradeSkillExecutePer | 173 local TradeSkillExecutePer |
174 do | 174 do |
582 if current_loot.sources then | 582 if current_loot.sources then |
583 for source_guid, loot_data in pairs(current_loot.sources) do | 583 for source_guid, loot_data in pairs(current_loot.sources) do |
584 local entry, source_id | 584 local entry, source_id |
585 | 585 |
586 if current_loot.target_type == AF.ITEM then | 586 if current_loot.target_type == AF.ITEM then |
587 -- Debug(("GenericLootUpdate: current_loot.identifier: '%s'"):format(tostring(current_loot.identifier))) | |
588 -- Items return the player as the source, so we need to use the item's ID (disenchant, milling, etc) | 587 -- Items return the player as the source, so we need to use the item's ID (disenchant, milling, etc) |
589 source_id = current_loot.identifier | 588 source_id = current_loot.identifier |
590 entry = DBEntry(data_type, source_id) | 589 entry = DBEntry(data_type, source_id) |
591 elseif current_loot.target_type == AF.OBJECT then | 590 elseif current_loot.target_type == AF.OBJECT then |
592 source_id = ("%s:%s"):format(current_loot.spell_label, select(2, ParseGUID(source_guid))) | 591 source_id = ("%s:%s"):format(current_loot.spell_label, select(2, ParseGUID(source_guid))) |
1034 end | 1033 end |
1035 local npc = NPCEntry(private.raid_finder_boss_id or private.world_boss_id) | 1034 local npc = NPCEntry(private.raid_finder_boss_id or private.world_boss_id) |
1036 ClearKilledBossID() | 1035 ClearKilledBossID() |
1037 | 1036 |
1038 if not npc then | 1037 if not npc then |
1039 Debug(("%s: NPC is nil."):format(event_name)) | 1038 Debug("%s: NPC is nil.", event_name) |
1040 return | 1039 return |
1041 end | 1040 end |
1042 local item_id = ItemLinkToID(item_link) | 1041 local item_id = ItemLinkToID(item_link) |
1043 | 1042 |
1044 if not item_id then | 1043 if not item_id then |
1045 Debug(("%s: ItemID is nil, from item link %s"):format(event_name, item_link)) | 1044 Debug("%s: ItemID is nil, from item link %s", event_name, item_link) |
1046 return | 1045 return |
1047 end | 1046 end |
1048 local loot_type = "drops" | 1047 local loot_type = "drops" |
1049 local encounter_data = npc:EncounterData()[InstanceDifficultyToken()] | 1048 local encounter_data = npc:EncounterData()[InstanceDifficultyToken()] |
1050 encounter_data[loot_type] = encounter_data[loot_type] or {} | 1049 encounter_data[loot_type] = encounter_data[loot_type] or {} |
1051 encounter_data.loot_counts = encounter_data.loot_counts or {} | 1050 encounter_data.loot_counts = encounter_data.loot_counts or {} |
1052 encounter_data.loot_counts[loot_type] = (encounter_data.loot_counts[loot_type] or 0) + 1 | 1051 encounter_data.loot_counts[loot_type] = (encounter_data.loot_counts[loot_type] or 0) + 1 |
1053 | 1052 |
1054 table.insert(encounter_data[loot_type], ("%d:%d"):format(item_id, quantity)) | 1053 table.insert(encounter_data[loot_type], ("%d:%d"):format(item_id, quantity)) |
1055 Debug(("%s: %sX%d (%d)"):format(event_name, item_link, quantity, item_id)) | 1054 Debug("%s: %sX%d (%d)", event_name, item_link, quantity, item_id) |
1056 end | 1055 end |
1057 | 1056 |
1058 | 1057 |
1059 do | 1058 do |
1060 local CHAT_MSG_LOOT_UPDATE_FUNCS = { | 1059 local CHAT_MSG_LOOT_UPDATE_FUNCS = { |
1061 [AF.NPC] = function(item_id, quantity) | 1060 [AF.NPC] = function(item_id, quantity) |
1062 Debug(("CHAT_MSG_LOOT: %d (%d)"):format(item_id, quantity)) | 1061 Debug("CHAT_MSG_LOOT: %d (%d)", item_id, quantity) |
1063 end, | 1062 end, |
1064 [AF.ZONE] = function(item_id, quantity) | 1063 [AF.ZONE] = function(item_id, quantity) |
1065 current_loot = { | 1064 current_loot = { |
1066 list = { | 1065 list = { |
1067 ("%d:%d"):format(item_id, quantity) | 1066 ("%d:%d"):format(item_id, quantity) |
1229 end, | 1228 end, |
1230 UNIT_DIED = function(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name) | 1229 UNIT_DIED = function(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name) |
1231 local unit_type, unit_idnum = ParseGUID(dest_guid) | 1230 local unit_type, unit_idnum = ParseGUID(dest_guid) |
1232 | 1231 |
1233 if not unit_idnum or not UnitTypeIsNPC(unit_type) then | 1232 if not unit_idnum or not UnitTypeIsNPC(unit_type) then |
1234 Debug(("%s: %s is not an NPC, or has no ID."):format(sub_event, dest_name or _G.UNKNOWN)) | 1233 Debug("%s: %s is not an NPC, or has no ID.", sub_event, dest_name or _G.UNKNOWN) |
1235 ClearKilledNPC() | 1234 ClearKilledNPC() |
1236 ClearKilledBossID() | 1235 ClearKilledBossID() |
1237 private.harvesting = nil | 1236 private.harvesting = nil |
1238 return | 1237 return |
1239 end | 1238 end |
1243 ClearKilledBossID() | 1242 ClearKilledBossID() |
1244 return | 1243 return |
1245 end | 1244 end |
1246 | 1245 |
1247 if private.RAID_FINDER_BOSS_IDS[unit_idnum] then | 1246 if private.RAID_FINDER_BOSS_IDS[unit_idnum] then |
1248 Debug(("%s: Matching boss %s."):format(sub_event, dest_name)) | 1247 Debug("%s: Matching boss %s.", sub_event, dest_name) |
1249 ClearKilledBossID() | 1248 ClearKilledBossID() |
1250 private.raid_finder_boss_id = unit_idnum | 1249 private.raid_finder_boss_id = unit_idnum |
1251 elseif private.WORLD_BOSS_IDS[unit_idnum] then | 1250 elseif private.WORLD_BOSS_IDS[unit_idnum] then |
1252 Debug(("%s: Matching world boss %s."):format(sub_event, dest_name)) | 1251 Debug("%s: Matching world boss %s.", sub_event, dest_name) |
1253 ClearKilledBossID() | 1252 ClearKilledBossID() |
1254 private.world_boss_id = unit_idnum | 1253 private.world_boss_id = unit_idnum |
1255 else | 1254 else |
1256 Debug(("%s: Killed NPC %s (ID: %d) is not in LFG or World boss list."):format(sub_event, dest_name, unit_idnum)) | 1255 Debug("%s: Killed NPC %s (ID: %d) is not in LFG or World boss list.", sub_event, dest_name, unit_idnum) |
1257 end | 1256 end |
1258 | 1257 |
1259 killed_npc_id = unit_idnum | 1258 killed_npc_id = unit_idnum |
1260 WDP:ScheduleTimer(ClearKilledNPC, 0.1) | 1259 WDP:ScheduleTimer(ClearKilledNPC, 0.1) |
1261 WDP:ScheduleTimer(ClearKilledBossID, 1) | 1260 WDP:ScheduleTimer(ClearKilledBossID, 1) |
1615 | 1614 |
1616 if not loot_guid_registry[current_loot.label][source_guid] then | 1615 if not loot_guid_registry[current_loot.label][source_guid] then |
1617 local loot_quantity = loot_info[loot_index + 1] | 1616 local loot_quantity = loot_info[loot_index + 1] |
1618 local source_type, source_id = ParseGUID(source_guid) | 1617 local source_type, source_id = ParseGUID(source_guid) |
1619 local source_key = ("%s:%d"):format(private.UNIT_TYPE_NAMES[source_type + 1], source_id) | 1618 local source_key = ("%s:%d"):format(private.UNIT_TYPE_NAMES[source_type + 1], source_id) |
1620 Debug(("GUID: %s - Type:ID: %s - Amount: %d"):format(loot_info[loot_index], source_key, loot_quantity)) | 1619 Debug("GUID: %s - Type:ID: %s - Amount: %d", loot_info[loot_index], source_key, loot_quantity) |
1621 | 1620 |
1622 if slot_type == _G.LOOT_SLOT_ITEM then | 1621 if slot_type == _G.LOOT_SLOT_ITEM then |
1623 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot)) | 1622 local item_id = ItemLinkToID(_G.GetLootSlotLink(loot_slot)) |
1624 current_loot.sources[source_guid] = current_loot.sources[source_guid] or {} | 1623 current_loot.sources[source_guid] = current_loot.sources[source_guid] or {} |
1625 current_loot.sources[source_guid][item_id] = current_loot.sources[source_guid][item_id] or 0 + loot_quantity | 1624 current_loot.sources[source_guid][item_id] = current_loot.sources[source_guid][item_id] or 0 + loot_quantity |
1626 guids_used[source_guid] = true | 1625 guids_used[source_guid] = true |
1627 elseif slot_type == _G.LOOT_SLOT_MONEY then | 1626 elseif slot_type == _G.LOOT_SLOT_MONEY then |
1628 Debug(("money:%d"):format(_toCopper(item_text))) | 1627 Debug("money:%d", _toCopper(item_text)) |
1629 table.insert(current_loot.list, ("money:%d"):format(_toCopper(item_text))) | 1628 table.insert(current_loot.list, ("money:%d"):format(_toCopper(item_text))) |
1630 elseif slot_type == _G.LOOT_SLOT_CURRENCY then | 1629 elseif slot_type == _G.LOOT_SLOT_CURRENCY then |
1631 Debug(("Found currency: %s"):format(icon_texture)) | 1630 Debug("Found currency: %s", icon_texture) |
1632 table.insert(current_loot.list, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower())) | 1631 table.insert(current_loot.list, ("currency:%d:%s"):format(quantity, icon_texture:match("[^\\]+$"):lower())) |
1633 end | 1632 end |
1634 end | 1633 end |
1635 end | 1634 end |
1636 end | 1635 end |