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