-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestPlates.lua
More file actions
141 lines (122 loc) · 4.28 KB
/
QuestPlates.lua
File metadata and controls
141 lines (122 loc) · 4.28 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
-- QuestPlates: Shows "!" on pfUI nameplates for quest objective mobs
-- Uses pfQuest database to resolve item objectives -> mob names
-- Try to increase nameplate distance
pcall(SetCVar, "nameplateDistance", "41")
local questMobs = {}
local function ScanQuestObjectives()
local newMobs = {}
-- need pfQuest loaded
if not pfDB or not pfDB.quests or not pfDB.items or not pfDB.units then return end
local qdata = pfDB["quests"]["data"]
local idata = pfDB["items"]["data"]
local udata = pfDB["units"]["data"]
local uloc = pfDB["units"]["loc"]
local refloot = pfDB["refloot"] and pfDB["refloot"]["data"]
for qlogid = 1, GetNumQuestLogEntries() do
local title, _, _, header, _, complete = GetQuestLogTitle(qlogid)
if title and not header and not complete then
-- get quest ID from pfQuest
local questids = pfDatabase and pfDatabase.GetQuestIDs and pfDatabase:GetQuestIDs(qlogid)
local questid = questids and tonumber(questids[1])
if questid and qdata[questid] and qdata[questid]["obj"] then
local obj = qdata[questid]["obj"]
-- direct unit objectives (kill quests)
if obj["U"] then
for _, unitid in pairs(obj["U"]) do
local name = uloc[unitid]
if name then
newMobs[name] = true
end
end
end
-- item objectives - find which mobs drop them
if obj["I"] then
for _, itemid in pairs(obj["I"]) do
if idata[itemid] then
-- direct unit drops
if idata[itemid]["U"] then
for unitid, _ in pairs(idata[itemid]["U"]) do
local name = uloc[unitid]
if name then
newMobs[name] = true
end
end
end
-- reference loot (shared loot tables)
if idata[itemid]["R"] and refloot then
for ref, _ in pairs(idata[itemid]["R"]) do
if refloot[ref] and refloot[ref]["U"] then
for unitid in pairs(refloot[ref]["U"]) do
local name = uloc[unitid]
if name then
newMobs[name] = true
end
end
end
end
end
end
end
end
end
-- fallback: also parse "monster" type objectives from quest log text
local objectives = GetNumQuestLeaderBoards(qlogid)
if objectives then
for i = 1, objectives do
local text, objtype, done = GetQuestLogLeaderBoard(i, qlogid)
if not done and text then
if objtype == "monster" then
local mobname = gsub(text, "%s*[:%-]%s*%d+%s*/%s*%d+%s*$", "")
mobname = gsub(mobname, "%s+slain$", "")
if mobname and mobname ~= "" then
newMobs[mobname] = true
end
end
end
end
end
end
end
questMobs = newMobs
end
-- Event scanner
local scanner = CreateFrame("Frame")
scanner:RegisterEvent("QUEST_LOG_UPDATE")
scanner:RegisterEvent("PLAYER_ENTERING_WORLD")
scanner:RegisterEvent("QUEST_WATCH_UPDATE")
scanner:RegisterEvent("UNIT_QUEST_LOG_CHANGED")
scanner:SetScript("OnEvent", ScanQuestObjectives)
-- Nameplate updater
local updater = CreateFrame("Frame")
local elapsed = 0
updater:SetScript("OnUpdate", function()
elapsed = elapsed + arg1
if elapsed < 0.2 then return end
elapsed = 0
local i = 1
while true do
local plate = getglobal("pfNamePlate" .. i)
if not plate then break end
-- Create quest icon if needed
if not plate.questIcon then
plate.questIcon = plate:CreateFontString(nil, "OVERLAY")
plate.questIcon:SetFont("Fonts\\FRIZQT__.TTF", 20, "OUTLINE")
plate.questIcon:SetTextColor(1, 0.82, 0, 1)
plate.questIcon:SetText("!")
plate.questIcon:SetPoint("RIGHT", plate.name, "LEFT", -3, 0)
plate.questIcon:Hide()
end
-- Show/hide
if plate:IsVisible() and plate.original and plate.original.name then
local name = plate.original.name:GetText()
if name and questMobs[name] then
plate.questIcon:Show()
else
plate.questIcon:Hide()
end
else
plate.questIcon:Hide()
end
i = i + 1
end
end)