-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArmoryRecipes.lua
152 lines (129 loc) · 4.83 KB
/
ArmoryRecipes.lua
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
local Armory, _ = Armory, nil
local ArmoryDbEntry = ArmoryDbEntry
local tostring = tostring
local table = table
local pairs = pairs
local ipairs = ipairs
local format = format
local container = "Professions"
local itemContainer = "SkillLines"
local recipeContainer = "Recipes"
local reagentContainer = "Reagents"
local recipes = {}
local function IsKnownReagent(id)
return Armory:GetSharedValue(container, reagentContainer, tostring(id)) ~= nil
end
local function AddCrafters(recipes)
local currentProfile = Armory:CurrentProfile()
for _, profile in ipairs(Armory:GetConnectedProfiles()) do
Armory:SelectProfile(profile)
local dbEntry = Armory.selectedDbBaseEntry
if ( dbEntry:Contains(container) ) then
local character = Armory:GetQualifiedCharacterName()
for _, recipe in ipairs(recipes) do
if ( dbEntry:Contains(container, recipe.profession) ) then
for i = 1, dbEntry:GetNumValues(container, recipe.profession, itemContainer) do
if ( dbEntry:GetValue(container, recipe.profession, itemContainer, i, "Data") == recipe.id ) then
table.insert(recipe.crafters, character)
break
end
end
end
end
end
end
Armory:SelectProfile(currentProfile)
end
local function GetReagentQuantity(recipe, reagentID)
local reagents = recipe.Reagents
if ( reagents ) then
for i = 1, #reagents do
local qualityReagents = { ArmoryDbEntry.Load(reagents[i]) }
if ( tContains(qualityReagents, reagentID) ) then
return qualityReagents[2]
end
end
end
return 0
end
local function AddRecipes(recipes, reagentID)
local recipeDB = Armory:GetSharedValue(container, recipeContainer)
for recipeID, recipe in pairs(recipeDB) do
local quantity = GetReagentQuantity(recipe, reagentID)
if ( quantity > 0 ) then
local professionInfo = C_TradeSkillUI.GetProfessionInfoByRecipeID(recipeID)
table.insert(recipes, {
id = recipeID,
name = Armory:GetNameFromLink(recipe.RecipeLink),
count = quantity,
profession = professionInfo and professionInfo.parentProfessionName or UNKNOWN,
crafters = {}
})
end
end
end
local function UpdateRecipes(recipes, itemID)
table.wipe(recipes)
if ( not IsKnownReagent(itemID) ) then
return
end
AddRecipes(recipes, itemID)
if ( #recipes > 0 ) then
AddCrafters(recipes)
end
end
local function FilterRecipes(recipes)
local filteredRecipes = {}
if ( IsAltKeyDown() ) then
filteredRecipes = recipes
else
local recipeProfessions = {}
for _, recipe in ipairs(recipes) do
if ( not recipeProfessions[recipe.profession] ) then
recipeProfessions[recipe.profession] = { name = recipe.profession, count = 0, crafters = {} }
end
recipeProfessions[recipe.profession].count = recipeProfessions[recipe.profession].count + 1
for _, crafter in ipairs(recipe.crafters) do
if ( not tContains(recipeProfessions[recipe.profession].crafters, crafter) ) then
table.insert(recipeProfessions[recipe.profession].crafters, crafter)
end
end
end
for _, recipeProfession in pairs(recipeProfessions) do
table.insert(filteredRecipes, recipeProfession)
end
end
table.sort(filteredRecipes, function(a, b) return a.name < b.name end)
return filteredRecipes
end
local currentItemID = nil
local function EnhanceItemTooltip(tooltip, itemID)
if ( currentItemID ~= itemID ) then
UpdateRecipes(recipes, itemID)
end
currentItemID = itemID
local filteredRecipes = FilterRecipes(recipes)
if ( #filteredRecipes > 0 ) then
tooltip:AddLine(" ")
if ( IsAltKeyDown() ) then
tooltip:AddLine(AUCTION_CATEGORY_RECIPES)
else
tooltip:AddLine(format("%s <%s - %s>", AUCTION_CATEGORY_RECIPES, ALT_KEY_TEXT, PROFESSIONS_CRAFTING_DETAILS_HEADER))
end
for _, recipe in ipairs(filteredRecipes) do
tooltip:AddDoubleLine(format("%s (%d)", recipe.name, recipe.count), table.concat(recipe.crafters, ", "), 1, 1, 1)
end
end
end
do
if ( not Armory:HasTradeSkills() ) then
Armory:PrintError("Professions module not enabled")
return
end
TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Item, function(tooltip, data)
if (tooltip == GameTooltip or tooltip == ItemRefTooltip) then
local _, _, id = tooltip:GetItem()
EnhanceItemTooltip(tooltip, id)
end
end)
end