comparison Main.lua @ 92:c62f2af669d9

Normalized event handlers (all have an event_name parameter). Added support for recording the locations of Anvils and Forges.
author James D. Callahan III <jcallahan@curse.com>
date Tue, 28 Aug 2012 21:43:07 -0500
parents 63287a0a0a2e
children 526e78d7ce51
comparison
equal deleted inserted replaced
91:63287a0a0a2e 92:c62f2af669d9
29 29
30 ----------------------------------------------------------------------- 30 -----------------------------------------------------------------------
31 -- Local constants. 31 -- Local constants.
32 ----------------------------------------------------------------------- 32 -----------------------------------------------------------------------
33 local DB_VERSION = 4 33 local DB_VERSION = 4
34
34 35
35 local DATABASE_DEFAULTS = { 36 local DATABASE_DEFAULTS = {
36 global = { 37 global = {
37 items = {}, 38 items = {},
38 npcs = {}, 39 npcs = {},
63 PLAYER_TARGET_CHANGED = true, 64 PLAYER_TARGET_CHANGED = true,
64 QUEST_COMPLETE = true, 65 QUEST_COMPLETE = true,
65 QUEST_DETAIL = true, 66 QUEST_DETAIL = true,
66 QUEST_LOG_UPDATE = true, 67 QUEST_LOG_UPDATE = true,
67 TAXIMAP_OPENED = true, 68 TAXIMAP_OPENED = true,
69 TRADE_SKILL_SHOW = true,
68 TRAINER_SHOW = true, 70 TRAINER_SHOW = true,
69 TRANSMOGRIFY_OPEN = true, 71 TRANSMOGRIFY_OPEN = true,
70 UNIT_QUEST_LOG_CHANGED = true, 72 UNIT_QUEST_LOG_CHANGED = true,
71 UNIT_SPELLCAST_FAILED = "HandleSpellFailure", 73 UNIT_SPELLCAST_FAILED = "HandleSpellFailure",
72 UNIT_SPELLCAST_FAILED_QUIET = "HandleSpellFailure", 74 UNIT_SPELLCAST_FAILED_QUIET = "HandleSpellFailure",
75 UNIT_SPELLCAST_SUCCEEDED = true, 77 UNIT_SPELLCAST_SUCCEEDED = true,
76 VOID_STORAGE_OPEN = true, 78 VOID_STORAGE_OPEN = true,
77 } 79 }
78 80
79 81
82 local OBJECT_ID_ANVIL = 192628
83 local OBJECT_ID_FORGE = 1685
84
85
80 local AF = private.ACTION_TYPE_FLAGS 86 local AF = private.ACTION_TYPE_FLAGS
81 87
82 88
83 local PLAYER_CLASS = _G.select(2, _G.UnitClass("player")) 89 local PLAYER_CLASS = _G.select(2, _G.UnitClass("player"))
84 local PLAYER_GUID = _G.UnitGUID("player") 90 local PLAYER_GUID = _G.UnitGUID("player")
85 local PLAYER_RACE = _G.select(2, _G.UnitRace("player")) 91 local PLAYER_RACE = _G.select(2, _G.UnitRace("player"))
86 92
87 ----------------------------------------------------------------------- 93 -----------------------------------------------------------------------
88 -- Local variables. 94 -- Local variables.
89 ----------------------------------------------------------------------- 95 -----------------------------------------------------------------------
96 local anvil_spell_ids = {}
97 local action_data = {}
98 local currently_drunk
90 local db 99 local db
91 local durability_timer_handle 100 local durability_timer_handle
101 local faction_standings = {}
102 local forge_spell_ids = {}
103 local reputation_npc_id
92 local target_location_timer_handle 104 local target_location_timer_handle
93 local action_data = {}
94 local currently_drunk
95 local faction_standings = {}
96 local reputation_npc_id
97 local current_target_id 105 local current_target_id
106
98 107
99 ----------------------------------------------------------------------- 108 -----------------------------------------------------------------------
100 -- Helper Functions. 109 -- Helper Functions.
101 ----------------------------------------------------------------------- 110 -----------------------------------------------------------------------
102 local ActualCopperCost 111 local ActualCopperCost
623 _G.DRUNK_MESSAGE_SELF2:gsub("%%s", ".+"), 632 _G.DRUNK_MESSAGE_SELF2:gsub("%%s", ".+"),
624 _G.DRUNK_MESSAGE_SELF3:gsub("%%s", ".+"), 633 _G.DRUNK_MESSAGE_SELF3:gsub("%%s", ".+"),
625 _G.DRUNK_MESSAGE_SELF4:gsub("%%s", ".+"), 634 _G.DRUNK_MESSAGE_SELF4:gsub("%%s", ".+"),
626 } 635 }
627 636
628 function WDP:CHAT_MSG_SYSTEM(event, message) 637 function WDP:CHAT_MSG_SYSTEM(event_name, message)
629 if currently_drunk then 638 if currently_drunk then
630 if message == _G.DRUNK_MESSAGE_SELF1 or message:match(SOBER_MATCH) then 639 if message == _G.DRUNK_MESSAGE_SELF1 or message:match(SOBER_MATCH) then
631 currently_drunk = nil 640 currently_drunk = nil
632 end 641 end
633 return 642 return
679 reputation_npc_id = unit_idnum 688 reputation_npc_id = unit_idnum
680 end, 689 end,
681 } 690 }
682 691
683 692
684 function WDP:COMBAT_LOG_EVENT_UNFILTERED(event, time_stamp, sub_event, hide_caster, source_guid, source_name, source_flags, source_raid_flags, dest_guid, dest_name, dest_flags, dest_raid_flags, ...) 693 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, ...)
685 local combat_log_func = COMBAT_LOG_FUNCS[sub_event] 694 local combat_log_func = COMBAT_LOG_FUNCS[sub_event]
686 695
687 if not combat_log_func then 696 if not combat_log_func then
688 return 697 return
689 end 698 end
754 modifier = 0.08, 763 modifier = 0.08,
755 } 764 }
756 } 765 }
757 766
758 767
759 function WDP:COMBAT_TEXT_UPDATE(event, message_type, faction_name, amount) 768 function WDP:COMBAT_TEXT_UPDATE(event_name, message_type, faction_name, amount)
760 if message_type ~= "FACTION" or not reputation_npc_id then 769 if message_type ~= "FACTION" or not reputation_npc_id then
761 return 770 return
762 end 771 end
763 UpdateFactionData() 772 UpdateFactionData()
764 773
796 reputation_npc_id = nil 805 reputation_npc_id = nil
797 end 806 end
798 end -- do-block 807 end -- do-block
799 808
800 809
801 function WDP:ITEM_TEXT_BEGIN() 810 function WDP:ITEM_TEXT_BEGIN(event_name)
802 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("npc")) 811 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("npc"))
803 812
804 if not unit_idnum or unit_type ~= private.UNIT_TYPES.OBJECT or _G.UnitName("npc") ~= _G.ItemTextGetItem() then 813 if not unit_idnum or unit_type ~= private.UNIT_TYPES.OBJECT or _G.UnitName("npc") ~= _G.ItemTextGetItem() then
805 return 814 return
806 end 815 end
934 } 943 }
935 944
936 -- Prevent opening the same loot window multiple times from recording data multiple times. 945 -- Prevent opening the same loot window multiple times from recording data multiple times.
937 local loot_guid_registry = {} 946 local loot_guid_registry = {}
938 947
939 function WDP:LOOT_OPENED() 948 function WDP:LOOT_OPENED(event_name)
940 if action_data.looting then 949 if action_data.looting then
941 return 950 return
942 end 951 end
943 952
944 if not action_data.type then 953 if not action_data.type then
1142 _G.MerchantFrame_Update() 1151 _G.MerchantFrame_Update()
1143 end 1152 end
1144 end -- do-block 1153 end -- do-block
1145 1154
1146 1155
1147 function WDP:PET_BAR_UPDATE() 1156 function WDP:PET_BAR_UPDATE(event_name)
1148 if not action_data.label or not action_data.label == "mind_control" then 1157 if not action_data.label or not action_data.label == "mind_control" then
1149 return 1158 return
1150 end 1159 end
1151 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("pet")) 1160 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("pet"))
1152 1161
1185 ["3"] = "ENERGY", 1194 ["3"] = "ENERGY",
1186 ["6"] = "RUNIC_POWER", 1195 ["6"] = "RUNIC_POWER",
1187 } 1196 }
1188 1197
1189 1198
1190 function WDP:PLAYER_TARGET_CHANGED() 1199 function WDP:PLAYER_TARGET_CHANGED(event_name)
1191 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or currently_drunk then 1200 if not _G.UnitExists("target") or _G.UnitPlayerControlled("target") or currently_drunk then
1192 current_target_id = nil 1201 current_target_id = nil
1193 return 1202 return
1194 end 1203 end
1195 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target")) 1204 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target"))
1250 1259
1251 return quest 1260 return quest
1252 end 1261 end
1253 1262
1254 1263
1255 function WDP:QUEST_COMPLETE() 1264 function WDP:QUEST_COMPLETE(event_name)
1256 -- Make sure the quest NPC isn't erroneously recorded as giving reputation for quests which award it. 1265 -- Make sure the quest NPC isn't erroneously recorded as giving reputation for quests which award it.
1257 reputation_npc_id = nil 1266 reputation_npc_id = nil
1258 UpdateQuestJuncture("end") 1267 UpdateQuestJuncture("end")
1259 end 1268 end
1260 1269
1261 1270
1262 function WDP:QUEST_DETAIL() 1271 function WDP:QUEST_DETAIL(event_name)
1263 local quest = UpdateQuestJuncture("begin") 1272 local quest = UpdateQuestJuncture("begin")
1264 1273
1265 if not quest then 1274 if not quest then
1266 return 1275 return
1267 end 1276 end
1273 quest.races[race] = true 1282 quest.races[race] = true
1274 end 1283 end
1275 end -- do-block 1284 end -- do-block
1276 1285
1277 1286
1278 function WDP:QUEST_LOG_UPDATE() 1287 function WDP:QUEST_LOG_UPDATE(event_name)
1279 local selected_quest = _G.GetQuestLogSelection() -- Save current selection to be restored when we're done. 1288 local selected_quest = _G.GetQuestLogSelection() -- Save current selection to be restored when we're done.
1280 local entry_index, processed_quests = 1, 0 1289 local entry_index, processed_quests = 1, 0
1281 local _, num_quests = _G.GetNumQuestLogEntries() 1290 local _, num_quests = _G.GetNumQuestLogEntries()
1282 1291
1283 while processed_quests <= num_quests do 1292 while processed_quests <= num_quests do
1298 _G.SelectQuestLogEntry(selected_quest) 1307 _G.SelectQuestLogEntry(selected_quest)
1299 self:UnregisterEvent("QUEST_LOG_UPDATE") 1308 self:UnregisterEvent("QUEST_LOG_UPDATE")
1300 end 1309 end
1301 1310
1302 1311
1303 function WDP:UNIT_QUEST_LOG_CHANGED(event, unit_id) 1312 function WDP:UNIT_QUEST_LOG_CHANGED(event_name, unit_id)
1304 if unit_id ~= "player" then 1313 if unit_id ~= "player" then
1305 return 1314 return
1306 end 1315 end
1307 self:RegisterEvent("QUEST_LOG_UPDATE") 1316 self:RegisterEvent("QUEST_LOG_UPDATE")
1308 end 1317 end
1309 1318
1310 1319
1311 function WDP:TRAINER_SHOW() 1320 do
1321 local TRADESKILL_TOOLS = {
1322 Anvil = anvil_spell_ids,
1323 Forge = forge_spell_ids,
1324 }
1325
1326
1327 function WDP:TRADE_SKILL_SHOW(event_name)
1328 local profession_name, prof_level = _G.GetTradeSkillLine()
1329
1330 if profession_name == _G.UNKNOWN then
1331 return
1332 end
1333
1334 if _G.TradeSkillFrame and _G.TradeSkillFrame:IsVisible() then
1335 -- Clear the search box focus so the scan will have correct results.
1336 local search_box = _G.TradeSkillFrameSearchBox
1337 search_box:SetText("")
1338 _G.TradeSkillSearch_OnTextChanged(search_box)
1339 search_box:ClearFocus()
1340 search_box:GetScript("OnEditFocusLost")(search_box)
1341 end
1342 local header_list = {}
1343
1344 -- Save the current state of the TradeSkillFrame so it can be restored after we muck with it.
1345 local have_materials = _G.TradeSkillFrame.filterTbl.hasMaterials
1346 local have_skillup = _G.TradeSkillFrame.filterTbl.hasSkillUp
1347
1348 if have_materials then
1349 _G.TradeSkillFrame.filterTbl.hasMaterials = false
1350 _G.TradeSkillOnlyShowMakeable(false)
1351 end
1352
1353 if have_skillup then
1354 _G.TradeSkillFrame.filterTbl.hasSkillUp = false
1355 _G.TradeSkillOnlyShowSkillUps(false)
1356 end
1357 _G.SetTradeSkillInvSlotFilter(0, 1, 1)
1358 _G.TradeSkillUpdateFilterBar()
1359 _G.TradeSkillFrame_Update()
1360
1361 -- Expand all headers so we can see all the recipes there are
1362 for tradeskill_index = 1, _G.GetNumTradeSkills() do
1363 local name, tradeskill_type, _, is_expanded = _G.GetTradeSkillInfo(tradeskill_index)
1364
1365 if tradeskill_type == "header" then
1366 if not is_expanded then
1367 header_list[name] = true
1368 _G.ExpandTradeSkillSubClass(tradeskill_index)
1369 end
1370 else
1371 local spell_id = tonumber(_G.GetTradeSkillRecipeLink(tradeskill_index):match("^|c%x%x%x%x%x%x%x%x|H%w+:(%d+)"))
1372 local required_tool = _G.GetTradeSkillTools(tradeskill_index)
1373
1374 if required_tool then
1375 for tool_name, registry in pairs(TRADESKILL_TOOLS) do
1376 if required_tool:find(tool_name) then
1377 print(("Set %s spell: %d"):format(tool_name, spell_id))
1378 registry[spell_id] = true
1379 end
1380 end
1381 end
1382 end
1383 end
1384
1385 -- Restore the state of the things we changed.
1386 for tradeskill_index = 1, _G.GetNumTradeSkills() do
1387 local name, tradeskill_type, _, is_expanded = _G.GetTradeSkillInfo(tradeskill_index)
1388
1389 if header_list[name] then
1390 _G.CollapseTradeSkillSubClass(tradeskill_index)
1391 end
1392 end
1393 _G.TradeSkillFrame.filterTbl.hasMaterials = have_materials
1394 _G.TradeSkillOnlyShowMakeable(have_materials)
1395 _G.TradeSkillFrame.filterTbl.hasSkillUp = have_skillup
1396 _G.TradeSkillOnlyShowSkillUps(have_skillup)
1397
1398 _G.TradeSkillUpdateFilterBar()
1399 _G.TradeSkillFrame_Update()
1400 end
1401 end -- do-block
1402
1403
1404 function WDP:TRAINER_SHOW(event_name)
1312 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target")) 1405 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target"))
1313 local npc = NPCEntry(unit_idnum) 1406 local npc = NPCEntry(unit_idnum)
1314 1407
1315 if not npc then 1408 if not npc then
1316 return 1409 return
1435 private.tracked_line = nil 1528 private.tracked_line = nil
1436 1529
1437 if spell_name:match("^Harvest.+") then 1530 if spell_name:match("^Harvest.+") then
1438 reputation_npc_id = current_target_id 1531 reputation_npc_id = current_target_id
1439 end 1532 end
1533
1534 if anvil_spell_ids[spell_id] then
1535 UpdateDBEntryLocation("objects", OBJECT_ID_ANVIL)
1536 elseif forge_spell_ids[spell_id] then
1537 UpdateDBEntryLocation("objects", OBJECT_ID_FORGE)
1538 end
1440 end 1539 end
1441 1540
1442 1541
1443 function WDP:HandleSpellFailure(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id) 1542 function WDP:HandleSpellFailure(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
1444 if unit_id ~= "player" then 1543 if unit_id ~= "player" then
1480 function WDP:BATTLEFIELDS_SHOW(event_name) 1579 function WDP:BATTLEFIELDS_SHOW(event_name)
1481 SetUnitField("battlemaster", private.UNIT_TYPES.NPC) 1580 SetUnitField("battlemaster", private.UNIT_TYPES.NPC)
1482 end 1581 end
1483 1582
1484 1583
1485 function WDP:FORGE_MASTER_OPENED() 1584 function WDP:FORGE_MASTER_OPENED(event_name)
1486 SetUnitField("arcane_reforger", private.UNIT_TYPES.NPC) 1585 SetUnitField("arcane_reforger", private.UNIT_TYPES.NPC)
1487 end 1586 end
1488 1587
1489 1588
1490 function WDP:GOSSIP_SHOW() 1589 function WDP:GOSSIP_SHOW(event_name)
1491 local gossip_options = { _G.GetGossipOptions() } 1590 local gossip_options = { _G.GetGossipOptions() }
1492 1591
1493 for index = 2, #gossip_options, 2 do 1592 for index = 2, #gossip_options, 2 do
1494 if gossip_options[index] == "binder" then 1593 if gossip_options[index] == "binder" then
1495 SetUnitField("innkeeper", private.UNIT_TYPES.NPC) 1594 SetUnitField("innkeeper", private.UNIT_TYPES.NPC)