Mercurial > wow > wowdb-profiler
comparison Main.lua @ 246:f506c09d75a9 5.2.0-5
Improved detection of LFR and World Boss IDs - take kills from party/raid members and pets into consideration instead of simply relying on the killed NPC being the player's target.
author | James D. Callahan III <jcallahan@curse.com> |
---|---|
date | Mon, 11 Mar 2013 12:34:58 -0500 |
parents | 9b1faccbccc8 |
children | 4cb26edfd905 |
comparison
equal
deleted
inserted
replaced
245:9b1faccbccc8 | 246:f506c09d75a9 |
---|---|
1 ----------------------------------------------------------------------- | 1 -- LUA API ------------------------------------------------------------ |
2 -- Upvalued Lua API. | 2 |
3 ----------------------------------------------------------------------- | |
4 local _G = getfenv(0) | 3 local _G = getfenv(0) |
5 | 4 |
6 local pairs = _G.pairs | 5 local pairs = _G.pairs |
7 local tonumber = _G.tonumber | 6 local tonumber = _G.tonumber |
8 | 7 |
11 local table = _G.table | 10 local table = _G.table |
12 | 11 |
13 local select = _G.select | 12 local select = _G.select |
14 | 13 |
15 | 14 |
16 ----------------------------------------------------------------------- | 15 -- ADDON NAMESPACE ---------------------------------------------------- |
17 -- AddOn namespace. | 16 |
18 ----------------------------------------------------------------------- | |
19 local ADDON_NAME, private = ... | 17 local ADDON_NAME, private = ... |
20 | 18 |
21 local LibStub = _G.LibStub | 19 local LibStub = _G.LibStub |
22 local WDP = LibStub("AceAddon-3.0"):NewAddon(ADDON_NAME, "AceEvent-3.0", "AceTimer-3.0") | 20 local WDP = LibStub("AceAddon-3.0"):NewAddon(ADDON_NAME, "AceEvent-3.0", "AceTimer-3.0") |
23 | 21 |
27 | 25 |
28 local DatamineTT = _G.CreateFrame("GameTooltip", "WDPDatamineTT", _G.UIParent, "GameTooltipTemplate") | 26 local DatamineTT = _G.CreateFrame("GameTooltip", "WDPDatamineTT", _G.UIParent, "GameTooltipTemplate") |
29 DatamineTT:SetOwner(_G.WorldFrame, "ANCHOR_NONE") | 27 DatamineTT:SetOwner(_G.WorldFrame, "ANCHOR_NONE") |
30 | 28 |
31 | 29 |
32 ----------------------------------------------------------------------- | 30 -- CONSTANTS ---------------------------------------------------------- |
33 -- Local constants. | 31 |
34 ----------------------------------------------------------------------- | 32 local AF = private.ACTION_TYPE_FLAGS |
33 local CLIENT_LOCALE = _G.GetLocale() | |
35 local DB_VERSION = 16 | 34 local DB_VERSION = 16 |
36 local DEBUGGING = true | 35 local DEBUGGING = false |
37 local EVENT_DEBUG = false | 36 local EVENT_DEBUG = false |
38 | 37 local OBJECT_ID_ANVIL = 192628 |
38 local OBJECT_ID_FORGE = 1685 | |
39 local PLAYER_CLASS = _G.select(2, _G.UnitClass("player")) | |
40 local PLAYER_FACTION = _G.UnitFactionGroup("player") | |
41 local PLAYER_GUID = _G.UnitGUID("player") | |
42 local PLAYER_NAME = _G.UnitName("player") | |
43 local PLAYER_RACE = _G.select(2, _G.UnitRace("player")) | |
44 | |
45 local ALLOWED_LOCALES = { | |
46 enUS = true, | |
47 enGB = true, | |
48 } | |
39 | 49 |
40 local DATABASE_DEFAULTS = { | 50 local DATABASE_DEFAULTS = { |
41 char = {}, | 51 char = {}, |
42 global = { | 52 global = { |
43 items = {}, | 53 items = {}, |
46 quests = {}, | 56 quests = {}, |
47 spells = {}, | 57 spells = {}, |
48 zones = {}, | 58 zones = {}, |
49 } | 59 } |
50 } | 60 } |
51 | |
52 | 61 |
53 local EVENT_MAPPING = { | 62 local EVENT_MAPPING = { |
54 AUCTION_HOUSE_SHOW = true, | 63 AUCTION_HOUSE_SHOW = true, |
55 BANKFRAME_OPENED = true, | 64 BANKFRAME_OPENED = true, |
56 BATTLEFIELDS_SHOW = true, | 65 BATTLEFIELDS_SHOW = true, |
63 COMBAT_LOG_EVENT_UNFILTERED = true, | 72 COMBAT_LOG_EVENT_UNFILTERED = true, |
64 COMBAT_TEXT_UPDATE = true, | 73 COMBAT_TEXT_UPDATE = true, |
65 CURSOR_UPDATE = true, | 74 CURSOR_UPDATE = true, |
66 FORGE_MASTER_OPENED = true, | 75 FORGE_MASTER_OPENED = true, |
67 GOSSIP_SHOW = true, | 76 GOSSIP_SHOW = true, |
77 GROUP_ROSTER_CHANGE = true, | |
68 GUILDBANKFRAME_OPENED = true, | 78 GUILDBANKFRAME_OPENED = true, |
69 ITEM_TEXT_BEGIN = true, | 79 ITEM_TEXT_BEGIN = true, |
70 ITEM_UPGRADE_MASTER_OPENED = true, | 80 ITEM_UPGRADE_MASTER_OPENED = true, |
71 LOOT_CLOSED = true, | 81 LOOT_CLOSED = true, |
72 LOOT_OPENED = true, | 82 LOOT_OPENED = true, |
87 TAXIMAP_OPENED = true, | 97 TAXIMAP_OPENED = true, |
88 TRADE_SKILL_SHOW = true, | 98 TRADE_SKILL_SHOW = true, |
89 TRAINER_CLOSED = true, | 99 TRAINER_CLOSED = true, |
90 TRAINER_SHOW = true, | 100 TRAINER_SHOW = true, |
91 TRANSMOGRIFY_OPEN = true, | 101 TRANSMOGRIFY_OPEN = true, |
102 UNIT_PET = true, | |
92 UNIT_QUEST_LOG_CHANGED = true, | 103 UNIT_QUEST_LOG_CHANGED = true, |
93 UNIT_SPELLCAST_FAILED = "HandleSpellFailure", | 104 UNIT_SPELLCAST_FAILED = "HandleSpellFailure", |
94 UNIT_SPELLCAST_FAILED_QUIET = "HandleSpellFailure", | 105 UNIT_SPELLCAST_FAILED_QUIET = "HandleSpellFailure", |
95 UNIT_SPELLCAST_INTERRUPTED = "HandleSpellFailure", | 106 UNIT_SPELLCAST_INTERRUPTED = "HandleSpellFailure", |
96 UNIT_SPELLCAST_SENT = true, | 107 UNIT_SPELLCAST_SENT = true, |
100 ZONE_CHANGED_INDOORS = "SetCurrentAreaID", | 111 ZONE_CHANGED_INDOORS = "SetCurrentAreaID", |
101 ZONE_CHANGED_NEW_AREA = "SetCurrentAreaID", | 112 ZONE_CHANGED_NEW_AREA = "SetCurrentAreaID", |
102 } | 113 } |
103 | 114 |
104 | 115 |
105 local OBJECT_ID_ANVIL = 192628 | 116 -- VARIABLES ---------------------------------------------------------- |
106 local OBJECT_ID_FORGE = 1685 | 117 |
107 | |
108 | |
109 local AF = private.ACTION_TYPE_FLAGS | |
110 | |
111 | |
112 local PLAYER_CLASS = _G.select(2, _G.UnitClass("player")) | |
113 local PLAYER_FACTION = _G.UnitFactionGroup("player") | |
114 local PLAYER_GUID = _G.UnitGUID("player") | |
115 local PLAYER_NAME = _G.UnitName("player") | |
116 local PLAYER_RACE = _G.select(2, _G.UnitRace("player")) | |
117 | |
118 | |
119 local CLIENT_LOCALE = _G.GetLocale() | |
120 | |
121 | |
122 local ALLOWED_LOCALES = { | |
123 enUS = true, | |
124 enGB = true, | |
125 } | |
126 | |
127 | |
128 ----------------------------------------------------------------------- | |
129 -- Local variables. | |
130 ----------------------------------------------------------------------- | |
131 local anvil_spell_ids = {} | 118 local anvil_spell_ids = {} |
132 local currently_drunk | 119 local currently_drunk |
133 local char_db | 120 local char_db |
134 local global_db | 121 local global_db |
122 local group_member_uids = {} | |
123 local group_owner_guids_to_pet_guids = {} | |
124 local group_pet_guids = {} | |
135 local item_process_timer_handle | 125 local item_process_timer_handle |
136 local faction_standings = {} | 126 local faction_standings = {} |
137 local forge_spell_ids = {} | 127 local forge_spell_ids = {} |
138 local languages_known = {} | 128 local languages_known = {} |
139 local name_to_id_map = {} | 129 local name_to_id_map = {} |
141 local target_location_timer_handle | 131 local target_location_timer_handle |
142 local current_target_id | 132 local current_target_id |
143 local current_area_id | 133 local current_area_id |
144 local current_loot | 134 local current_loot |
145 | 135 |
146 ----------------------------------------------------------------------- | |
147 -- Data for our current action. Including possible values as a reference. | 136 -- Data for our current action. Including possible values as a reference. |
148 ----------------------------------------------------------------------- | |
149 local current_action = { | 137 local current_action = { |
150 identifier = nil, | 138 identifier = nil, |
151 loot_label = nil, | 139 loot_label = nil, |
152 loot_list = nil, | 140 loot_list = nil, |
153 loot_sources = nil, | 141 loot_sources = nil, |
157 x = nil, | 145 x = nil, |
158 y = nil, | 146 y = nil, |
159 zone_data = nil, | 147 zone_data = nil, |
160 } | 148 } |
161 | 149 |
162 ----------------------------------------------------------------------- | 150 |
163 -- Helper Functions. | 151 -- HELPERS ------------------------------------------------------------ |
164 ----------------------------------------------------------------------- | 152 |
165 local function Debug(message, ...) | 153 local function Debug(message, ...) |
166 if not DEBUGGING then | 154 if not DEBUGGING then |
167 return | 155 return |
168 end | 156 end |
169 _G.print(message:format(...)) | 157 _G.print(message:format(...)) |
416 end -- do-block | 404 end -- do-block |
417 | 405 |
418 | 406 |
419 local UpdateDBEntryLocation | 407 local UpdateDBEntryLocation |
420 do | 408 do |
421 local pi = math.pi | |
422 | |
423 -- Fishing node coordinate code based on code in GatherMate2 with permission from Kagaro. | 409 -- Fishing node coordinate code based on code in GatherMate2 with permission from Kagaro. |
424 local function FishingCoordinates(x, y, yard_width, yard_height) | 410 local function FishingCoordinates(x, y, yard_width, yard_height) |
425 local facing = _G.GetPlayerFacing() | 411 local facing = _G.GetPlayerFacing() |
426 | 412 |
427 if not facing then | 413 if not facing then |
428 return x, y | 414 return x, y |
429 end | 415 end |
430 local rad = facing + pi | 416 local rad = facing + math.pi |
431 return x + math.sin(rad) * 15 / yard_width, y + math.cos(rad) * 15 / yard_height | 417 return x + math.sin(rad) * 15 / yard_width, y + math.cos(rad) * 15 / yard_height |
432 end | 418 end |
433 | 419 |
434 | 420 |
435 function UpdateDBEntryLocation(entry_type, identifier) | 421 function UpdateDBEntryLocation(entry_type, identifier) |
715 _G.SetCVar("Sound_EnableSFX", sfx_value) | 701 _G.SetCVar("Sound_EnableSFX", sfx_value) |
716 end | 702 end |
717 end | 703 end |
718 end | 704 end |
719 | 705 |
720 ----------------------------------------------------------------------- | 706 |
721 -- Methods. | 707 -- METHODS ------------------------------------------------------------ |
722 ----------------------------------------------------------------------- | 708 |
723 function WDP:OnInitialize() | 709 function WDP:OnInitialize() |
724 local db = LibStub("AceDB-3.0"):New("WoWDBProfilerData", DATABASE_DEFAULTS, "Default") | 710 local db = LibStub("AceDB-3.0"):New("WoWDBProfilerData", DATABASE_DEFAULTS, "Default") |
725 global_db = db.global | 711 global_db = db.global |
726 char_db = db.char | 712 char_db = db.char |
727 | 713 |
786 end | 772 end |
787 local _, item_link = _G.GetItemInfo(identifier) | 773 local _, item_link = _G.GetItemInfo(identifier) |
788 HandleItemUse(item_link) | 774 HandleItemUse(item_link) |
789 end) | 775 end) |
790 self:SetCurrentAreaID("OnEnable") | 776 self:SetCurrentAreaID("OnEnable") |
777 self:GROUP_ROSTER_CHANGE() | |
791 end | 778 end |
792 | 779 |
793 | 780 |
794 local ScrapeItemUpgradeStats | 781 local ScrapeItemUpgradeStats |
795 do | 782 do |
1006 zone_data[("%d:%d:%d"):format(map_level, x, y)] = true | 993 zone_data[("%d:%d:%d"):format(map_level, x, y)] = true |
1007 end | 994 end |
1008 end -- do-block | 995 end -- do-block |
1009 | 996 |
1010 | 997 |
1011 ----------------------------------------------------------------------- | 998 -- EVENT HANDLERS ----------------------------------------------------- |
1012 -- Event handlers. | 999 |
1013 ----------------------------------------------------------------------- | |
1014 function WDP:BLACK_MARKET_ITEM_UPDATE(event_name) | 1000 function WDP:BLACK_MARKET_ITEM_UPDATE(event_name) |
1015 if not ALLOWED_LOCALES[CLIENT_LOCALE] then | 1001 if not ALLOWED_LOCALES[CLIENT_LOCALE] then |
1016 return | 1002 return |
1017 end | 1003 end |
1018 local num_items = _G.C_BlackMarket.GetNumItems() | 1004 local num_items = _G.C_BlackMarket.GetNumItems() |
1021 local name, texture, quantity, item_type, is_usable, level, level_type, seller_name, min_bid, min_increment, current_bid, has_high_bid, num_bids, time_left, item_link, market_id = _G.C_BlackMarket.GetItemInfoByIndex(index); | 1007 local name, texture, quantity, item_type, is_usable, level, level_type, seller_name, min_bid, min_increment, current_bid, has_high_bid, num_bids, time_left, item_link, market_id = _G.C_BlackMarket.GetItemInfoByIndex(index); |
1022 | 1008 |
1023 if item_link then | 1009 if item_link then |
1024 DBEntry("items", ItemLinkToID(item_link)).black_market = seller_name or "UNKNOWN" | 1010 DBEntry("items", ItemLinkToID(item_link)).black_market = seller_name or "UNKNOWN" |
1025 end | 1011 end |
1012 end | |
1013 end | |
1014 | |
1015 | |
1016 function WDP:GROUP_ROSTER_CHANGE() | |
1017 local is_raid = _G.IsInRaid() | |
1018 local unit_type = is_raid and "raid" or "party" | |
1019 local group_size = is_raid and _G.GetNumGroupMembers() or _G.GetNumSubgroupMembers() | |
1020 | |
1021 table.wipe(group_member_uids) | |
1022 | |
1023 for index = 1, group_size do | |
1024 group_member_uids[_G.UnitGUID(unit_type .. index)] = true | |
1025 end | |
1026 group_member_uids[_G.UnitGUID("player")] = true | |
1027 end | |
1028 | |
1029 | |
1030 function WDP:UNIT_PET(event_name, unit_id) | |
1031 local unit_guid = _G.UnitGUID(unit_id) | |
1032 local current_pet_guid = group_owner_guids_to_pet_guids[unit_guid] | |
1033 | |
1034 if current_pet_guid then | |
1035 Debug("Removing existing pet GUID for %s", _G.UnitName(unit_id)) | |
1036 group_owner_guids_to_pet_guids[unit_guid] = nil | |
1037 group_pet_guids[current_pet_guid] = nil | |
1038 end | |
1039 local pet_guid = _G.UnitGUID(unit_id .. "pet") | |
1040 | |
1041 if pet_guid then | |
1042 Debug("Adding new pet GUID for %s.", _G.UnitName(unit_id)) | |
1043 group_owner_guids_to_pet_guids[unit_id] = pet_guid | |
1044 group_pet_guids[pet_guid] = true | |
1026 end | 1045 end |
1027 end | 1046 end |
1028 | 1047 |
1029 | 1048 |
1030 function WDP:SHOW_LOOT_TOAST(event_name, loot_type, item_link, quantity) | 1049 function WDP:SHOW_LOOT_TOAST(event_name, loot_type, item_link, quantity) |
1211 end | 1230 end |
1212 end | 1231 end |
1213 | 1232 |
1214 local HEAL_BATTLE_PETS_SPELL_ID = 125801 | 1233 local HEAL_BATTLE_PETS_SPELL_ID = 125801 |
1215 | 1234 |
1235 local previous_combat_event = {} | |
1236 | |
1216 local COMBAT_LOG_FUNCS = { | 1237 local COMBAT_LOG_FUNCS = { |
1217 SPELL_AURA_APPLIED = RecordNPCSpell, | 1238 SPELL_AURA_APPLIED = RecordNPCSpell, |
1218 SPELL_CAST_START = RecordNPCSpell, | 1239 SPELL_CAST_START = RecordNPCSpell, |
1219 SPELL_CAST_SUCCESS = function(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name) | 1240 SPELL_CAST_SUCCESS = function(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, spell_id, spell_name) |
1220 if spell_id == HEAL_BATTLE_PETS_SPELL_ID then | 1241 if spell_id == HEAL_BATTLE_PETS_SPELL_ID then |
1235 ClearKilledBossID() | 1256 ClearKilledBossID() |
1236 private.harvesting = nil | 1257 private.harvesting = nil |
1237 return | 1258 return |
1238 end | 1259 end |
1239 | 1260 |
1240 if dest_guid ~= _G.UnitGUID("target") then | 1261 if source_guid == "" then |
1262 source_guid = nil | |
1263 end | |
1264 local killer_guid = source_guid or previous_combat_event.source_guid | |
1265 local killer_name = source_name or previous_combat_event.source_name | |
1266 | |
1267 if not group_member_uids[killer_guid] and not group_pet_guids[killer_guid] then | |
1241 ClearKilledNPC() | 1268 ClearKilledNPC() |
1242 ClearKilledBossID() | 1269 ClearKilledBossID() |
1243 return | 1270 return |
1244 end | 1271 end |
1245 | 1272 |
1260 WDP:ScheduleTimer(ClearKilledBossID, 1) | 1287 WDP:ScheduleTimer(ClearKilledBossID, 1) |
1261 end, | 1288 end, |
1262 } | 1289 } |
1263 | 1290 |
1264 | 1291 |
1292 local NON_DAMAGE_EVENTS = { | |
1293 SPELL_AURA_APPLIED = true, | |
1294 SPELL_AURA_REMOVED = true, | |
1295 SPELL_AURA_REMOVED_DOSE = true, | |
1296 SPELL_CAST_FAILED = true, | |
1297 SWING_MISSED = true, | |
1298 } | |
1299 | |
1300 | |
1265 function WDP:COMBAT_LOG_EVENT_UNFILTERED(event_name, time_stamp, sub_event, hide_caster, source_guid, source_name, source_flags, source_raid_flags, dest_guid, dest_name, dest_flags, dest_raid_flags, ...) | 1301 function WDP:COMBAT_LOG_EVENT_UNFILTERED(event_name, time_stamp, sub_event, hide_caster, source_guid, source_name, source_flags, source_raid_flags, dest_guid, dest_name, dest_flags, dest_raid_flags, ...) |
1266 local combat_log_func = COMBAT_LOG_FUNCS[sub_event] | 1302 local combat_log_func = COMBAT_LOG_FUNCS[sub_event] |
1267 | 1303 |
1268 if not combat_log_func then | 1304 if not combat_log_func then |
1305 if not NON_DAMAGE_EVENTS[sub_event] then | |
1306 Debug("Recording for %s", sub_event) | |
1307 previous_combat_event.source_guid = source_guid | |
1308 previous_combat_event.source_name = source_name | |
1309 previous_combat_event.dest_guid = dest_guid | |
1310 previous_combat_event.dest_name = dest_name | |
1311 end | |
1269 return | 1312 return |
1270 end | 1313 end |
1271 combat_log_func(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, ...) | 1314 combat_log_func(sub_event, source_guid, source_name, source_flags, dest_guid, dest_name, dest_flags, ...) |
1315 table.wipe(previous_combat_event) | |
1272 end | 1316 end |
1273 | 1317 |
1274 local DIPLOMACY_SPELL_ID = 20599 | 1318 local DIPLOMACY_SPELL_ID = 20599 |
1275 local MR_POP_RANK1_SPELL_ID = 78634 | 1319 local MR_POP_RANK1_SPELL_ID = 78634 |
1276 local MR_POP_RANK2_SPELL_ID = 78635 | 1320 local MR_POP_RANK2_SPELL_ID = 78635 |