@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.
Files changed (62) hide show
  1. package/LICENSE +674 -0
  2. package/NOTICE +37 -0
  3. package/README.md +41 -2
  4. package/addon/WowMcp/AuctionTooltip.lua +106 -0
  5. package/addon/WowMcp/Commands.lua +259 -0
  6. package/addon/WowMcp/Compat.lua +167 -0
  7. package/addon/WowMcp/Core.lua +50 -0
  8. package/addon/WowMcp/Events.lua +62 -0
  9. package/addon/WowMcp/Items.lua +314 -0
  10. package/addon/WowMcp/Maps.lua +66 -0
  11. package/addon/WowMcp/MinimapButton.lua +114 -0
  12. package/addon/WowMcp/Options.lua +208 -0
  13. package/addon/WowMcp/Panel.lua +294 -0
  14. package/addon/WowMcp/QuestDb.lua +303 -0
  15. package/addon/WowMcp/QuestRewards.lua +137 -0
  16. package/addon/WowMcp/Sections/ActionBars.lua +54 -0
  17. package/addon/WowMcp/Sections/Auctions.lua +305 -0
  18. package/addon/WowMcp/Sections/Bank.lua +48 -0
  19. package/addon/WowMcp/Sections/Buyback.lua +47 -0
  20. package/addon/WowMcp/Sections/Character.lua +177 -0
  21. package/addon/WowMcp/Sections/Cooldowns.lua +76 -0
  22. package/addon/WowMcp/Sections/Currencies.lua +47 -0
  23. package/addon/WowMcp/Sections/Deaths.lua +43 -0
  24. package/addon/WowMcp/Sections/Dungeons.lua +117 -0
  25. package/addon/WowMcp/Sections/EquipmentSets.lua +83 -0
  26. package/addon/WowMcp/Sections/FlightPaths.lua +145 -0
  27. package/addon/WowMcp/Sections/Friends.lua +70 -0
  28. package/addon/WowMcp/Sections/Group.lua +101 -0
  29. package/addon/WowMcp/Sections/Guide.lua +317 -0
  30. package/addon/WowMcp/Sections/Guild.lua +131 -0
  31. package/addon/WowMcp/Sections/Inspect.lua +100 -0
  32. package/addon/WowMcp/Sections/Inventory.lua +64 -0
  33. package/addon/WowMcp/Sections/Legacy.lua +375 -0
  34. package/addon/WowMcp/Sections/Loot.lua +170 -0
  35. package/addon/WowMcp/Sections/Macros.lua +26 -0
  36. package/addon/WowMcp/Sections/Mail.lua +70 -0
  37. package/addon/WowMcp/Sections/Note.lua +38 -0
  38. package/addon/WowMcp/Sections/Pet.lua +127 -0
  39. package/addon/WowMcp/Sections/Played.lua +52 -0
  40. package/addon/WowMcp/Sections/Probe.lua +79 -0
  41. package/addon/WowMcp/Sections/Professions.lua +129 -0
  42. package/addon/WowMcp/Sections/Pvp.lua +45 -0
  43. package/addon/WowMcp/Sections/QuestDb.lua +106 -0
  44. package/addon/WowMcp/Sections/QuestGiver.lua +45 -0
  45. package/addon/WowMcp/Sections/Quests.lua +146 -0
  46. package/addon/WowMcp/Sections/Recipes.lua +195 -0
  47. package/addon/WowMcp/Sections/Reputation.lua +56 -0
  48. package/addon/WowMcp/Sections/Spells.lua +87 -0
  49. package/addon/WowMcp/Sections/Stable.lua +90 -0
  50. package/addon/WowMcp/Sections/Talents.lua +137 -0
  51. package/addon/WowMcp/Sections/Trainer.lua +58 -0
  52. package/addon/WowMcp/Sections/Vendor.lua +72 -0
  53. package/addon/WowMcp/Sections/XpGains.lua +258 -0
  54. package/addon/WowMcp/Snapshot.lua +412 -0
  55. package/addon/WowMcp/Store.lua +142 -0
  56. package/addon/WowMcp/TalentGrid.lua +171 -0
  57. package/addon/WowMcp/Timing.lua +61 -0
  58. package/addon/WowMcp/TraitTree.lua +158 -0
  59. package/addon/WowMcp/WowMcp.lua +24 -0
  60. package/addon/WowMcp/WowMcp.toc +72 -0
  61. package/bin/wow-mcp.js +248 -0
  62. package/package.json +41 -4
