@piekasz/wow-mcp 0.0.0-stage → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -0
- package/NOTICE +37 -0
- package/README.md +41 -2
- package/addon/WowMcp/AuctionTooltip.lua +106 -0
- package/addon/WowMcp/Commands.lua +259 -0
- package/addon/WowMcp/Compat.lua +167 -0
- package/addon/WowMcp/Core.lua +50 -0
- package/addon/WowMcp/Events.lua +62 -0
- package/addon/WowMcp/Items.lua +314 -0
- package/addon/WowMcp/Maps.lua +66 -0
- package/addon/WowMcp/MinimapButton.lua +114 -0
- package/addon/WowMcp/Options.lua +208 -0
- package/addon/WowMcp/Panel.lua +294 -0
- package/addon/WowMcp/QuestDb.lua +303 -0
- package/addon/WowMcp/QuestRewards.lua +137 -0
- package/addon/WowMcp/Sections/ActionBars.lua +54 -0
- package/addon/WowMcp/Sections/Auctions.lua +305 -0
- package/addon/WowMcp/Sections/Bank.lua +48 -0
- package/addon/WowMcp/Sections/Buyback.lua +47 -0
- package/addon/WowMcp/Sections/Character.lua +177 -0
- package/addon/WowMcp/Sections/Cooldowns.lua +76 -0
- package/addon/WowMcp/Sections/Currencies.lua +47 -0
- package/addon/WowMcp/Sections/Deaths.lua +43 -0
- package/addon/WowMcp/Sections/Dungeons.lua +117 -0
- package/addon/WowMcp/Sections/EquipmentSets.lua +83 -0
- package/addon/WowMcp/Sections/FlightPaths.lua +145 -0
- package/addon/WowMcp/Sections/Friends.lua +70 -0
- package/addon/WowMcp/Sections/Group.lua +101 -0
- package/addon/WowMcp/Sections/Guide.lua +317 -0
- package/addon/WowMcp/Sections/Guild.lua +131 -0
- package/addon/WowMcp/Sections/Inspect.lua +100 -0
- package/addon/WowMcp/Sections/Inventory.lua +64 -0
- package/addon/WowMcp/Sections/Legacy.lua +375 -0
- package/addon/WowMcp/Sections/Loot.lua +170 -0
- package/addon/WowMcp/Sections/Macros.lua +26 -0
- package/addon/WowMcp/Sections/Mail.lua +70 -0
- package/addon/WowMcp/Sections/Note.lua +38 -0
- package/addon/WowMcp/Sections/Pet.lua +127 -0
- package/addon/WowMcp/Sections/Played.lua +52 -0
- package/addon/WowMcp/Sections/Probe.lua +79 -0
- package/addon/WowMcp/Sections/Professions.lua +129 -0
- package/addon/WowMcp/Sections/Pvp.lua +45 -0
- package/addon/WowMcp/Sections/QuestDb.lua +106 -0
- package/addon/WowMcp/Sections/QuestGiver.lua +45 -0
- package/addon/WowMcp/Sections/Quests.lua +146 -0
- package/addon/WowMcp/Sections/Recipes.lua +195 -0
- package/addon/WowMcp/Sections/Reputation.lua +56 -0
- package/addon/WowMcp/Sections/Spells.lua +87 -0
- package/addon/WowMcp/Sections/Stable.lua +90 -0
- package/addon/WowMcp/Sections/Talents.lua +137 -0
- package/addon/WowMcp/Sections/Trainer.lua +58 -0
- package/addon/WowMcp/Sections/Vendor.lua +72 -0
- package/addon/WowMcp/Sections/XpGains.lua +258 -0
- package/addon/WowMcp/Snapshot.lua +412 -0
- package/addon/WowMcp/Store.lua +142 -0
- package/addon/WowMcp/TalentGrid.lua +171 -0
- package/addon/WowMcp/Timing.lua +61 -0
- package/addon/WowMcp/TraitTree.lua +158 -0
- package/addon/WowMcp/WowMcp.lua +24 -0
- package/addon/WowMcp/WowMcp.toc +72 -0
- package/bin/wow-mcp.js +248 -0
- package/package.json +41 -4
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
-- SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
-- Copyright (C) 2026 Piekasz (GitHub: Piekario). Author attribution must be kept: see NOTICE.
|
|
3
|
+
|
|
4
|
+
-- QuestDb: where quests start and end, read from the quest database of another addon the player has installed
|
|
5
|
+
-- (QuestieDB, the database Questie uses; global LibQuestieDB). The client itself has no API for "which NPC ends
|
|
6
|
+
-- this quest and where does it stand", and the quest text is often out of date, so this is the only source that
|
|
7
|
+
-- matches what the player sees on the map. WowMcp ships no quest data of its own: without QuestieDB every
|
|
8
|
+
-- function here returns nil.
|
|
9
|
+
--
|
|
10
|
+
-- Only reads (entity Get / IdsByName and C_Map.GetAreaInfo); never registers corrections or changes that addon.
|
|
11
|
+
-- Every read is wrapped in pcall: a change in the other addon costs a field, not the dump.
|
|
12
|
+
|
|
13
|
+
local _, ns = ...
|
|
14
|
+
local plain = ns.Compat.plain
|
|
15
|
+
local round1 = ns.round1
|
|
16
|
+
|
|
17
|
+
local QuestDb = {}
|
|
18
|
+
ns.QuestDb = QuestDb
|
|
19
|
+
|
|
20
|
+
QuestDb.MAX_LOCATIONS = 3 -- sample coordinates per NPC or object
|
|
21
|
+
QuestDb.MAX_ZONES = 4 -- zone names listed for something that spawns in many zones
|
|
22
|
+
QuestDb.MAX_TARGETS = 4 -- starters, finishers or objective targets listed per quest
|
|
23
|
+
QuestDb.MAX_MATCHES = 8 -- quests or NPCs returned for one name search
|
|
24
|
+
|
|
25
|
+
local function lib()
|
|
26
|
+
local db = _G.LibQuestieDB
|
|
27
|
+
if type(db) ~= "table" then return nil end
|
|
28
|
+
if type(db.Quest) ~= "table" or type(db.Npc) ~= "table" then return nil end
|
|
29
|
+
return db
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
function QuestDb.available()
|
|
33
|
+
return lib() ~= nil
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
-- Who supplies the data: goes into the dump so an answer can name its source.
|
|
37
|
+
function QuestDb.source()
|
|
38
|
+
local db = lib()
|
|
39
|
+
if not db then return nil end
|
|
40
|
+
local version
|
|
41
|
+
local getMeta = (C_AddOns and C_AddOns.GetAddOnMetadata) or _G.GetAddOnMetadata
|
|
42
|
+
if type(getMeta) == "function" and type(db.addonName) == "string" then
|
|
43
|
+
local ok, value = pcall(getMeta, db.addonName, "Version")
|
|
44
|
+
if ok then version = plain(value) end
|
|
45
|
+
end
|
|
46
|
+
return { name = "QuestieDB", version = version, contract = plain(db.contractVersion), readMode = plain(db.readMode) }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
-- One field of an entity ("Quest", "Npc", "Object", "Item"), or nil.
|
|
50
|
+
local function field(entityName, id, key)
|
|
51
|
+
local db = lib()
|
|
52
|
+
local entity = db and db[entityName]
|
|
53
|
+
if type(entity) ~= "table" or type(entity.Get) ~= "function" then return nil end
|
|
54
|
+
local ok, value = pcall(entity.Get, id, key)
|
|
55
|
+
if ok then return value end
|
|
56
|
+
return nil
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
local function exists(entityName, id)
|
|
60
|
+
local db = lib()
|
|
61
|
+
local entity = db and db[entityName]
|
|
62
|
+
if type(entity) ~= "table" or type(entity.Exists) ~= "function" then return false end
|
|
63
|
+
local ok, value = pcall(entity.Exists, id)
|
|
64
|
+
return ok and value == true
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
-- The database stores some strings as byte strings; both arrive as Lua strings.
|
|
68
|
+
local function text(value)
|
|
69
|
+
if type(value) == "string" and value ~= "" then return value end
|
|
70
|
+
return nil
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
local function positive(value)
|
|
74
|
+
if type(value) == "number" and value > 0 then return value end
|
|
75
|
+
return nil
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
-- Zone (area) name in the client's language, or nil.
|
|
79
|
+
function QuestDb.areaName(areaID)
|
|
80
|
+
if type(areaID) ~= "number" or areaID <= 0 then return nil end
|
|
81
|
+
if not (C_Map and C_Map.GetAreaInfo) then return nil end
|
|
82
|
+
local ok, name = pcall(C_Map.GetAreaInfo, areaID)
|
|
83
|
+
if ok then return text(plain(name)) end
|
|
84
|
+
return nil
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
local function sortedKeys(map)
|
|
88
|
+
local keys = {}
|
|
89
|
+
for key in pairs(map) do
|
|
90
|
+
if type(key) == "number" then keys[#keys + 1] = key end
|
|
91
|
+
end
|
|
92
|
+
table.sort(keys)
|
|
93
|
+
return keys
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
-- Spawns ({ [areaID] = { {x, y}, ... } }) as a short description: sample coordinates (the entity's main zone
|
|
97
|
+
-- first), the number of spawn points and the zones. A point of (-1, -1) means "inside this instance".
|
|
98
|
+
local function describeSpawns(target, spawns, mainArea)
|
|
99
|
+
if type(spawns) ~= "table" then return end
|
|
100
|
+
local areas = sortedKeys(spawns)
|
|
101
|
+
if type(mainArea) == "number" and spawns[mainArea] then
|
|
102
|
+
table.sort(areas, function(a, b)
|
|
103
|
+
if (a == mainArea) ~= (b == mainArea) then return a == mainArea end
|
|
104
|
+
return a < b
|
|
105
|
+
end)
|
|
106
|
+
end
|
|
107
|
+
local locations, zones, count = {}, {}, 0
|
|
108
|
+
for _, areaID in ipairs(areas) do
|
|
109
|
+
local points = spawns[areaID]
|
|
110
|
+
if type(points) == "table" then
|
|
111
|
+
local zone = QuestDb.areaName(areaID)
|
|
112
|
+
if #zones < QuestDb.MAX_ZONES then zones[#zones + 1] = zone or ("area " .. areaID) end
|
|
113
|
+
for _, point in ipairs(points) do
|
|
114
|
+
count = count + 1
|
|
115
|
+
if #locations < QuestDb.MAX_LOCATIONS and type(point) == "table" then
|
|
116
|
+
local x, y = point[1], point[2]
|
|
117
|
+
if x == -1 and y == -1 then
|
|
118
|
+
locations[#locations + 1] = { zone = zone, areaID = areaID, inInstance = true }
|
|
119
|
+
elseif type(x) == "number" and type(y) == "number" then
|
|
120
|
+
locations[#locations + 1] = { zone = zone, areaID = areaID, x = round1(x), y = round1(y) }
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
if count == 0 then return end
|
|
127
|
+
target.locations = locations
|
|
128
|
+
target.spawnCount = count
|
|
129
|
+
if #areas > 1 then
|
|
130
|
+
target.zones = zones
|
|
131
|
+
target.zoneCount = #areas
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
function QuestDb.npc(id)
|
|
136
|
+
if type(id) ~= "number" or not exists("Npc", id) then return nil end
|
|
137
|
+
local target = {
|
|
138
|
+
kind = "npc",
|
|
139
|
+
id = id,
|
|
140
|
+
name = text(field("Npc", id, "name")),
|
|
141
|
+
title = text(field("Npc", id, "subName")),
|
|
142
|
+
friendlyTo = text(field("Npc", id, "friendlyToFaction")),
|
|
143
|
+
minLevel = positive(field("Npc", id, "minLevel")),
|
|
144
|
+
maxLevel = positive(field("Npc", id, "maxLevel")),
|
|
145
|
+
}
|
|
146
|
+
describeSpawns(target, field("Npc", id, "spawns"), field("Npc", id, "zoneID"))
|
|
147
|
+
return target
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
function QuestDb.object(id)
|
|
151
|
+
if type(id) ~= "number" or not exists("Object", id) then return nil end
|
|
152
|
+
local target = { kind = "object", id = id, name = text(field("Object", id, "name")) }
|
|
153
|
+
describeSpawns(target, field("Object", id, "spawns"), field("Object", id, "zoneID"))
|
|
154
|
+
return target
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
-- An item is only named: where it drops is a separate (large) table we do not copy.
|
|
158
|
+
function QuestDb.item(id)
|
|
159
|
+
if type(id) ~= "number" or not exists("Item", id) then return nil end
|
|
160
|
+
return { kind = "item", id = id, name = text(field("Item", id, "name")) }
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
local DESCRIBE = { QuestDb.npc, QuestDb.object, QuestDb.item }
|
|
164
|
+
|
|
165
|
+
-- Quest givers / finishers: { npcIds?, objectIds?, itemIds? } -> list of targets (at most MAX_TARGETS).
|
|
166
|
+
local function describeGivers(givers)
|
|
167
|
+
local out, total = {}, 0
|
|
168
|
+
if type(givers) ~= "table" then return out, total end
|
|
169
|
+
for group = 1, 3 do
|
|
170
|
+
local ids = givers[group]
|
|
171
|
+
if type(ids) == "table" then
|
|
172
|
+
for _, id in ipairs(ids) do
|
|
173
|
+
total = total + 1
|
|
174
|
+
if #out < QuestDb.MAX_TARGETS then
|
|
175
|
+
out[#out + 1] = DESCRIBE[group](id) or { kind = ({ "npc", "object", "item" })[group], id = id }
|
|
176
|
+
end
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
return out, total
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
-- Objectives: { creatures, objects, items, ... }, each a list of { id, text? } -> list of targets with the
|
|
184
|
+
-- objective text. Reputation, kill credit and spell groups are left out.
|
|
185
|
+
local function describeObjectives(objectives)
|
|
186
|
+
local out = {}
|
|
187
|
+
if type(objectives) ~= "table" then return out end
|
|
188
|
+
for group = 1, 3 do
|
|
189
|
+
local entries = objectives[group]
|
|
190
|
+
if type(entries) == "table" then
|
|
191
|
+
for _, entry in ipairs(entries) do
|
|
192
|
+
if #out >= QuestDb.MAX_TARGETS then return out end
|
|
193
|
+
local id = type(entry) == "table" and entry[1] or nil
|
|
194
|
+
if type(id) == "number" then
|
|
195
|
+
local target = DESCRIBE[group](id) or { kind = ({ "npc", "object", "item" })[group], id = id }
|
|
196
|
+
target.text = text(entry[2])
|
|
197
|
+
out[#out + 1] = target
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
return out
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
local function nonEmpty(list)
|
|
206
|
+
if type(list) == "table" and #list > 0 then return list end
|
|
207
|
+
return nil
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
local function questRef(id)
|
|
211
|
+
if type(id) ~= "number" or id <= 0 or not exists("Quest", id) then return nil end
|
|
212
|
+
return { id = id, name = text(field("Quest", id, "name")) }
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
local function objectiveText(lines)
|
|
216
|
+
if type(lines) ~= "table" then return nil end
|
|
217
|
+
local parts = {}
|
|
218
|
+
for _, line in ipairs(lines) do
|
|
219
|
+
if text(line) then parts[#parts + 1] = line end
|
|
220
|
+
end
|
|
221
|
+
if #parts == 0 then return nil end
|
|
222
|
+
return table.concat(parts, " ")
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
-- Everything the database says about where a quest starts, what it needs and where it ends; nil when the
|
|
226
|
+
-- database is missing or does not know the quest.
|
|
227
|
+
function QuestDb.quest(id)
|
|
228
|
+
if type(id) ~= "number" or not exists("Quest", id) then return nil end
|
|
229
|
+
local quest = {
|
|
230
|
+
id = id,
|
|
231
|
+
name = text(field("Quest", id, "name")),
|
|
232
|
+
level = positive(field("Quest", id, "questLevel")),
|
|
233
|
+
requiredLevel = positive(field("Quest", id, "requiredLevel")),
|
|
234
|
+
objectivesText = objectiveText(field("Quest", id, "objectivesText")),
|
|
235
|
+
nextQuest = questRef(field("Quest", id, "nextQuestInChain")),
|
|
236
|
+
}
|
|
237
|
+
local zoneOrSort = field("Quest", id, "zoneOrSort")
|
|
238
|
+
if positive(zoneOrSort) then
|
|
239
|
+
quest.zone = QuestDb.areaName(zoneOrSort)
|
|
240
|
+
quest.zoneAreaID = zoneOrSort
|
|
241
|
+
end
|
|
242
|
+
local starters, starterCount = describeGivers(field("Quest", id, "startedBy"))
|
|
243
|
+
local finishers, finisherCount = describeGivers(field("Quest", id, "finishedBy"))
|
|
244
|
+
quest.startedBy = nonEmpty(starters)
|
|
245
|
+
quest.finishedBy = nonEmpty(finishers)
|
|
246
|
+
if starterCount > #starters then quest.startedByCount = starterCount end
|
|
247
|
+
if finisherCount > #finishers then quest.finishedByCount = finisherCount end
|
|
248
|
+
quest.objectives = nonEmpty(describeObjectives(field("Quest", id, "objectives")))
|
|
249
|
+
return quest
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
-- IDs whose name equals the given text exactly (the database's own name index; the first call builds it).
|
|
253
|
+
local function idsByName(entityName, name)
|
|
254
|
+
local db = lib()
|
|
255
|
+
local entity = db and db[entityName]
|
|
256
|
+
if type(entity) ~= "table" or type(entity.IdsByName) ~= "function" then return {} end
|
|
257
|
+
local ok, ids = pcall(entity.IdsByName, name)
|
|
258
|
+
if ok and type(ids) == "table" then return ids end
|
|
259
|
+
return {}
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
-- Capitalizes the first letter of every word, so "the glowing shard" finds "The Glowing Shard".
|
|
263
|
+
local function titleCase(name)
|
|
264
|
+
return (name:gsub("(%a)([%w']*)", function(first, rest) return first:upper() .. rest end))
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
local function nameCandidates(name)
|
|
268
|
+
local candidates = { name }
|
|
269
|
+
local cased = titleCase(name)
|
|
270
|
+
if cased ~= name then candidates[#candidates + 1] = cased end
|
|
271
|
+
return candidates
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
-- Looks a quest or NPC up by ID or by exact name (also with every word capitalized). Returns
|
|
275
|
+
-- { quests = { ... }, npcs = { ... } }, both possibly empty; nil when there is no database.
|
|
276
|
+
function QuestDb.lookup(query)
|
|
277
|
+
if not QuestDb.available() then return nil end
|
|
278
|
+
local result = { quests = {}, npcs = {} }
|
|
279
|
+
query = tostring(query or ""):match("^%s*(.-)%s*$")
|
|
280
|
+
local id = tonumber(query)
|
|
281
|
+
if id then
|
|
282
|
+
result.quests[1] = QuestDb.quest(id)
|
|
283
|
+
if #result.quests == 0 then result.npcs[1] = QuestDb.npc(id) end
|
|
284
|
+
return result
|
|
285
|
+
end
|
|
286
|
+
if query == "" then return result end
|
|
287
|
+
local seen = {}
|
|
288
|
+
for _, name in ipairs(nameCandidates(query)) do
|
|
289
|
+
for _, questID in ipairs(idsByName("Quest", name)) do
|
|
290
|
+
if not seen["q" .. questID] and #result.quests < QuestDb.MAX_MATCHES then
|
|
291
|
+
seen["q" .. questID] = true
|
|
292
|
+
result.quests[#result.quests + 1] = QuestDb.quest(questID)
|
|
293
|
+
end
|
|
294
|
+
end
|
|
295
|
+
for _, npcID in ipairs(idsByName("Npc", name)) do
|
|
296
|
+
if not seen["n" .. npcID] and #result.npcs < QuestDb.MAX_MATCHES then
|
|
297
|
+
seen["n" .. npcID] = true
|
|
298
|
+
result.npcs[#result.npcs + 1] = QuestDb.npc(npcID)
|
|
299
|
+
end
|
|
300
|
+
end
|
|
301
|
+
end
|
|
302
|
+
return result
|
|
303
|
+
end
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
-- SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
-- Copyright (C) 2026 Piekasz (GitHub: Piekario). Author attribution must be kept: see NOTICE.
|
|
3
|
+
|
|
4
|
+
-- Quest rewards: choosable items (choices), fixed items (items), money and experience.
|
|
5
|
+
-- Shared by the quest log (Sections/Quests) and the quest giver window (Sections/QuestGiver).
|
|
6
|
+
-- Read-only: the addon never chooses or turns in anything.
|
|
7
|
+
|
|
8
|
+
local _, ns = ...
|
|
9
|
+
local plain, callFirst, firstValue = ns.Compat.plain, ns.Compat.callFirst, ns.Compat.firstValue
|
|
10
|
+
local Items = ns.Items
|
|
11
|
+
|
|
12
|
+
local QuestRewards = {}
|
|
13
|
+
ns.QuestRewards = QuestRewards
|
|
14
|
+
|
|
15
|
+
local function positive(value)
|
|
16
|
+
value = plain(value)
|
|
17
|
+
if type(value) == "number" and value > 0 then return value end
|
|
18
|
+
return nil
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
-- Reward item from results of the form name, texture, count, quality, isUsable, itemID.
|
|
22
|
+
local function rewardItem(info, link, readTooltip)
|
|
23
|
+
info = info or {}
|
|
24
|
+
if not plain(info[1]) and not plain(link) then return nil end
|
|
25
|
+
local item = {
|
|
26
|
+
name = plain(info[1]),
|
|
27
|
+
count = positive(info[3]) or 1,
|
|
28
|
+
quality = plain(info[4]),
|
|
29
|
+
id = plain(info[6]),
|
|
30
|
+
}
|
|
31
|
+
if info[5] == false then item.usable = false end
|
|
32
|
+
return Items.describe(item, plain(link), readTooltip)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
-- Item list: count is the number of entries, read(i) returns { info, link, readTooltip }.
|
|
36
|
+
local function rewardList(count, read)
|
|
37
|
+
local list = {}
|
|
38
|
+
for i = 1, (type(count) == "number" and count or 0) do
|
|
39
|
+
local info, link, readTooltip = read(i)
|
|
40
|
+
local item = rewardItem(info, link, readTooltip)
|
|
41
|
+
if item then list[#list + 1] = item end
|
|
42
|
+
end
|
|
43
|
+
if #list == 0 then return nil end
|
|
44
|
+
return list
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
-- Currencies in the reward (new API): { name, id, count }.
|
|
48
|
+
local function rewardCurrencies(questID)
|
|
49
|
+
local r = callFirst({ "C_QuestLog.GetQuestRewardCurrencies", "C_QuestInfoSystem.GetQuestRewardCurrencies" }, questID)
|
|
50
|
+
if not r or type(r[1]) ~= "table" then return nil end
|
|
51
|
+
local list = {}
|
|
52
|
+
for _, c in ipairs(r[1]) do
|
|
53
|
+
if type(c) == "table" and plain(c.name) then
|
|
54
|
+
list[#list + 1] = { name = plain(c.name), id = plain(c.currencyID), count = plain(c.totalRewardAmount) }
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
if #list == 0 then return nil end
|
|
58
|
+
return list
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
-- Returns the rewards, or nil when the quest gives nothing (or the client supplied nothing).
|
|
62
|
+
local function nonEmpty(rewards)
|
|
63
|
+
if next(rewards) == nil then return nil end
|
|
64
|
+
return rewards
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
---------------------------------------------------------------------------
|
|
68
|
+
-- Quest log
|
|
69
|
+
---------------------------------------------------------------------------
|
|
70
|
+
|
|
71
|
+
-- Reads the i-th reward entry of the quest with the given ID (new API).
|
|
72
|
+
local function byQuestID(paths, questID)
|
|
73
|
+
return function(i)
|
|
74
|
+
local info = callFirst(paths, i, questID) -- without the second result (function paths)
|
|
75
|
+
return info
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
-- The new API takes the quest ID, so there is no need to select the quest in the log.
|
|
80
|
+
function QuestRewards.fromLog(questID)
|
|
81
|
+
if not questID then return nil end
|
|
82
|
+
return nonEmpty({
|
|
83
|
+
choices = rewardList(firstValue({ "GetNumQuestLogChoices" }, questID), byQuestID({ "GetQuestLogChoiceInfo" }, questID)),
|
|
84
|
+
items = rewardList(firstValue({ "GetNumQuestLogRewards" }, questID), byQuestID({ "GetQuestLogRewardInfo" }, questID)),
|
|
85
|
+
money = positive(firstValue({ "GetQuestLogRewardMoney" }, questID)),
|
|
86
|
+
xp = positive(firstValue({ "GetQuestLogRewardXP" }, questID)),
|
|
87
|
+
currencies = rewardCurrencies(questID),
|
|
88
|
+
})
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
-- The old API reads rewards of the selected quest. We select an entry only for the duration of the read
|
|
92
|
+
-- and restore the previous selection right away (the player sees no change).
|
|
93
|
+
-- Without GetQuestLogSelection we could not restore the selection, so then we skip the rewards.
|
|
94
|
+
-- Reads the i-th reward entry of the selected quest (old API) with the item link.
|
|
95
|
+
local function selectedQuestItem(kind, paths)
|
|
96
|
+
return function(i) return callFirst(paths, i), firstValue({ "GetQuestLogItemLink" }, kind, i) end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
local function selectedQuestRewards()
|
|
100
|
+
return nonEmpty({
|
|
101
|
+
choices = rewardList(firstValue({ "GetNumQuestLogChoices" }), selectedQuestItem("choice", { "GetQuestLogChoiceInfo" })),
|
|
102
|
+
items = rewardList(firstValue({ "GetNumQuestLogRewards" }), selectedQuestItem("reward", { "GetQuestLogRewardInfo" })),
|
|
103
|
+
money = positive(firstValue({ "GetQuestLogRewardMoney" })),
|
|
104
|
+
xp = positive(firstValue({ "GetQuestLogRewardXP" })),
|
|
105
|
+
})
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
function QuestRewards.fromLogEntry(questIndex)
|
|
109
|
+
if not (GetQuestLogSelection and SelectQuestLogEntry) then return nil end
|
|
110
|
+
local previous = GetQuestLogSelection()
|
|
111
|
+
SelectQuestLogEntry(questIndex)
|
|
112
|
+
local ok, rewards = pcall(selectedQuestRewards)
|
|
113
|
+
SelectQuestLogEntry(previous or 0)
|
|
114
|
+
if ok then return rewards end
|
|
115
|
+
return nil
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
---------------------------------------------------------------------------
|
|
119
|
+
-- Quest giver window (QUEST_DETAIL, QUEST_COMPLETE)
|
|
120
|
+
---------------------------------------------------------------------------
|
|
121
|
+
|
|
122
|
+
local function giverItem(kind)
|
|
123
|
+
return function(i)
|
|
124
|
+
local readTooltip = function() return ns.Compat.tooltipFor("GetQuestItem", kind, i) end
|
|
125
|
+
return callFirst({ "GetQuestItemInfo" }, kind, i), firstValue({ "GetQuestItemLink" }, kind, i), readTooltip
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
-- Rewards shown in the open quest window at an NPC.
|
|
130
|
+
function QuestRewards.fromGiver()
|
|
131
|
+
return nonEmpty({
|
|
132
|
+
choices = rewardList(firstValue({ "GetNumQuestChoices" }), giverItem("choice")),
|
|
133
|
+
items = rewardList(firstValue({ "GetNumQuestRewards" }), giverItem("reward")),
|
|
134
|
+
money = positive(firstValue({ "GetRewardMoney" })),
|
|
135
|
+
xp = positive(firstValue({ "GetRewardXP" })),
|
|
136
|
+
})
|
|
137
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
-- SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
-- Copyright (C) 2026 Piekasz (GitHub: Piekario). Author attribution must be kept: see NOTICE.
|
|
3
|
+
|
|
4
|
+
-- Section actionBars: what sits under which button. Helps with building rotations.
|
|
5
|
+
|
|
6
|
+
local _, ns = ...
|
|
7
|
+
local plain, callFirst, firstValue = ns.Compat.plain, ns.Compat.callFirst, ns.Compat.firstValue
|
|
8
|
+
|
|
9
|
+
local ACTION_SLOTS = 180
|
|
10
|
+
local BUTTONS_PER_BAR = 12
|
|
11
|
+
|
|
12
|
+
-- Name of what is in the slot: a spell, item or macro; otherwise the button text.
|
|
13
|
+
local function actionName(slot, kind, id)
|
|
14
|
+
local name
|
|
15
|
+
if kind == "spell" and id then
|
|
16
|
+
name = firstValue({ "C_Spell.GetSpellName" }, id)
|
|
17
|
+
elseif kind == "item" and id then
|
|
18
|
+
name = firstValue({ "C_Item.GetItemNameByID", "C_Item.GetItemInfo", "GetItemInfo" }, id)
|
|
19
|
+
elseif kind == "macro" and id then
|
|
20
|
+
name = firstValue({ "GetMacroInfo" }, id)
|
|
21
|
+
end
|
|
22
|
+
return name or firstValue({ "GetActionText" }, slot)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
local function action(slot)
|
|
26
|
+
local info = callFirst({ "GetActionInfo", "C_ActionBar.GetActionInfo" }, slot)
|
|
27
|
+
local kind, id = info and plain(info[1]), info and plain(info[2])
|
|
28
|
+
local entry = {
|
|
29
|
+
slot = slot,
|
|
30
|
+
bar = math.floor((slot - 1) / BUTTONS_PER_BAR) + 1,
|
|
31
|
+
button = (slot - 1) % BUTTONS_PER_BAR + 1,
|
|
32
|
+
kind = kind,
|
|
33
|
+
id = id,
|
|
34
|
+
name = actionName(slot, kind, id),
|
|
35
|
+
}
|
|
36
|
+
-- ACTIONBUTTON1-12 bindings apply only to the main bar.
|
|
37
|
+
if slot <= BUTTONS_PER_BAR then
|
|
38
|
+
entry.key = firstValue({ "GetBindingKey" }, "ACTIONBUTTON" .. slot)
|
|
39
|
+
end
|
|
40
|
+
return entry
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
local function collectActionBars()
|
|
44
|
+
local actions = {}
|
|
45
|
+
for slot = 1, ACTION_SLOTS do
|
|
46
|
+
local has = callFirst({ "HasAction", "C_ActionBar.HasAction" }, slot)
|
|
47
|
+
if has and has[1] then
|
|
48
|
+
actions[#actions + 1] = action(slot)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
return actions
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
ns.Snapshot.addSection("actionBars", collectActionBars)
|