vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[ |
2 | Auctioneer Addon for World of Warcraft(tm). |
||
3 | Version: 3.9.0.1000 (Kangaroo) |
||
4 | Revision: $Id: AucAskPrice.lua 994 2006-09-07 01:30:33Z mentalpower $ |
||
5 | |||
6 | Auctioneer AskPrice created by Mikezter and merged into Auctioneer by MentalPower. |
||
7 | Functions responsible for AskPrice's operation.. |
||
8 | |||
9 | License: |
||
10 | This program is free software; you can redistribute it and/or |
||
11 | modify it under the terms of the GNU General Public License |
||
12 | as published by the Free Software Foundation; either version 2 |
||
13 | of the License, or (at your option) any later version. |
||
14 | |||
15 | This program is distributed in the hope that it will be useful, |
||
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
18 | GNU General Public License for more details. |
||
19 | |||
20 | You should have received a copy of the GNU General Public License |
||
21 | along with this program(see GPL.txt); if not, write to the Free Software |
||
22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||
23 | ]] |
||
24 | |||
25 | --Local function prototypes |
||
26 | local init, askpriceFrame, commandHandler, chatPrintHelp, onOff, setTrigger, genVarSet, setCustomSmartWords, setKhaosSetKeyValue, eventHandler, sendWhisper, onEventHook |
||
27 | |||
28 | local whisperList = {} |
||
29 | |||
30 | function init() |
||
31 | askPriceFrame = CreateFrame("Frame") |
||
32 | |||
33 | askPriceFrame:RegisterEvent("CHAT_MSG_RAID_LEADER") |
||
34 | askPriceFrame:RegisterEvent("CHAT_MSG_WHISPER") |
||
35 | askPriceFrame:RegisterEvent("CHAT_MSG_OFFICER") |
||
36 | askPriceFrame:RegisterEvent("CHAT_MSG_PARTY") |
||
37 | askPriceFrame:RegisterEvent("CHAT_MSG_GUILD") |
||
38 | askPriceFrame:RegisterEvent("CHAT_MSG_RAID") |
||
39 | |||
40 | askPriceFrame:SetScript("OnEvent", function () Auctioneer.AskPrice.EventHandler(event, arg1, arg2) end) |
||
41 | |||
42 | Auctioneer.AskPrice.Language = GetDefaultLanguage("player"); |
||
43 | |||
44 | Stubby.RegisterFunctionHook("ChatFrame_OnEvent", -200, Auctioneer.AskPrice.OnEventHook); |
||
45 | end |
||
46 | |||
47 | function commandHandler(command, source) |
||
48 | |||
49 | --To print or not to print, that is the question... |
||
50 | local chatprint = nil; |
||
51 | |||
52 | if (source == "GUI") then |
||
53 | chatprint = false; |
||
54 | |||
55 | else |
||
56 | chatprint = true; |
||
57 | end; |
||
58 | |||
59 | --Divide the large command into smaller logical sections (Shameless copy from the original function) |
||
60 | local i,j, cmd, param = string.find(command, "^([^ ]+) (.+)$"); |
||
61 | |||
62 | if (not cmd) then cmd = command; end |
||
63 | if (not cmd) then cmd = ""; end |
||
64 | if (not param) then param = ""; end |
||
65 | cmd = Auctioneer.Util.DelocalizeCommand(cmd); |
||
66 | |||
67 | --Now for the real Command handling |
||
68 | |||
69 | --/auctioneer askprice help |
||
70 | if ((cmd == "") or (cmd == "help")) then |
||
71 | chatPrintHelp(); |
||
72 | |||
73 | --/auctioneer askprice (on|off|toggle) |
||
74 | elseif (cmd == 'on' or cmd == 'off' or cmd == 'toggle') then |
||
75 | onOff(cmd, chatprint); |
||
76 | |||
77 | --/auctioneer askprice trigger (char) |
||
78 | elseif (cmd == 'trigger') then |
||
79 | setTrigger(param, chatprint) |
||
80 | |||
81 | --/auctioneer askprice (party|guild|smart|ad|whispers) (on|off|toggle) |
||
82 | elseif ( |
||
83 | cmd == 'vendor' or cmd == 'party' or cmd == 'guild' or |
||
84 | cmd == 'smart' or cmd == 'ad' or cmd == 'whispers' |
||
85 | ) then |
||
86 | genVarSet(cmd, param, chatprint); |
||
87 | |||
88 | --/auctioneer askprice word # (customSmartWord) |
||
89 | elseif (cmd == 'word') then |
||
90 | setCustomSmartWords(param, nil, nil, chatprint); |
||
91 | |||
92 | --Command not recognized |
||
93 | else |
||
94 | if (chatprint) then |
||
95 | Auctioneer.Util.ChatPrint(string.format(_AUCT('FrmtActUnknown'), command)); |
||
96 | end |
||
97 | end |
||
98 | end |
||
99 | |||
100 | function chatPrintHelp() |
||
101 | local onOffToggle = " (".._AUCT('CmdOn').."|".._AUCT('CmdOff').."|".._AUCT('CmdToggle')..")"; |
||
102 | local lineFormat = " |cffffffff/auctioneer askprice %s"..onOffToggle.."|r |cff2040ff[%s]|r\n %s\n\n"; |
||
103 | |||
104 | Auctioneer.Util.ChatPrint(" |cffffffff/auctioneer askprice"..onOffToggle.."|r |cff2040ff["..Auctioneer.Util.GetLocalizedFilterVal('askprice').."]|r\n " .. _AUCT('HelpAskPrice') .. "\n\n"); |
||
105 | |||
106 | Auctioneer.Util.ChatPrint(string.format(lineFormat, _AUCT('CmdAskPriceWhispers'), Auctioneer.Util.GetLocalizedFilterVal('askprice-whispers'), _AUCT('HelpAskPriceWhispers'))); |
||
107 | Auctioneer.Util.ChatPrint(string.format(lineFormat, _AUCT('CmdAskPriceVendor'), Auctioneer.Util.GetLocalizedFilterVal('askprice-vendor'), _AUCT('HelpAskPriceVendor'))); |
||
108 | Auctioneer.Util.ChatPrint(string.format(lineFormat, _AUCT('CmdAskPriceParty'), Auctioneer.Util.GetLocalizedFilterVal('askprice-party'), _AUCT('HelpAskPriceParty'))); |
||
109 | Auctioneer.Util.ChatPrint(string.format(lineFormat, _AUCT('CmdAskPriceGuild'), Auctioneer.Util.GetLocalizedFilterVal('askprice-guild'), _AUCT('HelpAskPriceGuild'))); |
||
110 | Auctioneer.Util.ChatPrint(string.format(lineFormat, _AUCT('CmdAskPriceSmart'), Auctioneer.Util.GetLocalizedFilterVal('askprice-smart'), _AUCT('HelpAskPriceSmart'))); |
||
111 | Auctioneer.Util.ChatPrint(string.format(lineFormat, _AUCT('CmdAskPriceAd'), Auctioneer.Util.GetLocalizedFilterVal('askprice-ad'), _AUCT('HelpAskPriceAd'))); |
||
112 | |||
113 | lineFormat = " |cffffffff/auctioneer askprice %s|r |cff2040ff[%s]|r\n %s\n\n"; |
||
114 | Auctioneer.Util.ChatPrint(string.format(lineFormat, _AUCT('CmdAskPriceTrigger'), Auctioneer.Command.GetFilterVal('askprice-trigger'), _AUCT('HelpAskPriceTrigger'))); |
||
115 | |||
116 | lineFormat = " |cffffffff/auctioneer askprice %s %d|r |cff2040ff[%s]|r\n %s\n\n"; |
||
117 | Auctioneer.Util.ChatPrint(string.format(lineFormat, _AUCT('CmdAskPriceWord'), 1, Auctioneer.Command.GetFilterVal('askprice-word1'), _AUCT('HelpAskPriceWord'))); |
||
118 | Auctioneer.Util.ChatPrint(string.format(lineFormat, _AUCT('CmdAskPriceWord'), 2, Auctioneer.Command.GetFilterVal('askprice-word2'), _AUCT('HelpAskPriceWord'))); |
||
119 | end |
||
120 | |||
121 | --[[ |
||
122 | The onOff(state, chatprint) function handles AskPrice's state (whether it is currently on or off) |
||
123 | If "on" or "off" is specified in the first argument then AskPrice's state is changed to that value, |
||
124 | If "toggle" is specified then it will toggle AskPrice's state (if currently on then it will be turned off and vice-versa) |
||
125 | |||
126 | If a boolean (or nil) value is passed as the first argument the conversion is as follows: |
||
127 | "true" is the same as "on" |
||
128 | "false" is the same as "off" |
||
129 | "nil" is the same as "toggle" |
||
130 | |||
131 | If chatprint is "true" then the state will also be printed to the user. |
||
132 | ]] |
||
133 | function onOff(state, chatprint) |
||
134 | if (type(state) == "string") then |
||
135 | state = Auctioneer.Util.DelocalizeFilterVal(state); |
||
136 | |||
137 | elseif (state == true) then |
||
138 | state = 'on' |
||
139 | |||
140 | elseif (state == false) then |
||
141 | state = 'off' |
||
142 | |||
143 | elseif (state == nil) then |
||
144 | state = 'toggle' |
||
145 | end |
||
146 | |||
147 | if (state == 'on' or state == 'off') then |
||
148 | Auctioneer.Command.SetFilter('askprice', state); |
||
149 | elseif (state == 'toggle') then |
||
150 | Auctioneer.Command.SetFilter('askprice', not Auctioneer.Command.GetFilter('askprice')); |
||
151 | end |
||
152 | |||
153 | --Print the change and alert the GUI if the command came from slash commands. Do nothing if they came from the GUI. |
||
154 | if (chatprint) then |
||
155 | state = Auctioneer.Command.GetFilter('askprice') |
||
156 | setKhaosSetKeyValue("askprice", state) |
||
157 | |||
158 | if (state) then |
||
159 | Auctioneer.Util.ChatPrint(_AUCT('StatAskPriceOn')); |
||
160 | |||
161 | else |
||
162 | Auctioneer.Util.ChatPrint(_AUCT('StatAskPriceOff')); |
||
163 | end |
||
164 | end |
||
165 | end |
||
166 | |||
167 | function setTrigger(param, chatprint) |
||
168 | if (not (type(param) == 'string')) then |
||
169 | return |
||
170 | end |
||
171 | |||
172 | param = string.sub(param, 1, 1) |
||
173 | Auctioneer.Command.SetFilter('askprice-trigger', param) |
||
174 | |||
175 | if (chatprint) then |
||
176 | Auctioneer.Util.ChatPrint(string.format(_AUCT('FrmtActSet'), "askprice ".._AUCT('CmdAskPriceTrigger'), param)); |
||
177 | setKhaosSetKeyValue('askprice-trigger', param) |
||
178 | end |
||
179 | end |
||
180 | |||
181 | function genVarSet(variable, param, chatprint) |
||
182 | if (type(param) == "string") then |
||
183 | param = Auctioneer.Util.DelocalizeFilterVal(param); |
||
184 | end |
||
185 | |||
186 | local var = "askprice-"..variable |
||
187 | |||
188 | if (param == "on" or param == "off" or type(param) == "boolean") then |
||
189 | Auctioneer.Command.SetFilter(var, param); |
||
190 | |||
191 | elseif (param == "toggle" or param == nil or param == "") then |
||
192 | param = Auctioneer.Command.SetFilter(var, not Auctioneer.Command.GetFilter(var)); |
||
193 | end |
||
194 | |||
195 | if (chatprint) then |
||
196 | if (Auctioneer.Command.GetFilter(var)) then |
||
197 | Auctioneer.Util.ChatPrint(string.format(_AUCT('FrmtAskPriceEnable'), Auctioneer.Util.LocalizeCommand(variable))); |
||
198 | setKhaosSetKeyValue(var, true) |
||
199 | else |
||
200 | Auctioneer.Util.ChatPrint(string.format(_AUCT('FrmtAskPriceDisable'), Auctioneer.Util.LocalizeCommand(variable))); |
||
201 | setKhaosSetKeyValue(var, false) |
||
202 | end |
||
203 | end |
||
204 | end |
||
205 | |||
206 | --Function for users to add/modify smartWords (written by Kandoko, integrated into AskPrice by MentalPower) |
||
207 | function setCustomSmartWords(param, number, word, chatprint) |
||
208 | |||
209 | --Only parse the param if the pre-parsed components are not present. |
||
210 | if (not (number and word)) then |
||
211 | --Divide the large command into smaller logical sections (Shameless copy from the original function) |
||
212 | _, _, number, word = string.find(param, "^([^ ]+) (.+)$"); |
||
213 | |||
214 | if (not number) then number = param; end |
||
215 | if (not number) then number = ""; end |
||
216 | if (not word) then word = ""; end |
||
217 | end |
||
218 | |||
219 | number = tonumber(number) |
||
220 | |||
221 | if (not (((type(param) == 'string') or (type(word) == 'string'))and number)) then |
||
222 | Auctioneer.Util.ChatPrint(string.format(_AUCT('FrmtUnknownArg'), param or word, "askprice ".._AUCT('CmdAskPriceWord'))); |
||
223 | return |
||
224 | end |
||
225 | |||
226 | word = string.lower(word) |
||
227 | |||
228 | --Save choosen words. |
||
229 | if (number == 1) then |
||
230 | Auctioneer.Command.SetFilter('askprice-word1', word) |
||
231 | |||
232 | elseif (number == 2) then |
||
233 | Auctioneer.Command.SetFilter('askprice-word2', word) |
||
234 | else |
||
235 | Auctioneer.Util.ChatPrint(string.format(_AUCT('FrmtUnknownArg'), param, "askprice ".._AUCT('CmdAskPriceWord'))); |
||
236 | return; |
||
237 | end |
||
238 | |||
239 | if (chatprint) then |
||
240 | Auctioneer.Util.ChatPrint(string.format(_AUCT('FrmtActSet'), "askprice ".._AUCT('CmdAskPriceWord').." "..number, Auctioneer.Command.GetFilterVal('askprice-word'..number))); |
||
241 | setKhaosSetKeyValue('askprice-word'..number, word) |
||
242 | end |
||
243 | end |
||
244 | |||
245 | function setKhaosSetKeyValue(key, value) |
||
246 | if (Auctioneer_Khaos_Registered) then |
||
247 | local kKey = Khaos.getSetKey("Auctioneer", key) |
||
248 | |||
249 | if (not kKey) then |
||
250 | EnhTooltip.DebugPrint("setKhaosSetKeyParameter(): key " .. key .. " does not exist") |
||
251 | elseif (kKey.checked ~= nil) then |
||
252 | if (type(value) == "string") then value = (value == "on"); end |
||
253 | Khaos.setSetKeyParameter("Auctioneer", key, "checked", value) |
||
254 | elseif (kKey.value ~= nil) then |
||
255 | Khaos.setSetKeyParameter("Auctioneer", key, "value", value) |
||
256 | else |
||
257 | EnhTooltip.DebugPrint("setKhaosSetKeyValue(): don't know how to update key ", key) |
||
258 | end |
||
259 | end |
||
260 | end |
||
261 | |||
262 | function eventHandler(event, text, player) |
||
263 | --Nothing to do if askprice is disabled |
||
264 | if (not Auctioneer.Command.GetFilter('askprice')) then |
||
265 | return; |
||
266 | end |
||
267 | |||
268 | --Make sure that we recieve the proper events and that our settings allow a response |
||
269 | if (not ((event == "CHAT_MSG_WHISPER") |
||
270 | or (((event == "CHAT_MSG_GUILD") or (event == "CHAT_MSG_OFFICER")) and Auctioneer.Command.GetFilter('askprice-guild')) |
||
271 | or (((event == "CHAT_MSG_PARTY") or (event == "CHAT_MSG_RAID") or (event == "CHAT_MSG_RAID_LEADER")) and Auctioneer.Command.GetFilter('askprice-party')))) then |
||
272 | return; |
||
273 | end |
||
274 | |||
275 | local aCount, historicalMedian, snapshotMedian, vendorSell, eachstring, askedCount, items, usedStack, multipleItems; |
||
276 | |||
277 | -- Check for marker (trigger char or "smart" words) |
||
278 | if (not (string.sub(text, 1, 1) == Auctioneer.Command.GetFilterVal('askprice-trigger'))) then |
||
279 | |||
280 | --If the trigger char was not found scan the text for SmartWords (if the feature has been enabled) |
||
281 | if (Auctioneer.Command.GetFilter('askprice-smart')) then |
||
282 | if (not (string.find(string.lower(text), _AUCT('CmdAskPricSmartWord1')) and string.find(string.lower(text), _AUCT('CmdAskPriceSmartWord2')))) then |
||
283 | |||
284 | --Check if the custom SmartWords are present in the chat message |
||
285 | local customSmartWord1, customSmartWord2 = Auctioneer.Command.GetFilterVal('askprice-word1'), Auctioneer.Command.GetFilterVal('askprice-word1'); |
||
286 | if (not ((string.find(string.lower(text), customSmartWord1)) and string.find(string.lower(text), customSmartWord2))) then |
||
287 | return; |
||
288 | end |
||
289 | end |
||
290 | else |
||
291 | return; |
||
292 | end |
||
293 | end |
||
294 | |||
295 | -- Check for itemlink after trigger |
||
296 | if (not (string.find(text, "|Hitem:"))) then |
||
297 | return; |
||
298 | end |
||
299 | |||
300 | --Parse the text and separate out the different links |
||
301 | items = getItems(text) |
||
302 | for key, link in ipairs(items) do |
||
303 | -- |
||
304 | aCount, historicalMedian, snapshotMedian, vendorSell = getData(link[1]); |
||
305 | local askedCount; |
||
306 | |||
307 | --If there are multiple items send a separator line (since we can't send \n's as those would cause DC's) |
||
308 | if (multipleItems) then |
||
309 | Auctioneer.AskPrice.SendWhisper(" ", player); |
||
310 | end |
||
311 | |||
312 | --If the stackSize is grater than one, add the unit price to the message |
||
313 | if (link[2] > 1) then |
||
314 | eachstring = string.format(_AUCT('FrmtAskPriceEach'), EnhTooltip.GetTextGSC(historicalMedian, nil, true)); |
||
315 | else |
||
316 | eachstring = ""; |
||
317 | end |
||
318 | |||
319 | if (aCount > 0) then |
||
320 | Auctioneer.AskPrice.SendWhisper(link[1]..": "..string.format(_AUCT('FrmtInfoSeen'), aCount), player); |
||
321 | Auctioneer.AskPrice.SendWhisper(string.format(_AUCT('FrmtAskPriceBuyoutMedianHistorical'), " ", EnhTooltip.GetTextGSC(historicalMedian*link[2], nil, true), eachstring), player); |
||
322 | Auctioneer.AskPrice.SendWhisper(string.format(_AUCT('FrmtAskPriceBuyoutMedianSnapshot'), " ", EnhTooltip.GetTextGSC(snapshotMedian*link[2], nil, true), eachstring), player); |
||
323 | else |
||
324 | Auctioneer.AskPrice.SendWhisper(link[1]..": "..string.format(_AUCT('FrmtInfoNever'), Auctioneer.Util.GetAuctionKey()), player); |
||
325 | end |
||
326 | |||
327 | --Send out vendor info if we have it |
||
328 | if (Auctioneer.Command.GetFilter('askprice-vendor') and (vendorSell > 0)) then |
||
329 | |||
330 | --Again if the stackSize is grater than one, add the unit price to the message |
||
331 | if (link[2] > 1) then |
||
332 | eachstring = string.format(_AUCT('FrmtAskPriceEach'), EnhTooltip.GetTextGSC(vendorSell, nil, true)); |
||
333 | else |
||
334 | eachstring = ""; |
||
335 | end |
||
336 | |||
337 | Auctioneer.AskPrice.SendWhisper(string.format(_AUCT('FrmtAskPriceVendorPrice'), " ",EnhTooltip.GetTextGSC(vendorSell * link[2], nil, true), eachstring), player); |
||
338 | end |
||
339 | |||
340 | if (link[2] > 1) then |
||
341 | usedStack = link[2] |
||
342 | end |
||
343 | multipleItems = true; |
||
344 | end |
||
345 | |||
346 | --Once we're done sending out the itemInfo, check if the person used the stack size feature, if not send them the ad message. |
||
347 | if ((not usedStack) and (Auctioneer.Command.GetFilter('askprice-ad'))) then |
||
348 | Auctioneer.AskPrice.SendWhisper(string.format(_AUCT('AskPriceAd'), Auctioneer.Command.GetFilterVal('askprice-trigger')), player) |
||
349 | end |
||
350 | end |
||
351 | |||
352 | function getData(itemLink) |
||
353 | local itemID, randomProp, enchant, uniqID, lame = EnhTooltip.BreakLink(itemLink); |
||
354 | |||
355 | local auctKey = Auctioneer.Util.GetAuctionKey(); |
||
356 | local itemKey = itemID..":"..randomProp..":"..enchant; |
||
357 | |||
358 | local auctionPriceItem = Auctioneer.Core.GetAuctionPriceItem(itemKey, auctKey); |
||
359 | local aCount,minCount,minPrice,bidCount,bidPrice,buyCount,buyPrice = Auctioneer.Core.GetAuctionPrices(auctionPriceItem.data); |
||
360 | local historicalMedian, historicalMedCount = Auctioneer.Statistic.GetItemHistoricalMedianBuyout(itemKey, auctKey); |
||
361 | local snapshotMedian, snapshotMedCount = Auctioneer.Statistic.GetItemSnapshotMedianBuyout(itemKey, auctKey); |
||
362 | local median, medCount = Auctioneer.Statistic.GetUsableMedian(itemKey, auctKey); |
||
363 | local vendorSell = Auctioneer.API.GetVendorSellPrice(itemID) |
||
364 | |||
365 | if (aCount > 0) then |
||
366 | -- calculate auction values |
||
367 | |||
368 | local avgMin = math.floor(minPrice / minCount); |
||
369 | |||
370 | local bidPct = math.floor(bidCount / minCount * 100); |
||
371 | local avgBid = 0; |
||
372 | if (bidCount > 0) then |
||
373 | avgBid = math.floor(bidPrice / bidCount); |
||
374 | end |
||
375 | |||
376 | local buyPct = math.floor(buyCount / minCount * 100); |
||
377 | local avgBuy = 0; |
||
378 | if (buyCount > 0) then |
||
379 | avgBuy = math.floor(buyPrice / buyCount); |
||
380 | end |
||
381 | end |
||
382 | |||
383 | return aCount or 0, historicalMedian or 0, snapshotMedian or 0, vendorSell or 0; |
||
384 | end |
||
385 | |||
386 | --Many thanks to the guys at irc://chat.freenode.net/wowi-lounge for their help in creating this function |
||
387 | function getItems(str) |
||
388 | if (not str) then return nil end |
||
389 | local itemList = {}; |
||
390 | |||
391 | for number, color, item, name in string.gfind(str, "(%d*)|c(%x+)|Hitem:(%d+:%d+:%d+:%d+)|h%[(.-)%]|h|r") do |
||
392 | table.insert(itemList, {"|c"..color.."|Hitem:"..item.."|h["..name.."]|h|r", tonumber(number) or 1}) |
||
393 | end |
||
394 | return itemList; |
||
395 | end |
||
396 | |||
397 | function sendWhisper(text, player) |
||
398 | whisperList[text] = true |
||
399 | SendChatMessage(text, "WHISPER", Auctioneer.AskPrice.Language, player) |
||
400 | end |
||
401 | |||
402 | function onEventHook() |
||
403 | if (Auctioneer.Command.GetFilter('askprice-whisper')) then |
||
404 | if ((event == "CHAT_MSG_WHISPER_INFORM") and (whisperList[arg1])) then |
||
405 | return "killorig" |
||
406 | end |
||
407 | end |
||
408 | end |
||
409 | |||
410 | Auctioneer.AskPrice = { |
||
411 | Init = init, |
||
412 | CommandHandler = commandHandler, |
||
413 | ChatPrintHelp = chatPrintHelp, |
||
414 | OnOff = onOff, |
||
415 | SetTrigger = setTrigger, |
||
416 | GenVarSet = genVarSet, |
||
417 | SetCustomSmartWords = setCustomSmartWords, |
||
418 | EventHandler = eventHandler, |
||
419 | SendWhisper = sendWhisper, |
||
420 | OnEventHook = onEventHook, |
||
421 | } |