vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 Enchantrix Addon for World of Warcraft(tm).
3 Version: 3.6.1 (Platypus)
4 Revision: $Id: EnxCommand.lua 944 2006-07-11 03:31:50Z mentalpower $
5  
6 Slash command and GUI functions.
7  
8 License:
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13  
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18  
19 You should have received a copy of the GNU General Public License
20 along with this program(see GLP.txt); if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 ]]
23  
24 -- Global functions
25 local addonLoaded -- Enchantrix.Command.AddonLoaded()
26 local auctioneerLoaded -- Enchantrix.Command.AuctioneerLoaded()
27 local handleCommand -- Enchantrix.Command.HandleCommand()
28 local register -- Enchantrix.Command.Register()
29 local resetKhaos -- Enchantrix.Command.ResetKhaos()
30 local setKhaosSetKeyValue -- Enchantrix.Command.SetKhaosSetKeyValue()
31 local setKhaosSetKeyParameter -- Enchantrix.Command.SetKhaosSetKeyParameter()
32  
33 -- Local functions
34 local getKhaosLocaleList
35 local getKhaosLoadList
36 local registerKhaos
37 local registerAuctioneerOptions
38 local chatPrintHelp
39 local onOff
40 local clear
41 local default
42 local genVarSet
43 local percentLessFilter
44 local bidBrokerFilter
45 local profitComparisonSort
46 local bidBrokerSort
47 local doBidBroker
48 local doPercentLess
49 local getAuctionItemDisenchants
50  
51 -- GUI Init Variables (Added by MentalPower)
52 Enchantrix.State.GUI_Registered = nil
53 Enchantrix.State.Khaos_Registered = nil
54  
55 -- Local variables
56 local optionSet
57 local profitMargins
58  
59 -- Local constants
60 local MAX_BUYOUT_PRICE = 800000;
61 local MIN_PROFIT_MARGIN = 1000;
62 local MIN_PERCENT_LESS_THAN_HSP = 20; -- 20% default
63 local MIN_PROFIT_PRICE_PERCENT = 10; -- 10% default
64  
65 function addonLoaded()
66 if IsAddOnLoaded("Khaos") then
67 registerKhaos()
68 end
69 end
70  
71 function getKhaosLocaleList()
72 local options = { [_ENCH('CmdDefault')] = 'default' };
73 for locale, data in EnchantrixLocalizations do
74 options[locale] = locale;
75 end
76 return options
77 end
78  
79 function getKhaosLoadList()
80 return {
81 [_ENCH('GuiLoad_Always')] = 'always',
82 [_ENCH('GuiLoad_Never')] = 'never',
83 }
84 end
85  
86 function registerKhaos()
87 optionSet = {
88 id="Enchantrix";
89 text="Enchantrix";
90 helptext=function()
91 return _ENCH('GuiMainHelp');
92 end;
93 difficulty=1;
94 default={checked=true};
95 options={
96 {
97 id="Header";
98 text="Enchantrix";
99 helptext=function()
100 return _ENCH('GuiMainHelp')
101 end;
102 type=K_HEADER;
103 difficulty=1;
104 };
105 {
106 id="all";
107 type=K_TEXT;
108 text=function()
109 return _ENCH('GuiMainEnable')
110 end;
111 helptext=function()
112 return _ENCH('HelpOnoff')
113 end;
114 callback=function(state)
115 if (state.checked) then
116 onOff('on');
117 else
118 onOff('off');
119 end
120 end;
121 feedback=function(state)
122 if (state.checked) then
123 return _ENCH('StatOn');
124 else
125 return _ENCH('StatOff');
126 end
127 end;
128 check=true;
129 default={checked=Enchantrix.Config.GetFilterDefaults('all')};
130 disabled={checked=false};
131 difficulty=1;
132 };
133 {
134 id="barker";
135 type=K_TEXT;
136 text=function()
137 return _ENCH('GuiBarker') -- "Enable Barker"
138 end;
139 helptext=function()
140 return _ENCH('HelpBarker') -- "Turn Enchantrix Barker on or off"
141 end;
142 callback=function(state)
143 genVarSet('barker', state.checked)
144 end;
145 feedback=function(state)
146 if (state.checked) then
147 return _ENCH('BarkerOn')
148 else
149 return _ENCH('BarkerOff')
150 end
151 end;
152 check=true;
153 default={checked=Enchantrix.Config.GetFilterDefaults('barker')};
154 disabled={checked=false};
155 difficulty=1;
156 };
157 {
158 id="locale";
159 type=K_PULLDOWN;
160 setup = {
161 options = getKhaosLocaleList;
162 multiSelect = false;
163 };
164 text=function()
165 return _ENCH('GuiLocale')
166 end;
167 helptext=function()
168 return _ENCH('HelpLocale')
169 end;
170 callback = function(state)
171 end;
172 feedback = function (state)
173 Enchantrix.Config.SetLocale(state.value);
174 return string.format(_ENCH('FrmtActSet'), _ENCH('CmdLocale'), state.value);
175 end;
176 default = {
177 value = Enchantrix.Config.GetLocale();
178 };
179 disabled = {
180 value = Enchantrix.Config.GetLocale();
181 };
182 dependencies={all={checked=true;}};
183 difficulty=2;
184 };
185 {
186 id="LoadSettings";
187 type=K_PULLDOWN;
188 setup = {
189 options = getKhaosLoadList;
190 multiSelect = false;
191 };
192 text=function()
193 return _ENCH('GuiLoad')
194 end;
195 helptext=function()
196 return _ENCH('HelpLoad')
197 end;
198 callback=function(state) end;
199 feedback=function(state)
200 handleCommand("load " .. state.value, "GUI");
201 end;
202 default={value = 'always'};
203 disabled={value = 'never'};
204 difficulty=1;
205 };
206 {
207 id="embed";
208 type=K_TEXT;
209 text=function()
210 return _ENCH('GuiEmbed')
211 end;
212 helptext=function()
213 return _ENCH('HelpEmbed')
214 end;
215 callback=function(state)
216 genVarSet('embed', state.checked);
217 end;
218 feedback=function(state)
219 if (state.checked) then
220 return (string.format(_ENCH('FrmtActEnable'), _ENCH('ShowEmbed')));
221 else
222 return (string.format(_ENCH('FrmtActDisable'), _ENCH('ShowEmbed')));
223 end
224 end;
225 check=true;
226 default={checked=Enchantrix.Config.GetFilterDefaults('embed')};
227 disabled={checked=false};
228 dependencies={all={checked=true;}};
229 difficulty=1;
230 };
231 {
232 id="terse";
233 type=K_TEXT;
234 text=function()
235 return _ENCH('GuiTerse')
236 end;
237 helptext=function()
238 return _ENCH('HelpTerse')
239 end;
240 callback=function(state)
241 genVarSet('terse', state.checked);
242 end;
243 feedback=function(state)
244 if (state.checked) then
245 return (string.format(_ENCH('FrmtActEnable'), _ENCH('ShowTerse')));
246 else
247 return (string.format(_ENCH('FrmtActDisable'), _ENCH('ShowTerse')));
248 end
249 end;
250 check=true;
251 default={checked=Enchantrix.Config.GetFilterDefaults('terse')};
252 disabled={checked=false};
253 dependencies={all={checked=true;}};
254 difficulty=2;
255 };
256 {
257 id="counts";
258 type=K_TEXT;
259 text=function()
260 return _ENCH('GuiCount')
261 end;
262 helptext=function()
263 return _ENCH('HelpCount')
264 end;
265 callback=function(state)
266 genVarSet('counts', state.checked);
267 end;
268 feedback=function(state)
269 if (state.checked) then
270 return (string.format(_ENCH('FrmtActEnable'), _ENCH('ShowCount')));
271 else
272 return (string.format(_ENCH('FrmtActDisable'), _ENCH('ShowCount')));
273 end
274 end;
275 check=true;
276 default={checked=Enchantrix.Config.GetFilterDefaults('counts')};
277 disabled={checked=false};
278 dependencies={all={checked=true;}};
279 difficulty=3;
280 };
281 {
282 id="EnchantrixValuateHeader";
283 type=K_HEADER;
284 text=function()
285 return _ENCH('GuiValuateHeader')
286 end;
287 helptext=function()
288 return _ENCH('HelpValue')
289 end;
290 difficulty=2;
291 };
292 {
293 id="valuate";
294 type=K_TEXT;
295 text=function()
296 return _ENCH('GuiValuateEnable')
297 end;
298 helptext=function()
299 return _ENCH('HelpValue').."\n".._ENCH('HelpGuessNoauctioneer')
300 end;
301 callback=function(state)
302 genVarSet('valuate', state.checked);
303 end;
304 feedback=function(state)
305 if (state.checked) then
306 return (string.format(_ENCH('FrmtActEnable'), _ENCH('ShowValue')));
307 else
308 return (string.format(_ENCH('FrmtActDisable'), _ENCH('ShowValue')));
309 end
310 end;
311 check=true;
312 default={checked=Enchantrix.Config.GetFilterDefaults('valuate')};
313 disabled={checked=false};
314 dependencies={all={checked=true;}};
315 difficulty=1;
316 };
317 {
318 id="valuate-baseline";
319 type=K_TEXT;
320 text=function()
321 return _ENCH('GuiValuateBaseline')
322 end;
323 helptext=function()
324 return _ENCH('HelpGuessBaseline')
325 end;
326 callback=function(state)
327 genVarSet('valuate-baseline', state.checked);
328 end;
329 feedback=function(state)
330 if (state.checked) then
331 return (string.format(_ENCH('FrmtActEnable'), _ENCH('ShowGuessBaseline')));
332 else
333 return (string.format(_ENCH('FrmtActDisable'), _ENCH('ShowGuessBaseline')));
334 end
335 end;
336 check=true;
337 default={checked=Enchantrix.Config.GetFilterDefaults('valuate-baseline')};
338 disabled={checked=false};
339 dependencies={valuate={checked=true;}, all={checked=true;}};
340 difficulty=2;
341 };
342 {
343 id="EnchantrixOtherHeader";
344 type=K_HEADER;
345 text=function()
346 return _ENCH('GuiOtherHeader')
347 end;
348 helptext=function()
349 return _ENCH('GuiOtherHelp')
350 end;
351 difficulty=1;
352 };
353 {
354 id="EnchantrixClearAll";
355 type=K_BUTTON;
356 setup={
357 buttonText = function()
358 return _ENCH('GuiClearallButton')
359 end;
360 };
361 text=function()
362 return _ENCH('GuiClearall')
363 end;
364 helptext=function()
365 return _ENCH('GuiClearallHelp')
366 end;
367 callback=function()
368 clear(_ENCH('CmdClearAll'));
369 end;
370 feedback=function()
371 return string.format(_ENCH('FrmtActClearall'), _ENCH('GuiClearallNote'));
372 end;
373 dependencies={all={checked=true;}};
374 difficulty=3;
375 };
376 {
377 id="DefaultAll";
378 type=K_BUTTON;
379 setup={
380 buttonText = function()
381 return _ENCH('GuiDefaultAllButton')
382 end;
383 };
384 text=function()
385 return _ENCH('GuiDefaultAll')
386 end;
387 helptext=function()
388 return _ENCH('GuiDefaultAllHelp')
389 end;
390 callback=function()
391 default(_ENCH('CmdClearAll'));
392 end;
393 feedback=function()
394 return _ENCH('FrmtActDefaultAll');
395 end;
396 dependencies={all={checked=true;}};
397 difficulty=1;
398 };
399 {
400 id="printframe";
401 type=K_PULLDOWN;
402 setup = {
403 options = Enchantrix.Config.GetFrameNames;
404 multiSelect = false;
405 };
406 text=function()
407 return _ENCH('GuiPrintin')
408 end;
409 helptext=function()
410 return _ENCH('HelpPrintin')
411 end;
412 callback=function(state)
413 Enchantrix.Config.SetFrame(state.value);
414 end;
415 feedback=function(state)
416 local _, frameName = Enchantrix.Config.GetFrameNames(state.value)
417 return string.format(_ENCH('FrmtPrintin'), frameName);
418 end;
419 default = {
420 value=Enchantrix.Config.GetFrameIndex();
421 };
422 disabled = {
423 value=Enchantrix.Config.GetFrameIndex();
424 };
425 dependencies={all={checked=true;}};
426 difficulty=3;
427 };
428 {
429 id="DefaultOption";
430 type=K_EDITBOX;
431 setup = {
432 callOn = {"tab", "escape", "enter"};
433 };
434 text=function()
435 return _ENCH('GuiDefaultOption')
436 end;
437 helptext=function()
438 return _ENCH('HelpDefault')
439 end;
440 callback = function(state)
441 default(state.value);
442 end;
443 feedback = function (state)
444 if (state.value == _ENCH('CmdClearAll')) then
445 return _ENCH('FrmtActDefaultAll');
446 else
447 return string.format(_ENCH('FrmtActDefault'), state.value);
448 end
449 end;
450 default = {
451 value = "";
452 };
453 disabled = {
454 value = "";
455 };
456 dependencies={all={checked=true;}};
457 difficulty=4;
458 };
459 };
460 };
461  
462 Khaos.registerOptionSet("tooltip",optionSet);
463 Enchantrix.State.Khaos_Registered = true;
464 Khaos.refresh();
465  
466 return true;
467 end
468  
469 function registerAuctioneerOptions()
470 local insertPos
471 for key, value in ipairs(optionSet.options) do
472 if value.id == "valuate" then
473 insertPos = key + 1
474 end
475 end
476  
477 if (optionSet.options[insertPos].id == 'valuate-hsp') then
478 return
479 end
480  
481 local AuctioneerOptions = {
482 {
483 id="valuate-hsp";
484 type=K_TEXT;
485 text=function()
486 return _ENCH('GuiValuateAverages')
487 end;
488 helptext=function()
489 return _ENCH('HelpGuessAuctioneerHsp')
490 end;
491 callback=function(state)
492 genVarSet('valuate-hsp', state.checked);
493 end;
494 feedback=function(state)
495 if (state.checked) then
496 return (string.format(_ENCH('FrmtActEnable'), _ENCH('ShowGuessAuctioneerHsp')));
497 else
498 return (string.format(_ENCH('FrmtActDisable'), _ENCH('ShowGuessAuctioneerHsp')));
499 end
500 end;
501 check=true;
502 default={checked = Enchantrix.Config.GetFilterDefaults('valuate-hsp')};
503 disabled={checked = false};
504 dependencies={valuate={checked=true;}, all={checked=true;}};
505 difficulty=2;
506 };
507 {
508 id="valuate-median";
509 type=K_TEXT;
510 text=function()
511 return _ENCH('GuiValuateMedian')
512 end;
513 helptext=function()
514 return _ENCH('HelpGuessAuctioneerMedian')
515 end;
516 callback=function(state)
517 genVarSet('valuate-median', state.checked);
518 end;
519 feedback=function(state)
520 if (state.checked) then
521 return (string.format(_ENCH('FrmtActEnable'), _ENCH('ShowGuessAuctioneerMed')));
522 else
523 return (string.format(_ENCH('FrmtActDisable'), _ENCH('ShowGuessAuctioneerMed')));
524 end
525 end;
526 check=true;
527 default={checked = Enchantrix.Config.GetFilterDefaults('valuate-median')};
528 disabled={checked = false};
529 dependencies={valuate={checked=true;}, all={checked=true;}};
530 difficulty=2;
531 };
532 };
533  
534 optionSet.options[insertPos - 1].helptext = function() return _ENCH('HelpValue') end;
535  
536 for i, opt in ipairs(AuctioneerOptions) do
537 tinsert(optionSet.options, insertPos + i - 1, opt);
538 end
539  
540 Khaos.unregisterOptionSet("Enchantrix");
541 Khaos.registerOptionSet("tooltip", optionSet);
542 Khaos.refresh();
543 end
544  
545 function auctioneerLoaded()
546 Stubby.UnregisterAddOnHook("Auctioneer", "Enchantrix")
547  
548 -- Make sure we have a usable version of Auctioneer loaded (3.4 or higher)
549 if Auctioneer and Auctioneer.Version then
550 local ver = Enchantrix.Util.Split(Auctioneer.Version, ".")
551 local major = tonumber(ver[1]) or 0
552 local minor = tonumber(ver[2]) or 0
553 if ver[3] == "DEV" then minor = minor + 1 end
554  
555 if major > 3 or (major >= 3 and minor >= 4) then
556 Enchantrix.State.Auctioneer_Loaded = true
557 end
558 end
559  
560 if not Enchantrix.State.Auctioneer_Loaded then
561 -- Old version of Auctioneer
562 if not EnchantConfig.displayedAuctioneerWarning then
563 -- Yell at the user, but only once
564 message(_ENCH('MesgAuctVersion'))
565 EnchantConfig.displayedAuctioneerWarning = true
566 else
567 Enchantrix.Util.ChatPrint(_ENCH('MesgAuctVersion'))
568 end
569 return
570 end
571 EnchantConfig.displayedAuctioneerWarning = nil
572  
573 if Enchantrix.State.Khaos_Registered then
574 registerAuctioneerOptions()
575 end
576 end
577  
578 function setKhaosSetKeyParameter(key, parameter, value)
579 if (Enchantrix.State.Khaos_Registered) then
580 if (Khaos.getSetKey("Enchantrix", key)) then
581 Khaos.setSetKeyParameter("Enchantrix", key, parameter, value)
582 else
583 EnhTooltip.DebugPrint("setKhaosSetKeyParameter(): key " .. key .. " does not exist")
584 end
585 end
586 end
587  
588 function setKhaosSetKeyValue(key, value)
589 if (Enchantrix.State.Khaos_Registered) then
590 local kKey = Khaos.getSetKey("Enchantrix", key)
591  
592 if (not kKey) then
593 EnhTooltip.DebugPrint("setKhaosSetKeyParameter(): key " .. key .. " does not exist")
594 elseif (kKey.checked ~= nil) then
595 -- EnhTooltip.DebugPrint("setKhaosSetKeyParameter(): setting ", value, " for key ", key)
596 Khaos.setSetKeyParameter("Enchantrix", key, "checked", value)
597 elseif (kKey.value ~= nil) then
598 Khaos.setSetKeyParameter("Enchantrix", key, "value", value)
599 else
600 EnhTooltip.DebugPrint("setKhaosSetKeyParameter(): don't know how to update key ", key)
601 end
602 end
603 end
604  
605 -- Cleaner Command Handling Functions (added by MentalPower)
606 function handleCommand(command, source)
607  
608 -- To print or not to print, that is the question...
609 local chatprint = nil;
610 if (source == "GUI") then
611 chatprint = false;
612 else
613 chatprint = true;
614 end;
615  
616 -- Divide the large command into smaller logical sections (Shameless copy from the original function)
617 local i,j, cmd, param = string.find(command, "^([^ ]+) (.+)$")
618 if (not cmd) then cmd = command end
619 if (not cmd) then cmd = "" end
620 if (not param) then param = "" end
621 cmd = Enchantrix.Locale.DelocalizeCommand(cmd)
622  
623 if ((cmd == "") or (cmd == "help")) then
624 -- /enchantrix help
625 chatPrintHelp();
626 return;
627  
628 elseif ((cmd == "on") or (cmd == "off") or (cmd == "toggle")) then
629 -- /enchantrix on|off|toggle
630 onOff(cmd, chatprint);
631  
632 elseif (cmd == 'disable') then
633 -- /enchantrix disable
634 Enchantrix.Util.ChatPrint(_ENCH('MesgDisable'));
635 Stubby.SetConfig("Enchantrix", "LoadType", "never");
636  
637 elseif (cmd == 'load') then
638 -- /enchantrix load always|never
639 if (param == "always") or (param == "never") then
640 Stubby.SetConfig("Enchantrix", "LoadType", param);
641 if (chatprint) then
642 Enchantrix.Util.ChatPrint("Setting Enchantrix to "..param.." load for this toon");
643 setKhaosSetKeyValue("LoadSettings", param)
644 end
645 end
646  
647 elseif (cmd == 'clear') then
648 -- /enchantrix clear
649 clear(param, chatprint);
650  
651 elseif (cmd == 'locale') then
652 -- /enchantrix locale
653 Enchantrix.Config.SetLocale(param, chatprint);
654  
655 elseif (cmd == 'default') then
656 -- /enchantrix default
657 default(param, chatprint);
658  
659 elseif (cmd == 'print-in') then
660 -- /enchantrix print-in
661 Enchantrix.Config.SetFrame(param, chatprint)
662  
663 elseif (cmd == 'bidbroker' or cmd == 'bb') then
664 -- /enchantrix bidbroker
665 doBidBroker(param);
666  
667 elseif (cmd == 'percentless' or cmd == 'pl') then
668 doPercentLess(param);
669  
670 elseif (Enchantrix.Config.GetFilterDefaults(cmd) ~= nil) then
671 genVarSet(cmd, param, chatprint);
672  
673 elseif (chatprint) then
674 Enchantrix.Util.ChatPrint(string.format(_ENCH('FrmtActUnknown'), cmd));
675 end
676 end
677  
678 -- Help ME!! (The Handler) (Another shameless copy from the original function)
679 function chatPrintHelp()
680 Enchantrix.Util.ChatPrint(_ENCH('FrmtUsage'));
681 local onOffToggle = " (".._ENCH('CmdOn').."|".._ENCH('CmdOff').."|".._ENCH('CmdToggle')..")";
682 local lineFormat = " |cffffffff/enchantrix %s "..onOffToggle.."|r |cff2040ff[%s]|r - %s";
683  
684 Enchantrix.Util.ChatPrint(" |cffffffff/enchantrix "..onOffToggle.."|r |cff2040ff["..Enchantrix.Locale.GetLocalizedFilterVal('all').."]|r - " .. _ENCH('HelpOnoff'));
685  
686 Enchantrix.Util.ChatPrint(" |cffffffff/enchantrix ".._ENCH('CmdDisable').."|r - " .. _ENCH('HelpDisable'));
687  
688 Enchantrix.Util.ChatPrint(string.format(lineFormat, _ENCH('CmdBarker'), Enchantrix.Locale.GetLocalizedFilterVal('barker'), _ENCH('HelpBarker')));
689  
690 Enchantrix.Util.ChatPrint(string.format(lineFormat, _ENCH('ShowCount'), Enchantrix.Locale.GetLocalizedFilterVal('counts'), _ENCH('HelpCount')));
691 Enchantrix.Util.ChatPrint(string.format(lineFormat, _ENCH('ShowTerse'), Enchantrix.Locale.GetLocalizedFilterVal('terse'), _ENCH('HelpTerse')));
692 Enchantrix.Util.ChatPrint(string.format(lineFormat, _ENCH('ShowEmbed'), Enchantrix.Locale.GetLocalizedFilterVal('embed'), _ENCH('HelpEmbed')));
693 Enchantrix.Util.ChatPrint(string.format(lineFormat, _ENCH('ShowValue'), Enchantrix.Locale.GetLocalizedFilterVal('valuate'), _ENCH('HelpValue')));
694 if Enchantrix.State.Auctioneer_Loaded then
695 Enchantrix.Util.ChatPrint(string.format(lineFormat, _ENCH('ShowGuessAuctioneerHsp'), Enchantrix.Locale.GetLocalizedFilterVal('valuate-hsp'), _ENCH('HelpGuessAuctioneerHsp')));
696 Enchantrix.Util.ChatPrint(string.format(lineFormat, _ENCH('ShowGuessAuctioneerMed'), Enchantrix.Locale.GetLocalizedFilterVal('valuate-median'), _ENCH('HelpGuessAuctioneerMedian')));
697 else
698 Enchantrix.Util.ChatPrint(_ENCH('HelpGuessNoauctioneer'));
699 end
700 Enchantrix.Util.ChatPrint(string.format(lineFormat, _ENCH('ShowGuessBaseline'), Enchantrix.Locale.GetLocalizedFilterVal('valuate-baseline'), _ENCH('HelpGuessBaseline')));
701  
702 lineFormat = " |cffffffff/enchantrix %s %s|r - %s";
703 Enchantrix.Util.ChatPrint(string.format(lineFormat, _ENCH('CmdLocale'), _ENCH('OptLocale'), _ENCH('HelpLocale')));
704 Enchantrix.Util.ChatPrint(string.format(lineFormat, _ENCH('CmdClear'), _ENCH('OptClear'), _ENCH('HelpClear')));
705  
706 Enchantrix.Util.ChatPrint(string.format(lineFormat, _ENCH('CmdFindBidauct'), _ENCH('OptFindBidauct'), _ENCH('HelpFindBidauct')));
707 Enchantrix.Util.ChatPrint(string.format(lineFormat, _ENCH('CmdFindBuyauct'), _ENCH('OptFindBuyauct'), _ENCH('HelpFindBuyauct')));
708 Enchantrix.Util.ChatPrint(string.format(lineFormat, _ENCH('CmdDefault'), _ENCH('OptDefault'), _ENCH('HelpDefault')));
709 Enchantrix.Util.ChatPrint(string.format(lineFormat, _ENCH('CmdPrintin'), _ENCH('OptPrintin'), _ENCH('HelpPrintin')));
710 end
711 --[[
712 The onOff(state, chatprint) function handles the state of the Enchantrix AddOn (whether it is currently on or off)
713 If "on" or "off" is specified in the "state" variable then Enchantrix's state is changed to that value,
714 If "toggle" is specified then it will toggle Enchantrix's state (if currently on then it will be turned off and vice-versa)
715  
716 If a boolean (or nil) value is passed as the first argument the conversion is as follows:
717 "true" is the same as "on"
718 "false" is the same as "off"
719 "nil" is the same as "toggle"
720  
721 If chatprint is "true" then the state will also be printed to the user.
722 ]]
723 function onOff(state, chatprint)
724 if (type(state) == "string") then
725 state = Enchantrix.Locale.DelocalizeFilterVal(state)
726  
727 elseif (state == true) then
728 state = 'on'
729  
730 elseif (state == false) then
731 state = 'off'
732  
733 elseif (state == nil) then
734 state = 'toggle'
735 end
736  
737 if (state == 'on') or (state == 'off') then
738 Enchantrix.Config.SetFilter('all', state);
739 elseif (state == "toggle") then
740 Enchantrix.Config.SetFilter('all', not Enchantrix.Config.GetFilter('all'))
741 end
742  
743 -- Print the change and alert the GUI if the command came from slash commands. Do nothing if they came from the GUI.
744 if (chatprint) then
745 state = Enchantrix.Config.GetFilter('all')
746 setKhaosSetKeyParameter('all', "checked", state);
747  
748 if (state) then
749 Enchantrix.Util.ChatPrint(_ENCH('StatOn'));
750  
751 else
752 Enchantrix.Util.ChatPrint(_ENCH('StatOff'));
753 end
754 end
755  
756 return state;
757 end
758  
759 -- The following functions are almost verbatim copies of the original functions but modified in order to make them compatible with direct GUI access.
760 function clear(param, chatprint)
761 if (param == _ENCH('CmdClearAll')) or (param == "all") then
762 EnchantedLocal = {}
763 if (chatprint) then
764 Enchantrix.Util.ChatPrint(_ENCH('FrmtActClearall'));
765 end
766 else
767 for link in string.gfind(param, "|c%x+|Hitem:%d+:%d+:%d+:%d+|h%b[]|h|r") do
768 local sig = Enchantrix.Util.GetSigFromLink(link)
769 EnchantedLocal[sig] = nil
770  
771 if (chatprint) then
772 Enchantrix.Util.ChatPrint(string.format(_ENCH('FrmtActClearOk'), link))
773 end
774 end
775 end
776 end
777  
778 -- This function was added by MentalPower to implement the /enx default command
779 function default(param, chatprint)
780 local paramLocalized
781  
782 if (param == nil) or (param == "") then
783 return
784 elseif (param == _ENCH('CmdClearAll')) or (param == "all") then
785 param = "all"
786 EnchantConfig.filters = {}
787 else
788 paramLocalized = param
789 param = Enchantrix.Locale.DelocalizeCommand(param)
790 Enchantrix.Config.SetFilter(param, nil)
791 end
792  
793 if (chatprint) then
794 if (param == "all") then
795 Enchantrix.Util.ChatPrint(_ENCH('FrmtActDefaultAll'));
796  
797 for k,v in pairs(EnchantConfig.filters) do
798 setKhaosSetKeyValue(k, Enchantrix.Config.GetFilter(k));
799 end
800  
801 else
802 Enchantrix.Util.ChatPrint(string.format(_ENCH('FrmtActDefault'), paramLocalized));
803 setKhaosSetKeyValue(param, Enchantrix.Config.GetFilter(param));
804 end
805 end
806 end
807  
808 function genVarSet(variable, param, chatprint)
809  
810 param = Enchantrix.Locale.DelocalizeFilterVal(param);
811  
812 if (param == 'on' or param == 'off' or param == true or param == false) then
813 Enchantrix.Config.SetFilter(variable, param);
814  
815 elseif (param == 'toggle' or param == nil or param == "") then
816 Enchantrix.Config.SetFilter(variable, not Enchantrix.Config.GetFilter(variable))
817 end
818  
819 if (chatprint) then
820 if (Enchantrix.Config.GetFilter(variable)) then
821 Enchantrix.Util.ChatPrint(string.format(_ENCH('FrmtActEnable'), Enchantrix.Locale.LocalizeCommand(variable)));
822 setKhaosSetKeyParameter(variable, "checked", true);
823  
824 else
825 Enchantrix.Util.ChatPrint(string.format(_ENCH('FrmtActDisable'), Enchantrix.Locale.LocalizeCommand(variable)));
826 setKhaosSetKeyParameter(variable, "checked", false);
827 end
828 end
829 end
830  
831 ---------------------------------------
832 -- Auctioneer dependant commands --
833 ---------------------------------------
834  
835 function percentLessFilter(percentLess, signature)
836 local filterAuction = true;
837 local id,rprop,enchant, name, count,min,buyout,uniq = Auctioneer.Core.GetItemSignature(signature);
838 local disenchantsTo = getAuctionItemDisenchants(signature, true);
839 if not disenchantsTo.totals then return filterAuction; end
840  
841 local hspValue = disenchantsTo.totals.hspValue or 0;
842 local medValue = disenchantsTo.totals.medValue or 0;
843 local mktValue = disenchantsTo.totals.mktValue or 0;
844 local confidence = disenchantsTo.totals.conf or 0;
845  
846 local myValue = confidence * (hspValue + medValue + mktValue) / 3;
847 local margin = Auctioneer.Statistic.PercentLessThan(myValue, buyout/count);
848 local profit = (myValue * count) - buyout;
849  
850 local results = {
851 buyout = buyout,
852 count = count,
853 value = myValue,
854 margin = margin,
855 profit = profit,
856 conf = confidence
857 };
858 if (buyout > 0) and (margin >= tonumber(percentLess)) and (profit >= MIN_PROFIT_MARGIN) then
859 filterAuction = false;
860 profitMargins[signature] = results;
861 end
862  
863 return filterAuction;
864 end
865  
866 function bidBrokerFilter(minProfit, signature)
867 local filterAuction = true;
868 local id,rprop,enchant, name, count,min,buyout,uniq = Auctioneer.Core.GetItemSignature(signature);
869 local currentBid = Auctioneer.Statistic.GetCurrentBid(signature);
870 local disenchantsTo = getAuctionItemDisenchants(signature, true);
871 if not disenchantsTo.totals then return filterAuction; end
872  
873 local hspValue = disenchantsTo.totals.hspValue or 0;
874 local medValue = disenchantsTo.totals.medValue or 0;
875 local mktValue = disenchantsTo.totals.mktValue or 0;
876 local confidence = disenchantsTo.totals.conf or 0;
877  
878 local myValue = confidence * (hspValue + medValue + mktValue) / 3;
879 local margin = Auctioneer.Statistic.PercentLessThan(myValue, currentBid/count);
880 local profit = (myValue * count) - currentBid;
881 local profitPricePercent = math.floor((profit / currentBid) * 100);
882  
883 local results = {
884 buyout = buyout,
885 count = count,
886 value = myValue,
887 margin = margin,
888 profit = profit,
889 conf = confidence
890 };
891 if (currentBid <= MAX_BUYOUT_PRICE) and (profit >= tonumber(minProfit)) and (profit >= MIN_PROFIT_MARGIN) and (profitPricePercent >= MIN_PROFIT_PRICE_PERCENT) then
892 filterAuction = false;
893 profitMargins[signature] = results;
894 end
895 return filterAuction;
896 end
897  
898 function profitComparisonSort(a, b)
899 if (not a) or (not b) then return false; end
900 local aSig = a.signature;
901 local bSig = b.signature;
902 if (not aSig) or (not bSig) then return false; end
903 local aEpm = profitMargins[aSig];
904 local bEpm = profitMargins[bSig];
905 if (not aEpm) and (not bEpm) then return false; end
906 local aProfit = aEpm.profit or 0;
907 local bProfit = bEpm.profit or 0;
908 local aMargin = aEpm.margin or 0;
909 local bMargin = bEpm.margin or 0;
910 local aValue = aEpm.value or 0;
911 local bValue = bEpm.value or 0;
912 if (aProfit > bProfit) then return true; end
913 if (aProfit < bProfit) then return false; end
914 if (aMargin > bMargin) then return true; end
915 if (aMargin < bMargin) then return false; end
916 if (aValue > bValue) then return true; end
917 if (aValue < bValue) then return false; end
918 return false;
919 end
920  
921 function bidBrokerSort(a, b)
922 if (not a) or (not b) then return false; end
923 local aTime = a.timeLeft or 0;
924 local bTime = b.timeLeft or 0;
925 if (aTime > bTime) then return true; end
926 if (aTime < bTime) then return false; end
927 return profitComparisonSort(a, b);
928 end
929  
930 function doPercentLess(percentLess)
931 if not Auctioneer then
932 Enchantrix.Util.ChatPrint("You do not have Auctioneer installed. Auctioneer must be installed to do an enchanting percentless scan");
933 return;
934 elseif not (Auctioneer.Filter or Auctioneer.Filter.QuerySnapshot) then
935 Enchantrix.Util.ChatPrint("You do not have the correct version of Auctioneer installed, this feature requires Auctioneer v3.3.0.0675 or later");
936 return;
937 end
938  
939 if not percentLess or percentLess == "" then percentLess = MIN_PERCENT_LESS_THAN_HSP end
940 local output = string.format(_ENCH('FrmtPctlessHeader'), percentLess);
941 Enchantrix.Util.ChatPrint(output);
942  
943 Enchantrix.Storage.Price_Cache = {t=time()};
944 profitMargins = {};
945 local targetAuctions = Auctioneer.Filter.QuerySnapshot(percentLessFilter, percentLess);
946  
947 -- sort by profit based on median
948 table.sort(targetAuctions, profitComparisonSort);
949  
950 -- output the list of auctions
951 for _,a in targetAuctions do
952 if (a.signature and profitMargins[a.signature]) then
953 local quality = EnhTooltip.QualityFromLink(a.itemLink);
954 if (quality and quality >= 2) then
955 local id,rprop,enchant, name, count,_,buyout,_ = Auctioneer.Core.GetItemSignature(a.signature);
956 local value = profitMargins[a.signature].value;
957 local margin = profitMargins[a.signature].margin;
958 local profit = profitMargins[a.signature].profit;
959 local output = string.format(_ENCH('FrmtPctlessLine'), Auctioneer.Util.ColorTextWhite(count.."x")..a.itemLink, EnhTooltip.GetTextGSC(value * count), EnhTooltip.GetTextGSC(buyout), EnhTooltip.GetTextGSC(profit * count), Auctioneer.Util.ColorTextWhite(margin.."%"));
960 Enchantrix.Util.ChatPrint(output);
961 end
962 end
963 end
964  
965 Enchantrix.Util.ChatPrint(_ENCH('FrmtPctlessDone'));
966 end
967  
968 function doBidBroker(minProfit)
969 if not Auctioneer then
970 Enchantrix.Util.ChatPrint("You do not have Auctioneer installed. Auctioneer must be installed to do an enchanting percentless scan");
971 return;
972 elseif not (Auctioneer.Filter and Auctioneer.Filter.QuerySnapshot) then
973 Enchantrix.Util.ChatPrint("You do not have the correct version of Auctioneer installed, this feature requires Auctioneer v3.3.0.0675 or later");
974 return;
975 end
976  
977 if not minProfit or minProfit == "" then minProfit = MIN_PROFIT_MARGIN; else minProfit = tonumber(minProfit) * 100; end
978 local output = string.format(_ENCH('FrmtBidbrokerHeader'), EnhTooltip.GetTextGSC(minProfit));
979 Enchantrix.Util.ChatPrint(output);
980  
981 Enchantrix.Storage.Price_Cache = {t=time()};
982 profitMargins = {};
983 local targetAuctions = Auctioneer.Filter.QuerySnapshot(bidBrokerFilter, minProfit);
984  
985 -- sort by profit based on median
986 table.sort(targetAuctions, bidBrokerSort);
987  
988 -- output the list of auctions
989 for _,a in targetAuctions do
990 if (a.signature and profitMargins[a.signature]) then
991 local quality = EnhTooltip.QualityFromLink(a.itemLink);
992 if (quality and quality >= 2) then
993 local id,rprop,enchant, name, count, min, buyout,_ = Auctioneer.Core.GetItemSignature(a.signature);
994 local currentBid = Auctioneer.Statistic.GetCurrentBid(a.signature);
995 local value = profitMargins[a.signature].value;
996 local margin = profitMargins[a.signature].margin;
997 local profit = profitMargins[a.signature].profit;
998 local bidText = _ENCH('FrmtBidbrokerCurbid');
999 if (currentBid == min) then
1000 bidText = _ENCH('FrmtBidbrokerMinbid');
1001 end
1002 local output = string.format(_ENCH('FrmtBidbrokerLine'), Auctioneer.Util.ColorTextWhite(count.."x")..a.itemLink, EnhTooltip.GetTextGSC(value * count), bidText, EnhTooltip.GetTextGSC(currentBid), EnhTooltip.GetTextGSC(profit * count), Auctioneer.Util.ColorTextWhite(margin.."%"), Auctioneer.Util.ColorTextWhite(Auctioneer.Util.GetTimeLeftString(a.timeLeft)));
1003 Enchantrix.Util.ChatPrint(output);
1004 end
1005 end
1006 end
1007  
1008 Enchantrix.Util.ChatPrint(_ENCH('FrmtBidbrokerDone'));
1009 end
1010  
1011 function getAuctionItemDisenchants(auctionSignature, useCache)
1012 local id,rprop,enchant, name, count,min,buyout,uniq = Auctioneer.Core.GetItemSignature(auctionSignature);
1013 local sig = string.format("%d:%d:%d", id, enchant, rprop);
1014 return Enchantrix.Storage.GetItemDisenchants(sig, name, useCache);
1015 end
1016  
1017 Enchantrix.Command = {
1018 Revision = "$Revision: 944 $",
1019  
1020 AddonLoaded = addonLoaded,
1021 AuctioneerLoaded = auctioneerLoaded,
1022  
1023 HandleCommand = handleCommand,
1024  
1025 Register = register,
1026 SetKhaosSetKeyValue = setKhaosSetKeyValue,
1027 SetKhaosSetKeyParameter = setKhaosSetKeyParameter,
1028 SetKhaosSetKeyValue = setKhaosSetKeyValue,
1029 }