vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | -- |
2 | -- Chat Colors |
||
3 | -- |
||
4 | |||
5 | local STATUS_COLOR = "|c000066FF"; |
||
6 | local CONNECTION_COLOR = "|c0033FF66"; |
||
7 | local MONEY_COLOR = "|c00FFCC33"; |
||
8 | local DEBUG_COLOR = "|c0000FF00"; |
||
9 | local GREY = "|c00909090"; |
||
10 | local BRIGHTGREY = "|c00D0D0D0"; |
||
11 | local WHITE = "|c00FFFFFF"; |
||
12 | local SILVER = "|c00C0C0C0"; |
||
13 | local COPPER = "|c00CC9900"; |
||
14 | local GOLD = "|c00FFFF66"; |
||
15 | |||
16 | local AR_CurrentVersion = "0.6"; |
||
17 | local AR_DiagOpen = false; |
||
18 | local AR_CB= nil; |
||
19 | local AR_CBV; |
||
20 | local AR_CBT = 0; |
||
21 | |||
22 | -- |
||
23 | -- Event Handlers |
||
24 | -- |
||
25 | function AutoRepair_OnLoad() |
||
26 | this:RegisterEvent("VARIABLES_LOADED"); |
||
27 | this:RegisterEvent("MERCHANT_SHOW"); |
||
28 | end |
||
29 | |||
30 | function AutoRepair_OnEvent(event) |
||
31 | if ( event == "VARIABLES_LOADED" ) then |
||
32 | AR_Load() |
||
33 | end |
||
34 | |||
35 | if ( event == "MERCHANT_SHOW") then |
||
36 | if (CanMerchantRepair() and AR_Save.enabled) then |
||
37 | AR_RepairHandler(false); |
||
38 | end |
||
39 | end |
||
40 | |||
41 | end |
||
42 | |||
43 | function AutoRepair_OnUpdate(dt) |
||
44 | if (AR_CB) then |
||
45 | AR_CBT = AR_CBT + dt |
||
46 | if (AR_CBT > 1) then |
||
47 | AR_CBT = 0; |
||
48 | if (AR_CBV) then |
||
49 | AR_CB(AR_CBV); |
||
50 | else |
||
51 | AR_CB(); |
||
52 | end |
||
53 | end |
||
54 | end |
||
55 | end |
||
56 | |||
57 | -- |
||
58 | -- Initialization And Configuration. |
||
59 | -- |
||
60 | |||
61 | function AR_Load() |
||
62 | |||
63 | AR_Chat("AutoRepair v"..AR_CurrentVersion.." loaded."); |
||
64 | |||
65 | if (AR_Save == nil) then |
||
66 | AR_SaveSetup(); |
||
67 | end |
||
68 | |||
69 | if (AR_Save.version ~= AR_CurrentVersion) then |
||
70 | AR_UpgradeFrom(AR_Save.version); |
||
71 | end |
||
72 | |||
73 | SlashCmdList["AUTOREPAIR"] = AR_SlashHandler; |
||
74 | SLASH_AUTOREPAIR1 = "/autorepair"; |
||
75 | SLASH_AUTOREPAIR2 = "/ar"; |
||
76 | |||
77 | end |
||
78 | |||
79 | function AR_UpgradeFrom(oldVersion) |
||
80 | |||
81 | if (oldVersion == "0.5") then |
||
82 | AR_Save.version = AR_CurrentVersion; |
||
83 | AR_Save.verbose = true; |
||
84 | AR_Save.skipInv = false; |
||
85 | end |
||
86 | |||
87 | end |
||
88 | |||
89 | |||
90 | function AR_SaveSetup() |
||
91 | AR_Chat("Default Variable Values Loaded."); |
||
92 | AR_Chat("To Learn How To Change Settings Type /ar"); |
||
93 | AR_Save = {}; |
||
94 | AR_Save.version = AR_CurrentVersion; |
||
95 | AR_Save.enabled = true; |
||
96 | AR_Save.costThreshold = 0; |
||
97 | AR_Save.minCost = 0; |
||
98 | AR_Save.promptEnabled = true; |
||
99 | AR_Save.verbose = true; |
||
100 | AR_Save.skipInv = false; |
||
101 | end |
||
102 | |||
103 | -- |
||
104 | -- Helper Functions |
||
105 | -- |
||
106 | |||
107 | function AR_Chat(text) |
||
108 | DEFAULT_CHAT_FRAME:AddMessage(STATUS_COLOR..text); |
||
109 | end |
||
110 | |||
111 | -- function By Turan (turan@gryffon.com) - AuctionIt! |
||
112 | -- http://turan.gryffon.com/wow.html -- gryphon globals.lua |
||
113 | -- moved this function here since he updates his library's often |
||
114 | function setAmountString(amt, sep) |
||
115 | local str = ""; |
||
116 | local gold, silver, copper; |
||
117 | |||
118 | if (amt == 0) then |
||
119 | str = COPPER .. "0 Copper" .. STATUS_COLOR; |
||
120 | return str; |
||
121 | end |
||
122 | if ( not sep ) then sep = " " end; |
||
123 | |||
124 | copper = mod(floor(amt + .5), 100); |
||
125 | silver = mod(floor(amt/100), 100); |
||
126 | gold = mod(floor(amt/(100*100)), 100); |
||
127 | |||
128 | if ( gold > 0 ) then str = GOLD .. gold .. " Gold" end; |
||
129 | if ( silver > 0 ) then |
||
130 | if ( str ~= "" ) then str = str .. sep end; |
||
131 | str = str .. SILVER .. silver .. " Silver"; |
||
132 | end; |
||
133 | if ( copper > 0 ) then |
||
134 | if ( str ~= "" ) then str = str .. sep end; |
||
135 | str = str .. COPPER .. copper .. " Copper"; |
||
136 | end; |
||
137 | |||
138 | str = str .. STATUS_COLOR; |
||
139 | return str; |
||
140 | end |
||
141 | |||
142 | function setEnabledString(enabled) |
||
143 | if (enabled) then |
||
144 | return "Enabled."; |
||
145 | else |
||
146 | return "Disabled."; |
||
147 | end |
||
148 | end |
||
149 | -- |
||
150 | -- Slash Command Handlers |
||
151 | -- |
||
152 | |||
153 | function AR_SlashHandler(msg) |
||
154 | |||
155 | local _,_,command,options = string.find(msg,"([%w%p]+)%s*(.*)$"); |
||
156 | |||
157 | if (command) then |
||
158 | command = string.lower(command); |
||
159 | end |
||
160 | if (command == nil or command == "") then |
||
161 | AR_Chat("Current Settings:"); |
||
162 | AR_Chat("MinCost: ".. WHITE .. setAmountString(AR_Save.minCost)); |
||
163 | AR_Chat("Threshold: " .. WHITE .. setAmountString(AR_Save.costThreshold)); |
||
164 | AR_Chat("Prompts: " .. WHITE .. setEnabledString(AR_Save.promptEnabled)); |
||
165 | AR_Chat("Verbose: " .. WHITE .. setEnabledString(AR_Save.verbose)); |
||
166 | AR_Chat("Skipping Inventory: " .. WHITE .. setEnabledString(AR_Save.skipInv)); |
||
167 | AR_Chat("Available Commands:"); |
||
168 | AR_Chat("/ar MinCost <number> -- " .. WHITE .."Sets the minimal ammount you wish to ever auto repair for. This is compared to the total repair costs."); |
||
169 | AR_Chat("/ar Threshold <number> -- " .. WHITE .."Sets the most your willing to pay for without being prompt. If your total repair bill is less then your threshold and more than your min. then you'll automatically repair everything."); |
||
170 | AR_Chat("/ar Prompts -- " .. WHITE .."This toggles showing prompts. If prompts are disabled Auto Repair will still repair your stuff as long as you can afford it."); |
||
171 | AR_Chat("/ar Enable -- " .. WHITE .."This turns AutoRepair on and off."); |
||
172 | AR_Chat("/ar Verbose -- " .. WHITE .. "This toggles showing repair ammounts in the chat area after repair has been done."); |
||
173 | AR_Chat("/ar SkipInv -- " .. WHITE .. "This toggles skipping inventory check/repair. If enabled, AR will NOT check your inventory."); |
||
174 | |||
175 | elseif (command == 'enable') then AR_EnableHandler(); |
||
176 | elseif (command == 'mincost') then AR_MinCostHandler(options); |
||
177 | elseif (command == 'threshold') then AR_ThresholdHandler(options); |
||
178 | elseif (command == 'prompt') then AR_PromptHandler(); |
||
179 | elseif (command == 'verbose') then AR_VerboseHandler(); |
||
180 | elseif (command == 'skipinv') then AR_SkipInvHandler(); |
||
181 | end |
||
182 | |||
183 | end |
||
184 | |||
185 | function AR_SkipInvHandler() |
||
186 | if (AR_Save.skipInv) then |
||
187 | AR_Save.skipInv = false; |
||
188 | AR_Chat("Auto Repair will NOW check your inventory and offer to repair it. Type /ar skipinv to turn this off."); |
||
189 | else |
||
190 | AR_Save.skipInv = true; |
||
191 | AR_Chat("Auto Repair will NO LONGER check your inventory and offer to repair it. Type /ar skipinv to turn this back on."); |
||
192 | end |
||
193 | end |
||
194 | |||
195 | function AR_VerboseHandler() |
||
196 | if (AR_Save.verbose) then |
||
197 | AR_Save.verbose = false; |
||
198 | AR_Chat("Auto Repair's verbose mode has been disabled. Type /ar verbose to enable it."); |
||
199 | else |
||
200 | AR_Save.verbose = true; |
||
201 | AR_Chat("Auto Repair's verbose mode has been enabled. type /ar verbose to disable it."); |
||
202 | end |
||
203 | end |
||
204 | |||
205 | function AR_PromptHandler() |
||
206 | if (AR_Save.promptEnabled) then |
||
207 | AR_Save.promptEnabled = false; |
||
208 | AR_Chat("Auto Repair prompts have been disabled. Type /ar prompt to enable them."); |
||
209 | AR_Chat("Please note that this dosn't disable Auto Repair and if the ammount is affordable and over your minimal cost, your equipment will still be repaired."); |
||
210 | else |
||
211 | AR_Save.promptEnabled = true; |
||
212 | AR_Chat("Auto Repair prompts have been enabled. type /ar prompt to disable them."); |
||
213 | end |
||
214 | end |
||
215 | |||
216 | function AR_EnableHandler() |
||
217 | if (AR_Save.enabled) then |
||
218 | AR_Save.enabled= false; |
||
219 | AR_Chat("Auto Repair has been disabled. Type /ar enable to turn it back on."); |
||
220 | else |
||
221 | AR_Save.enabled= true; |
||
222 | AR_Chat("Auto Repair has been enabled. type /ar enable to turn it off."); |
||
223 | end |
||
224 | end |
||
225 | |||
226 | |||
227 | function AR_MinCostHandler(option) |
||
228 | |||
229 | if(option == nil or option == "") then |
||
230 | AR_Chat("AutoRepair: Min. Repair Cost: "..setAmountString(AR_Save.minCost).."."); |
||
231 | AR_Chat("To Change MinCost Use:"); |
||
232 | AR_Chat("/ar mincost <number>"); |
||
233 | AR_Chat("<number> must be greater than Zero."); |
||
234 | AR_Chat("<number> is entered in copper."); |
||
235 | else |
||
236 | num = tonumber(option); |
||
237 | if (num < 0) then |
||
238 | AR_Chat("AutoRepair: Min. Repair Cost Set Error."); |
||
239 | AR_Chat("Correct Usage:"); |
||
240 | AR_Chat("/ar mincost <number>"); |
||
241 | AR_Chat("<number> must be greater than Zero."); |
||
242 | AR_Chat("<number> is entered in copper."); |
||
243 | else |
||
244 | AR_Save.minCost = num; |
||
245 | AR_Chat("AutoRepair: Min. Repair Cost Set To: "..setAmountString(AR_Save.minCost).."."); |
||
246 | end |
||
247 | |||
248 | end |
||
249 | |||
250 | end |
||
251 | |||
252 | function AR_ThresholdHandler(option) |
||
253 | |||
254 | if(option == nil or option == "") then |
||
255 | AR_Chat("AutoRepair: Threshold Amount: "..setAmountString(AR_Save.costThreshold).."."); |
||
256 | AR_Chat("To Change Threshold Use:"); |
||
257 | AR_Chat("/ar threshold <number>"); |
||
258 | AR_Chat("<number> must be greater than Zero."); |
||
259 | AR_Chat("<number> is entered in copper."); |
||
260 | else |
||
261 | num = tonumber(option); |
||
262 | if (num < 0) then |
||
263 | AR_Chat("AutoRepair: Threshold Set Error."); |
||
264 | AR_Chat("Correct Usage:"); |
||
265 | AR_Chat("/ar threshold <number>"); |
||
266 | AR_Chat("<number> must be greater than Zero."); |
||
267 | AR_Chat("<number> is entered in copper."); |
||
268 | else |
||
269 | AR_Save.costThreshold = num; |
||
270 | AR_Chat("AutoRepair: Threshold Amount Set To: "..setAmountString(AR_Save.costThreshold).."."); |
||
271 | |||
272 | end |
||
273 | |||
274 | end |
||
275 | |||
276 | end |
||
277 | |||
278 | -- |
||
279 | -- Repair Functions |
||
280 | -- |
||
281 | |||
282 | function AR_RepairHandler(skip_equip) |
||
283 | if (AR_Save.promptEnabled and CanMerchantRepair()) then |
||
284 | local AR_EquipCost = GetRepairAllCost(); |
||
285 | local AR_InvCost = AR_GetInventoryCost(); |
||
286 | local AR_Funds = GetMoney(); |
||
287 | local AR_TotalCost = AR_EquipCost + AR_InvCost; |
||
288 | |||
289 | local AR_Afford = AR_TotalCost < AR_Funds; |
||
290 | local AR_UnderThreshold = AR_TotalCost < AR_Save.costThreshold; |
||
291 | local AR_OverMin = AR_TotalCost > AR_Save.minCost; |
||
292 | local AR_Needed = AR_TotalCost > 0; |
||
293 | |||
294 | if (AR_Afford and AR_UnderThreshold and AR_OverMin and AR_Needed) then |
||
295 | AR_RepairEquipment(); |
||
296 | |||
297 | if (AR_Save.skipInv) then |
||
298 | AR_TotalCost = AR_EquipCost; |
||
299 | else |
||
300 | AR_RepairInventory(); |
||
301 | end |
||
302 | return; |
||
303 | end |
||
304 | if (not skip_equip) then |
||
305 | AR_Afford = AR_EquipCost < AR_Funds; |
||
306 | AR_OverMin = AR_EquipCost > AR_Save.minCost; |
||
307 | AR_Needed = AR_EquipCost > 0; |
||
308 | |||
309 | if (AR_Afford and AR_OverMin and AR_Needed) then |
||
310 | AR_ShowEquipPrompt(AR_EquipCost); |
||
311 | if (not AR_Save.skipInv) then |
||
312 | AR_CB= AR_RepairHandler; |
||
313 | AR_CBV = true; |
||
314 | AR_CBT = 0; |
||
315 | end |
||
316 | end |
||
317 | end |
||
318 | |||
319 | if (AR_DiagOpen) then |
||
320 | return; |
||
321 | else |
||
322 | AR_CB= nil; |
||
323 | AR_CBV = nil; |
||
324 | AR_CBT = 0; |
||
325 | end |
||
326 | |||
327 | AR_Funds = GetMoney(); |
||
328 | AR_Afford = AR_InvCost < AR_Funds; |
||
329 | AR_OverMin = AR_InvCost > AR_Save.minCost; |
||
330 | AR_Needed = AR_InvCost > 0; |
||
331 | AR_Wanted = not AR_Save.skipInv; |
||
332 | |||
333 | if (AR_Afford and AR_OverMin and AR_Needed and AR_Wanted) then |
||
334 | AR_ShowInvPrompt(AR_InvCost); |
||
335 | end |
||
336 | |||
337 | elseif (CanMerchantRepair()) then |
||
338 | local AR_EquipCost = GetRepairAllCost(); |
||
339 | local AR_InvCost = AR_GetInventoryCost(); |
||
340 | local AR_Funds = GetMoney(); |
||
341 | local AR_TotalCost = AR_EquipCost + AR_InvCost; |
||
342 | |||
343 | local AR_Afford = AR_TotalCost < AR_Funds; |
||
344 | local AR_OverMin = AR_TotalCost > AR_Save.minCost; |
||
345 | local AR_Needed = AR_TotalCost > 0; |
||
346 | if (AR_Afford and AR_OverMin and AR_Needed) then |
||
347 | AR_RepairEquipment(); |
||
348 | if (AR_Save.skipInv) then |
||
349 | AR_TotalCost = AR_EquipCost; |
||
350 | else |
||
351 | AR_RepairInventory(); |
||
352 | end |
||
353 | end |
||
354 | end |
||
355 | end |
||
356 | |||
357 | function AR_OpenDiagToggle() |
||
358 | if (AR_DiagOpen) then |
||
359 | AR_DiagOpen = false; |
||
360 | else |
||
361 | AR_DiagOpen = true; |
||
362 | end |
||
363 | |||
364 | end |
||
365 | |||
366 | function AR_ShowEquipPrompt(cost) |
||
367 | local AR_CostText = setAmountString(cost); |
||
368 | StaticPopupDialogs["REPAIR_EQUIP_BIND"] = { |
||
369 | text = TEXT(STATUS_COLOR.."AutoRepair v"..AR_CurrentVersion.." (Kael Cycle)\n\n\nIt Will Cost "..AR_CostText.." To Fix Your Equipment.\n\nDo You Wish To Repair Your Equipment?"), |
||
370 | button1 = TEXT(OKAY), |
||
371 | button2 = TEXT(CANCEL), |
||
372 | OnAccept = function() |
||
373 | AR_RepairEquipment(); |
||
374 | end, |
||
375 | OnShow = function() |
||
376 | AR_OpenDiagToggle(); |
||
377 | end, |
||
378 | OnHide = function() |
||
379 | AR_OpenDiagToggle(); |
||
380 | end, |
||
381 | showAlert = 1, |
||
382 | timeout = 0, |
||
383 | exclusive = 0, |
||
384 | whileDead = 1, |
||
385 | interruptCinematic = 1 |
||
386 | }; |
||
387 | PlaySound("QUESTADDED"); |
||
388 | StaticPopup_Show("REPAIR_EQUIP_BIND"); |
||
389 | end |
||
390 | |||
391 | function AR_ShowInvPrompt(cost) |
||
392 | local AR_CostText = setAmountString(cost); |
||
393 | StaticPopupDialogs["REPAIR_INV_BIND"] = { |
||
394 | text = TEXT(STATUS_COLOR.."AutoRepair v"..AR_CurrentVersion.." (Kael Cycle)\n\n\nIt Will Cost "..AR_CostText.." To Fix The Items In Your Inventory.\n\nDo You Wish To Repair Your Items?"), |
||
395 | button1 = TEXT(OKAY), |
||
396 | button2 = TEXT(CANCEL), |
||
397 | OnAccept = function() |
||
398 | AR_RepairInventory(); |
||
399 | end, |
||
400 | OnShow = function() |
||
401 | AR_OpenDiagToggle(); |
||
402 | end, |
||
403 | OnHide = function() |
||
404 | AR_OpenDiagToggle(); |
||
405 | end, |
||
406 | showAlert = 1, |
||
407 | timeout = 0, |
||
408 | exclusive = 0, |
||
409 | whileDead = 1, |
||
410 | interruptCinematic = 1 |
||
411 | }; |
||
412 | PlaySound("QUESTADDED"); |
||
413 | StaticPopup_Show("REPAIR_INV_BIND"); |
||
414 | end |
||
415 | |||
416 | function AR_GetInventoryCost() |
||
417 | |||
418 | local AR_InventoryCost = 0; |
||
419 | |||
420 | for bag = 0,4,1 do |
||
421 | for slot = 1, GetContainerNumSlots(bag) , 1 do |
||
422 | local hasCooldown, repairCost = GameTooltip:SetBagItem(bag,slot); |
||
423 | if (repairCost) then |
||
424 | AR_InventoryCost = AR_InventoryCost + repairCost; |
||
425 | end |
||
426 | end |
||
427 | end |
||
428 | |||
429 | return AR_InventoryCost; |
||
430 | end |
||
431 | |||
432 | function AR_RepairEquipment() |
||
433 | RepairAllItems(); |
||
434 | if (AR_Save.verbose) then |
||
435 | local cost = GetRepairAllCost(); |
||
436 | AR_Chat("Your repair bill for work done to your equipment was: " .. setAmountString(cost) .. "."); |
||
437 | |||
438 | end |
||
439 | end |
||
440 | |||
441 | function AR_RepairInventory() |
||
442 | ShowRepairCursor(); |
||
443 | for bag = 0,4,1 do |
||
444 | for slot = 1, GetContainerNumSlots(bag) , 1 do |
||
445 | local hasCooldown, repairCost = GameTooltip:SetBagItem(bag,slot); |
||
446 | if (repairCost and repairCost > 0) then |
||
447 | UseContainerItem(bag,slot); |
||
448 | end |
||
449 | end |
||
450 | end |
||
451 | HideRepairCursor(); |
||
452 | if (AR_Save.verbose) then |
||
453 | local cost = AR_GetInventoryCost(); |
||
454 | AR_Chat("Your repair bill for work done to your inventory was: " .. setAmountString(cost) .. "."); |
||
455 | |||
456 | end |
||
457 | end |