comparison Main.lua @ 167:0820f3ab783e 1.0.19

Record tradeskill discoveries.
author James D. Callahan III <jcallahan@curse.com>
date Mon, 15 Oct 2012 16:58:47 -0500
parents 135ef8805021
children 5f6d5a1a62e1
comparison
equal deleted inserted replaced
166:135ef8805021 167:0820f3ab783e
42 global = { 42 global = {
43 items = {}, 43 items = {},
44 npcs = {}, 44 npcs = {},
45 objects = {}, 45 objects = {},
46 quests = {}, 46 quests = {},
47 spells = {},
47 zones = {}, 48 zones = {},
48 } 49 }
49 } 50 }
50 51
51 52
81 QUEST_DETAIL = true, 82 QUEST_DETAIL = true,
82 QUEST_LOG_UPDATE = true, 83 QUEST_LOG_UPDATE = true,
83 QUEST_PROGRESS = true, 84 QUEST_PROGRESS = true,
84 TAXIMAP_OPENED = true, 85 TAXIMAP_OPENED = true,
85 TRADE_SKILL_SHOW = true, 86 TRADE_SKILL_SHOW = true,
87 TRAINER_CLOSED = true,
86 TRAINER_SHOW = true, 88 TRAINER_SHOW = true,
87 TRANSMOGRIFY_OPEN = true, 89 TRANSMOGRIFY_OPEN = true,
88 UNIT_QUEST_LOG_CHANGED = true, 90 UNIT_QUEST_LOG_CHANGED = true,
89 UNIT_SPELLCAST_FAILED = "HandleSpellFailure", 91 UNIT_SPELLCAST_FAILED = "HandleSpellFailure",
90 UNIT_SPELLCAST_FAILED_QUIET = "HandleSpellFailure", 92 UNIT_SPELLCAST_FAILED_QUIET = "HandleSpellFailure",
164 end 166 end
165 _G.print(...) 167 _G.print(...)
166 end 168 end
167 169
168 170
171 local function TradeSkillExecutePer(iter_func)
172 if _G.TradeSkillFrame and _G.TradeSkillFrame:IsVisible() then
173 -- Clear the search box focus so the scan will have correct results.
174 local search_box = _G.TradeSkillFrameSearchBox
175 search_box:SetText("")
176 _G.TradeSkillSearch_OnTextChanged(search_box)
177 search_box:ClearFocus()
178 search_box:GetScript("OnEditFocusLost")(search_box)
179 end
180 local header_list = {}
181
182 -- Save the current state of the TradeSkillFrame so it can be restored after we muck with it.
183 local have_materials = _G.TradeSkillFrame.filterTbl.hasMaterials
184 local have_skillup = _G.TradeSkillFrame.filterTbl.hasSkillUp
185
186 if have_materials then
187 _G.TradeSkillFrame.filterTbl.hasMaterials = false
188 _G.TradeSkillOnlyShowMakeable(false)
189 end
190
191 if have_skillup then
192 _G.TradeSkillFrame.filterTbl.hasSkillUp = false
193 _G.TradeSkillOnlyShowSkillUps(false)
194 end
195 _G.SetTradeSkillInvSlotFilter(0, 1, 1)
196 _G.TradeSkillUpdateFilterBar()
197 _G.TradeSkillFrame_Update()
198
199 -- Expand all headers so we can see all the recipes there are
200 for tradeskill_index = 1, _G.GetNumTradeSkills() do
201 local name, tradeskill_type, _, is_expanded = _G.GetTradeSkillInfo(tradeskill_index)
202
203 if tradeskill_type == "header" or tradeskill_type == "subheader" then
204 if not is_expanded then
205 header_list[name] = true
206 _G.ExpandTradeSkillSubClass(tradeskill_index)
207 end
208 else
209 iter_func(name, tradeskill_index)
210 end
211 end
212
213 -- Restore the state of the things we changed.
214 for tradeskill_index = 1, _G.GetNumTradeSkills() do
215 local name, tradeskill_type, _, is_expanded = _G.GetTradeSkillInfo(tradeskill_index)
216
217 if header_list[name] then
218 _G.CollapseTradeSkillSubClass(tradeskill_index)
219 end
220 end
221 _G.TradeSkillFrame.filterTbl.hasMaterials = have_materials
222 _G.TradeSkillOnlyShowMakeable(have_materials)
223 _G.TradeSkillFrame.filterTbl.hasSkillUp = have_skillup
224 _G.TradeSkillOnlyShowSkillUps(have_skillup)
225
226 _G.TradeSkillUpdateFilterBar()
227 _G.TradeSkillFrame_Update()
228 end
229
230
169 local ActualCopperCost 231 local ActualCopperCost
170 do 232 do
171 local BARTERING_SPELL_ID = 83964 233 local BARTERING_SPELL_ID = 83964
172 234
173 local STANDING_DISCOUNTS = { 235 local STANDING_DISCOUNTS = {
955 _G.DRUNK_MESSAGE_SELF2:gsub("%%s", ".+"), 1017 _G.DRUNK_MESSAGE_SELF2:gsub("%%s", ".+"),
956 _G.DRUNK_MESSAGE_SELF3:gsub("%%s", ".+"), 1018 _G.DRUNK_MESSAGE_SELF3:gsub("%%s", ".+"),
957 _G.DRUNK_MESSAGE_SELF4:gsub("%%s", ".+"), 1019 _G.DRUNK_MESSAGE_SELF4:gsub("%%s", ".+"),
958 } 1020 }
959 1021
1022 local RECIPE_MATCH = _G.ERR_LEARN_RECIPE_S:gsub("%%s", "(.*)")
1023
1024
1025 local function RecordDiscovery(tradeskill_name, tradeskill_index)
1026 if tradeskill_name == private.discovered_recipe_name then
1027 DBEntry("spells", tonumber(_G.GetTradeSkillRecipeLink(tradeskill_index):match("^|c%x%x%x%x%x%x%x%x|H%w+:(%d+)"))).discovery = ("%d:%d"):format(private.previous_spell_id, private.profession_level)
1028
1029 private.discovered_recipe_name = nil
1030 private.profession_level = nil
1031 private.previous_spell_id = nil
1032 end
1033 end
1034
1035
1036 local function IterativeRecordDiscovery()
1037 TradeSkillExecutePer(RecordDiscovery)
1038 end
1039
1040
960 function WDP:CHAT_MSG_SYSTEM(event_name, message) 1041 function WDP:CHAT_MSG_SYSTEM(event_name, message)
1042 if not private.trainer_shown then
1043 local recipe_name = message:match(RECIPE_MATCH)
1044
1045 if recipe_name and private.previous_spell_id then
1046 local profession_name, prof_level = _G.GetTradeSkillLine()
1047
1048 if profession_name == _G.UNKNOWN then
1049 return
1050 end
1051 private.discovered_recipe_name = recipe_name
1052 private.profession_level = prof_level
1053
1054 self:ScheduleTimer(IterativeRecordDiscovery, 0.2)
1055 end
1056 end
1057
961 if currently_drunk then 1058 if currently_drunk then
962 if message == _G.DRUNK_MESSAGE_SELF1 or message:match(SOBER_MATCH) then 1059 if message == _G.DRUNK_MESSAGE_SELF1 or message:match(SOBER_MATCH) then
963 currently_drunk = nil 1060 currently_drunk = nil
964 end 1061 end
965 return 1062 return
1721 Anvil = anvil_spell_ids, 1818 Anvil = anvil_spell_ids,
1722 Forge = forge_spell_ids, 1819 Forge = forge_spell_ids,
1723 } 1820 }
1724 1821
1725 1822
1823 local function RegisterTools(tradeskill_name, tradeskill_index)
1824 local spell_id = tonumber(_G.GetTradeSkillRecipeLink(tradeskill_index):match("^|c%x%x%x%x%x%x%x%x|H%w+:(%d+)"))
1825 local required_tool = _G.GetTradeSkillTools(tradeskill_index)
1826
1827 if required_tool then
1828 for tool_name, registry in pairs(TRADESKILL_TOOLS) do
1829 if required_tool:find(tool_name) then
1830 registry[spell_id] = true
1831 end
1832 end
1833 end
1834 end
1835
1836
1726 function WDP:TRADE_SKILL_SHOW(event_name) 1837 function WDP:TRADE_SKILL_SHOW(event_name)
1727 local profession_name, prof_level = _G.GetTradeSkillLine() 1838 local profession_name, prof_level = _G.GetTradeSkillLine()
1728 1839
1729 if profession_name == _G.UNKNOWN then 1840 if profession_name == _G.UNKNOWN then
1730 return 1841 return
1731 end 1842 end
1732 1843 TradeSkillExecutePer(RegisterTools)
1733 if _G.TradeSkillFrame and _G.TradeSkillFrame:IsVisible() then
1734 -- Clear the search box focus so the scan will have correct results.
1735 local search_box = _G.TradeSkillFrameSearchBox
1736 search_box:SetText("")
1737 _G.TradeSkillSearch_OnTextChanged(search_box)
1738 search_box:ClearFocus()
1739 search_box:GetScript("OnEditFocusLost")(search_box)
1740 end
1741 local header_list = {}
1742
1743 -- Save the current state of the TradeSkillFrame so it can be restored after we muck with it.
1744 local have_materials = _G.TradeSkillFrame.filterTbl.hasMaterials
1745 local have_skillup = _G.TradeSkillFrame.filterTbl.hasSkillUp
1746
1747 if have_materials then
1748 _G.TradeSkillFrame.filterTbl.hasMaterials = false
1749 _G.TradeSkillOnlyShowMakeable(false)
1750 end
1751
1752 if have_skillup then
1753 _G.TradeSkillFrame.filterTbl.hasSkillUp = false
1754 _G.TradeSkillOnlyShowSkillUps(false)
1755 end
1756 _G.SetTradeSkillInvSlotFilter(0, 1, 1)
1757 _G.TradeSkillUpdateFilterBar()
1758 _G.TradeSkillFrame_Update()
1759
1760 -- Expand all headers so we can see all the recipes there are
1761 for tradeskill_index = 1, _G.GetNumTradeSkills() do
1762 local name, tradeskill_type, _, is_expanded = _G.GetTradeSkillInfo(tradeskill_index)
1763
1764 if tradeskill_type == "header" or tradeskill_type == "subheader" then
1765 if not is_expanded then
1766 header_list[name] = true
1767 _G.ExpandTradeSkillSubClass(tradeskill_index)
1768 end
1769 else
1770 local spell_id = tonumber(_G.GetTradeSkillRecipeLink(tradeskill_index):match("^|c%x%x%x%x%x%x%x%x|H%w+:(%d+)"))
1771 local required_tool = _G.GetTradeSkillTools(tradeskill_index)
1772
1773 if required_tool then
1774 for tool_name, registry in pairs(TRADESKILL_TOOLS) do
1775 if required_tool:find(tool_name) then
1776 registry[spell_id] = true
1777 end
1778 end
1779 end
1780 end
1781 end
1782
1783 -- Restore the state of the things we changed.
1784 for tradeskill_index = 1, _G.GetNumTradeSkills() do
1785 local name, tradeskill_type, _, is_expanded = _G.GetTradeSkillInfo(tradeskill_index)
1786
1787 if header_list[name] then
1788 _G.CollapseTradeSkillSubClass(tradeskill_index)
1789 end
1790 end
1791 _G.TradeSkillFrame.filterTbl.hasMaterials = have_materials
1792 _G.TradeSkillOnlyShowMakeable(have_materials)
1793 _G.TradeSkillFrame.filterTbl.hasSkillUp = have_skillup
1794 _G.TradeSkillOnlyShowSkillUps(have_skillup)
1795
1796 _G.TradeSkillUpdateFilterBar()
1797 _G.TradeSkillFrame_Update()
1798 end 1844 end
1799 end -- do-block 1845 end -- do-block
1846
1847
1848 function WDP:TRAINER_CLOSED(event_name)
1849 private.trainer_shown = nil
1850 end
1800 1851
1801 1852
1802 function WDP:TRAINER_SHOW(event_name) 1853 function WDP:TRAINER_SHOW(event_name)
1803 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target")) 1854 local unit_type, unit_idnum = ParseGUID(_G.UnitGUID("target"))
1804 local trainer = NPCEntry(unit_idnum) 1855 local trainer = NPCEntry(unit_idnum)
1806 if not trainer then 1857 if not trainer then
1807 return 1858 return
1808 end 1859 end
1809 local trainer_standing = select(2, UnitFactionStanding("target")) 1860 local trainer_standing = select(2, UnitFactionStanding("target"))
1810 trainer.teaches = trainer.teaches or {} 1861 trainer.teaches = trainer.teaches or {}
1862
1863 private.trainer_shown = true
1811 1864
1812 -- Get the initial trainer filters 1865 -- Get the initial trainer filters
1813 local available = _G.GetTrainerServiceTypeFilter("available") 1866 local available = _G.GetTrainerServiceTypeFilter("available")
1814 local unavailable = _G.GetTrainerServiceTypeFilter("unavailable") 1867 local unavailable = _G.GetTrainerServiceTypeFilter("unavailable")
1815 local used = _G.GetTrainerServiceTypeFilter("used") 1868 local used = _G.GetTrainerServiceTypeFilter("used")
1926 function WDP:UNIT_SPELLCAST_SUCCEEDED(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id) 1979 function WDP:UNIT_SPELLCAST_SUCCEEDED(event_name, unit_id, spell_name, spell_rank, spell_line, spell_id)
1927 if unit_id ~= "player" then 1980 if unit_id ~= "player" then
1928 return 1981 return
1929 end 1982 end
1930 private.tracked_line = nil 1983 private.tracked_line = nil
1984 private.previous_spell_id = spell_id
1931 1985
1932 if spell_name:match("^Harvest.+") then 1986 if spell_name:match("^Harvest.+") then
1933 reputation_npc_id = current_target_id 1987 reputation_npc_id = current_target_id
1934 private.harvesting = true 1988 private.harvesting = true
1935 end 1989 end