adam@0
|
1 local _, AskMrRobot = ...
|
yellowfive@11
|
2 local L = AskMrRobot.L;
|
adam@0
|
3
|
adam@0
|
4 --------------------------------------------------------------------
|
adam@0
|
5 -- Local Reforge Utility Code
|
adam@0
|
6 --------------------------------------------------------------------
|
adam@0
|
7
|
adam@0
|
8 StaticPopupDialogs["REFORGE_TAB_PLEASE_OPEN"] = {
|
yellowfive@11
|
9 text = L.AMR_REFORGESTAB_OPEN_WINDOW,
|
yellowfive@11
|
10 button1 = L.AMR_REFORGESTAB_BUTTON_OK,
|
adam@0
|
11 timeout = 0,
|
adam@0
|
12 whileDead = true,
|
adam@0
|
13 hideOnEscape = true,
|
adam@0
|
14 preferredIndex = 3, -- avoid some UI taint, see http://www.wowace.com/announcements/how-to-avoid-some-ui-taint/
|
adam@0
|
15 }
|
adam@0
|
16
|
adam@0
|
17 --from LibReforge
|
adam@0
|
18 local SPI = 1
|
adam@0
|
19 local DODGE = 2
|
adam@0
|
20 local PARRY = 3
|
adam@0
|
21 local HIT = 4
|
adam@0
|
22 local CRIT = 5
|
adam@0
|
23 local HASTE = 6
|
adam@0
|
24 local EXP = 7
|
adam@0
|
25 local MASTERY = 8
|
adam@0
|
26
|
adam@0
|
27 --from LibReforge
|
adam@0
|
28 local StatNames = {
|
adam@0
|
29 ITEM_MOD_SPIRIT_SHORT,
|
adam@0
|
30 ITEM_MOD_DODGE_RATING_SHORT,
|
adam@0
|
31 ITEM_MOD_PARRY_RATING_SHORT,
|
adam@0
|
32 ITEM_MOD_HIT_RATING_SHORT,
|
adam@0
|
33 ITEM_MOD_CRIT_RATING_SHORT,
|
adam@0
|
34 ITEM_MOD_HASTE_RATING_SHORT,
|
adam@0
|
35 ITEM_MOD_EXPERTISE_RATING_SHORT,
|
adam@0
|
36 ITEM_MOD_MASTERY_RATING_SHORT
|
adam@0
|
37 }
|
adam@0
|
38 StatNames[0] = NONE
|
adam@0
|
39 local StatToString = {
|
adam@0
|
40 "ITEM_MOD_SPIRIT_SHORT",
|
adam@0
|
41 "ITEM_MOD_DODGE_RATING_SHORT",
|
adam@0
|
42 "ITEM_MOD_PARRY_RATING_SHORT",
|
adam@0
|
43 "ITEM_MOD_HIT_RATING_SHORT",
|
adam@0
|
44 "ITEM_MOD_CRIT_RATING_SHORT",
|
adam@0
|
45 "ITEM_MOD_HASTE_RATING_SHORT",
|
adam@0
|
46 "ITEM_MOD_EXPERTISE_RATING_SHORT",
|
adam@0
|
47 "ITEM_MOD_MASTERY_RATING_SHORT"
|
adam@0
|
48 }
|
adam@0
|
49
|
adam@0
|
50
|
adam@0
|
51 local REFORGE_TABLE_BASE = 112
|
adam@0
|
52 local REFORGE_TABLE = {
|
adam@0
|
53 {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {1, 7}, {1, 8},
|
adam@0
|
54 {2, 1}, {2, 3}, {2, 4}, {2, 5}, {2, 6}, {2, 7}, {2, 8},
|
adam@0
|
55 {3, 1}, {3, 2}, {3, 4}, {3, 5}, {3, 6}, {3, 7}, {3, 8},
|
adam@0
|
56 {4, 1}, {4, 2}, {4, 3}, {4, 5}, {4, 6}, {4, 7}, {4, 8},
|
adam@0
|
57 {5, 1}, {5, 2}, {5, 3}, {5, 4}, {5, 6}, {5, 7}, {5, 8},
|
adam@0
|
58 {6, 1}, {6, 2}, {6, 3}, {6, 4}, {6, 5}, {6, 7}, {6, 8},
|
adam@0
|
59 {7, 1}, {7, 2}, {7, 3}, {7, 4}, {7, 5}, {7, 6}, {7, 8},
|
adam@0
|
60 {8, 1}, {8, 2}, {8, 3}, {8, 4}, {8, 5}, {8, 6}, {8, 7},
|
adam@0
|
61 }
|
adam@0
|
62
|
adam@0
|
63 --------------- returns the index into the REFORGE_TABLE or nil
|
adam@0
|
64 -- returns the reforge id or 0
|
adam@0
|
65 local function GetReforgeIdForItem(item)
|
adam@0
|
66 local id = tonumber(item:match("item:%d+:%d+:%d+:%d+:%d+:%d+:%-?%d+:%-?%d+:%d+:(%d+)"))
|
adam@0
|
67 return (id and id ~= 0 and id or 0)
|
adam@0
|
68 end
|
adam@0
|
69
|
adam@0
|
70 local function GetReforgeIdFromStats(fromStat, toStat)
|
adam@0
|
71 if (toStat > fromStat) then
|
adam@0
|
72 return REFORGE_TABLE_BASE + 7 * (fromStat - 1) + toStat - 1;
|
adam@0
|
73 else
|
adam@0
|
74 return REFORGE_TABLE_BASE + 7 * (fromStat - 1) + toStat;
|
adam@0
|
75 end
|
adam@0
|
76 end
|
adam@0
|
77
|
adam@0
|
78
|
adam@0
|
79 --------------------------------------------------------------------
|
adam@0
|
80 -- Initialization
|
adam@0
|
81 --------------------------------------------------------------------
|
adam@0
|
82 AskMrRobot.ReforgesTab = AskMrRobot.inheritsFrom(AskMrRobot.Frame)
|
adam@0
|
83
|
adam@0
|
84 function AskMrRobot.ReforgesTab:new(parent)
|
adam@0
|
85
|
adam@0
|
86 local tab = AskMrRobot.Frame:new(nil, parent)
|
adam@0
|
87 setmetatable(tab, { __index = AskMrRobot.ReforgesTab })
|
adam@0
|
88 tab:SetPoint("TOPLEFT")
|
adam@0
|
89 tab:SetPoint("BOTTOMRIGHT")
|
adam@0
|
90 tab:Hide()
|
adam@0
|
91
|
adam@0
|
92 local text = tab:CreateFontString("AmrReforgesHeader", "ARTWORK", "GameFontNormalLarge")
|
adam@0
|
93 text:SetPoint("TOPLEFT", 0, -5)
|
yellowfive@11
|
94 text:SetText(L.AMR_REFORGESTAB_TITLE)
|
adam@0
|
95
|
adam@0
|
96 tab.stamp = AskMrRobot.RobotStamp:new(nil, tab)
|
adam@0
|
97 tab.stamp:Hide()
|
yellowfive@11
|
98 tab.stamp.smallText:SetText(L.AMR_REFORGESTAB_OPTIMAL)
|
adam@0
|
99 tab.stamp:SetPoint("TOPLEFT", text, "BOTTOMLEFT", 2, -15)
|
adam@0
|
100 tab.stamp:SetPoint("RIGHT", tab, "RIGHT", -20, 0)
|
adam@0
|
101
|
adam@0
|
102 tab.reforgeDetails = tab:CreateFontString("AmrReforgeDetails", "ARTWORK", "GameFontWhite")
|
adam@0
|
103 tab.reforgeDetails:SetPoint("TOPLEFT", text, "BOTTOMLEFT", 0, -15)
|
adam@0
|
104 tab.reforgeDetails:SetPoint("RIGHT", -30, 0)
|
adam@0
|
105 tab.reforgeDetails:SetWordWrap(true)
|
adam@0
|
106 tab.reforgeDetails:SetJustifyH("LEFT")
|
yellowfive@11
|
107 tab.reforgeDetails:SetText(L.AMR_REFORGESTAB_INSTRUCTION)
|
adam@0
|
108 tab.reforgeDetails:SetHeight(50)
|
adam@0
|
109
|
adam@0
|
110 tab.reforgeButton = CreateFrame("Button", "AmrReforgeButton", tab, "UIPanelButtonTemplate")
|
yellowfive@11
|
111 tab.reforgeButton:SetText(L.AMR_REFORGESTAB_BUTTON)
|
adam@0
|
112 tab.reforgeButton:SetPoint("TOPLEFT", 0, -80)
|
adam@0
|
113 tab.reforgeButton:SetWidth(140)
|
adam@0
|
114 tab.reforgeButton:SetHeight(20)
|
adam@0
|
115 tab.reforgeButton:SetScript("OnClick", function()
|
adam@0
|
116 tab:OnReforge()
|
adam@0
|
117 end)
|
adam@0
|
118
|
adam@0
|
119 tab.reforgeCost = tab:CreateFontString(nil, "ARTWORK", "GameFontNormal")
|
adam@0
|
120 tab.reforgeCost:SetPoint("TOPLEFT", tab.reforgeButton, "TOPRIGHT", 25, 0)
|
adam@0
|
121 tab.reforgeCost:SetPoint("BOTTOM", tab.reforgeButton, "BOTTOM", 0, 0)
|
adam@0
|
122 tab.reforgeCost:SetPoint("RIGHT", tab, "RIGHT", -30, 0)
|
adam@0
|
123 tab.reforgeCost:SetText('')
|
adam@0
|
124
|
adam@0
|
125 tab.slotHeader = tab:CreateFontString(nil, "ARTWORK", "GameFontNormal")
|
yellowfive@11
|
126 tab.slotHeader:SetText(L.AMR_REFORGESTAB_SLOT)
|
adam@0
|
127 tab.slotHeader:SetPoint("TOPLEFT", tab.reforgeButton, "BOTTOMLEFT", 0, -30)
|
adam@0
|
128
|
adam@0
|
129 tab.reforgeHeader = tab:CreateFontString(nil, "ARTWORK", "GameFontNormal")
|
yellowfive@11
|
130 tab.reforgeHeader:SetText(L.AMR_REFORGESTAB_OPTIMAL_REFORGE)
|
adam@0
|
131 tab.reforgeHeader:SetPoint("TOPLEFT", tab.slotHeader, "TOPLEFT", 100, 0)
|
adam@0
|
132
|
adam@0
|
133 -- pre-allocate a visual element for all possible slots; showBadReforges will set text and show the number that are needed, and hide the rest
|
adam@0
|
134 tab.slots = {}
|
adam@0
|
135 tab.optimized = {}
|
adam@0
|
136
|
adam@0
|
137 for i = 1, #AskMrRobot.slotNames do
|
adam@0
|
138 tab.slots[i] = tab:CreateFontString(nil, "ARTWORK", "GameFontWhite")
|
adam@0
|
139 tab.slots[i]:SetPoint("TOPLEFT", tab.slotHeader, "TOPLEFT", 0, -20 * i)
|
adam@0
|
140 tab.slots[i]:Hide()
|
adam@0
|
141
|
adam@0
|
142 tab.optimized[i] = tab:CreateFontString(nil, "ARTWORK", "GameFontWhite")
|
adam@0
|
143 tab.optimized[i]:SetPoint("TOPLEFT", tab.reforgeHeader, "TOPLEFT", 0, -20 * i)
|
adam@0
|
144 tab.optimized[i]:Hide()
|
adam@0
|
145 end
|
adam@0
|
146
|
adam@0
|
147 tab:RegisterEvent("FORGE_MASTER_ITEM_CHANGED")
|
adam@0
|
148 tab:RegisterEvent("FORGE_MASTER_SET_ITEM")
|
adam@0
|
149 tab:RegisterEvent("FORGE_MASTER_OPENED")
|
adam@0
|
150 tab:RegisterEvent("FORGE_MASTER_CLOSED")
|
adam@0
|
151
|
adam@0
|
152 tab:SetScript("OnEvent", function(...)
|
adam@0
|
153 tab:OnEvent(...)
|
adam@0
|
154 end)
|
adam@0
|
155
|
adam@0
|
156
|
adam@0
|
157 -- initialize stat required for performing the reforges
|
adam@0
|
158 tab.state = {}
|
adam@0
|
159 tab:ResetState()
|
adam@0
|
160
|
adam@0
|
161
|
adam@0
|
162 return tab
|
adam@0
|
163 end
|
adam@0
|
164
|
adam@0
|
165
|
adam@0
|
166 --------------------------------------------------------------------
|
adam@0
|
167 -- Rendering
|
adam@0
|
168 --------------------------------------------------------------------
|
adam@0
|
169
|
adam@0
|
170 local function GetReforgeString(fromId, toId)
|
adam@0
|
171 if toId == 0 then
|
adam@0
|
172 return "Restore"
|
adam@0
|
173 end
|
adam@0
|
174 local pair = REFORGE_TABLE[toId - REFORGE_TABLE_BASE]
|
adam@0
|
175
|
adam@0
|
176 local text = _G[StatToString[pair[1]]] .. ' -> ' .. _G[StatToString[pair[2]]]
|
adam@0
|
177 --print('from ' .. fromId)
|
adam@0
|
178 if fromId == 0 then
|
adam@0
|
179 return text
|
adam@0
|
180 end
|
yellowfive@11
|
181 return L.AMR_REFORGESTAB_RESTORE_THEN .. text
|
adam@0
|
182 end
|
adam@0
|
183
|
adam@0
|
184 -- draw all of the reforges that still need to be performed
|
adam@0
|
185 function AskMrRobot.ReforgesTab:Render()
|
adam@0
|
186
|
adam@0
|
187 local reforges = AskMrRobot.itemDiffs.reforges
|
adam@0
|
188 local i = 1
|
adam@0
|
189 local cost = 0
|
adam@0
|
190
|
adam@0
|
191 -- for all the bad items
|
adam@0
|
192 for slotNum, badReforge in AskMrRobot.sortSlots(reforges) do
|
adam@0
|
193
|
adam@0
|
194 self.optimized[i]:SetText(GetReforgeString(badReforge.current, badReforge.optimized))
|
adam@0
|
195 self.optimized[i]:Show()
|
adam@0
|
196
|
adam@0
|
197 self.slots[i]:SetText(_G[strupper(AskMrRobot.slotNames[slotNum])])
|
adam@0
|
198 self.slots[i]:Show()
|
adam@0
|
199
|
adam@0
|
200 -- Restore is free, so only add cost for non-restore reforges
|
adam@0
|
201 if badReforge.optimized > 0 then
|
adam@0
|
202 local slotId = AskMrRobot.slotIds[slotNum]
|
adam@0
|
203 local itemLink = GetInventoryItemLink("player", slotId)
|
adam@0
|
204 cost = cost + (itemLink and select (11, GetItemInfo(itemLink)) or 0)
|
adam@0
|
205 end
|
adam@0
|
206
|
adam@0
|
207 i = i + 1
|
adam@0
|
208 end
|
adam@0
|
209
|
yellowfive@11
|
210 self.reforgeCost:SetText(L.AMR_REFORGESTAB_TOTAL_COST:format(math.ceil(cost / 10000)))
|
adam@0
|
211
|
adam@0
|
212 -- hide / show the headers
|
adam@0
|
213 if i == 1 then
|
adam@0
|
214 self.reforgeHeader:Hide()
|
adam@0
|
215 self.slotHeader:Hide()
|
adam@0
|
216 self.reforgeButton:Hide()
|
adam@0
|
217 self.reforgeCost:Hide()
|
adam@0
|
218 self.reforgeDetails:Hide()
|
adam@0
|
219 self.stamp:Show()
|
adam@0
|
220 else
|
adam@0
|
221 self.stamp:Hide()
|
adam@0
|
222 self.reforgeButton:Show()
|
adam@0
|
223 self.reforgeCost:Show()
|
adam@0
|
224 self.reforgeHeader:Show()
|
adam@0
|
225 self.reforgeDetails:Show()
|
adam@0
|
226 self.slotHeader:Show()
|
adam@0
|
227 end
|
adam@0
|
228
|
adam@0
|
229 -- hide the remaining slots
|
adam@0
|
230 while i <= #self.slots do
|
adam@0
|
231 self.optimized[i]:Hide()
|
adam@0
|
232 self.slots[i]:Hide()
|
adam@0
|
233 i = i + 1
|
adam@0
|
234 end
|
adam@0
|
235 end
|
adam@0
|
236
|
adam@0
|
237 --------------------------------------------------------------------
|
adam@0
|
238 -- Reforge Logic
|
adam@0
|
239 --------------------------------------------------------------------
|
adam@0
|
240
|
adam@0
|
241 -- reset state for a fresh pass at automatic reforging
|
adam@0
|
242 function AskMrRobot.ReforgesTab:ResetState()
|
adam@0
|
243
|
adam@0
|
244 self.state.queue = {} -- list of all reforges actions that still need to be performed
|
adam@0
|
245 self.state.currentItem = nil -- the current item we are trying to reforge
|
adam@0
|
246 self.state.pendingSlot = nil -- the slot that we have requested to place into the reforger
|
adam@0
|
247 self.state.currentSlot = nil -- the current slot in the reforger
|
adam@0
|
248 self.state.pendingReforge = -1 -- the reforge that we have requested to perform on the current item
|
adam@0
|
249 end
|
adam@0
|
250
|
adam@0
|
251 -- refresh the queue of reforges that still need to be performed
|
adam@0
|
252 function AskMrRobot.ReforgesTab:RefreshQueue()
|
adam@0
|
253
|
adam@0
|
254 -- clear the queue
|
adam@0
|
255 self.state.queue = {}
|
adam@0
|
256
|
adam@0
|
257 local reforges = AskMrRobot.itemDiffs.reforges
|
adam@0
|
258
|
adam@0
|
259 -- add all reforges that need updating to the reforge queue
|
adam@0
|
260 for slotNum, badReforge in AskMrRobot.sortSlots(reforges) do
|
adam@0
|
261 self:AddToReforgeQueue(slotNum, badReforge.optimized);
|
adam@0
|
262 end
|
adam@0
|
263 end
|
adam@0
|
264
|
adam@0
|
265 function AskMrRobot.ReforgesTab:AddToReforgeQueue(itemSlot, reforgeId)
|
adam@0
|
266
|
adam@0
|
267 -- the game's slot id, not the same as the ids that we use on our servers
|
adam@0
|
268 local gameSlot = AskMrRobot.slotIds[itemSlot]
|
adam@0
|
269
|
adam@0
|
270 local item = GetInventoryItemLink("player", gameSlot)
|
adam@0
|
271 if item == nil then
|
adam@0
|
272 --print ('no item')
|
adam@0
|
273 return
|
adam@0
|
274 end
|
adam@0
|
275
|
adam@0
|
276 local current = GetReforgeIdForItem(item)
|
adam@0
|
277
|
adam@0
|
278 if current ~= reforgeId then
|
adam@0
|
279 -- restore first
|
adam@0
|
280 if current ~= 0 and reforgeId ~= 0 then
|
adam@0
|
281 tinsert(self.state.queue, { ["slot"] = gameSlot, ["reforge"] = 0 })
|
adam@0
|
282 end
|
adam@0
|
283
|
adam@0
|
284 -- then reforge to the specified reforge
|
adam@0
|
285 tinsert(self.state.queue, { ["slot"] = gameSlot, ["reforge"] = reforgeId })
|
adam@0
|
286 end
|
adam@0
|
287 end
|
adam@0
|
288
|
adam@0
|
289 function AskMrRobot.ReforgesTab:IsQueueEmpty()
|
adam@0
|
290 return self.state.queue == nil or #self.state.queue == 0 or self.state.queue == {};
|
adam@0
|
291 end
|
adam@0
|
292
|
adam@0
|
293 -- returns true if we are waiting on the game to finish a pending async reforge operation
|
adam@0
|
294 function AskMrRobot.ReforgesTab:HasPendingOperation()
|
adam@0
|
295
|
adam@0
|
296 -- waiting for an item to be placed into the reforger
|
adam@0
|
297 if self.state.pendingSlot then
|
adam@0
|
298 return true
|
adam@0
|
299 end
|
adam@0
|
300
|
adam@0
|
301 -- waiting for a reforge to be completed
|
adam@0
|
302 if self.state.pendingReforge ~= -1 then
|
adam@0
|
303 return true
|
adam@0
|
304 end
|
adam@0
|
305
|
adam@0
|
306 return false
|
adam@0
|
307 end
|
adam@0
|
308
|
adam@0
|
309 -- put the next item in the reforge queue into the game's reforge UI
|
adam@0
|
310 function AskMrRobot.ReforgesTab:PutNextItemInForge()
|
adam@0
|
311
|
adam@0
|
312 if self:IsQueueEmpty() or self:HasPendingOperation() then
|
adam@0
|
313 return
|
adam@0
|
314 end
|
adam@0
|
315
|
adam@0
|
316 -- get the first action in the queue
|
adam@0
|
317 local currentAction = self.state.queue[1]
|
adam@0
|
318 local itemSlot = currentAction.slot
|
adam@0
|
319
|
adam@0
|
320 local item = GetInventoryItemLink("player", itemSlot)
|
adam@0
|
321
|
adam@0
|
322 -- set current item that we are trying to reforge
|
adam@0
|
323 self.state.currentItem = item
|
adam@0
|
324
|
adam@0
|
325 -- if this item isn't already in the reforger, put it in
|
adam@0
|
326 if self.state.currentSlot ~= itemSlot then
|
adam@0
|
327 ClearCursor() -- make sure no item is selected
|
adam@0
|
328 SetReforgeFromCursorItem() -- pick up the old item (calling this with an item already in the reforger will put it back on the mouse cursor)
|
adam@0
|
329 ClearCursor() -- clear the cursor to finish removing any current item from the game reforge UI
|
adam@0
|
330 PickupInventoryItem(itemSlot) -- pick up the right equipped item
|
adam@0
|
331
|
adam@0
|
332 -- pending, listen for an event from the game to complete setting this item into the reforger
|
adam@0
|
333 self.state.pendingSlot = itemSlot
|
adam@0
|
334
|
adam@0
|
335 SetReforgeFromCursorItem() -- put the item into the reforger, and wait for the FORGE_MASTER_SET_ITEM event, which calls DoReforge
|
adam@0
|
336 end
|
adam@0
|
337
|
adam@0
|
338 end
|
adam@0
|
339
|
adam@0
|
340 -- an item is in the reforger, ready to be reforged, so do it
|
adam@0
|
341 function AskMrRobot.ReforgesTab:DoReforge()
|
adam@0
|
342
|
adam@0
|
343 if self:IsQueueEmpty() or self:HasPendingOperation() then
|
adam@0
|
344 return
|
adam@0
|
345 end
|
adam@0
|
346
|
adam@0
|
347 local currentAction = self.state.queue[1]
|
adam@0
|
348 local desiredReforge = currentAction.reforge
|
adam@0
|
349
|
adam@0
|
350 -- the index that needs to be provided to WoW's ReforgeItem method, corresponds to one of the options in the game reforge UI
|
adam@0
|
351 local reforgeIndex = -1
|
adam@0
|
352
|
adam@0
|
353 if desiredReforge ~= 0 then
|
adam@0
|
354 local targetFrom = REFORGE_TABLE[desiredReforge - REFORGE_TABLE_BASE][1];
|
adam@0
|
355 local targetTo = REFORGE_TABLE[desiredReforge - REFORGE_TABLE_BASE][2];
|
adam@0
|
356
|
adam@0
|
357 for i=1, GetNumReforgeOptions() do
|
adam@0
|
358 local from, _, _, to, _, _ = GetReforgeOptionInfo(i)
|
adam@0
|
359 --print(i .. ': ' .. from .. " -> " .. to)
|
adam@0
|
360 if StatNames[targetFrom] == from and StatNames[targetTo] == to then
|
adam@0
|
361 reforgeIndex = i
|
adam@0
|
362 break
|
adam@0
|
363 end
|
adam@0
|
364 end
|
adam@0
|
365 else
|
adam@0
|
366 reforgeIndex = 0
|
adam@0
|
367 end
|
adam@0
|
368
|
adam@0
|
369 if reforgeIndex == -1 then
|
adam@0
|
370 -- we couldn't do this reforge... we either had a bad reforge (wrong stats on an item), or the game had no options in the UI for some reason
|
adam@0
|
371
|
adam@0
|
372 -- remove the item from the reforge window
|
adam@0
|
373 ClearCursor()
|
adam@0
|
374 SetReforgeFromCursorItem()
|
adam@0
|
375 ClearCursor()
|
adam@0
|
376
|
adam@0
|
377 -- reset state and quit reforging (clears the queue)
|
adam@0
|
378 self:ResetState()
|
adam@0
|
379
|
adam@0
|
380 else
|
adam@0
|
381
|
adam@0
|
382 local currentReforge = GetReforgeIdForItem(self.state.currentItem);
|
adam@0
|
383 if currentReforge == desiredReforge then
|
adam@0
|
384 -- we already have this reforge on the item... probably shouldn't ever happen, but if it does, recalculate and start over
|
adam@0
|
385 tremove(self.state.queue, 1)
|
adam@0
|
386
|
adam@0
|
387 -- remove the item from the reforge window
|
adam@0
|
388 ClearCursor()
|
adam@0
|
389 SetReforgeFromCursorItem()
|
adam@0
|
390 ClearCursor()
|
adam@0
|
391
|
adam@0
|
392 -- update the state of the entire UI, and start again with the next required reforge
|
adam@0
|
393 AskMrRobot_ReforgeFrame:OnUpdate()
|
adam@0
|
394 self:OnReforge()
|
adam@0
|
395
|
adam@0
|
396 else
|
adam@0
|
397 -- we have a reforge (or restore) to do, kick it off and wait for CheckReforge to respond to completion
|
adam@0
|
398 self:TryReforge(reforgeIndex)
|
adam@0
|
399 end
|
adam@0
|
400
|
adam@0
|
401 end
|
adam@0
|
402
|
adam@0
|
403 end
|
adam@0
|
404
|
adam@0
|
405 -- wraps WoW API call to ReforgeItem, fires a manual timeout in case the UI does not raise an event
|
adam@0
|
406 function AskMrRobot.ReforgesTab:TryReforge(reforgeIndex)
|
adam@0
|
407
|
adam@0
|
408 -- we have a reforge (or restore) to do, kick it off and wait for FORGE_MASTER_ITEM_CHANGED, which calls CheckReforge
|
adam@0
|
409 self.state.pendingReforge = reforgeIndex
|
adam@0
|
410 ReforgeItem(reforgeIndex)
|
adam@0
|
411
|
adam@0
|
412 -- sometimes the game doesn't send the FORGE_MASTER_ITEM_CHANGED event, so also check after a delay also
|
adam@0
|
413 AskMrRobot.wait(0.250, AskMrRobot.ReforgesTab.CheckReforge, self)
|
adam@0
|
414
|
adam@0
|
415 end
|
adam@0
|
416
|
adam@0
|
417 -- check that a requested reforge has been completed
|
adam@0
|
418 function AskMrRobot.ReforgesTab:CheckReforge()
|
adam@0
|
419
|
adam@0
|
420 if self:IsQueueEmpty() or self.state.pendingReforge == -1 then
|
adam@0
|
421
|
adam@0
|
422 -- responding to a reforge that the user has manually performed, update the UI and terminate any automatic process that is going on
|
adam@0
|
423 AskMrRobot_ReforgeFrame:OnUpdate()
|
adam@0
|
424 self:ResetState()
|
adam@0
|
425
|
adam@0
|
426 else
|
adam@0
|
427 -- responding to a reforge that we have initiated
|
adam@0
|
428
|
adam@0
|
429 local currentReforge, icon, name, quality, bound, cost = GetReforgeItemInfo();
|
adam@0
|
430 if currentReforge == self.state.pendingReforge then
|
adam@0
|
431 tremove(self.state.queue, 1)
|
adam@0
|
432
|
adam@0
|
433 -- remove the item from the reforge window
|
adam@0
|
434 ClearCursor()
|
adam@0
|
435 SetReforgeFromCursorItem()
|
adam@0
|
436 ClearCursor()
|
adam@0
|
437
|
adam@0
|
438 -- update the state of the entire UI, and start again with the next required reforge
|
adam@0
|
439 AskMrRobot_ReforgeFrame:OnUpdate()
|
adam@0
|
440 self:OnReforge()
|
adam@0
|
441 else
|
adam@0
|
442 -- try again
|
adam@0
|
443 self:TryReforge(self.state.pendingReforge)
|
adam@0
|
444 end
|
adam@0
|
445 end
|
adam@0
|
446
|
adam@0
|
447 end
|
adam@0
|
448
|
adam@0
|
449
|
adam@0
|
450 --------------------------------------------------------------------
|
adam@0
|
451 -- Event Handling
|
adam@0
|
452 --------------------------------------------------------------------
|
adam@0
|
453
|
adam@0
|
454 -- event called when the Mr. Robot Reforge button is clicked, kicks off automatic reforge
|
adam@0
|
455 function AskMrRobot.ReforgesTab:OnReforge()
|
adam@0
|
456
|
adam@0
|
457 -- need to be at a reforger for this to work
|
adam@0
|
458 if not self.isReforgeOpen then
|
adam@0
|
459 StaticPopup_Show("REFORGE_TAB_PLEASE_OPEN")
|
adam@0
|
460 return
|
adam@0
|
461 end
|
adam@0
|
462
|
adam@0
|
463 -- reset state and refresh the queue of reforges that still need to be done
|
adam@0
|
464 self:ResetState()
|
adam@0
|
465 self:RefreshQueue()
|
adam@0
|
466
|
adam@0
|
467 -- get goin, put the first item in the reforger
|
adam@0
|
468 self:PutNextItemInForge()
|
adam@0
|
469 end
|
adam@0
|
470
|
adam@0
|
471 function AskMrRobot.ReforgesTab:On_FORGE_MASTER_SET_ITEM()
|
adam@0
|
472
|
adam@0
|
473 if self.state.pendingSlot then
|
adam@0
|
474
|
adam@0
|
475 -- we have successfully finished placing an item into the reforger
|
adam@0
|
476 self.state.currentSlot = self.state.pendingSlot
|
adam@0
|
477
|
adam@0
|
478 -- indicate that we are no longer waiting for an item
|
adam@0
|
479 self.state.pendingSlot = nil
|
adam@0
|
480
|
adam@0
|
481 -- now reforge it
|
adam@0
|
482 self:DoReforge()
|
adam@0
|
483 end
|
adam@0
|
484
|
adam@0
|
485 end
|
adam@0
|
486
|
adam@0
|
487 function AskMrRobot.ReforgesTab:On_FORGE_MASTER_ITEM_CHANGED()
|
adam@0
|
488 self:CheckReforge()
|
adam@0
|
489 end
|
adam@0
|
490
|
adam@0
|
491 function AskMrRobot.ReforgesTab:On_FORGE_MASTER_OPENED()
|
adam@0
|
492 self.isReforgeOpen = true
|
adam@0
|
493 end
|
adam@0
|
494
|
adam@0
|
495 function AskMrRobot.ReforgesTab:On_FORGE_MASTER_CLOSED()
|
adam@0
|
496 self.isReforgeOpen = false
|
adam@0
|
497 end
|
adam@0
|
498
|
adam@0
|
499 function AskMrRobot.ReforgesTab:OnEvent(frame, event, ...)
|
adam@0
|
500 --print("EVENT " .. event)
|
adam@0
|
501 local handler = self["On_" .. event]
|
adam@0
|
502 if handler then
|
adam@0
|
503 handler(self, ...)
|
adam@0
|
504 end
|
adam@0
|
505 end |