@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,317 @@
|
|
|
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
|
+
-- Guide: the leveling guide the player follows in the Guidelime addon (for example a TUGs guide) and how far
|
|
5
|
+
-- they are in it, so the assistant can answer "what is my next step" from the guide instead of from memory.
|
|
6
|
+
--
|
|
7
|
+
-- Guidelime keeps its parsed guides private. What another addon can see is:
|
|
8
|
+
-- * the guide texts, at the moment a guide addon registers them (Guidelime.registerGuide; we listen with
|
|
9
|
+
-- hooksecurefunc, which runs after the original and cannot change it), and
|
|
10
|
+
-- * GuidelimeDataChar: the name of the current guide and the steps the player ticked or skipped by hand.
|
|
11
|
+
-- Quest steps Guidelime completes by itself are not stored there, so their state is read from the quest log.
|
|
12
|
+
-- WowMcp ships no guide text; the dump holds only the next few steps of the player's own installed guide.
|
|
13
|
+
--
|
|
14
|
+
-- Only reads. Nothing here calls into Guidelime or changes its data.
|
|
15
|
+
|
|
16
|
+
local _, ns = ...
|
|
17
|
+
local plain = ns.Compat.plain
|
|
18
|
+
|
|
19
|
+
local Guide = {}
|
|
20
|
+
ns.Guide = Guide
|
|
21
|
+
|
|
22
|
+
Guide.MAX_NEXT_STEPS = 15
|
|
23
|
+
Guide.MAX_PASSED_STEPS = 5 -- open steps before the furthest done step that may take places in the list
|
|
24
|
+
Guide.MAX_STEP_TEXT = 400
|
|
25
|
+
|
|
26
|
+
local registered = {} -- { text, group } in registration order
|
|
27
|
+
local lastQuestIDs = {} -- quest IDs of the steps listed by the last collect()
|
|
28
|
+
|
|
29
|
+
---------------------------------------------------------------------------
|
|
30
|
+
-- Guide texts
|
|
31
|
+
---------------------------------------------------------------------------
|
|
32
|
+
|
|
33
|
+
function Guide.remember(text, group)
|
|
34
|
+
if type(text) ~= "string" then return end
|
|
35
|
+
registered[#registered + 1] = { text = text, group = type(group) == "string" and group or nil }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
function Guide.registeredCount()
|
|
39
|
+
return #registered
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
-- Listens for guide registrations. Guidelime must already be loaded (## OptionalDeps in the .toc), and the
|
|
43
|
+
-- guide addons, which depend on Guidelime, load after it.
|
|
44
|
+
function Guide.listen()
|
|
45
|
+
local guidelime = _G.Guidelime
|
|
46
|
+
if type(guidelime) ~= "table" or type(guidelime.registerGuide) ~= "function" then return false end
|
|
47
|
+
if type(hooksecurefunc) ~= "function" then return false end
|
|
48
|
+
return (pcall(hooksecurefunc, guidelime, "registerGuide", Guide.remember))
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
local function squeeze(text)
|
|
52
|
+
return (tostring(text or ""):gsub("%s+", ""))
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
-- Content of the first [<code>...] tag in the text, e.g. tagContent(text, "NX").
|
|
56
|
+
local function tagContent(text, code)
|
|
57
|
+
return text:match("%[" .. code .. "%s*([^%]]-)%s*%]")
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
-- Guidelime names a guide "<group> <min>-<max> <title>" from the group and the [N...] tag. Whitespace is
|
|
61
|
+
-- ignored in the comparison, so the exact spacing rules do not matter.
|
|
62
|
+
local function guideName(entry)
|
|
63
|
+
local group = entry.group or ""
|
|
64
|
+
if group:sub(1, 10) == "Guidelime_" then group = group:sub(11) end
|
|
65
|
+
local title = entry.text:match("%[N([^X%]][^%]]*)%]") or ""
|
|
66
|
+
return squeeze(group .. title)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
function Guide.findText(name)
|
|
70
|
+
local wanted = squeeze(name)
|
|
71
|
+
if wanted == "" then return nil end
|
|
72
|
+
for i = #registered, 1, -1 do -- a guide registered twice: the last one wins, as in Guidelime
|
|
73
|
+
if guideName(registered[i]) == wanted then return registered[i].text end
|
|
74
|
+
end
|
|
75
|
+
return nil
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
---------------------------------------------------------------------------
|
|
79
|
+
-- Steps
|
|
80
|
+
---------------------------------------------------------------------------
|
|
81
|
+
|
|
82
|
+
local HEADER_CODES = { GA = true, N = true, NX = true, D = true, DL = true }
|
|
83
|
+
local QUEST_ACTIONS = { A = "accept", P = "accept", C = "complete", W = "complete", T = "turnin", S = "skip" }
|
|
84
|
+
|
|
85
|
+
-- Non-empty lines of a guide with their line numbers. Guidelime counts every line break (also the two of a
|
|
86
|
+
-- CRLF pair) and keys the player's progress by that number, so the counting here must match it.
|
|
87
|
+
function Guide.lines(text)
|
|
88
|
+
local out, number = {}, 1
|
|
89
|
+
local rest = text:gsub("([^\n\r]-)[\n\r]", function(line)
|
|
90
|
+
if line ~= "" then out[#out + 1] = { line = number, text = line } end
|
|
91
|
+
number = number + 1
|
|
92
|
+
return ""
|
|
93
|
+
end)
|
|
94
|
+
if rest ~= "" then out[#out + 1] = { line = number, text = rest } end
|
|
95
|
+
return out
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
local function questTags(text)
|
|
99
|
+
local quests = {}
|
|
100
|
+
for code, id, rest in text:gmatch("%[Q(%u)%s*(%d+)([^%]]*)%]") do
|
|
101
|
+
local action = QUEST_ACTIONS[code]
|
|
102
|
+
if action then
|
|
103
|
+
quests[#quests + 1] = { id = tonumber(id), action = action, objective = tonumber(rest:match("^,%s*(%d+)")) }
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
return quests
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
-- A step from one guide line; nil for a header line (guide name, next guide, description).
|
|
110
|
+
function Guide.parseStep(entry)
|
|
111
|
+
local code = entry.text:match("^%s*%[(%u+)")
|
|
112
|
+
if code and HEADER_CODES[code] then return nil end
|
|
113
|
+
local step = { line = entry.line, text = entry.text, quests = questTags(entry.text) }
|
|
114
|
+
step.applies = tagContent(entry.text, "A%s")
|
|
115
|
+
if entry.text:find("%[OC?%]") then step.optional = true end
|
|
116
|
+
return step
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
---------------------------------------------------------------------------
|
|
120
|
+
-- Who the step is for
|
|
121
|
+
---------------------------------------------------------------------------
|
|
122
|
+
|
|
123
|
+
local RACES = {
|
|
124
|
+
human = true, dwarf = true, nightelf = true, gnome = true, orc = true, undead = true, tauren = true, troll = true,
|
|
125
|
+
draenei = true, bloodelf = true, worgen = true, goblin = true, pandaren = true,
|
|
126
|
+
}
|
|
127
|
+
local CLASSES = {
|
|
128
|
+
warrior = true, paladin = true, hunter = true, rogue = true, priest = true, shaman = true, mage = true,
|
|
129
|
+
warlock = true, druid = true, deathknight = true, monk = true,
|
|
130
|
+
}
|
|
131
|
+
local FACTIONS = { alliance = true, horde = true }
|
|
132
|
+
local RACE_TOKEN_NAMES = { scourge = "undead" } -- the client's token for Undead
|
|
133
|
+
|
|
134
|
+
local function token(value)
|
|
135
|
+
return squeeze(plain(value) or ""):lower()
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
-- The player's race, class and faction as the lower-case English words guides use.
|
|
139
|
+
function Guide.player()
|
|
140
|
+
local _, raceToken = UnitRace("player")
|
|
141
|
+
local _, classToken = UnitClass("player")
|
|
142
|
+
local race = token(raceToken)
|
|
143
|
+
return { race = RACE_TOKEN_NAMES[race] or race, class = token(classToken), faction = token(UnitFactionGroup("player")) }
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
-- Whether a step restricted by [A Orc, Troll] (races, classes, a faction) is for this player. Races and
|
|
147
|
+
-- classes restrict separately; words we do not know restrict nothing.
|
|
148
|
+
function Guide.appliesTo(applies, player)
|
|
149
|
+
if type(applies) ~= "string" then return true end
|
|
150
|
+
local races, classes, factions = {}, {}, {}
|
|
151
|
+
for word in applies:gmatch("[^,]+") do
|
|
152
|
+
word = squeeze(word):lower()
|
|
153
|
+
if RACES[word] then races[#races + 1] = word
|
|
154
|
+
elseif CLASSES[word] then classes[#classes + 1] = word
|
|
155
|
+
elseif FACTIONS[word] then factions[#factions + 1] = word end
|
|
156
|
+
end
|
|
157
|
+
local function allows(list, value)
|
|
158
|
+
if #list == 0 then return true end
|
|
159
|
+
for _, word in ipairs(list) do
|
|
160
|
+
if word == value then return true end
|
|
161
|
+
end
|
|
162
|
+
return false
|
|
163
|
+
end
|
|
164
|
+
return allows(races, player.race) and allows(classes, player.class) and allows(factions, player.faction)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
---------------------------------------------------------------------------
|
|
168
|
+
-- Quest state
|
|
169
|
+
---------------------------------------------------------------------------
|
|
170
|
+
|
|
171
|
+
-- Quests in the log: { [questID] = "complete" | "active" }.
|
|
172
|
+
function Guide.logState()
|
|
173
|
+
local state = {}
|
|
174
|
+
if C_QuestLog and C_QuestLog.GetNumQuestLogEntries and C_QuestLog.GetInfo then
|
|
175
|
+
for i = 1, C_QuestLog.GetNumQuestLogEntries() or 0 do
|
|
176
|
+
local info = C_QuestLog.GetInfo(i)
|
|
177
|
+
local id = info and not info.isHeader and plain(info.questID)
|
|
178
|
+
if id then
|
|
179
|
+
local complete = C_QuestLog.IsComplete and C_QuestLog.IsComplete(id)
|
|
180
|
+
state[id] = complete and "complete" or "active"
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
elseif GetNumQuestLogEntries and GetQuestLogTitle then
|
|
184
|
+
for i = 1, GetNumQuestLogEntries() or 0 do
|
|
185
|
+
local _, _, _, isHeader, _, isComplete, _, questID = GetQuestLogTitle(i)
|
|
186
|
+
questID = plain(questID)
|
|
187
|
+
if not isHeader and questID then
|
|
188
|
+
state[questID] = (isComplete == 1 or isComplete == true) and "complete" or "active"
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
return state
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
local function turnedIn(questID)
|
|
196
|
+
local results = ns.Compat.callFirst({ "C_QuestLog.IsQuestFlaggedCompleted", "IsQuestFlaggedCompleted" }, questID)
|
|
197
|
+
return results ~= nil and results[1] == true
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
local function objectiveFinished(questID, index)
|
|
201
|
+
if not (index and C_QuestLog and C_QuestLog.GetQuestObjectives) then return false end
|
|
202
|
+
local ok, objectives = pcall(C_QuestLog.GetQuestObjectives, questID)
|
|
203
|
+
local objective = ok and type(objectives) == "table" and objectives[index]
|
|
204
|
+
return type(objective) == "table" and objective.finished == true
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
-- Whether the quest part of a step is already behind the player.
|
|
208
|
+
local function questDone(quest, log)
|
|
209
|
+
if quest.action == "skip" then return true end
|
|
210
|
+
if turnedIn(quest.id) then return true end
|
|
211
|
+
if quest.action == "accept" then return log[quest.id] ~= nil end
|
|
212
|
+
if quest.action == "complete" then
|
|
213
|
+
return log[quest.id] == "complete" or (log[quest.id] ~= nil and objectiveFinished(quest.id, quest.objective))
|
|
214
|
+
end
|
|
215
|
+
return false -- turnin: only a quest flagged completed counts
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
local function allQuestsDone(step, log)
|
|
219
|
+
if #step.quests == 0 then return false end
|
|
220
|
+
for _, quest in ipairs(step.quests) do
|
|
221
|
+
if not questDone(quest, log) then return false end
|
|
222
|
+
end
|
|
223
|
+
return true
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
---------------------------------------------------------------------------
|
|
227
|
+
-- Section
|
|
228
|
+
---------------------------------------------------------------------------
|
|
229
|
+
|
|
230
|
+
local function tickedByPlayer(progress, line)
|
|
231
|
+
local entry = type(progress) == "table" and progress[line]
|
|
232
|
+
return type(entry) == "table" and (entry.completed == true or entry.skip == true)
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
local function clip(text)
|
|
236
|
+
if #text <= Guide.MAX_STEP_TEXT then return text end
|
|
237
|
+
return ns.Note.clip(text, Guide.MAX_STEP_TEXT)
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
-- The player's steps of a guide text with their state, and the counts for the summary.
|
|
241
|
+
function Guide.progress(text, progress, player, log)
|
|
242
|
+
local steps, notForPlayer = {}, 0
|
|
243
|
+
local lastDone = 0
|
|
244
|
+
for _, entry in ipairs(Guide.lines(text)) do
|
|
245
|
+
local step = Guide.parseStep(entry)
|
|
246
|
+
if step then
|
|
247
|
+
if Guide.appliesTo(step.applies, player) then
|
|
248
|
+
step.done = tickedByPlayer(progress, step.line) or allQuestsDone(step, log)
|
|
249
|
+
steps[#steps + 1] = step
|
|
250
|
+
if step.done then lastDone = #steps end
|
|
251
|
+
else
|
|
252
|
+
notForPlayer = notForPlayer + 1
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
-- A step without a quest (travel, a hint) leaves no trace when it is done: once a later step is done,
|
|
257
|
+
-- the player has passed it.
|
|
258
|
+
local done = 0
|
|
259
|
+
for index, step in ipairs(steps) do
|
|
260
|
+
if not step.done and #step.quests == 0 and index < lastDone then step.done = true end
|
|
261
|
+
if step.done then done = done + 1 end
|
|
262
|
+
step.passed = (not step.done and index < lastDone) or nil
|
|
263
|
+
end
|
|
264
|
+
return steps, done, notForPlayer
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
local function collectGuide()
|
|
268
|
+
lastQuestIDs = {}
|
|
269
|
+
local data = _G.GuidelimeDataChar
|
|
270
|
+
if type(_G.Guidelime) ~= "table" or type(data) ~= "table" then return nil end
|
|
271
|
+
local name = plain(data.currentGuide)
|
|
272
|
+
if type(name) ~= "string" or name == "" then return { addon = "Guidelime" } end
|
|
273
|
+
local guide = { addon = "Guidelime", name = name }
|
|
274
|
+
local text = Guide.findText(name)
|
|
275
|
+
if not text then
|
|
276
|
+
guide.textUnavailable = true
|
|
277
|
+
guide.registeredGuides = #registered
|
|
278
|
+
return guide
|
|
279
|
+
end
|
|
280
|
+
guide.nextGuide = tagContent(text, "NX")
|
|
281
|
+
local progress = type(data.progress) == "table" and data.progress[name] or nil
|
|
282
|
+
local steps, done, notForPlayer = Guide.progress(text, progress, Guide.player(), Guide.logState())
|
|
283
|
+
guide.totalSteps = #steps
|
|
284
|
+
guide.doneSteps = done
|
|
285
|
+
guide.notForPlayer = notForPlayer > 0 and notForPlayer or nil
|
|
286
|
+
-- Open steps before the furthest done one (skipped or left for later) must not push the current step
|
|
287
|
+
-- off the list: only the first few are listed, the rest are counted.
|
|
288
|
+
guide.next = {}
|
|
289
|
+
local passed = 0
|
|
290
|
+
for _, step in ipairs(steps) do
|
|
291
|
+
if not step.done then
|
|
292
|
+
if step.passed then passed = passed + 1 end
|
|
293
|
+
local listed = #guide.next < Guide.MAX_NEXT_STEPS and (not step.passed or passed <= Guide.MAX_PASSED_STEPS)
|
|
294
|
+
if listed then
|
|
295
|
+
guide.next[#guide.next + 1] = {
|
|
296
|
+
line = step.line,
|
|
297
|
+
text = clip(step.text),
|
|
298
|
+
quests = #step.quests > 0 and step.quests or nil,
|
|
299
|
+
optional = step.optional,
|
|
300
|
+
passed = step.passed,
|
|
301
|
+
}
|
|
302
|
+
for _, quest in ipairs(step.quests) do lastQuestIDs[#lastQuestIDs + 1] = quest.id end
|
|
303
|
+
end
|
|
304
|
+
end
|
|
305
|
+
end
|
|
306
|
+
guide.passedSteps = passed > 0 and passed or nil
|
|
307
|
+
return guide
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
-- Quest IDs named by the steps of the last collected guide section (for the quest database section).
|
|
311
|
+
function Guide.pendingQuestIDs()
|
|
312
|
+
return lastQuestIDs
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
Guide.listen()
|
|
316
|
+
|
|
317
|
+
ns.Snapshot.addSection("guide", collectGuide)
|
|
@@ -0,0 +1,131 @@
|
|
|
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 guild (from the window): the player's guild and the member list the client already has in memory.
|
|
5
|
+
-- Collected on GUILD_ROSTER_UPDATE (the client sends it e.g. after the guild window opens).
|
|
6
|
+
-- The addon never asks the server for the list (no GuildRoster or C_GuildInfo.GuildRoster).
|
|
7
|
+
-- For a large guild (over 200 people) it saves only those who are online.
|
|
8
|
+
|
|
9
|
+
local _, ns = ...
|
|
10
|
+
local plain, callFirst = ns.Compat.plain, ns.Compat.callFirst
|
|
11
|
+
|
|
12
|
+
local MAX_MEMBERS = 500
|
|
13
|
+
local ONLINE_ONLY_ABOVE = 200
|
|
14
|
+
local MIN_SECONDS_BETWEEN = 5 -- the event is frequent; the same state is not read again
|
|
15
|
+
|
|
16
|
+
local lastRead = 0
|
|
17
|
+
local lastSignature
|
|
18
|
+
|
|
19
|
+
local function textOrNil(value)
|
|
20
|
+
value = plain(value)
|
|
21
|
+
if type(value) == "string" and value ~= "" then return value end
|
|
22
|
+
return nil
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
-- GetGuildRosterInfo: fullName, rank, rankIndex, level, class, zone, note, officerNote, online, status, classFileName, ...
|
|
26
|
+
local function readMember(index)
|
|
27
|
+
local info = callFirst({ "GetGuildRosterInfo", "C_GuildInfo.GetGuildRosterInfo" }, index)
|
|
28
|
+
if not info then return nil end
|
|
29
|
+
local name = textOrNil(info[1])
|
|
30
|
+
if not name then return nil end
|
|
31
|
+
return {
|
|
32
|
+
name = name, rank = textOrNil(info[2]), rankIndex = plain(info[3]), level = plain(info[4]),
|
|
33
|
+
class = textOrNil(info[5]), zone = textOrNil(info[6]), online = plain(info[9]) and true or false,
|
|
34
|
+
}
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
local function readMembers(total)
|
|
38
|
+
local onlineOnly = total > ONLINE_ONLY_ABOVE
|
|
39
|
+
local members = {}
|
|
40
|
+
for index = 1, total do
|
|
41
|
+
local member = readMember(index)
|
|
42
|
+
if member and (member.online or not onlineOnly) then
|
|
43
|
+
members[#members + 1] = member
|
|
44
|
+
if #members >= MAX_MEMBERS then break end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
return members, onlineOnly
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
local function signature(guild)
|
|
51
|
+
local parts = { tostring(guild.name), tostring(guild.rank), tostring(guild.total), tostring(guild.online) }
|
|
52
|
+
for _, m in ipairs(guild.members or {}) do
|
|
53
|
+
parts[#parts + 1] = (m.name or "") .. "|" .. (m.zone or "") .. "|" .. tostring(m.level) .. "|" .. tostring(m.online)
|
|
54
|
+
end
|
|
55
|
+
return table.concat(parts, "\n")
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
-- A character without a guild: only the fact remains instead of a list (inGuild = false), so that having no guild
|
|
59
|
+
-- can be told apart from a list the client has not shown yet.
|
|
60
|
+
local function notInGuild()
|
|
61
|
+
return { inGuild = false, capturedAt = time() }
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
local function forgetGuild()
|
|
65
|
+
ns.Snapshot.current().guild = notInGuild()
|
|
66
|
+
lastSignature = nil
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
local function collectGuild()
|
|
70
|
+
local now = time()
|
|
71
|
+
if now - lastRead < MIN_SECONDS_BETWEEN and type(ns.Snapshot.current().guild) == "table" then return nil end
|
|
72
|
+
lastRead = now
|
|
73
|
+
|
|
74
|
+
local inGuild = callFirst({ "IsInGuild" })
|
|
75
|
+
if inGuild and not plain(inGuild[1]) then
|
|
76
|
+
forgetGuild()
|
|
77
|
+
return nil
|
|
78
|
+
end
|
|
79
|
+
local mine = callFirst({ "GetGuildInfo" }, "player")
|
|
80
|
+
local guild = { inGuild = true, capturedAt = now }
|
|
81
|
+
if mine then
|
|
82
|
+
guild.name, guild.rank, guild.rankIndex = textOrNil(mine[1]), textOrNil(mine[2]), plain(mine[3])
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
-- GetNumGuildMembers: total, onlineAndMobile, online. Returns 0 without a loaded list.
|
|
86
|
+
local counts = callFirst({ "GetNumGuildMembers", "C_GuildInfo.GetNumGuildMembers" })
|
|
87
|
+
local total = counts and plain(counts[1])
|
|
88
|
+
if type(total) == "number" and total > 0 then
|
|
89
|
+
guild.total = total
|
|
90
|
+
guild.online = plain(counts[3]) or plain(counts[2])
|
|
91
|
+
guild.members, guild.onlineOnly = readMembers(total)
|
|
92
|
+
guild.onlineOnly = guild.onlineOnly or nil
|
|
93
|
+
else
|
|
94
|
+
-- List not loaded yet: keep the previous member data, refresh only the player's guild.
|
|
95
|
+
local previous = ns.Snapshot.current().guild
|
|
96
|
+
if type(previous) == "table" then
|
|
97
|
+
guild.total, guild.online, guild.members, guild.onlineOnly = previous.total, previous.online, previous.members, previous.onlineOnly
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
if not (guild.name or guild.members) then return nil end
|
|
101
|
+
|
|
102
|
+
local current = signature(guild)
|
|
103
|
+
if current == lastSignature and type(ns.Snapshot.current().guild) == "table" then return nil end
|
|
104
|
+
lastSignature = current
|
|
105
|
+
return guild
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
-- On every dump: only IsInGuild and GetGuildInfo("player") (client memory, no GuildRoster).
|
|
109
|
+
-- Without a guild: { inGuild = false }. In a guild: the previous record with the list, or just the name and rank.
|
|
110
|
+
local function refreshMembership(previous)
|
|
111
|
+
local inGuild = callFirst({ "IsInGuild" })
|
|
112
|
+
if not inGuild then return previous end -- client without this function: what was there stays
|
|
113
|
+
if not plain(inGuild[1]) then
|
|
114
|
+
if type(previous) == "table" and previous.inGuild == false then return previous end
|
|
115
|
+
return notInGuild()
|
|
116
|
+
end
|
|
117
|
+
if type(previous) == "table" and previous.inGuild ~= false then
|
|
118
|
+
previous.inGuild = true
|
|
119
|
+
return previous
|
|
120
|
+
end
|
|
121
|
+
local mine = callFirst({ "GetGuildInfo" }, "player")
|
|
122
|
+
local guild = { inGuild = true, capturedAt = time() }
|
|
123
|
+
if mine then
|
|
124
|
+
guild.name, guild.rank, guild.rankIndex = textOrNil(mine[1]), textOrNil(mine[2]), plain(mine[3])
|
|
125
|
+
end
|
|
126
|
+
return guild
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
-- GUILD_ROSTER_UPDATE: the list; PLAYER_GUILD_UPDATE: the player's name and rank (e.g. right after login).
|
|
130
|
+
ns.Snapshot.addWindowSection("guild", collectGuild, { "GUILD_ROSTER_UPDATE", "PLAYER_GUILD_UPDATE" }, { quiet = true })
|
|
131
|
+
ns.Snapshot.refreshOnDump("guild", refreshMembership)
|
|
@@ -0,0 +1,100 @@
|
|
|
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 inspect (from the window): equipment of players inspected via the Inspect window, name -> result.
|
|
5
|
+
-- We save only when the player clicked Inspect themselves (the INSPECT_READY event);
|
|
6
|
+
-- the addon sends no inspection requests.
|
|
7
|
+
|
|
8
|
+
local _, ns = ...
|
|
9
|
+
local plain, callFirst, firstValue = ns.Compat.plain, ns.Compat.callFirst, ns.Compat.firstValue
|
|
10
|
+
local round1, Items = ns.round1, ns.Items
|
|
11
|
+
|
|
12
|
+
local INSPECT_MAX = 30
|
|
13
|
+
local INSPECT_UNITS = { "target", "mouseover", "focus" }
|
|
14
|
+
local SHIRT_SLOT, TABARD_SLOT = 4, 19
|
|
15
|
+
|
|
16
|
+
local function unitMatches(unit, guid)
|
|
17
|
+
return not guid or firstValue({ "UnitGUID" }, unit) == guid
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
-- Units under which the inspected player may be found when the Inspect window does not give its own.
|
|
21
|
+
local function candidateUnits()
|
|
22
|
+
local candidates = {}
|
|
23
|
+
for _, u in ipairs(INSPECT_UNITS) do candidates[#candidates + 1] = u end
|
|
24
|
+
for i = 1, 4 do candidates[#candidates + 1] = "party" .. i end
|
|
25
|
+
for i = 1, 40 do candidates[#candidates + 1] = "raid" .. i end
|
|
26
|
+
return candidates
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
local function inspectUnitFor(guid)
|
|
30
|
+
if InspectFrame and type(InspectFrame.unit) == "string" then
|
|
31
|
+
local u = InspectFrame.unit
|
|
32
|
+
if unitMatches(u, guid) then return u end
|
|
33
|
+
end
|
|
34
|
+
for _, u in ipairs(candidateUnits()) do
|
|
35
|
+
if UnitExists and UnitExists(u) and unitMatches(u, guid) then return u end
|
|
36
|
+
end
|
|
37
|
+
return nil
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
local function inspectedItem(unit, slot)
|
|
41
|
+
local link = firstValue({ "GetInventoryItemLink" }, unit, slot)
|
|
42
|
+
if not link then return nil end
|
|
43
|
+
local item = { slot = Items.EQUIPMENT_SLOTS[slot] or tostring(slot), id = Items.idFromLink(link), name = Items.nameFromLink(link) }
|
|
44
|
+
local info = callFirst({ "C_Item.GetItemInfo", "GetItemInfo" }, link)
|
|
45
|
+
if info then
|
|
46
|
+
item.quality = plain(info[3])
|
|
47
|
+
item.itemLevel = plain(info[4])
|
|
48
|
+
end
|
|
49
|
+
return item
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
-- Adds the equipment; returns the average item level or nil.
|
|
53
|
+
local function addInspectedEquipment(out, unit)
|
|
54
|
+
local levels, sum = 0, 0
|
|
55
|
+
for slot = 1, 19 do
|
|
56
|
+
-- Shirt and tabard do not count toward item level.
|
|
57
|
+
if slot ~= SHIRT_SLOT and slot ~= TABARD_SLOT then
|
|
58
|
+
local item = inspectedItem(unit, slot)
|
|
59
|
+
if item then
|
|
60
|
+
if type(item.itemLevel) == "number" then
|
|
61
|
+
levels, sum = levels + 1, sum + item.itemLevel
|
|
62
|
+
end
|
|
63
|
+
out.equipment[#out.equipment + 1] = item
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
if levels > 0 then return round1(sum / levels) end
|
|
68
|
+
return nil
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
local function collectInspect(guid)
|
|
72
|
+
local unit = inspectUnitFor(guid)
|
|
73
|
+
if not unit then return nil end
|
|
74
|
+
local out = ns.Group.unitIdentity(unit)
|
|
75
|
+
if not out then return nil end
|
|
76
|
+
out.capturedAt = time()
|
|
77
|
+
out.equipment = {}
|
|
78
|
+
local guild = callFirst({ "GetGuildInfo" }, unit)
|
|
79
|
+
if guild then out.guild = plain(guild[1]) end
|
|
80
|
+
out.averageItemLevel = addInspectedEquipment(out, unit)
|
|
81
|
+
-- The level supplied by the client is more accurate than the average from the links.
|
|
82
|
+
local ilvl = firstValue({ "C_PaperDollInfo.GetInspectItemLevel" }, unit)
|
|
83
|
+
if type(ilvl) == "number" and ilvl > 0 then out.averageItemLevel = round1(ilvl) end
|
|
84
|
+
if #out.equipment == 0 then return nil end
|
|
85
|
+
return out
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
local function captureInspect(guid)
|
|
89
|
+
local ok, result = pcall(collectInspect, guid)
|
|
90
|
+
if not ok or not result then return end
|
|
91
|
+
local current = ns.Snapshot.current()
|
|
92
|
+
if type(current.inspect) ~= "table" then current.inspect = {} end
|
|
93
|
+
current.inspect[result.name] = result
|
|
94
|
+
-- The longest-ago inspected fall off when there are too many.
|
|
95
|
+
ns.Snapshot.keepNewest(current.inspect, INSPECT_MAX)
|
|
96
|
+
ns.Snapshot.windowCaptured("inspect")
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
ns.Snapshot.addWindowSection("inspect")
|
|
100
|
+
ns.Events.on("INSPECT_READY", ns.Snapshot.whenEnabled("inspect", captureInspect))
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
-- Sections bags (contents of equipped bags) and equipment (equipped gear).
|
|
5
|
+
|
|
6
|
+
local _, ns = ...
|
|
7
|
+
local plain, callFirst, firstValue = ns.Compat.plain, ns.Compat.callFirst, ns.Compat.firstValue
|
|
8
|
+
local tooltipFor = ns.Compat.tooltipFor
|
|
9
|
+
local Items = ns.Items
|
|
10
|
+
|
|
11
|
+
local function collectBags()
|
|
12
|
+
local bags = {}
|
|
13
|
+
for bag = 0, Items.lastEquippedBag() do
|
|
14
|
+
local ok, container = pcall(Items.scanContainer, bag)
|
|
15
|
+
if ok and container then bags[#bags + 1] = container end
|
|
16
|
+
end
|
|
17
|
+
return bags
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
local AMMO_SLOT = 0
|
|
21
|
+
|
|
22
|
+
-- Every slot read goes through callFirst (pcall), so one bad slot does not spoil the rest.
|
|
23
|
+
local function addDurability(item, slot)
|
|
24
|
+
local durability = callFirst({ "GetInventoryItemDurability" }, slot)
|
|
25
|
+
if not durability then return end
|
|
26
|
+
item.durability = plain(durability[1])
|
|
27
|
+
item.durabilityMax = plain(durability[2])
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
local function equippedItem(slot, link)
|
|
31
|
+
local item = {
|
|
32
|
+
slot = Items.EQUIPMENT_SLOTS[slot] or tostring(slot),
|
|
33
|
+
id = firstValue({ "GetInventoryItemID" }, "player", slot) or Items.idFromLink(link),
|
|
34
|
+
name = Items.nameFromLink(link),
|
|
35
|
+
quality = firstValue({ "GetInventoryItemQuality" }, "player", slot),
|
|
36
|
+
}
|
|
37
|
+
addDurability(item, slot)
|
|
38
|
+
pcall(Items.addDetails, item, link)
|
|
39
|
+
if slot == AMMO_SLOT then
|
|
40
|
+
-- Ammo has no durability, but what counts is how much of it is left.
|
|
41
|
+
item.count = firstValue({ "GetInventoryItemCount" }, "player", AMMO_SLOT)
|
|
42
|
+
item.durability, item.durabilityMax = nil, nil
|
|
43
|
+
else
|
|
44
|
+
Items.attachTooltip(item, tooltipFor("GetInventoryItem", "player", slot))
|
|
45
|
+
end
|
|
46
|
+
return item
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
local function collectEquipment()
|
|
50
|
+
local equipment = {}
|
|
51
|
+
-- Slots 1-19, and last slot 0: ammo (arrows, bullets) in clients that have it.
|
|
52
|
+
for i = 1, 20 do
|
|
53
|
+
local slot = i % 20
|
|
54
|
+
local link = firstValue({ "GetInventoryItemLink" }, "player", slot)
|
|
55
|
+
if link then
|
|
56
|
+
local ok, item = pcall(equippedItem, slot, link)
|
|
57
|
+
if ok then equipment[#equipment + 1] = item end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
return equipment
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
ns.Snapshot.addSection("bags", collectBags)
|
|
64
|
+
ns.Snapshot.addSection("equipment", collectEquipment)
|