@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,146 @@
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 quests (quest log with objectives and rewards) and completedQuests (IDs of completed quests).
5
+
6
+ local _, ns = ...
7
+ local plain, callFirst = ns.Compat.plain, ns.Compat.callFirst
8
+
9
+ local function modernObjectives(questID)
10
+ local objectives = C_QuestLog.GetQuestObjectives(questID)
11
+ if not objectives then return nil end
12
+ local out = {}
13
+ for _, o in ipairs(objectives) do
14
+ out[#out + 1] = {
15
+ text = plain(o.text),
16
+ done = o.finished and true or false,
17
+ have = plain(o.numFulfilled),
18
+ need = plain(o.numRequired),
19
+ }
20
+ end
21
+ return out
22
+ end
23
+
24
+ -- Quest rewards (QuestRewards); a reward read error does not spoil the rest of the quest.
25
+ local function questRewards(read, key)
26
+ local ok, rewards = pcall(read, key)
27
+ if ok then return rewards end
28
+ return nil
29
+ end
30
+
31
+ local function positiveNumber(value)
32
+ if type(value) == "number" and value > 0 then return value end
33
+ return nil
34
+ end
35
+
36
+ local function modernQuest(info, zone, zoneMapID)
37
+ local q = {
38
+ id = plain(info.questID),
39
+ title = plain(info.title),
40
+ level = plain(info.level),
41
+ zone = zone,
42
+ zoneMapID = zoneMapID,
43
+ suggestedGroup = positiveNumber(plain(info.suggestedGroup)),
44
+ }
45
+ if info.questID then
46
+ if C_QuestLog.IsComplete then
47
+ q.complete = C_QuestLog.IsComplete(info.questID) and true or false
48
+ end
49
+ if C_QuestLog.IsFailed then
50
+ q.failed = C_QuestLog.IsFailed(info.questID) and true or nil
51
+ end
52
+ if C_QuestLog.GetQuestObjectives then
53
+ q.objectives = modernObjectives(info.questID)
54
+ end
55
+ q.rewards = questRewards(ns.QuestRewards.fromLog, info.questID)
56
+ end
57
+ return q
58
+ end
59
+
60
+ -- Map ID of a log header that is a zone name (nil for other headers); the same number in every client language.
61
+ local function headerMapID(zoneIDs, header)
62
+ if type(header) ~= "string" then return nil end
63
+ return zoneIDs[header]
64
+ end
65
+
66
+ -- New quest log API (C_QuestLog). A log header is usually the zone name; zoneMapID is that zone's UiMapID.
67
+ local function modernQuestLog()
68
+ local quests = {}
69
+ local header
70
+ local okIDs, zoneIDs = pcall(ns.Maps.zoneIDsByName)
71
+ if not okIDs then zoneIDs = {} end
72
+ for i = 1, C_QuestLog.GetNumQuestLogEntries() or 0 do
73
+ local info = C_QuestLog.GetInfo(i)
74
+ if info then
75
+ if info.isHeader then
76
+ header = plain(info.title)
77
+ elseif not info.isHidden then
78
+ quests[#quests + 1] = modernQuest(info, header, headerMapID(zoneIDs, header))
79
+ end
80
+ end
81
+ end
82
+ return quests
83
+ end
84
+
85
+ local function legacyObjectives(questIndex)
86
+ local objectives = {}
87
+ for j = 1, GetNumQuestLeaderBoards(questIndex) or 0 do
88
+ local text, _, finished = GetQuestLogLeaderBoard(j, questIndex)
89
+ objectives[#objectives + 1] = { text = plain(text), done = finished and true or false }
90
+ end
91
+ return objectives
92
+ end
93
+
94
+ -- Old quest log API.
95
+ local function legacyQuestLog()
96
+ local quests = {}
97
+ local header
98
+ for i = 1, GetNumQuestLogEntries() or 0 do
99
+ local title, level, _, isHeader, _, isComplete, _, questID = GetQuestLogTitle(i)
100
+ title = plain(title)
101
+ if isHeader then
102
+ header = title
103
+ elseif title then
104
+ local q = {
105
+ id = plain(questID),
106
+ title = title,
107
+ level = plain(level),
108
+ zone = header,
109
+ complete = (isComplete == 1 or isComplete == true),
110
+ failed = (isComplete == -1) or nil,
111
+ }
112
+ if GetNumQuestLeaderBoards and GetQuestLogLeaderBoard then
113
+ q.objectives = legacyObjectives(i)
114
+ end
115
+ q.rewards = questRewards(ns.QuestRewards.fromLogEntry, i)
116
+ quests[#quests + 1] = q
117
+ end
118
+ end
119
+ return quests
120
+ end
121
+
122
+ local function collectQuests()
123
+ if C_QuestLog and C_QuestLog.GetNumQuestLogEntries and C_QuestLog.GetInfo then
124
+ return modernQuestLog()
125
+ end
126
+ if GetNumQuestLogEntries and GetQuestLogTitle then
127
+ return legacyQuestLog()
128
+ end
129
+ return {}
130
+ end
131
+
132
+ -- IDs of all completed quests. Lets us check whether the character has already done
133
+ -- the prerequisite quest for another quest.
134
+ local function collectCompletedQuests()
135
+ local results = callFirst({ "C_QuestLog.GetAllCompletedQuestIDs" })
136
+ if not results or type(results[1]) ~= "table" then return nil end
137
+ local ids = {}
138
+ for _, id in ipairs(results[1]) do
139
+ if type(id) == "number" then ids[#ids + 1] = id end
140
+ end
141
+ table.sort(ids)
142
+ return ids
143
+ end
144
+
145
+ ns.Snapshot.addSection("quests", collectQuests)
146
+ ns.Snapshot.addSection("completedQuests", collectCompletedQuests)
@@ -0,0 +1,195 @@
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 recipes (from the window): recipes of the open profession, saved under its name.
5
+ -- Each profession overwrites only its own entry; others stay from earlier visits.
6
+
7
+ local _, ns = ...
8
+ local plain, callFirst, firstValue = ns.Compat.plain, ns.Compat.callFirst, ns.Compat.firstValue
9
+ local pick = ns.Compat.pick
10
+ local Items = ns.Items
11
+
12
+ -- Recipe color: whether it still gives skill points.
13
+ -- optimal = orange (always), medium = yellow, easy = green, trivial = grey (never).
14
+ local DIFFICULTY_BY_INDEX = { [0] = "optimal", [1] = "medium", [2] = "easy", [3] = "trivial" }
15
+
16
+ -- Reagent read shared by the profession window (TradeSkill) and the Craft window (Enchanting, Beast Training).
17
+ local function readReagents(countFn, infoFn, index)
18
+ local count = firstValue({ countFn }, index)
19
+ if type(count) ~= "number" or count <= 0 then return nil end
20
+ local reagents = {}
21
+ for j = 1, count do
22
+ local r = callFirst({ infoFn }, index, j)
23
+ if r and plain(r[1]) then
24
+ reagents[#reagents + 1] = { name = r[1], need = plain(r[3]), have = plain(r[4]) }
25
+ end
26
+ end
27
+ return reagents
28
+ end
29
+
30
+ local function positiveNumber(value)
31
+ if type(value) == "number" and value > 0 then return value end
32
+ return nil
33
+ end
34
+
35
+ -- Craft: name, subName, type, numAvailable, isExpanded, trainingPointCost, requiredLevel.
36
+ local function addCraftDetails(recipe, info, index)
37
+ local rank = plain(info[2])
38
+ if rank and rank ~= "" then recipe.rank = rank end
39
+ recipe.trainingPoints = positiveNumber(plain(info[6]))
40
+ recipe.levelRequired = positiveNumber(plain(info[7]))
41
+ recipe.reagents = readReagents("GetCraftNumReagents", "GetCraftReagentInfo", index)
42
+ end
43
+
44
+ -- TradeSkill: name, type, numAvailable; item and cooldown from separate functions.
45
+ local function addTradeSkillDetails(recipe, index)
46
+ recipe.reagents = readReagents("GetTradeSkillNumReagents", "GetTradeSkillReagentInfo", index)
47
+ local link = firstValue({ "GetTradeSkillItemLink" }, index)
48
+ recipe.itemId = Items.idFromLink(link)
49
+ local cd = firstValue({ "GetTradeSkillCooldown" }, index)
50
+ if type(cd) == "number" and cd > 0 then
51
+ recipe.cooldownSeconds = math.floor(cd)
52
+ recipe.readyAt = time() + math.floor(cd)
53
+ end
54
+ end
55
+
56
+ -- Old-style profession window (GetTradeSkillInfo) or the Craft window (GetCraftInfo).
57
+ -- Collapsed headers hide recipes, so it is good to have them expanded on open.
58
+ local function collectClassicRecipes(kind)
59
+ local isCraft = kind == "craft"
60
+ local line = callFirst({ isCraft and "GetCraftDisplaySkillLine" or "GetTradeSkillLine" })
61
+ local name = line and plain(line[1])
62
+ if not name or name == "UNKNOWN" then return nil end
63
+ local count = firstValue({ isCraft and "GetNumCrafts" or "GetNumTradeSkills" })
64
+ if type(count) ~= "number" or count == 0 then return nil end
65
+
66
+ local profession = {
67
+ name = name, rank = plain(line[2]), maxRank = plain(line[3]),
68
+ capturedAt = time(), recipes = {},
69
+ }
70
+ local header
71
+ for index = 1, count do
72
+ local info = callFirst({ isCraft and "GetCraftInfo" or "GetTradeSkillInfo" }, index)
73
+ if info and plain(info[1]) then
74
+ local recipeName = info[1]
75
+ local difficulty = plain(pick(isCraft, info[3], info[2]))
76
+ local available = plain(pick(isCraft, info[4], info[3]))
77
+ if difficulty == "header" then
78
+ header = recipeName
79
+ else
80
+ local recipe = {
81
+ name = recipeName, difficulty = difficulty, group = header,
82
+ canCraft = positiveNumber(available),
83
+ }
84
+ if isCraft then
85
+ addCraftDetails(recipe, info, index)
86
+ else
87
+ addTradeSkillDetails(recipe, index)
88
+ end
89
+ profession.recipes[#profession.recipes + 1] = recipe
90
+ end
91
+ end
92
+ end
93
+ return profession
94
+ end
95
+
96
+ -- Reagents, item and cooldown of a recipe from the new API (C_TradeSkillUI.GetRecipeSchematic,
97
+ -- GetRecipeCooldown). Only reads data of the open window; crafts nothing.
98
+ local REAGENT_TYPE_BASIC = 1 -- Enum.CraftingReagentType.Basic; optional extras are skipped
99
+
100
+ local function modernReagents(schematic)
101
+ local slots = type(schematic.reagentSlotSchematics) == "table" and schematic.reagentSlotSchematics or {}
102
+ local reagents = {}
103
+ for _, slot in ipairs(slots) do
104
+ local kind = plain(slot.reagentType)
105
+ local first = type(slot.reagents) == "table" and slot.reagents[1]
106
+ local id = type(first) == "table" and plain(first.itemID)
107
+ if id and (kind == nil or kind == REAGENT_TYPE_BASIC) then
108
+ reagents[#reagents + 1] = {
109
+ id = id,
110
+ name = firstValue({ "C_Item.GetItemNameByID", "GetItemInfo" }, id),
111
+ need = plain(slot.quantityRequired),
112
+ have = firstValue({ "C_Item.GetItemCount", "GetItemCount" }, id),
113
+ }
114
+ end
115
+ end
116
+ if #reagents == 0 then return nil end
117
+ return reagents
118
+ end
119
+
120
+ local function addModernDetails(recipe, id)
121
+ local schematic = callFirst({ "C_TradeSkillUI.GetRecipeSchematic" }, id, false)
122
+ if schematic and type(schematic[1]) == "table" then
123
+ recipe.itemId = plain(schematic[1].outputItemID)
124
+ recipe.reagents = modernReagents(schematic[1])
125
+ end
126
+ local cd = firstValue({ "C_TradeSkillUI.GetRecipeCooldown" }, id)
127
+ if type(cd) == "number" and cd > 0 then
128
+ recipe.cooldownSeconds = math.floor(cd)
129
+ recipe.readyAt = time() + math.floor(cd)
130
+ end
131
+ end
132
+
133
+ -- Profession window in the new API (C_TradeSkillUI).
134
+ local function collectModernRecipes()
135
+ if not (C_TradeSkillUI and C_TradeSkillUI.GetAllRecipeIDs and C_TradeSkillUI.GetRecipeInfo) then return nil end
136
+ local base = callFirst({ "C_TradeSkillUI.GetChildProfessionInfo", "C_TradeSkillUI.GetBaseProfessionInfo" })
137
+ local info = base and type(base[1]) == "table" and base[1]
138
+ local name = info and (plain(info.professionName) or plain(info.parentProfessionName))
139
+ if not name then return nil end
140
+ local profession = {
141
+ name = name, rank = plain(info.skillLevel), maxRank = plain(info.maxSkillLevel),
142
+ capturedAt = time(), recipes = {},
143
+ }
144
+ local okIDs, ids = pcall(C_TradeSkillUI.GetAllRecipeIDs)
145
+ for _, id in ipairs(okIDs and ids or {}) do
146
+ local ok, r = pcall(C_TradeSkillUI.GetRecipeInfo, id)
147
+ if ok and type(r) == "table" and plain(r.name) and r.learned ~= false then
148
+ local recipe = {
149
+ id = id, name = r.name,
150
+ difficulty = DIFFICULTY_BY_INDEX[r.relativeDifficulty] or plain(r.relativeDifficulty),
151
+ canCraft = positiveNumber(plain(r.numAvailable)),
152
+ }
153
+ pcall(addModernDetails, recipe, id)
154
+ profession.recipes[#profession.recipes + 1] = recipe
155
+ end
156
+ end
157
+ if #profession.recipes == 0 then return nil end
158
+ return profession
159
+ end
160
+
161
+ local function collectOpenProfession(kind)
162
+ if kind == "craft" then return collectClassicRecipes("craft") end
163
+ return collectClassicRecipes("trade") or collectModernRecipes()
164
+ end
165
+
166
+ local function captureRecipes(kind)
167
+ local ok, profession = pcall(collectOpenProfession, kind)
168
+ if not ok or not profession then return end
169
+ local current = ns.Snapshot.current()
170
+ current.recipes = (type(current.recipes) == "table" and current.recipes) or {}
171
+ current.recipes[profession.name] = profession
172
+ ns.Snapshot.windowCaptured("recipes")
173
+ end
174
+
175
+ -- TRADE_SKILL_UPDATE can arrive many times per second; we scan at most once a second.
176
+ local lastRecipeScan = {}
177
+ local function throttledRecipes(kind)
178
+ local t = GetTime and GetTime() or time()
179
+ if lastRecipeScan[kind] and t - lastRecipeScan[kind] < 1 then return end
180
+ lastRecipeScan[kind] = t
181
+ captureRecipes(kind)
182
+ end
183
+
184
+ local scanTradeSkill = ns.Snapshot.whenEnabled("recipes", function() throttledRecipes("trade") end)
185
+ local scanCraft = ns.Snapshot.whenEnabled("recipes", function() throttledRecipes("craft") end)
186
+
187
+ -- Forever 1.60.1 (per /mcp probe) accepts TRADE_SKILL_SHOW and TRADE_SKILL_LIST_UPDATE; TRADE_SKILL_UPDATE,
188
+ -- CRAFT_SHOW and CRAFT_UPDATE (and the classic GetTradeSkill*, GetCraft*) remain for older clients.
189
+ ns.Snapshot.addWindowSection("recipes")
190
+ for _, event in ipairs({ "TRADE_SKILL_SHOW", "TRADE_SKILL_UPDATE", "TRADE_SKILL_LIST_UPDATE" }) do
191
+ ns.Events.on(event, scanTradeSkill)
192
+ end
193
+ for _, event in ipairs({ "CRAFT_SHOW", "CRAFT_UPDATE" }) do
194
+ ns.Events.on(event, scanCraft)
195
+ end
@@ -0,0 +1,56 @@
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 reputation: factions with reputation level (no group headers).
5
+
6
+ local _, ns = ...
7
+ local plain = ns.Compat.plain
8
+
9
+ -- Reputation level name (e.g. "Friendly"); when the client does not know it, just the number.
10
+ local function standingLabel(reaction)
11
+ return reaction and _G["FACTION_STANDING_LABEL" .. reaction] or reaction
12
+ end
13
+
14
+ local function modernFactions()
15
+ local factions = {}
16
+ for index = 1, C_Reputation.GetNumFactions() or 0 do
17
+ local ok, data = pcall(C_Reputation.GetFactionDataByIndex, index)
18
+ if ok and type(data) == "table" and data.name and not data.isHeader then
19
+ factions[#factions + 1] = {
20
+ name = data.name,
21
+ standing = standingLabel(plain(data.reaction)),
22
+ value = plain(data.currentStanding),
23
+ floor = plain(data.currentReactionThreshold),
24
+ ceiling = plain(data.nextReactionThreshold),
25
+ }
26
+ end
27
+ end
28
+ return factions
29
+ end
30
+
31
+ local function legacyFactions()
32
+ local factions = {}
33
+ for index = 1, GetNumFactions() or 0 do
34
+ local name, _, standingID, floorValue, ceilingValue, earned, _, _, isHeader = GetFactionInfo(index)
35
+ if name and not isHeader then
36
+ factions[#factions + 1] = {
37
+ name = name,
38
+ standing = standingLabel(standingID),
39
+ value = earned, floor = floorValue, ceiling = ceilingValue,
40
+ }
41
+ end
42
+ end
43
+ return factions
44
+ end
45
+
46
+ local function collectReputation()
47
+ if C_Reputation and C_Reputation.GetNumFactions and C_Reputation.GetFactionDataByIndex then
48
+ return modernFactions()
49
+ end
50
+ if GetNumFactions and GetFactionInfo then
51
+ return legacyFactions()
52
+ end
53
+ return {}
54
+ end
55
+
56
+ ns.Snapshot.addSection("reputation", collectReputation)
@@ -0,0 +1,87 @@
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 spells (spellbook). Reading a spellbook entry is shared with the pet's
5
+ -- spellbook (Pet.lua), and the spell list with cooldowns (Cooldowns.lua).
6
+
7
+ local _, ns = ...
8
+
9
+ local Compat = ns.Compat
10
+ local Spellbook = {}
11
+ ns.Spellbook = Spellbook
12
+
13
+ -- Spellbook entry from C_SpellBook.GetSpellBookItemInfo. petAction marks pet commands and stances (the entry type
14
+ -- Enum.SpellBookItemType.PetAction), so the server does not depend on the subtext ("Pet Stance") in the client's language.
15
+ function Spellbook.entryFromItemInfo(info)
16
+ local petActionType = Enum and Enum.SpellBookItemType and Enum.SpellBookItemType.PetAction
17
+ return {
18
+ id = info.spellID or info.actionID,
19
+ name = info.name,
20
+ rank = (info.subName and info.subName ~= "") and info.subName or nil,
21
+ passive = info.isPassive and true or nil,
22
+ icon = Compat.plain(info.iconID),
23
+ petAction = (petActionType ~= nil and info.itemType == petActionType) or nil,
24
+ }
25
+ end
26
+
27
+ -- true when the client says the spell is a buff the character casts on itself (C_Spell.IsSelfBuff); nil otherwise.
28
+ -- The server compares the spell's icon with the icons of active auras, so it needs no spell names to tell
29
+ -- that a self buff is not active.
30
+ local function selfBuffFlag(spell)
31
+ if not (spell.id and not spell.passive and C_Spell and C_Spell.IsSelfBuff) then return nil end
32
+ local ok, result = pcall(C_Spell.IsSelfBuff, spell.id)
33
+ if ok and Compat.plain(result) == true then return true end
34
+ return nil
35
+ end
36
+
37
+ local function modernSpellbook()
38
+ local spells = {}
39
+ local bank = Enum and Enum.SpellBookSpellBank and Enum.SpellBookSpellBank.Player or 0
40
+ for line = 1, C_SpellBook.GetNumSpellBookSkillLines() or 0 do
41
+ local lineInfo = C_SpellBook.GetSpellBookSkillLineInfo(line)
42
+ if lineInfo then
43
+ local offset = lineInfo.itemIndexOffset or 0
44
+ for i = offset + 1, offset + (lineInfo.numSpellBookItems or 0) do
45
+ local info = C_SpellBook.GetSpellBookItemInfo and C_SpellBook.GetSpellBookItemInfo(i, bank)
46
+ if info and info.name then
47
+ local spell = Spellbook.entryFromItemInfo(info)
48
+ spell.tab = lineInfo.name
49
+ spell.selfBuff = selfBuffFlag(spell)
50
+ spells[#spells + 1] = spell
51
+ end
52
+ end
53
+ end
54
+ end
55
+ return spells
56
+ end
57
+
58
+ local function legacySpellbook()
59
+ local spells = {}
60
+ for tab = 1, GetNumSpellTabs() or 0 do
61
+ local tabName, _, offset, numSpells = GetSpellTabInfo(tab)
62
+ for i = (offset or 0) + 1, (offset or 0) + (numSpells or 0) do
63
+ local name, rank = GetSpellBookItemName(i, "spell")
64
+ if name then
65
+ spells[#spells + 1] = {
66
+ name = name,
67
+ rank = (rank and rank ~= "") and rank or nil,
68
+ tab = tabName,
69
+ }
70
+ end
71
+ end
72
+ end
73
+ return spells
74
+ end
75
+
76
+ -- All of the character's spells with the spellbook tab name.
77
+ function Spellbook.knownSpells()
78
+ if C_SpellBook and C_SpellBook.GetNumSpellBookSkillLines and C_SpellBook.GetSpellBookSkillLineInfo then
79
+ return modernSpellbook()
80
+ end
81
+ if GetNumSpellTabs and GetSpellTabInfo and GetSpellBookItemName then
82
+ return legacySpellbook()
83
+ end
84
+ return {}
85
+ end
86
+
87
+ ns.Snapshot.addSection("spells", Spellbook.knownSpells)
@@ -0,0 +1,90 @@
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 stable (from the window): pets in the stable, saved when the player opens the stable window.
5
+ -- The addon changes nothing in the stable.
6
+
7
+ local _, ns = ...
8
+ local plain, callFirst, firstValue = ns.Compat.plain, ns.Compat.callFirst, ns.Compat.firstValue
9
+
10
+ local CURRENT_PET_SLOT = 0 -- in the classic API slot 0 is the pet with the character
11
+ local MAX_SLOTS = 50 -- guard against an unrealistic number of slots from the API
12
+
13
+ -- Pet from a new API table (C_StableInfo).
14
+ local function petFromTable(info, slot)
15
+ return {
16
+ slot = plain(info.slotID) or slot,
17
+ name = plain(info.name),
18
+ level = plain(info.level),
19
+ family = plain(info.familyName) or plain(info.type),
20
+ specialization = plain(info.specialization),
21
+ }
22
+ end
23
+
24
+ -- Pet from classic GetStablePetInfo results: icon, name, level, family, loyalty.
25
+ local function petFromValues(r, slot)
26
+ return {
27
+ slot = slot,
28
+ name = plain(r[2]),
29
+ level = plain(r[3]),
30
+ family = plain(r[4]),
31
+ loyalty = plain(r[5]),
32
+ }
33
+ end
34
+
35
+ local function stabledPet(slot)
36
+ local r = callFirst({ "C_StableInfo.GetStablePetInfo", "GetStablePetInfo" }, slot)
37
+ if not r then return nil end
38
+ local pet
39
+ if type(r[1]) == "table" then
40
+ pet = petFromTable(r[1], slot)
41
+ else
42
+ pet = petFromValues(r, slot)
43
+ end
44
+ if not pet.name then return nil end
45
+ if slot == CURRENT_PET_SLOT then pet.current = true end
46
+ return pet
47
+ end
48
+
49
+ -- New API: a ready list of stabled pets, preceded by the active (summoned) one with active = true.
50
+ local function petsFromList()
51
+ local r = callFirst({ "C_StableInfo.GetStabledPetList" })
52
+ if not r or type(r[1]) ~= "table" then return nil end
53
+ local pets = {}
54
+ local active = callFirst({ "C_StableInfo.GetActivePetList" })
55
+ for i, info in ipairs(active and type(active[1]) == "table" and active[1] or {}) do
56
+ if type(info) == "table" then
57
+ local pet = petFromTable(info, i)
58
+ pet.active = true
59
+ if pet.name then pets[#pets + 1] = pet end
60
+ end
61
+ end
62
+ for i, info in ipairs(r[1]) do
63
+ if type(info) == "table" then pets[#pets + 1] = petFromTable(info, i) end
64
+ end
65
+ return pets
66
+ end
67
+
68
+ -- Classic API: slots from 0 (the pet with the character) to the number of purchased slots.
69
+ local function petsBySlot()
70
+ local slots = firstValue({ "C_StableInfo.GetNumStableSlots", "GetNumStableSlots" })
71
+ if type(slots) ~= "number" then return nil end
72
+ local pets = {}
73
+ for slot = CURRENT_PET_SLOT, math.min(slots, MAX_SLOTS) do
74
+ local pet = stabledPet(slot)
75
+ if pet then pets[#pets + 1] = pet end
76
+ end
77
+ return pets
78
+ end
79
+
80
+ local function collectStable()
81
+ local pets = petsFromList() or petsBySlot()
82
+ if not pets then return nil end
83
+ return {
84
+ capturedAt = time(),
85
+ slots = firstValue({ "C_StableInfo.GetNumStableSlots", "GetNumStableSlots" }),
86
+ pets = pets,
87
+ }
88
+ end
89
+
90
+ ns.Snapshot.addWindowSection("stable", collectStable, { "PET_STABLE_SHOW", "PET_STABLE_UPDATE" })