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