yellowfive@57
|
1 local Amr = LibStub("AceAddon-3.0"):GetAddon("AskMrRobot")
|
yellowfive@57
|
2 local L = LibStub("AceLocale-3.0"):GetLocale("AskMrRobot", true)
|
yellowfive@57
|
3 local AceGUI = LibStub("AceGUI-3.0")
|
yellowfive@57
|
4
|
yellowfive@57
|
5 local _frameShop
|
yellowfive@57
|
6 local _panelContent
|
yellowfive@57
|
7 local _cboPlayers
|
yellowfive@57
|
8 local _selectedPlayer
|
yellowfive@81
|
9
|
yellowfive@57
|
10 local _specs = {
|
yellowfive@57
|
11 [1] = true,
|
yellowfive@81
|
12 [2] = true,
|
yellowfive@81
|
13 [3] = true,
|
yellowfive@81
|
14 [4] = true,
|
yellowfive@57
|
15 }
|
yellowfive@81
|
16
|
yellowfive@57
|
17 local _chk1
|
yellowfive@57
|
18 local _chk2
|
yellowfive@81
|
19 local _chk3
|
yellowfive@81
|
20 local _chk4
|
yellowfive@57
|
21 local _isAhOpen = false
|
yellowfive@57
|
22
|
yellowfive@57
|
23 local function onShopFrameClose(widget)
|
yellowfive@57
|
24 AceGUI:Release(widget)
|
yellowfive@57
|
25 _frameShop = nil
|
yellowfive@57
|
26 _cboPlayers = nil
|
yellowfive@57
|
27 _chk1 = nil
|
yellowfive@57
|
28 _chk2 = nil
|
yellowfive@81
|
29 _chk3 = nil
|
yellowfive@81
|
30 _chk4 = nil
|
yellowfive@57
|
31 _panelContent = nil
|
yellowfive@57
|
32 end
|
yellowfive@57
|
33
|
yellowfive@57
|
34 function Amr:HideShopWindow()
|
yellowfive@57
|
35 if not _frameShop then return end
|
yellowfive@57
|
36 _frameShop:Hide()
|
yellowfive@57
|
37 end
|
yellowfive@57
|
38
|
yellowfive@57
|
39 local function onPlayerChange(widget, eventName, value)
|
yellowfive@57
|
40 _selectedPlayer = value
|
yellowfive@57
|
41 Amr:RefreshShoppingUi()
|
yellowfive@57
|
42 end
|
yellowfive@57
|
43
|
yellowfive@57
|
44 local function onSpecClick(widget)
|
yellowfive@57
|
45 local spec = widget:GetUserData("spec")
|
yellowfive@57
|
46 _specs[spec] = not _specs[spec]
|
yellowfive@57
|
47
|
yellowfive@57
|
48 Amr:RefreshShoppingUi()
|
yellowfive@57
|
49 end
|
yellowfive@57
|
50
|
yellowfive@57
|
51 local function onItemClick(widget)
|
yellowfive@57
|
52 local name = widget:GetUserData("itemName")
|
yellowfive@57
|
53 if name then
|
yellowfive@57
|
54 QueryAuctionItems(name)
|
yellowfive@57
|
55 end
|
yellowfive@57
|
56 end
|
yellowfive@57
|
57
|
yellowfive@57
|
58 function Amr:ShowShopWindow()
|
yellowfive@57
|
59 if not _frameShop then
|
yellowfive@57
|
60 _frameShop = AceGUI:Create("AmrUiFrame")
|
yellowfive@57
|
61 _frameShop:SetStatusTable(Amr.db.profile.shopWindow) -- window position is remembered in db
|
yellowfive@57
|
62 _frameShop:SetCallback("OnClose", onShopFrameClose)
|
yellowfive@57
|
63 _frameShop:SetLayout("None")
|
yellowfive@57
|
64 _frameShop:SetWidth(500)
|
yellowfive@57
|
65 _frameShop:SetHeight(500)
|
yellowfive@57
|
66 _frameShop:SetBorderColor(Amr.Colors.BorderBlue)
|
yellowfive@57
|
67 _frameShop:SetBackgroundColor(Amr.Colors.Bg)
|
yellowfive@57
|
68
|
yellowfive@61
|
69 if Amr.db.profile.options.uiScale ~= 1 then
|
yellowfive@61
|
70 local scale = tonumber(Amr.db.profile.options.uiScale)
|
yellowfive@61
|
71 _frameShop:SetScale(scale)
|
yellowfive@61
|
72 end
|
yellowfive@61
|
73
|
yellowfive@57
|
74 local lbl = AceGUI:Create("AmrUiLabel")
|
yellowfive@57
|
75 lbl:SetWidth(400)
|
yellowfive@57
|
76 lbl:SetFont(Amr.CreateFont("Bold", 28, Amr.Colors.White))
|
yellowfive@57
|
77 lbl:SetText(L.ShopTitle)
|
yellowfive@57
|
78 lbl:SetWordWrap(false)
|
yellowfive@57
|
79 lbl:SetJustifyH("CENTER")
|
yellowfive@57
|
80 lbl:SetPoint("TOP", _frameShop.content, "TOP", 0, 30)
|
yellowfive@57
|
81 _frameShop:AddChild(lbl)
|
yellowfive@57
|
82
|
yellowfive@57
|
83 lbl:SetCallback("OnMouseDown", function(widget) _frameShop:StartMove() end)
|
yellowfive@57
|
84 lbl:SetCallback("OnMouseUp", function(widget) _frameShop:EndMove() end)
|
yellowfive@57
|
85
|
yellowfive@57
|
86 -- player picker
|
yellowfive@57
|
87 _cboPlayers = AceGUI:Create("AmrUiDropDown")
|
yellowfive@57
|
88 _cboPlayers:SetWidth(400)
|
yellowfive@57
|
89 _cboPlayers:SetPoint("TOPLEFT", _frameShop.content, "TOPLEFT", 0, -30)
|
yellowfive@57
|
90 _frameShop:AddChild(_cboPlayers)
|
yellowfive@57
|
91
|
yellowfive@57
|
92 -- spec pickers
|
yellowfive@57
|
93 _chk1 = AceGUI:Create("AmrUiCheckBox")
|
yellowfive@57
|
94 _chk1:SetPoint("TOPLEFT", _cboPlayers.frame, "BOTTOMLEFT", 0, -20)
|
yellowfive@57
|
95 _chk1:SetUserData("spec", 1)
|
yellowfive@57
|
96 _chk1:SetCallback("OnClick", onSpecClick)
|
yellowfive@57
|
97 _frameShop:AddChild(_chk1)
|
yellowfive@57
|
98
|
yellowfive@57
|
99 _chk2 = AceGUI:Create("AmrUiCheckBox")
|
yellowfive@57
|
100 _chk2:SetPoint("LEFT", _chk1.frame, "RIGHT", 30, 0)
|
yellowfive@57
|
101 _chk2:SetUserData("spec", 2)
|
yellowfive@57
|
102 _chk2:SetCallback("OnClick", onSpecClick)
|
yellowfive@57
|
103 _frameShop:AddChild(_chk2)
|
yellowfive@57
|
104
|
yellowfive@81
|
105 _chk3 = AceGUI:Create("AmrUiCheckBox")
|
yellowfive@81
|
106 _chk3:SetPoint("LEFT", _chk2.frame, "RIGHT", 30, 0)
|
yellowfive@81
|
107 _chk3:SetUserData("spec", 3)
|
yellowfive@81
|
108 _chk3:SetCallback("OnClick", onSpecClick)
|
yellowfive@81
|
109 _frameShop:AddChild(_chk3)
|
yellowfive@81
|
110
|
yellowfive@81
|
111 _chk4 = AceGUI:Create("AmrUiCheckBox")
|
yellowfive@81
|
112 _chk4:SetPoint("LEFT", _chk3.frame, "RIGHT", 30, 0)
|
yellowfive@81
|
113 _chk4:SetUserData("spec", 4)
|
yellowfive@81
|
114 _chk4:SetCallback("OnClick", onSpecClick)
|
yellowfive@81
|
115 _frameShop:AddChild(_chk4)
|
yellowfive@81
|
116
|
yellowfive@57
|
117 _panelContent = AceGUI:Create("AmrUiPanel")
|
yellowfive@57
|
118 _panelContent:SetLayout("None")
|
yellowfive@57
|
119 _panelContent:SetTransparent()
|
yellowfive@57
|
120 _panelContent:SetPoint("TOPLEFT", _chk1.frame, "BOTTOMLEFT", 0, -10)
|
yellowfive@57
|
121 _panelContent:SetPoint("BOTTOMRIGHT", _frameShop.content, "BOTTOMRIGHT")
|
yellowfive@57
|
122 _frameShop:AddChild(_panelContent)
|
yellowfive@57
|
123
|
yellowfive@57
|
124 -- update shopping list data
|
yellowfive@57
|
125 local player = Amr:ExportCharacter()
|
yellowfive@57
|
126 Amr:UpdateShoppingData(player)
|
yellowfive@57
|
127
|
yellowfive@57
|
128 -- fill player list
|
yellowfive@57
|
129 local playerList = {}
|
yellowfive@57
|
130 for name, data in pairs(Amr.db.global.Shopping) do
|
yellowfive@57
|
131 table.insert(playerList, { text = name, value = name })
|
yellowfive@57
|
132 end
|
yellowfive@57
|
133 _cboPlayers:SetItems(playerList)
|
yellowfive@57
|
134
|
yellowfive@57
|
135 -- set default selected player
|
yellowfive@57
|
136 if not _selectedPlayer then
|
yellowfive@57
|
137 _selectedPlayer = player.Name .. "-" .. player.Realm
|
yellowfive@57
|
138 end
|
yellowfive@57
|
139 _cboPlayers:SelectItem(_selectedPlayer)
|
yellowfive@57
|
140
|
yellowfive@57
|
141 Amr:RefreshShoppingUi()
|
yellowfive@57
|
142
|
yellowfive@57
|
143 -- set event on dropdown after UI has been initially rendered
|
yellowfive@57
|
144 _cboPlayers:SetCallback("OnChange", onPlayerChange)
|
yellowfive@57
|
145 else
|
yellowfive@57
|
146 _frameShop:Show()
|
yellowfive@57
|
147 Amr:RefreshShoppingUi()
|
yellowfive@57
|
148 end
|
yellowfive@57
|
149
|
yellowfive@57
|
150 _frameShop:Raise()
|
yellowfive@57
|
151 end
|
yellowfive@57
|
152
|
yellowfive@57
|
153 -- helper to render a section of the shopping list
|
yellowfive@57
|
154 local function renderShopSection(list, scroll, header)
|
yellowfive@57
|
155 if not list or next(list) == nil then return end
|
yellowfive@57
|
156
|
yellowfive@57
|
157 local w = 440
|
yellowfive@57
|
158
|
yellowfive@57
|
159 local panel = AceGUI:Create("AmrUiPanel")
|
yellowfive@57
|
160 panel:SetLayout("None")
|
yellowfive@57
|
161 panel:SetTransparent()
|
yellowfive@57
|
162 panel:SetWidth(w)
|
yellowfive@57
|
163 panel:SetHeight(40)
|
yellowfive@57
|
164 scroll:AddChild(panel)
|
yellowfive@57
|
165
|
yellowfive@57
|
166 local lbl = AceGUI:Create("AmrUiLabel")
|
yellowfive@57
|
167 lbl:SetWidth(w)
|
yellowfive@57
|
168 lbl:SetFont(Amr.CreateFont("Regular", 18, Amr.Colors.TextHeaderActive))
|
yellowfive@57
|
169 lbl:SetText(header)
|
yellowfive@57
|
170 lbl:SetPoint("BOTTOMLEFT", panel.content, "BOTTOMLEFT")
|
yellowfive@57
|
171 panel:AddChild(lbl)
|
yellowfive@57
|
172
|
yellowfive@57
|
173 for itemId, count in pairs(list) do
|
yellowfive@57
|
174 panel = AceGUI:Create("AmrUiPanel")
|
yellowfive@57
|
175 panel:SetLayout("None")
|
yellowfive@57
|
176 panel:SetTransparent()
|
yellowfive@57
|
177 panel:SetWidth(w)
|
yellowfive@57
|
178 panel:SetHeight(30)
|
yellowfive@57
|
179 scroll:AddChild(panel)
|
yellowfive@57
|
180
|
yellowfive@57
|
181 lbl = AceGUI:Create("AmrUiLabel")
|
yellowfive@57
|
182 lbl:SetWidth(35)
|
yellowfive@57
|
183 lbl:SetWordWrap(false)
|
yellowfive@57
|
184 lbl:SetFont(Amr.CreateFont("Bold", 20, Amr.Colors.White))
|
yellowfive@57
|
185 lbl:SetText(count .. "x")
|
yellowfive@57
|
186 lbl:SetPoint("LEFT", panel.content, "LEFT")
|
yellowfive@57
|
187 panel:AddChild(lbl)
|
yellowfive@57
|
188
|
yellowfive@57
|
189 local icon = AceGUI:Create("AmrUiIcon")
|
yellowfive@57
|
190 icon:SetBorderWidth(1)
|
yellowfive@57
|
191 icon:SetIconBorderColor(Amr.Colors.White)
|
yellowfive@57
|
192 icon:SetWidth(18)
|
yellowfive@57
|
193 icon:SetHeight(18)
|
yellowfive@57
|
194 icon:SetPoint("LEFT", lbl.frame, "RIGHT", 5, 0)
|
yellowfive@57
|
195 panel:AddChild(icon)
|
yellowfive@57
|
196
|
yellowfive@57
|
197 local btn = AceGUI:Create("AmrUiTextButton")
|
yellowfive@57
|
198 btn:SetWidth(w - 30 - 18 - 15)
|
yellowfive@57
|
199 btn:SetJustifyH("LEFT")
|
yellowfive@57
|
200 btn:SetWordWrap(false)
|
yellowfive@57
|
201 btn:SetFont(Amr.CreateFont("Bold", 14, Amr.Colors.White))
|
yellowfive@57
|
202 btn:SetHoverFont(Amr.CreateFont("Bold", 14, Amr.Colors.White))
|
yellowfive@57
|
203 btn:SetPoint("LEFT", icon.frame, "RIGHT", 5, 0)
|
yellowfive@57
|
204 btn:SetCallback("OnClick", onItemClick)
|
yellowfive@57
|
205 panel:AddChild(btn)
|
yellowfive@57
|
206
|
yellowfive@57
|
207 Amr.GetItemInfo(itemId, function(obj, name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture)
|
yellowfive@57
|
208 -- set icon, name, and a tooltip
|
yellowfive@57
|
209 obj.itemIcon:SetIcon(texture)
|
yellowfive@57
|
210 obj.itemText:SetText(link:gsub("%[", ""):gsub("%]", ""))
|
yellowfive@57
|
211 obj.itemText:SetUserData("itemName", name)
|
yellowfive@57
|
212 Amr:SetItemTooltip(obj.itemText, link)
|
yellowfive@57
|
213 end, { itemIcon = icon, itemText = btn })
|
yellowfive@57
|
214 end
|
yellowfive@57
|
215
|
yellowfive@57
|
216 end
|
yellowfive@57
|
217
|
yellowfive@57
|
218 function Amr:RefreshShoppingUi()
|
yellowfive@57
|
219
|
yellowfive@57
|
220 _chk1:SetVisible(false)
|
yellowfive@57
|
221 _chk2:SetVisible(false)
|
yellowfive@81
|
222 _chk3:SetVisible(false)
|
yellowfive@81
|
223 _chk4:SetVisible(false)
|
yellowfive@57
|
224
|
yellowfive@57
|
225 _chk1:SetChecked(false)
|
yellowfive@57
|
226 _chk2:SetChecked(false)
|
yellowfive@81
|
227 _chk3:SetChecked(false)
|
yellowfive@81
|
228 _chk4:SetChecked(false)
|
yellowfive@57
|
229
|
yellowfive@57
|
230 -- clear out any previous data
|
yellowfive@57
|
231 _panelContent:ReleaseChildren()
|
yellowfive@57
|
232
|
yellowfive@57
|
233 local data = Amr.db.global.Shopping[_selectedPlayer]
|
yellowfive@57
|
234 if not data then
|
yellowfive@57
|
235 _panelContent:SetLayout("None")
|
yellowfive@57
|
236
|
yellowfive@57
|
237 local lbl = AceGUI:Create("AmrUiLabel")
|
yellowfive@57
|
238 lbl:SetFont(Amr.CreateFont("Italic", 18, Amr.Colors.TextTan))
|
yellowfive@57
|
239 lbl:SetText(L.ShopEmpty)
|
yellowfive@57
|
240 lbl:SetJustifyH("CENTER")
|
yellowfive@57
|
241 lbl:SetPoint("TOP", _panelContent.content, "TOP", 0, -30)
|
yellowfive@57
|
242 _panelContent:AddChild(lbl)
|
yellowfive@57
|
243 else
|
yellowfive@57
|
244 -- set labels on checkboxes
|
yellowfive@61
|
245 if data.specs[1] and data.specs[1] ~= 0 then
|
yellowfive@81
|
246 _chk1:SetText(L.SpecsShort[data.specs[1]])
|
yellowfive@57
|
247 _chk1:SetVisible(true)
|
yellowfive@57
|
248 _chk1:SetChecked(_specs[1])
|
yellowfive@57
|
249 end
|
yellowfive@57
|
250
|
yellowfive@61
|
251 if data.specs[2] and data.specs[2] ~= 0 then
|
yellowfive@81
|
252 _chk2:SetText(L.SpecsShort[data.specs[2]])
|
yellowfive@57
|
253 _chk2:SetVisible(true)
|
yellowfive@57
|
254 _chk2:SetChecked(_specs[2])
|
yellowfive@57
|
255 end
|
yellowfive@57
|
256
|
yellowfive@81
|
257 if data.specs[3] and data.specs[3] ~= 0 then
|
yellowfive@81
|
258 _chk3:SetText(L.SpecsShort[data.specs[3]])
|
yellowfive@81
|
259 _chk3:SetVisible(true)
|
yellowfive@81
|
260 _chk3:SetChecked(_specs[3])
|
yellowfive@81
|
261 end
|
yellowfive@81
|
262
|
yellowfive@81
|
263 if data.specs[4] and data.spes[4] ~= 0 then
|
yellowfive@81
|
264 _chk4:SetText(L.SpecsShort[data.specs[4]])
|
yellowfive@81
|
265 _chk4:SetVisible(true)
|
yellowfive@81
|
266 _chk4:SetChecked(_specs[4])
|
yellowfive@81
|
267 end
|
yellowfive@81
|
268
|
yellowfive@57
|
269 local spec = 0
|
yellowfive@81
|
270 if not _specs[1] and not _specs[2] and not _specs[3] and not _specs[4] then
|
yellowfive@81
|
271 -- all unchecked, show nothing
|
yellowfive@57
|
272 else
|
yellowfive@57
|
273 -- both is 0, otherwise the one that is selected
|
yellowfive@57
|
274 if not _specs[1] or not _specs[2] then
|
yellowfive@57
|
275 spec = _specs[1] and 1 or 2
|
yellowfive@57
|
276 end
|
yellowfive@57
|
277
|
yellowfive@57
|
278 _panelContent:SetLayout("Fill")
|
yellowfive@57
|
279
|
yellowfive@57
|
280 local scroll = AceGUI:Create("AmrUiScrollFrame")
|
yellowfive@57
|
281 scroll:SetLayout("List")
|
yellowfive@57
|
282 _panelContent:AddChild(scroll)
|
yellowfive@57
|
283
|
yellowfive@57
|
284 renderShopSection(data.gems[spec], scroll, L.ShopHeaderGems)
|
yellowfive@57
|
285 renderShopSection(data.enchants[spec], scroll, L.ShopHeaderEnchants)
|
yellowfive@57
|
286 renderShopSection(data.materials[spec], scroll, L.ShopHeaderMaterials)
|
yellowfive@57
|
287 end
|
yellowfive@57
|
288 end
|
yellowfive@57
|
289
|
yellowfive@57
|
290 end
|
yellowfive@57
|
291
|
yellowfive@57
|
292 -- compare gear to everything the player owns, and return the minimum gems/enchants/materials needed to optimize
|
yellowfive@57
|
293 local function getShoppingData(player, gear, spec)
|
yellowfive@57
|
294
|
yellowfive@57
|
295 local ret = {
|
yellowfive@57
|
296 gems = {},
|
yellowfive@57
|
297 enchants = {},
|
yellowfive@57
|
298 materials = {}
|
yellowfive@57
|
299 }
|
yellowfive@57
|
300
|
yellowfive@57
|
301 -- used to prevent considering the same item twice
|
yellowfive@57
|
302 local usedItems = {}
|
yellowfive@57
|
303
|
yellowfive@57
|
304 for slotId, optimalItem in pairs(gear) do
|
yellowfive@57
|
305 local matchItemLink, matchItem = Amr:FindMatchingItem(optimalItem, player, usedItems)
|
yellowfive@57
|
306 local itemInfo = Amr.db.char.ExtraItemData[spec][optimalItem.id]
|
yellowfive@57
|
307
|
yellowfive@57
|
308 -- find gem/enchant differences on the best-matching item
|
yellowfive@57
|
309
|
yellowfive@57
|
310 -- gems
|
yellowfive@57
|
311 if itemInfo and itemInfo.socketColors then
|
yellowfive@57
|
312 for i = 1, #itemInfo.socketColors do
|
yellowfive@57
|
313 local g = optimalItem.gemIds[i]
|
yellowfive@57
|
314 local isGemEquipped = g ~= 0 and matchItem and matchItem.gemIds and matchItem.gemIds[i] == g
|
yellowfive@57
|
315
|
yellowfive@57
|
316 if not isGemEquipped then
|
yellowfive@57
|
317 ret.gems[g] = ret.gems[g] and ret.gems[g] + 1 or 1
|
yellowfive@57
|
318 end
|
yellowfive@57
|
319 end
|
yellowfive@57
|
320 end
|
yellowfive@57
|
321
|
yellowfive@57
|
322 -- enchant
|
yellowfive@57
|
323 if optimalItem.enchantId and optimalItem.enchantId ~= 0 then
|
yellowfive@57
|
324 local e = optimalItem.enchantId
|
yellowfive@57
|
325 local isEnchantEquipped = matchItem and matchItem.enchantId and matchItem.enchantId == e
|
yellowfive@57
|
326
|
yellowfive@57
|
327 if not isEnchantEquipped then
|
yellowfive@57
|
328 ret.enchants[e] = ret.enchants[e] and ret.enchants[e] + 1 or 1
|
yellowfive@57
|
329 end
|
yellowfive@57
|
330 end
|
yellowfive@57
|
331 end
|
yellowfive@57
|
332
|
yellowfive@57
|
333 return ret
|
yellowfive@57
|
334 end
|
yellowfive@57
|
335
|
yellowfive@57
|
336 -- get the number of a specified item that the player currently owns
|
yellowfive@57
|
337 local function getOwnedCount(itemId)
|
yellowfive@57
|
338 local ret = 0
|
yellowfive@57
|
339
|
yellowfive@57
|
340 local list = Amr.db.char.BagItemsAndCounts
|
yellowfive@57
|
341 if list and list[itemId] then
|
yellowfive@57
|
342 ret = ret + list[itemId]
|
yellowfive@57
|
343 end
|
yellowfive@57
|
344
|
yellowfive@57
|
345 list = Amr.db.char.BankItemsAndCounts
|
yellowfive@57
|
346 if list and list[itemId] then
|
yellowfive@57
|
347 ret = ret + list[itemId]
|
yellowfive@57
|
348 end
|
yellowfive@57
|
349
|
yellowfive@57
|
350 return ret
|
yellowfive@57
|
351 end
|
yellowfive@57
|
352
|
yellowfive@57
|
353 -- look at both gear sets and find stuff that a player needs to acquire to gem/enchant their gear
|
yellowfive@57
|
354 function Amr:UpdateShoppingData(player)
|
yellowfive@57
|
355
|
yellowfive@81
|
356 -- TODO: re-enable shopping list when Legion comes out
|
yellowfive@81
|
357 do return end
|
yellowfive@81
|
358
|
yellowfive@81
|
359 -- 0 is combination of all specs
|
yellowfive@57
|
360 local required = {
|
yellowfive@57
|
361 gems = {
|
yellowfive@57
|
362 [0] = {},
|
yellowfive@57
|
363 [1] = {},
|
yellowfive@81
|
364 [2] = {},
|
yellowfive@81
|
365 [3] = {},
|
yellowfive@81
|
366 [4] = {}
|
yellowfive@57
|
367 },
|
yellowfive@57
|
368 enchants = {
|
yellowfive@57
|
369 [0] = {},
|
yellowfive@57
|
370 [1] = {},
|
yellowfive@81
|
371 [2] = {},
|
yellowfive@81
|
372 [3] = {},
|
yellowfive@81
|
373 [4] = {}
|
yellowfive@57
|
374 },
|
yellowfive@57
|
375 materials = {
|
yellowfive@57
|
376 [0] = {},
|
yellowfive@57
|
377 [1] = {},
|
yellowfive@81
|
378 [2] = {},
|
yellowfive@81
|
379 [3] = {},
|
yellowfive@81
|
380 [4] = {}
|
yellowfive@57
|
381 },
|
yellowfive@57
|
382 specs = player.Specs
|
yellowfive@57
|
383 }
|
yellowfive@57
|
384
|
yellowfive@57
|
385 local enchantItemIdToId = {}
|
yellowfive@57
|
386
|
yellowfive@57
|
387 for spec, gear in pairs(Amr.db.char.GearSets) do
|
yellowfive@57
|
388 local obj = getShoppingData(player, gear, spec)
|
yellowfive@57
|
389 for k, v in pairs(obj.gems) do
|
yellowfive@57
|
390 local gemInfo = Amr.db.char.ExtraGemData[spec][k]
|
yellowfive@57
|
391 if gemInfo then
|
yellowfive@57
|
392 local prev = required.gems[spec][gemInfo.id]
|
yellowfive@57
|
393 required.gems[spec][gemInfo.id] = prev and prev + v or v
|
yellowfive@57
|
394
|
yellowfive@57
|
395 prev = required.gems[0][gemInfo.id]
|
yellowfive@57
|
396 required.gems[0][gemInfo.id] = prev and prev + v or v
|
yellowfive@57
|
397 end
|
yellowfive@57
|
398 end
|
yellowfive@57
|
399 for k, v in pairs(obj.enchants) do
|
yellowfive@57
|
400 local enchInfo = Amr.db.char.ExtraEnchantData[spec][k]
|
yellowfive@57
|
401 if enchInfo then
|
yellowfive@57
|
402 enchantItemIdToId[enchInfo.itemId] = k
|
yellowfive@57
|
403
|
yellowfive@57
|
404 local prev = required.enchants[spec][enchInfo.itemId]
|
yellowfive@57
|
405 required.enchants[spec][enchInfo.itemId] = prev and prev + v or v
|
yellowfive@57
|
406
|
yellowfive@57
|
407 prev = required.enchants[0][enchInfo.itemId]
|
yellowfive@57
|
408 required.enchants[0][enchInfo.itemId] = prev and prev + v or v
|
yellowfive@57
|
409 end
|
yellowfive@57
|
410 end
|
yellowfive@57
|
411 end
|
yellowfive@57
|
412
|
yellowfive@57
|
413 -- now subtract stuff the player already has, and generate a list of materials as well
|
yellowfive@81
|
414 for spec = 0, 4 do
|
yellowfive@81
|
415 local specId = spec == 0 and 1 or GetSpecializationInfo(spec)
|
yellowfive@81
|
416 if specId then
|
yellowfive@81
|
417 -- now check if the player has any of the gems or enchants in their inventory, and subtract those
|
yellowfive@81
|
418 for itemId, count in pairs(required.gems[spec]) do
|
yellowfive@81
|
419 required.gems[spec][itemId] = math.max(count - getOwnedCount(itemId), 0)
|
yellowfive@81
|
420
|
yellowfive@81
|
421 if required.gems[spec][itemId] == 0 then
|
yellowfive@81
|
422 required.gems[spec][itemId] = nil
|
yellowfive@57
|
423 end
|
yellowfive@57
|
424 end
|
yellowfive@57
|
425
|
yellowfive@81
|
426 for itemId, count in pairs(required.enchants[spec]) do
|
yellowfive@81
|
427 -- look in both spec extra info cache
|
yellowfive@81
|
428 local e = enchantItemIdToId[itemId]
|
yellowfive@81
|
429 local enchInfo = nil
|
yellowfive@81
|
430 if Amr.db.char.ExtraEnchantData[1] then
|
yellowfive@81
|
431 enchInfo = Amr.db.char.ExtraEnchantData[1][e]
|
yellowfive@81
|
432 end
|
yellowfive@81
|
433 if not enchInfo then
|
yellowfive@81
|
434 if Amr.db.char.ExtraEnchantData[2] then
|
yellowfive@81
|
435 enchInfo = Amr.db.char.ExtraEnchantData[2][e]
|
yellowfive@81
|
436 end
|
yellowfive@81
|
437 end
|
yellowfive@81
|
438
|
yellowfive@81
|
439 if enchInfo then
|
yellowfive@81
|
440 required.enchants[spec][itemId] = math.max(count - getOwnedCount(itemId), 0)
|
yellowfive@57
|
441
|
yellowfive@81
|
442 if required.enchants[spec][itemId] == 0 then
|
yellowfive@81
|
443 required.enchants[spec][itemId] = nil
|
yellowfive@81
|
444 else
|
yellowfive@81
|
445 -- count up required materials
|
yellowfive@81
|
446 if enchInfo.materials then
|
yellowfive@81
|
447 local c = required.enchants[spec][itemId]
|
yellowfive@81
|
448 for k, v in pairs(enchInfo.materials) do
|
yellowfive@81
|
449 local prev = required.materials[spec][k]
|
yellowfive@81
|
450 required.materials[spec][k] = prev and prev + (v * c) or (v * c)
|
yellowfive@81
|
451 end
|
yellowfive@57
|
452 end
|
yellowfive@81
|
453 end
|
yellowfive@81
|
454 end
|
yellowfive@81
|
455 end
|
yellowfive@57
|
456
|
yellowfive@81
|
457 -- check if player has any of the materials already
|
yellowfive@81
|
458 for itemId, count in pairs(required.materials[spec]) do
|
yellowfive@81
|
459 required.materials[spec][itemId] = math.max(count - getOwnedCount(itemId), 0)
|
yellowfive@81
|
460
|
yellowfive@81
|
461 if required.materials[spec][itemId] == 0 then
|
yellowfive@81
|
462 required.materials[spec][itemId] = nil
|
yellowfive@81
|
463 end
|
yellowfive@57
|
464 end
|
yellowfive@57
|
465 end
|
yellowfive@57
|
466 end
|
yellowfive@57
|
467
|
yellowfive@57
|
468 Amr.db.global.Shopping[player.Name .. "-" .. player.Realm] = required
|
yellowfive@57
|
469 end
|
yellowfive@57
|
470
|
yellowfive@81
|
471 -- TODO: re-enable shopping list with Legion
|
yellowfive@81
|
472 --[[
|
yellowfive@57
|
473 Amr:AddEventHandler("AUCTION_HOUSE_SHOW", function()
|
yellowfive@57
|
474 _isAhOpen = true
|
yellowfive@57
|
475 if Amr.db.profile.options.shopAh then
|
yellowfive@57
|
476 Amr:ShowShopWindow()
|
yellowfive@57
|
477 end
|
yellowfive@57
|
478 end)
|
yellowfive@57
|
479
|
yellowfive@57
|
480 Amr:AddEventHandler("AUCTION_HOUSE_CLOSED", function()
|
yellowfive@57
|
481 _isAhOpen = false
|
yellowfive@57
|
482 if Amr.db.profile.options.shopAh then
|
yellowfive@57
|
483 Amr:HideShopWindow()
|
yellowfive@57
|
484 end
|
yellowfive@81
|
485 end)
|
yellowfive@81
|
486 ]] |