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