-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathRecipeTracker.lua
More file actions
99 lines (71 loc) · 2.3 KB
/
RecipeTracker.lua
File metadata and controls
99 lines (71 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
local ZGV = ZygorGuidesViewer if not ZGV then return end
local L = ZGV.L
ZGV.RecipeTracker = {}
ZGV.RecipeTracker.scanAnnounced = false
---------------------------------------------------
-- Scan open profession and save learned recipes
---------------------------------------------------
function ZGV.RecipeTracker:ScanProfession()
-- announce scan once per open
if not self.scanAnnounced then
ZGV:Print(L["scan_precipe"])
self.scanAnnounced = true
end
-- advanced scanner if present
if ZGV.Professions and ZGV.Professions.CheckRecipesLearned then
ZGV.Professions.CheckRecipesLearned()
return
end
-- WoTLK-safe scan
local num = GetNumTradeSkills()
if not num or num == 0 then return end
ZGV.db.char.RecipesKnown = ZGV.db.char.RecipesKnown or {}
for i = 1, num do
local name, type = GetTradeSkillInfo(i)
-- skip headers
if type ~= "header" and name then
local link = GetTradeSkillItemLink(i)
if link then
local itemId = link:match("item:(%d+)")
if itemId then
ZGV.db.char.RecipesKnown[tonumber(itemId)] = true
end
end
end
end
end
---------------------------------------------------
-- Event: skill learned
---------------------------------------------------
function ZGV.RecipeTracker:OnSkillLearned(event, message)
if not message then return end
if message:find(L["has learned"])
or message:find("изучает")
or message:find("learns") then
self:ScanProfession()
end
end
---------------------------------------------------
-- Delayed scan helper
---------------------------------------------------
local function DelayedScan(self)
-- reset announcement flag
self.scanAnnounced = false
-- profession UI needs time to populate
ZGV:ScheduleTimer(function()
self:ScanProfession()
end, 0.5)
end
---------------------------------------------------
-- Initialize
---------------------------------------------------
function ZGV.RecipeTracker:Initialize()
ZGV.db.char.RecipesKnown = ZGV.db.char.RecipesKnown or {}
ZGV:AddEvent("CHAT_MSG_SKILL",
function(...) self:OnSkillLearned(...) end)
ZGV:AddEvent("TRADE_SKILL_SHOW",
function() DelayedScan(self) end)
--ZGV:AddEvent("TRADE_SKILL_UPDATE",
--function() DelayedScan(self) end)
ZGV:Print(L["recipe_tracking_init"])
end