-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibTradeSkillRecipes.lua
More file actions
executable file
·225 lines (195 loc) · 7.25 KB
/
LibTradeSkillRecipes.lua
File metadata and controls
executable file
·225 lines (195 loc) · 7.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
local MAJOR = "LibTradeSkillRecipes-1"
local MINOR = 5
assert(LibStub, MAJOR .. " requires LibStub")
local lib = LibStub:NewLibrary(MAJOR, MINOR)
if not lib then
return
end
local function getOrCreate(tOfT, key)
local t = tOfT[key]
if t == nil then
t = {}
tOfT[key] = t
end
return t
end
local tInsertUnique = tInsertUnique or table.insert
lib.categories = lib.categories or {}
lib.recipes = lib.recipes or {}
lib.spells = lib.spells or {}
lib.items = lib.items or {}
lib.enchantments = lib.enchantments or {}
lib.effects = lib.effects or {}
lib.expansions = lib.expansions or {}
lib.skillLines = lib.skillLines or {}
function lib:AddSkillLine(skillLineId, name, category, spells)
local hasRecipes = skillLineId ~= 182 and skillLineId ~= 356 and skillLineId ~= 393
lib.skillLines[skillLineId] = { name = name, isSecondary = category == 9, hasRecipes = hasRecipes, spells = spells}
end
function lib:GetSkillLines()
return lib.skillLines
end
---Adds the expansion a spell was added.
---@param spellId number
---@param expansionId number
function lib:AddExpansion(spellId, expansionId)
local info = lib.spells[spellId]
if info then
info.expansionId = expansionId
local expansions = getOrCreate(lib.expansions, expansionId)
table.insert(expansions, info)
end
end
---Adds the name of the enchantment.
---@param id number
---@param name string
function lib:AddEffect(id, name)
lib.effects[id] = name
end
---Adds an enchantment recipe.
---@param categoryId number
---@param recipeId number|nil
---@param spellId number
---@param effectId number
function lib:AddEnchantmentRecipe(categoryId, recipeId, spellId, effectId)
self:AddRecipe(categoryId, recipeId, spellId, nil, nil, effectId)
end
function lib:AddCraftingDataRecipe(categoryId, recipeId, spellId, craftingDataId)
local info = self:AddRecipe(categoryId, recipeId, spellId, nil, nil, nil)
info.craftingDataId = craftingDataId
end
function lib:AddSalvageRecipe(categoryId, recipeId, spellId, salvageId)
local info = self:AddRecipe(categoryId, recipeId, spellId, nil, nil, nil)
info.salvageId = salvageId
end
---Adds a recipe.
---@param categoryId number
---@param recipeId number|nil
---@param spellId number
---@param itemId number|nil
---@param itemSpellId number|nil
---@param effectId number|nil
function lib:AddRecipe(categoryId, recipeId, spellId, itemId, itemSpellId, effectId)
local info = lib.spells[spellId] or { spellId = spellId }
lib.spells[spellId] = info
local categories = getOrCreate(lib.categories, categoryId)
tInsertUnique(categories, info)
if info.categoryId then
-- Currently not sure how retail works, but this works for classic.
-- assert(info.categoryId == categoryId, "Duplicate spellId doesn't match categoryId: " .. spellId)
end
info.categoryId = categoryId
info.recipeIds = info.recipeIds or {}
if recipeId then
lib.recipes[recipeId] = info
tInsertUnique(info.recipeIds, recipeId)
end
if itemId then
local items = getOrCreate(lib.items, itemId)
tInsertUnique(items, info)
if info.itemId then
assert(info.itemId == itemId, "Duplicate spellId doesn't match itemId: " .. spellId)
end
info.itemId = itemId
if itemSpellId then
if info.itemSpellId then
assert(info.itemSpellId == itemSpellId, "Duplicate spellId doesn't match itemSpellId: " .. spellId)
end
info.itemSpellId = itemSpellId
end
end
if effectId then
if info.spellEffectId then
assert(info.spellEffectId == effectId, "Duplicate spellId doesn't match effectId:" .. spellId)
end
info.spellEffectId = effectId
end
return info
end
---Gets the name of the effect.
---@param effectId string|number id of the effect
---@return string name of the effect
function lib:GetEffect(effectId)
return lib.effects[tonumber(effectId)]
end
---Gets all effects, id to name.
---@return table all the effects
function lib:GetEffects()
return lib.effects
end
---Maps the effect and slot to the spell.
---@param spellId number id of the spell
---@param effectId number id of the effect
---@param slotIds number[] slots this effect can be applied
function lib:AddEnchantment(spellId, effectId, slotIds)
for _, slotId in ipairs(slotIds) do
lib.enchantments[effectId] = lib.enchantments[effectId] or {}
lib.enchantments[effectId][slotId] = spellId
end
end
---Gets the spell for the effect and slot if it exists.
---@param effectId string|number id of the effect
---@param slotId string|number id of the slot
---@return number id of the spell
function lib:GetEnchantment(effectId, slotId)
local slots = lib.enchantments[tonumber(effectId)] or {}
return slots[tonumber(slotId)]
end
function lib:GetEnchantments()
return lib.enchantments
end
---Gets all the associated spells to the given category.
---@param categoryId string|number id of the category
---@return table spell ids associated to the category
function lib:GetCategorySpells(categoryId)
return lib.categories[tonumber(categoryId)]
end
---Gets all trade categories, id to a table of all the info.
---@return table TradeSkillInfos the categories
function lib:GetCategories()
return lib.categories
end
---Gets all the associated spells to the given expansion.
---@param expansion string|number
---@return table TradeSkillInfos all skills for that expansion
function lib:GetExpansionSpells(expansion)
return lib.expansions[tonumber(expansion)]
end
---Gets all expansions, id to a table of all the spells
---@return table expansions to spells
function lib:GetExpansions()
return lib.expansions
end
---Given an recipe id, returns associated information for crafting.
---@param recipeId string|number
---@return table? TradeSkillInfo
function lib:GetInfoByRecipeId(recipeId)
---@diagnostic disable-next-line: cast-local-type
recipeId = tonumber(recipeId)
return lib.recipes[recipeId]
end
---Given an item id, returns associated information for crafting.
---@param itemId string|number
---@return table? TradeSkillInfos items can have multiple spells if there are different levels created
function lib:GetInfoByItemId(itemId)
---@diagnostic disable-next-line: cast-local-type
itemId = tonumber(itemId)
return lib.items[itemId]
end
---Given a spellId id, returns associated information for crafting.
---@param spellId string|number
---@return table? TradeSkillInfo
function lib:GetInfoBySpellId(spellId)
---@diagnostic disable-next-line: cast-local-type
spellId = tonumber(spellId)
return lib.spells[spellId]
end
---@class TradeSkillInfo
---@field categoryId number trade skill category id for the item or effect
---@field expansionId number original expansion for the item or effect (0 based)
---@field recipeIds (number)[] list of the all recipe ids to learn the trade skill
---@field spellId number spell used to create the item or effect
---@field itemId? number item that is created from the spell
---@field spellEffectId? number effect provided by the spell or using the item, e.g. an enchantment
---@field salvageId? number items received from salving, currently has no lookup
---@field craftingDataId? number crafting elements created from the spell