@@ -0,0 +1,305 @@
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 auctions (from the window): prices from search results that the player opened
5
+ -- in the auction window, and the player's own auctions. The addon searches and posts nothing;
6
+ -- it only reads what the client has already shown. Prices accumulate between visits
7
+ -- (the latest observation wins), and seen keeps several last minimums to judge the trend. Since 0.13.0 a gear entry also has
8
+ -- the item details the client already holds (Items.addCachedDetails: never a request), so the server can compare it.
9
+
10
+ local _, ns = ...
11
+ local plain, callFirst, firstValue = ns.Compat.plain, ns.Compat.callFirst, ns.Compat.firstValue
12
+ local Items, pick = ns.Items, ns.Compat.pick
13
+
14
+ local AUCTION_MAX_ITEMS = 400
15
+ local AUCTION_MAX_SEEN = 5
16
+ local SAME_VISIT_SECONDS = 600
17
+ local AUCTION_STATUS_SOLD = 1
18
+
19
+ ---------------------------------------------------------------------------
20
+ -- Storing prices in the dump
21
+ ---------------------------------------------------------------------------
22
+
23
+ local function auctionsSection()
24
+ local current = ns.Snapshot.current()
25
+ if type(current.auctions) ~= "table" then current.auctions = {} end
26
+ local auctions = current.auctions
27
+ if type(auctions.prices) ~= "table" then auctions.prices = {} end
28
+ return auctions
29
+ end
30
+
31
+ -- Removes the longest-unseen prices when there are too many.
32
+ local function pruneAuctionPrices(prices)
33
+ local names = {}
34
+ for name in pairs(prices) do names[#names + 1] = name end
35
+ if #names <= AUCTION_MAX_ITEMS then return end
36
+ table.sort(names, function(a, b) return (prices[a].seenAt or 0) > (prices[b].seenAt or 0) end)
37
+ for i = AUCTION_MAX_ITEMS + 1, #names do prices[names[i]] = nil end
38
+ end
39
+
40
+ -- Appends a minimum to the history; the same visit overwrites the last point instead of adding a new one.
41
+ local function recordSeenMinimum(entry, minBuyout, now)
42
+ entry.seen = type(entry.seen) == "table" and entry.seen or {}
43
+ local last = entry.seen[#entry.seen]
44
+ if last and now - (last.at or 0) < SAME_VISIT_SECONDS then
45
+ last.at, last.minBuyout = now, minBuyout
46
+ else
47
+ entry.seen[#entry.seen + 1] = { at = now, minBuyout = minBuyout }
48
+ while #entry.seen > AUCTION_MAX_SEEN do table.remove(entry.seen, 1) end
49
+ end
50
+ end
51
+
52
+ -- Item details that stay on a price entry (0.13.0). Filled from the client's cache only (Items.addCachedDetails); a later
53
+ -- visit with uncached data keeps what an earlier one saved. The section is bounded (400 prices), so there is no tooltip text,
54
+ -- no localized stat labels (statTokens say the same) and details only for gear: details for every price would add about
55
+ -- 165 kB at the cap of 400, gear only about 135 kB (a cached weapon entry grows by about 340 bytes).
56
+ local function addItemDetails(entry, itemID)
57
+ local details = {}
58
+ Items.addCachedDetails(details, itemID, true)
59
+ details.stats = nil
60
+ for key, value in pairs(details) do entry[key] = value end
61
+ end
62
+
63
+ -- Stores the results gathered from one screen: observations[name] = {id, unitBuyout, unitBid, quantity, listings}.
64
+ local function storeAuctionPrices(observations, source)
65
+ local auctions = auctionsSection()
66
+ local now = time()
67
+ auctions.capturedAt = now
68
+ for name, o in pairs(observations) do
69
+ local entry = auctions.prices[name] or { name = name }
70
+ entry.id = o.id or entry.id
71
+ pcall(addItemDetails, entry, entry.id)
72
+ entry.minBuyout = o.unitBuyout
73
+ entry.minBid = o.unitBid
74
+ entry.quantity = o.quantity
75
+ entry.listings = o.listings
76
+ entry.seenAt = now
77
+ entry.source = source
78
+ if o.unitBuyout then recordSeenMinimum(entry, o.unitBuyout, now) end
79
+ auctions.prices[name] = entry
80
+ end
81
+ pruneAuctionPrices(auctions.prices)
82
+ ns.Snapshot.windowCaptured("auctions")
83
+ end
84
+
85
+ local function unitPrice(total, count)
86
+ return math.floor(total / count + 0.5)
87
+ end
88
+
89
+ -- Adds one auction to an item's observation: totals of items and auctions, minimum per-unit prices.
90
+ local function observe(observations, name, id, count, buyout, bid)
91
+ if type(name) ~= "string" or name == "" then return end
92
+ count = (type(count) == "number" and count > 0) and count or 1
93
+ local o = observations[name] or { id = id, quantity = 0, listings = 0 }
94
+ o.id = o.id or id
95
+ o.quantity = o.quantity + count
96
+ o.listings = o.listings + 1
97
+ if type(buyout) == "number" and buyout > 0 then
98
+ local unit = unitPrice(buyout, count)
99
+ if not o.unitBuyout or unit < o.unitBuyout then o.unitBuyout = unit end
100
+ end
101
+ if type(bid) == "number" and bid > 0 then
102
+ local unit = unitPrice(bid, count)
103
+ if not o.unitBid or unit < o.unitBid then o.unitBid = unit end
104
+ end
105
+ observations[name] = o
106
+ end
107
+
108
+ -- Item name by ID for the new API, which provides only the ID.
109
+ local function itemNameByID(itemID)
110
+ if not itemID then return nil end
111
+ return firstValue({ "C_Item.GetItemNameByID", "GetItemInfo" }, itemID)
112
+ end
113
+
114
+ ---------------------------------------------------------------------------
115
+ -- Classic auction window (GetAuctionItemInfo)
116
+ ---------------------------------------------------------------------------
117
+
118
+ -- Row of the classic auction list. Returns name, count, minBid, buyout, owner, saleStatus, itemID.
119
+ local function classicAuctionRow(kind, index)
120
+ local r = callFirst({ "GetAuctionItemInfo" }, kind, index)
121
+ if not r or not plain(r[1]) then return nil end
122
+ -- Newer clients have a levelColHeader string after the level (r[6]) and later fields shifted by one.
123
+ local o = (type(r[7]) == "string" or r[7] == nil and type(r[8]) == "number") and 1 or 0
124
+ local minBid, buyout = plain(r[7 + o]), plain(r[9 + o])
125
+ local owner = plain(pick(o == 1, r[14], r[12]))
126
+ local saleStatus = pick(o == 1, plain(r[16]), nil)
127
+ local itemID = pick(o == 1, plain(r[17]), nil)
128
+ local link = firstValue({ "GetAuctionItemLink" }, kind, index)
129
+ return r[1], plain(r[3]), minBid, buyout, owner, saleStatus, itemID or Items.idFromLink(link)
130
+ end
131
+
132
+ -- Current page of search results.
133
+ local function captureClassicAuctionList()
134
+ local counts = callFirst({ "GetNumAuctionItems" }, "list")
135
+ local batch = counts and plain(counts[1])
136
+ if type(batch) ~= "number" or batch <= 0 then return end
137
+ local observations = {}
138
+ for index = 1, batch do
139
+ local name, count, minBid, buyout, _, _, itemID = classicAuctionRow("list", index)
140
+ observe(observations, name, itemID, count, buyout, minBid)
141
+ end
142
+ storeAuctionPrices(observations, "list")
143
+ local total = plain(counts[2])
144
+ if type(total) == "number" and total > batch then
145
+ auctionsSection().lastSearchPartial = { shown = batch, total = total }
146
+ else
147
+ auctionsSection().lastSearchPartial = nil
148
+ end
149
+ end
150
+
151
+ local function classicOwnedAuctions()
152
+ local counts = callFirst({ "GetNumAuctionItems" }, "owner")
153
+ local batch = counts and plain(counts[1])
154
+ if type(batch) ~= "number" then return nil end
155
+ local owned = {}
156
+ for index = 1, batch do
157
+ local name, count, minBid, buyout, _, saleStatus, itemID = classicAuctionRow("owner", index)
158
+ if name then
159
+ owned[#owned + 1] = {
160
+ name = name, id = itemID, count = count, buyout = buyout, bid = minBid,
161
+ sold = (saleStatus == AUCTION_STATUS_SOLD) or nil,
162
+ }
163
+ end
164
+ end
165
+ return owned
166
+ end
167
+
168
+ ---------------------------------------------------------------------------
169
+ -- New auction window (C_AuctionHouse)
170
+ ---------------------------------------------------------------------------
171
+
172
+ -- Adds a browse result to the observation. Several item keys (e.g. different levels)
173
+ -- may share a name: we take the lowest per-unit price and sum the quantities, as in observe.
174
+ local function observeBrowseResult(observations, name, id, unitBuyout, quantity)
175
+ local o = observations[name]
176
+ if not o then
177
+ observations[name] = { id = id, unitBuyout = unitBuyout, quantity = quantity, listings = nil }
178
+ return
179
+ end
180
+ o.id = o.id or id
181
+ if unitBuyout and (not o.unitBuyout or unitBuyout < o.unitBuyout) then o.unitBuyout = unitBuyout end
182
+ if quantity then o.quantity = (o.quantity or 0) + quantity end
183
+ end
184
+
185
+ -- Browse results (minimum per-unit price for each item).
186
+ local function captureBrowseResults()
187
+ local r = callFirst({ "C_AuctionHouse.GetBrowseResults" })
188
+ if not r or type(r[1]) ~= "table" then return end
189
+ local observations = {}
190
+ for _, result in ipairs(r[1]) do
191
+ local key = type(result.itemKey) == "table" and result.itemKey or {}
192
+ local id = plain(key.itemID)
193
+ local name = itemNameByID(id)
194
+ if name then
195
+ observeBrowseResult(observations, name, id, plain(result.minPrice), plain(result.totalQuantity))
196
+ end
197
+ end
198
+ storeAuctionPrices(observations, "browse")
199
+ end
200
+
201
+ -- Commodity details after clicking a result.
202
+ local function captureCommodityResults(itemID)
203
+ local n = firstValue({ "C_AuctionHouse.GetNumCommoditySearchResults" }, itemID)
204
+ if type(n) ~= "number" or n <= 0 then return end
205
+ local name = itemNameByID(itemID)
206
+ if not name then return end
207
+ local observations = {}
208
+ for index = 1, n do
209
+ local r = callFirst({ "C_AuctionHouse.GetCommoditySearchResultInfo" }, itemID, index)
210
+ local info = r and r[1]
211
+ if type(info) == "table" then
212
+ local qty = plain(info.quantity) or 1
213
+ observe(observations, name, itemID, qty, (plain(info.unitPrice) or 0) * qty, nil)
214
+ end
215
+ end
216
+ storeAuctionPrices(observations, "commodity")
217
+ end
218
+
219
+ -- Item (non-commodity) details after clicking a result.
220
+ local function captureItemResults(itemKey)
221
+ if type(itemKey) ~= "table" then return end
222
+ local n = firstValue({ "C_AuctionHouse.GetNumItemSearchResults" }, itemKey)
223
+ if type(n) ~= "number" or n <= 0 then return end
224
+ local id = plain(itemKey.itemID)
225
+ local name = itemNameByID(id)
226
+ if not name then return end
227
+ local observations = {}
228
+ for index = 1, n do
229
+ local r = callFirst({ "C_AuctionHouse.GetItemSearchResultInfo" }, itemKey, index)
230
+ local info = r and r[1]
231
+ if type(info) == "table" then
232
+ observe(observations, name, id, plain(info.quantity) or 1, plain(info.buyoutAmount), plain(info.bidAmount))
233
+ end
234
+ end
235
+ storeAuctionPrices(observations, "item")
236
+ end
237
+
238
+ local function modernOwnedAuctions(count)
239
+ local owned = {}
240
+ for index = 1, count do
241
+ local r = callFirst({ "C_AuctionHouse.GetOwnedAuctionInfo" }, index)
242
+ local info = r and r[1]
243
+ if type(info) == "table" then
244
+ local key = type(info.itemKey) == "table" and info.itemKey or {}
245
+ local id = plain(key.itemID)
246
+ owned[#owned + 1] = {
247
+ name = Items.nameFromLink(plain(info.itemLink)) or itemNameByID(id), id = id,
248
+ count = plain(info.quantity), buyout = plain(info.buyoutAmount), bid = plain(info.bidAmount),
249
+ sold = (info.status == AUCTION_STATUS_SOLD) or nil, timeLeftSeconds = plain(info.timeLeftSeconds),
250
+ }
251
+ end
252
+ end
253
+ return owned
254
+ end
255
+
256
+ ---------------------------------------------------------------------------
257
+ -- Auction window events
258
+ ---------------------------------------------------------------------------
259
+
260
+ -- The player's own auctions (the Auctions tab in the auction window), from the new or classic API.
261
+ local function captureOwnedAuctions()
262
+ local owned
263
+ local n = firstValue({ "C_AuctionHouse.GetNumOwnedAuctions" })
264
+ if type(n) == "number" then
265
+ owned = modernOwnedAuctions(n)
266
+ else
267
+ owned = classicOwnedAuctions()
268
+ if not owned then return end
269
+ end
270
+ local auctions = auctionsSection()
271
+ auctions.owned = owned
272
+ auctions.ownedAt = time()
273
+ ns.Snapshot.windowCaptured("auctions")
274
+ end
275
+
276
+ local function captureAuctionVisit()
277
+ local auctions = auctionsSection()
278
+ auctions.capturedAt = time()
279
+ auctions.lastVisitAt = time()
280
+ auctions.npc = plain(UnitName("npc"))
281
+ ns.Snapshot.windowCaptured("auctions")
282
+ end
283
+
284
+ local function onAuctionHouseShow()
285
+ pcall(captureAuctionVisit)
286
+ pcall(captureClassicAuctionList)
287
+ end
288
+
289
+ -- Event handler: does nothing when the section is disabled; a read error does not escape.
290
+ local function guarded(capture)
291
+ return ns.Snapshot.whenEnabled("auctions", function(...) pcall(capture, ...) end)
292
+ end
293
+
294
+ -- Events: the classic window (older clients) and the new C_AuctionHouse. Forever 1.60.1 (per /mcp probe)
295
+ -- knows only the new ones: AUCTION_HOUSE_BROWSE_RESULTS_*, ITEM_SEARCH_RESULTS_UPDATED,
296
+ -- COMMODITY_SEARCH_RESULTS_UPDATED and OWNED_AUCTIONS_UPDATED; the client harmlessly rejects unknown events.
297
+ ns.Snapshot.addWindowSection("auctions")
298
+ ns.Events.on("AUCTION_HOUSE_SHOW", ns.Snapshot.whenEnabled("auctions", onAuctionHouseShow))
299
+ ns.Events.on("AUCTION_ITEM_LIST_UPDATE", guarded(captureClassicAuctionList))
300
+ ns.Events.on("AUCTION_OWNED_LIST_UPDATE", guarded(captureOwnedAuctions))
301
+ ns.Events.on("AUCTION_HOUSE_BROWSE_RESULTS_UPDATED", guarded(captureBrowseResults))
302
+ ns.Events.on("AUCTION_HOUSE_BROWSE_RESULTS_ADDED", guarded(captureBrowseResults))
303
+ ns.Events.on("COMMODITY_SEARCH_RESULTS_UPDATED", guarded(captureCommodityResults))
304
+ ns.Events.on("ITEM_SEARCH_RESULTS_UPDATED", guarded(captureItemResults))
305
+ ns.Events.on("OWNED_AUCTIONS_UPDATED", guarded(captureOwnedAuctions))
@@ -0,0 +1,48 @@
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 bank (from the window): bank contents. Bank container numbers differ between
5
+ -- client versions, so we check all known variants and take the ones that exist.
6
+
7
+ local _, ns = ...
8
+ local Items = ns.Items
9
+
10
+ local LEGACY_BANK_CONTAINER = -1 -- main part of the bank in older clients
11
+
12
+ local function bankContainerIndexes()
13
+ local candidates, seen = {}, {}
14
+ local function add(index)
15
+ if type(index) == "number" and not seen[index] then
16
+ seen[index] = true
17
+ candidates[#candidates + 1] = index
18
+ end
19
+ end
20
+ add(LEGACY_BANK_CONTAINER)
21
+ local firstBankBag = Items.lastEquippedBag() + 1
22
+ for index = firstBankBag, firstBankBag + (NUM_BANKBAGSLOTS or 7) - 1 do add(index) end
23
+ if Enum and Enum.BagIndex then
24
+ -- pairs() gives a random order, and the dump must be reproducible.
25
+ local indexes = {}
26
+ for name, index in pairs(Enum.BagIndex) do
27
+ if type(name) == "string" and name:find("Bank") and type(index) == "number" then
28
+ indexes[#indexes + 1] = index
29
+ end
30
+ end
31
+ table.sort(indexes)
32
+ for _, index in ipairs(indexes) do add(index) end
33
+ end
34
+ return candidates
35
+ end
36
+
37
+ local function collectBank()
38
+ local candidates = bankContainerIndexes()
39
+ local bank = { capturedAt = time(), containers = {} }
40
+ for _, index in ipairs(candidates) do
41
+ local ok, container = pcall(Items.scanContainer, index)
42
+ if ok and container then bank.containers[#bank.containers + 1] = container end
43
+ end
44
+ if #bank.containers == 0 then return nil end
45
+ return bank
46
+ end
47
+
48
+ ns.Snapshot.addWindowSection("bank", collectBank, { "BANKFRAME_OPENED" })
@@ -0,0 +1,47 @@
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 buyback (from the window): the vendor's buyback list (recently sold items).
5
+ -- Read-only from the open vendor window; buys nothing back.
6
+
7
+ local _, ns = ...
8
+ local plain, callFirst, firstValue = ns.Compat.plain, ns.Compat.callFirst, ns.Compat.firstValue
9
+ local Items = ns.Items
10
+
11
+ local function buybackItem(index)
12
+ local item = { index = index }
13
+ -- GetBuybackItemInfo: name, icon, price, quantity, numAvailable, isUsable (price for the whole stack).
14
+ local info = callFirst({ "GetBuybackItemInfo", "C_MerchantFrame.GetBuybackItemInfo" }, index)
15
+ if info then
16
+ if type(info[1]) == "table" then
17
+ local data = info[1]
18
+ item.name, item.priceCopper, item.count = plain(data.name), plain(data.price), plain(data.quantity)
19
+ else
20
+ item.name, item.priceCopper, item.count = plain(info[1]), plain(info[3]), plain(info[4])
21
+ end
22
+ end
23
+ local link = firstValue({ "GetBuybackItemLink" }, index)
24
+ if link then
25
+ item.id = Items.idFromLink(link)
26
+ item.name = item.name or Items.nameFromLink(link)
27
+ end
28
+ item.id = item.id or firstValue({ "C_MerchantFrame.GetBuybackItemID" }, index)
29
+ return item
30
+ end
31
+
32
+ local function collectBuyback()
33
+ local count = firstValue({ "GetNumBuybackItems", "C_MerchantFrame.GetNumBuybackItems" })
34
+ if type(count) ~= "number" then return nil end
35
+ -- The buyback list makes sense only with the vendor window open; otherwise the old record stays.
36
+ local merchantItems = firstValue({ "GetMerchantNumItems" })
37
+ if count == 0 and not (type(merchantItems) == "number" and merchantItems > 0) then return nil end
38
+
39
+ local buyback = { npc = plain(UnitName("npc")), capturedAt = time(), items = {} }
40
+ for index = 1, count do
41
+ local item = buybackItem(index)
42
+ if item.name then buyback.items[#buyback.items + 1] = item end
43
+ end
44
+ return buyback
45
+ end
46
+
47
+ ns.Snapshot.addWindowSection("buyback", collectBuyback, { "MERCHANT_SHOW", "MERCHANT_UPDATE" })
@@ -0,0 +1,177 @@
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 character (who the character is and where they stand), stats (statistics from the
5
+ -- character window) and auras (active effects).
6
+
7
+ local _, ns = ...
8
+ local plain, callFirst, firstValue = ns.Compat.plain, ns.Compat.callFirst, ns.Compat.firstValue
9
+ local round1 = ns.round1
10
+
11
+ -- Position on the zone map in percent (as on the world map).
12
+ local function addMapPosition(c)
13
+ if not (C_Map and C_Map.GetBestMapForUnit) then return end
14
+ local mapID = plain(C_Map.GetBestMapForUnit("player"))
15
+ c.mapID = mapID
16
+ if not (mapID and C_Map.GetPlayerMapPosition) then return end
17
+ local pos = C_Map.GetPlayerMapPosition(mapID, "player")
18
+ if not (pos and pos.GetXY) then return end
19
+ local rawX, rawY = pos:GetXY()
20
+ local x, y = plain(rawX), plain(rawY)
21
+ if x and y then
22
+ c.x = round1(x * 100)
23
+ c.y = round1(y * 100)
24
+ end
25
+ end
26
+
27
+ local function addClientVersion(c)
28
+ if not GetBuildInfo then return end
29
+ local version, build, _, interface = GetBuildInfo()
30
+ c.clientVersion = plain(version)
31
+ c.clientBuild = plain(build)
32
+ c.clientInterface = plain(interface)
33
+ end
34
+
35
+ local function collectCharacter()
36
+ local c = {}
37
+ c.name = plain(UnitName("player"))
38
+ c.level = plain(UnitLevel("player"))
39
+ local className, classToken = UnitClass("player")
40
+ c.class = plain(className)
41
+ c.classToken = plain(classToken)
42
+ local raceName, raceToken = UnitRace("player")
43
+ c.race = plain(raceName)
44
+ c.raceToken = plain(raceToken)
45
+ c.faction = plain(UnitFactionGroup("player"))
46
+ c.moneyCopper = plain(GetMoney())
47
+ c.xp = plain(UnitXP("player"))
48
+ c.xpMax = plain(UnitXPMax("player"))
49
+ c.restedXp = firstValue({ "GetXPExhaustion" })
50
+ -- In an inn or city: rested XP accumulates there.
51
+ local resting = callFirst({ "IsResting" })
52
+ if resting then c.resting = plain(resting[1]) and true or false end
53
+ c.zone = firstValue({ "GetRealZoneText" })
54
+ c.subZone = firstValue({ "GetSubZoneText" })
55
+ -- The place the Hearthstone returns to.
56
+ c.bindLocation = firstValue({ "GetBindLocation" })
57
+ -- Below this level quests are grey (no XP). Classically GetQuestGreenRange,
58
+ -- in the new API UnitQuestTrivialLevelRange.
59
+ c.questGreenRange = firstValue({ "UnitQuestTrivialLevelRange", "GetQuestGreenRange" }, "player")
60
+ c.maxQuests = firstValue({ "C_QuestLog.GetMaxNumQuestsCanAccept", "C_QuestLog.GetMaxNumQuests" })
61
+ or plain(MAX_QUESTLOG_QUESTS)
62
+ -- Client language (enUS, deDE...): the server knows which text in the dump it can read as English.
63
+ c.locale = firstValue({ "GetLocale" })
64
+ addMapPosition(c)
65
+ addClientVersion(c)
66
+ c.addonVersion = ns.ADDON_VERSION
67
+ return c
68
+ end
69
+
70
+ local STAT_NAMES = { "strength", "agility", "stamina", "intellect", "spirit" }
71
+
72
+ -- Attack power: base plus positive and negative bonus; nil when the client does not supply it.
73
+ local function attackPower(apiName)
74
+ local results = callFirst({ apiName }, "player")
75
+ if results and plain(results[1]) then
76
+ return results[1] + (plain(results[2]) or 0) + (plain(results[3]) or 0)
77
+ end
78
+ return nil
79
+ end
80
+
81
+ local function addRangedDamage(s)
82
+ local ranged = callFirst({ "UnitRangedDamage" }, "player")
83
+ if ranged and plain(ranged[1]) then
84
+ s.rangedSpeed = round1(ranged[1])
85
+ s.rangedDamageMin = round1(plain(ranged[2]))
86
+ s.rangedDamageMax = round1(plain(ranged[3]))
87
+ end
88
+ end
89
+
90
+ local function addMeleeDamage(s)
91
+ local melee = callFirst({ "UnitDamage" }, "player")
92
+ if melee and plain(melee[1]) then
93
+ s.meleeDamageMin = round1(melee[1])
94
+ s.meleeDamageMax = round1(plain(melee[2]))
95
+ end
96
+ end
97
+
98
+ local function collectStats()
99
+ local s = {}
100
+ s.healthMax = firstValue({ "UnitHealthMax" }, "player")
101
+ s.manaMax = firstValue({ "UnitPowerMax" }, "player", 0)
102
+
103
+ for index, name in ipairs(STAT_NAMES) do
104
+ local results = callFirst({ "UnitStat" }, "player", index)
105
+ if results then
106
+ -- Returns: base value, value with equipment, positive bonus, negative bonus.
107
+ s[name] = plain(results[2]) or plain(results[1])
108
+ end
109
+ end
110
+
111
+ local armor = callFirst({ "UnitArmor" }, "player")
112
+ if armor then s.armor = plain(armor[2]) or plain(armor[1]) end
113
+
114
+ s.attackPower = attackPower("UnitAttackPower")
115
+ s.rangedAttackPower = attackPower("UnitRangedAttackPower")
116
+
117
+ s.critChance = round1(firstValue({ "GetCritChance" }))
118
+ s.rangedCritChance = round1(firstValue({ "GetRangedCritChance" }))
119
+ s.dodgeChance = round1(firstValue({ "GetDodgeChance" }))
120
+ s.parryChance = round1(firstValue({ "GetParryChance" }))
121
+
122
+ addRangedDamage(s)
123
+ addMeleeDamage(s)
124
+ s.meleeSpeed = round1(firstValue({ "UnitAttackSpeed" }, "player"))
125
+ return s
126
+ end
127
+
128
+ local AURA_FILTERS = { "HELPFUL", "HARMFUL" }
129
+ local MAX_AURAS = 40
130
+
131
+ -- Aura end time as unix time: expirationTime is on the GetTime() clock, so
132
+ -- we convert it to the wall clock. An aura without a duration (duration 0) has no end.
133
+ local function auraTiming(aura)
134
+ local duration, expiration = plain(aura.duration), plain(aura.expirationTime)
135
+ if type(duration) ~= "number" or duration <= 0 then return nil, nil end
136
+ local expiresAt
137
+ if type(expiration) == "number" and expiration > 0 and GetTime then
138
+ local ok, now = pcall(GetTime)
139
+ if ok and type(plain(now)) == "number" then
140
+ expiresAt = math.floor(time() + (expiration - now) + 0.5)
141
+ end
142
+ end
143
+ return expiresAt, round1(duration)
144
+ end
145
+
146
+ local function auraEntry(aura, filter)
147
+ local name = plain(aura.name)
148
+ if not name then return nil end
149
+ local expiresAt, duration = auraTiming(aura)
150
+ return {
151
+ name = name,
152
+ id = plain(aura.spellId),
153
+ icon = plain(aura.icon),
154
+ harmful = (filter == "HARMFUL") or nil,
155
+ stacks = (type(plain(aura.applications)) == "number" and aura.applications > 1) and aura.applications or nil,
156
+ expiresAt = expiresAt,
157
+ duration = duration,
158
+ }
159
+ end
160
+
161
+ local function collectAuras()
162
+ local auras = {}
163
+ if not (C_UnitAuras and C_UnitAuras.GetAuraDataByIndex) then return auras end
164
+ for _, filter in ipairs(AURA_FILTERS) do
165
+ for index = 1, MAX_AURAS do
166
+ local ok, aura = pcall(C_UnitAuras.GetAuraDataByIndex, "player", index, filter)
167
+ if not ok or type(aura) ~= "table" then break end
168
+ local entry = auraEntry(aura, filter)
169
+ if entry then auras[#auras + 1] = entry end
170
+ end
171
+ end
172
+ return auras
173
+ end
174
+
175
+ ns.Snapshot.addSection("character", collectCharacter)
176
+ ns.Snapshot.addSection("stats", collectStats)
177
+ ns.Snapshot.addSection("auras", collectAuras)
@@ -0,0 +1,76 @@
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 cooldowns: long cooldowns (over 90 s) of abilities, items in bags
5
+ -- (Hearthstone) and professions (e.g. transmutes). readyAt is unix time, so the server
6
+ -- computes how much is left, even long after the dump.
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
+ -- Shorter cooldowns expire before anyone reads the dump.
13
+ local MIN_DURATION = 90
14
+
15
+ -- Cooldown read: the new API returns a table, the old one three values. Result: start, duration.
16
+ local function cooldownTimes(results)
17
+ if not results then return nil end
18
+ local start, duration
19
+ if type(results[1]) == "table" then
20
+ start, duration = plain(results[1].startTime), plain(results[1].duration)
21
+ else
22
+ start, duration = plain(results[1]), plain(results[2])
23
+ end
24
+ if type(start) ~= "number" or type(duration) ~= "number" then return nil end
25
+ return start, duration
26
+ end
27
+
28
+ -- Set of cooldowns without repeated names. GetTime() is the game clock, time() is unix time.
29
+ local function newCooldownList()
30
+ local nowGame, nowUnix = GetTime(), time()
31
+ local list, seen = {}, {}
32
+ local function add(name, kind, start, duration, id)
33
+ if not name or seen[name] or not start or start <= 0 or duration <= MIN_DURATION then return end
34
+ local remaining = start + duration - nowGame
35
+ if remaining <= 0 then return end
36
+ seen[name] = true
37
+ list[#list + 1] = {
38
+ name = name, kind = kind, id = id,
39
+ remainingSeconds = math.floor(remaining + 0.5),
40
+ readyAt = nowUnix + math.floor(remaining + 0.5),
41
+ }
42
+ end
43
+ return list, add
44
+ end
45
+
46
+ local function addSpellCooldowns(add)
47
+ for _, spell in ipairs(ns.Spellbook.knownSpells()) do
48
+ if not spell.passive then
49
+ local start, duration = cooldownTimes(callFirst({ "C_Spell.GetSpellCooldown", "GetSpellCooldown" }, spell.id or spell.name))
50
+ add(spell.name, "spell", start, duration, spell.id)
51
+ end
52
+ end
53
+ end
54
+
55
+ local function addBagItemCooldowns(add)
56
+ for bag = 0, Items.lastEquippedBag() do
57
+ for slot = 1, Items.containerSlotCount(bag) do
58
+ local start, duration = cooldownTimes(callFirst({ "C_Container.GetContainerItemCooldown", "GetContainerItemCooldown" }, bag, slot))
59
+ if start and start > 0 then
60
+ local link = firstValue({ "C_Container.GetContainerItemLink", "GetContainerItemLink" }, bag, slot)
61
+ add(Items.nameFromLink(link), "item", start, duration, Items.idFromLink(link))
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ local function collectCooldowns()
68
+ if not GetTime then return nil end
69
+ local cooldowns, add = newCooldownList()
70
+ addSpellCooldowns(add)
71
+ addBagItemCooldowns(add)
72
+ table.sort(cooldowns, function(a, b) return a.remainingSeconds < b.remainingSeconds end)
73
+ return cooldowns
74
+ end
75
+
76
+ ns.Snapshot.addSection("cooldowns", collectCooldowns)