vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2  
3 Enchantrix v3.6.1 (Platypus)
4 $Id: EnchantrixBarker.lua 933 2006-07-08 03:10:18Z mentalpower $
5  
6 By Norganna
7 http://enchantrix.org/
8  
9 This is an addon for World of Warcraft that add a list of what an item
10 disenchants into to the items that you mouse-over in the game.
11  
12 License:
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License
15 as published by the Free Software Foundation; either version 2
16 of the License, or (at your option) any later version.
17  
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22  
23 You should have received a copy of the GNU General Public License
24 along with this program(see GLP.txt); if not, write to the Free Software
25 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  
27 ]]
28  
29 local priorityList = {};
30  
31 local categories = { --TODO: Localize
32 Bracer = {search = "Bracer", print = "Bracer" },
33 Gloves = {search = "Gloves", print = "Gloves" },
34 Boots = {search = "Boots", print = "Boots" },
35 Shield = {search = "Shield", print = "Shield" },
36 Chest = {search = "Chest", print = "Chest" },
37 Cloak = {search = "Cloak", print = "Cloak" },
38 TwoHanded = {search = "2H", print = "2H Weapon"},
39 AnyWeapon = {search = "Enchant Weapon", print = "Any Weapon" }
40 };
41  
42  
43 local print_order = { 'Bracer', 'Gloves', 'Boots', 'Chest', 'Cloak', 'Shield', 'TwoHanded', 'AnyWeapon' }; --TODO: Localize
44  
45 local attributes = { --TODO: Localize
46 'intellect',
47 'stamina',
48 'spirit',
49 'strength',
50 'agility',
51 'fire resistance',
52 'resistance to fire',
53 'resistance',
54 'all stats',
55 'mana',
56 'health',
57 'additional armor',
58 'additional points of armor',
59 'increase armor',
60 'increase its armor',
61 'absorption',
62 'damage to beasts',
63 'points? of damage',
64 '\+[0-9]+ damage',
65 'defense'
66 };
67  
68 local short_attributes = { --TODO: Localize
69 'INT',
70 'STA',
71 'SPI',
72 'STR',
73 'AGI',
74 'fire res',
75 'fire res',
76 'all res',
77 'all stats',
78 'mana',
79 'health',
80 'armour',
81 'armour',
82 'armour',
83 'armour',
84 'DMG absorb',
85 'Beastslayer',
86 'DMG',
87 'DMG',
88 'DEF'
89 };
90  
91 -- UI code
92  
93  
94 function EnchantrixBarker_OnEvent()
95 --Enchantrix.Util.ChatPrint("GotUIEvent...");
96  
97 -- Returns "Enchanting" for enchantwindow and nil for Beast Training
98 local craftName, rank, maxRank = GetCraftDisplaySkillLine()
99  
100 if craftName then
101 --Enchantrix.Util.ChatPrint("Barker config is "..tostring(Enchantrix.Config.GetFilter('barker')) );
102 if( event == "CRAFT_SHOW" ) then
103 if( Enchantrix.Config.GetFilter('barker') and GetLocale() == "enUS" ) then
104 Enchantrix_BarkerButton:Show();
105 Enchantrix_BarkerButton.tooltipText = 'Posts a sales message to the Trade channel, if available.'; --TODO: Localize
106  
107 Enchantrix_BarkerOptionsButton:Show();
108 Enchantrix_BarkerButton.tooltipText = 'Opens the barker options window.'; --TODO: Localize
109 else
110 Enchantrix_BarkerButton:Hide();
111 Enchantrix_BarkerOptionsButton:Hide();
112 Enchantrix_BarkerOptions_Frame:Hide();
113 end
114 elseif( event == "CRAFT_CLOSE" )then
115 Enchantrix_BarkerButton:Hide();
116 Enchantrix_BarkerOptionsButton:Hide();
117 Enchantrix_BarkerOptions_Frame:Hide();
118 end
119 end
120 end
121  
122 function Enchantrix_BarkerOptions_OnShow()
123 Enchantrix_BarkerOptions_ShowFrame(1);
124 end
125  
126 function Enchantrix_BarkerOnClick()
127 --EnhTooltip.DebugPrint(Enchantrix_CreateBarker());
128 local barker = Enchantrix_CreateBarker();
129 local id = GetChannelName("Trade - City") --TODO: Localize
130 EnhTooltip.DebugPrint("EnxBarker: Attempting to send barker", barker, "Trade Channel ID", id)
131  
132 if (id and (not(id == 0))) then
133 if (barker) then
134 SendChatMessage(barker,"CHANNEL", GetDefaultLanguage("player"), id);
135 end
136 else
137 Enchantrix.Util.ChatPrint("Enchantrix: You aren't in a trade zone."); --TODO: Localize
138 end
139 end
140  
141 function Enchantrix.Barker.AddonLoaded()
142 Enchantrix.Util.ChatPrint("Barker Loaded...");
143 if( not EnchantConfig.barker ) then
144 EnchantConfig.barker = {};
145 end
146 --EnchantConfig.barker = EnchantConfig.barker;
147 if( not EnchantConfig.barker.profit_margin ) then
148 EnchantConfig.barker.profit_margin = 10;
149 end
150 if( not EnchantConfig.barker.randomise ) then
151 EnchantConfig.barker.randomise = 10;
152 end
153 if( not EnchantConfig.barker.lowest_price ) then
154 EnchantConfig.barker.lowest_price = 100;
155 end
156 end
157  
158 local function relevel(frame)
159 local myLevel = frame:GetFrameLevel() + 1
160 local children = { frame:GetChildren() }
161 for _,child in pairs(children) do
162 child:SetFrameLevel(myLevel)
163 relevel(child)
164 end
165 end
166  
167 local function craftUILoaded()
168 Stubby.UnregisterAddOnHook("Blizzard_CraftUI", "Enchantrix")
169  
170 Enchantrix_BarkerButton:SetParent(CraftFrame);
171 Enchantrix_BarkerButton:SetPoint("TOPRIGHT", CraftFrame, "TOPRIGHT", -40, -60 );
172  
173 Enchantrix_BarkerOptionsButton:SetParent(CraftFrame);
174 Enchantrix_BarkerOptionsButton:SetPoint("BOTTOMRIGHT", Enchantrix_BarkerButton, "BOTTOMLEFT");
175  
176 Enchantrix_BarkerOptions_Frame:SetParent(CraftFrame);
177 Enchantrix_BarkerOptions_Frame:SetPoint("TOPLEFT", CraftFrame, "TOPRIGHT");
178 relevel(Enchantrix_BarkerOptions_Frame)
179 end
180  
181 function EnchantrixBarker_OnLoad()
182 Stubby.RegisterAddOnHook("Blizzard_CraftUI", "Enchantrix", craftUILoaded)
183 end
184  
185  
186  
187 local config_defaults = {
188 lowest_price = 5000,
189 sweet_price = 50000,
190 high_price = 500000,
191 profit_margin = 10,
192 highest_profit = 100000,
193 randomise = 10,
194 AnyWeapon = 100,
195 TwoHanded = 90,
196 Bracer = 70,
197 Gloves = 70,
198 Boots = 70,
199 Chest = 70,
200 Cloak = 70,
201 Shield = 70,
202 INT = 90,
203 STA = 70,
204 AGI = 70,
205 STR = 70,
206 SPI = 45,
207 ["all stats"] = 75,
208 ["all res"] = 55,
209 armour = 65,
210 ["fire res"] = 85,
211 mana = 35,
212 health = 40,
213 DMG = 90,
214 DEF = 60,
215 other = 70,
216 factor_price = 20,
217 factor_item = 40,
218 factor_stat = 40
219 };
220  
221 function Enchantrix_BarkerGetConfig( key )
222 if( not EnchantConfig.barker ) then
223 EnchantConfig.barker = {};
224 end
225 local config = EnchantConfig.barker;
226  
227 if( not config[key] ) then
228 config[key] = config_defaults[key];
229 end
230 --Enchantrix.Util.ChatPrint("Getting config: "..key.." - "..config[key]);
231  
232 return config[key];
233 end
234  
235 function Enchantrix_BarkerSetConfig( key, value )
236 --Enchantrix.Util.ChatPrint("Setting config: "..key.." - "..value);
237 if( not EnchantConfig.barker ) then
238 EnchantConfig.barker = {};
239 end
240 local config = EnchantConfig.barker;
241  
242 config[key] = value;
243 end
244  
245 function Enchantrix_BarkerOptions_TestButton_OnClick()
246 --EnhTooltip.DebugPrint(Enchantrix_CreateBarker());
247 local barker = Enchantrix_CreateBarker();
248 local id = GetChannelName("Trade - City") --TODO: Localize
249 EnhTooltip.DebugPrint("EnxBarker: Attempting to send test barker", barker, "Trade Channel ID", id)
250  
251 if (id and (not(id == 0))) then
252 if (barker) then
253 Enchantrix.Util.ChatPrint(barker);
254 end
255 else
256 Enchantrix.Util.ChatPrint("Enchantrix: You aren't in a trade zone."); --TODO: Localize
257 end
258 end
259  
260  
261 function Enchantrix_BarkerOptions_Factors_Slider_GetValue(id)
262 if (not id) then
263 id = this:GetID();
264 end
265 return Enchantrix_BarkerGetConfig(Enchantrix_BarkerOptions_TabFrames[Enchantrix_BarkerOptions_ActiveTab].options[id].key);
266 end
267  
268 function Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged(id)
269 if (not id) then
270 id = this:GetID();
271 end
272 Enchantrix_BarkerSetConfig(Enchantrix_BarkerOptions_TabFrames[Enchantrix_BarkerOptions_ActiveTab].options[id].key, this:GetValue());
273 end
274  
275 Enchantrix_BarkerOptions_ActiveTab = -1;
276  
277 Enchantrix_BarkerOptions_TabFrames = { --TODO: Localize
278 {
279 title = 'Profit and Price Priorities',
280 options = {
281 {
282 name = 'Profit Margin',
283 tooltip = 'The percentage profit to add to the base mats cost.',
284 units = 'percentage',
285 min = 0,
286 max = 100,
287 step = 1,
288 key = 'profit_margin',
289 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
290 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
291 },
292 {
293 name = 'Highest Profit',
294 tooltip = 'The highest total cash profit to make on an enchant.',
295 units = 'money',
296 min = 0,
297 max = 250000,
298 step = 500,
299 key = 'highest_profit',
300 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
301 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
302 },
303 {
304 name = 'Lowest Price',
305 tooltip = 'The lowest cash price to quote for an enchant.',
306 units = 'money',
307 min = 0,
308 max = 50000,
309 step = 500,
310 key = 'lowest_price',
311 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
312 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
313 },
314 {
315 name = 'Overall Price Priority',
316 tooltip = 'This sets how important pricing is to the overall priority for advertising.',
317 units = 'percentage',
318 min = 0,
319 max = 100,
320 step = 1,
321 key = 'factor_price',
322 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
323 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
324 },
325 {
326 name = 'PriceFactor SweetSpot',
327 tooltip = 'This is used to prioritise enchants near this price for advertising.',
328 units = 'money',
329 min = 0,
330 max = 500000,
331 step = 5000,
332 key = 'sweet_price',
333 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
334 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
335 },
336 {
337 name = 'PriceFactor Highest',
338 tooltip = 'Enchants receive a score of zero for price priority at or above this value.',
339 units = 'money',
340 min = 0,
341 max = 1000000,
342 step = 50000,
343 key = 'high_price',
344 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
345 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
346 },
347 {
348 name = 'Random Factor',
349 tooltip = 'The amount of randomness in the enchants chosen for the trade shout.',
350 units = 'percentage',
351 min = 0,
352 max = 100,
353 step = 1,
354 key = 'randomise',
355 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
356 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
357 }
358 }
359 },
360 {
361 title = 'Item Priorities',
362 options = {
363 {
364 name = 'Overall Items Priority',
365 tooltip = 'This sets how important the item is to the overall priority for advertising.',
366 units = 'percentage',
367 min = 0,
368 max = 100,
369 step = 1,
370 key = 'factor_item',
371 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
372 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
373 },
374 {
375 name = '2H Weapon',
376 tooltip = 'The priority score for 2H weapon enchants.',
377 units = 'percentage',
378 min = 0,
379 max = 100,
380 step = 1,
381 key = 'TwoHanded',
382 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
383 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
384 },
385 {
386 name = 'Any Weapon',
387 tooltip = 'The priority score for enchants to any weapon.',
388 units = 'percentage',
389 min = 0,
390 max = 100,
391 step = 1,
392 key = 'AnyWeapon',
393 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
394 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
395 },
396 {
397 name = 'Bracer',
398 tooltip = 'The priority score for bracer enchants.',
399 units = 'percentage',
400 min = 0,
401 max = 100,
402 step = 1,
403 key = 'Bracer',
404 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
405 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
406 },
407 {
408 name = 'Gloves',
409 tooltip = 'The priority score for glove enchants.',
410 units = 'percentage',
411 min = 0,
412 max = 100,
413 step = 1,
414 key = 'Gloves',
415 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
416 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
417 },
418 {
419 name = 'Boots',
420 tooltip = 'The priority score for boots enchants.',
421 units = 'percentage',
422 min = 0,
423 max = 100,
424 step = 1,
425 key = 'Boots',
426 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
427 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
428 },
429 {
430 name = 'Chest',
431 tooltip = 'The priority score for chest enchants.',
432 units = 'percentage',
433 min = 0,
434 max = 100,
435 step = 1,
436 key = 'Chest',
437 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
438 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
439 },
440 {
441 name = 'Cloak',
442 tooltip = 'The priority score for cloak enchants.',
443 units = 'percentage',
444 min = 0,
445 max = 100,
446 step = 1,
447 key = 'Cloak',
448 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
449 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
450 },
451 {
452 name = 'Shield',
453 tooltip = 'The priority score for shield enchants.',
454 units = 'percentage',
455 min = 0,
456 max = 100,
457 step = 1,
458 key = 'Shield',
459 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
460 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
461 }
462 }
463 },
464 {
465 title = 'Stats 1',
466 options = {
467 {
468 name = 'Overall Stats Priority',
469 tooltip = 'This sets how important the stat is to the overall priority for advertising.',
470 units = 'percentage',
471 min = 0,
472 max = 100,
473 step = 1,
474 key = 'factor_stat',
475 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
476 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
477 },
478 {
479 name = 'Intellect',
480 tooltip = 'The priority score for Intellect enchants.',
481 units = 'percentage',
482 min = 0,
483 max = 100,
484 step = 1,
485 key = 'INT',
486 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
487 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
488 },
489 {
490 name = 'Strength',
491 tooltip = 'The priority score for Strength enchants.',
492 units = 'percentage',
493 min = 0,
494 max = 100,
495 step = 1,
496 key = 'STR',
497 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
498 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
499 },
500 {
501 name = 'Agility',
502 tooltip = 'The priority score for Agility enchants.',
503 units = 'percentage',
504 min = 0,
505 max = 100,
506 step = 1,
507 key = 'AGI',
508 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
509 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
510 },
511 {
512 name = 'Stamina',
513 tooltip = 'The priority score for Stamina enchants.',
514 units = 'percentage',
515 min = 0,
516 max = 100,
517 step = 1,
518 key = 'STA',
519 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
520 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
521 },
522 {
523 name = 'Spirit',
524 tooltip = 'The priority score for Spirit enchants.',
525 units = 'percentage',
526 min = 0,
527 max = 100,
528 step = 1,
529 key = 'SPI',
530 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
531 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
532 },
533 {
534 name = 'All Stats',
535 tooltip = 'The priority score for enchants that increase all stats.',
536 units = 'percentage',
537 min = 0,
538 max = 100,
539 step = 1,
540 key = 'all stats',
541 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
542 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
543 }
544 }
545 },
546 {
547 title = 'Stats 2',
548 options = {
549 {
550 name = 'All Resistances',
551 tooltip = 'The priority score for enchants that boost all resistances.',
552 units = 'percentage',
553 min = 0,
554 max = 100,
555 step = 1,
556 key = 'all res',
557 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
558 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
559 },
560 {
561 name = 'Armour',
562 tooltip = 'The priority score for Armour enchants.',
563 units = 'percentage',
564 min = 0,
565 max = 100,
566 step = 1,
567 key = 'armour',
568 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
569 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
570 },
571 {
572 name = 'Fire Resistance',
573 tooltip = 'The priority score for Fire Resistance enchants.',
574 units = 'percentage',
575 min = 0,
576 max = 100,
577 step = 1,
578 key = 'INT',
579 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
580 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
581 },
582 {
583 name = 'Mana',
584 tooltip = 'The priority score for Mana enchants.',
585 units = 'percentage',
586 min = 0,
587 max = 100,
588 step = 1,
589 key = 'mana',
590 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
591 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
592 },
593 {
594 name = 'Health',
595 tooltip = 'The priority score for Health enchants.',
596 units = 'percentage',
597 min = 0,
598 max = 100,
599 step = 1,
600 key = 'health',
601 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
602 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
603 },
604 {
605 name = 'Damage',
606 tooltip = 'The priority score for Damage enchants.',
607 units = 'percentage',
608 min = 0,
609 max = 100,
610 step = 1,
611 key = 'DMG',
612 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
613 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
614 },
615 {
616 name = 'Defense',
617 tooltip = 'The priority score for Defense enchants.',
618 units = 'percentage',
619 min = 0,
620 max = 100,
621 step = 1,
622 key = 'DEF',
623 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
624 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
625 },
626 {
627 name = 'Other',
628 tooltip = 'The priority score for enchants such as skinning, mining, riding etc.',
629 units = 'percentage',
630 min = 0,
631 max = 100,
632 step = 1,
633 key = 'other',
634 getvalue = Enchantrix_BarkerOptions_Factors_Slider_GetValue,
635 valuechanged = Enchantrix_BarkerOptions_Factors_Slider_OnValueChanged
636 },
637 }
638 }
639 };
640  
641  
642  
643 function EnchantrixBarker_OptionsSlider_OnValueChanged()
644 if Enchantrix_BarkerOptions_ActiveTab ~= -1 then
645 --Enchantrix.Util.ChatPrint( "Tab - Slider changed: "..Enchantrix_BarkerOptions_ActiveTab..' - '..this:GetID() );
646 Enchantrix_BarkerOptions_TabFrames[Enchantrix_BarkerOptions_ActiveTab].options[this:GetID()].valuechanged();
647 value = this:GetValue();
648 --Enchantrix_BarkerOptions_TabFrames[Enchantrix_BarkerOptions_ActiveTab].options[this:GetID()].getvalue();
649  
650 valuestr = EnchantrixBarker_OptionsSlider_GetTextFromValue( value, Enchantrix_BarkerOptions_TabFrames[Enchantrix_BarkerOptions_ActiveTab].options[this:GetID()].units );
651  
652 getglobal(this:GetName().."Text"):SetText(Enchantrix_BarkerOptions_TabFrames[Enchantrix_BarkerOptions_ActiveTab].options[this:GetID()].name.." - "..valuestr );
653 end
654 end
655  
656 function EnchantrixBarker_OptionsSlider_GetTextFromValue( value, units )
657  
658 local valuestr = ''
659  
660 if units == 'percentage' then
661 valuestr = value..'%'
662 elseif units == 'money' then
663 local p_gold,p_silver,p_copper = EnhTooltip.GetGSC(value);
664  
665 if( p_gold > 0 ) then
666 valuestr = p_gold.."g";
667 end
668 if( p_silver > 0 ) then
669 valuestr = valuestr..p_silver.."s";
670 end
671 end
672 return valuestr;
673 end
674  
675  
676 function Enchantrix_BarkerOptions_Tab_OnClick()
677 --Enchantrix.Util.ChatPrint( "Clicked Tab: "..this:GetID() );
678 Enchantrix_BarkerOptions_ShowFrame( this:GetID() )
679  
680 end
681  
682 function Enchantrix_BarkerOptions_ShowFrame( frame_index )
683 Enchantrix_BarkerOptions_ActiveTab = -1
684 for index, frame in pairs(Enchantrix_BarkerOptions_TabFrames) do
685 if ( index == frame_index ) then
686 --Enchantrix.Util.ChatPrint( "Showing Frame: "..index );
687 for i = 1,10 do
688 local slider = getglobal('EnchantrixBarker_OptionsSlider_'..i);
689 slider:Hide();
690 end
691 for i, opt in pairs(frame.options) do
692 local slidername = 'EnchantrixBarker_OptionsSlider_'..i
693 local slider = getglobal(slidername);
694 slider:SetMinMaxValues(opt.min, opt.max);
695 slider:SetValueStep(opt.step);
696 slider.tooltipText = opt.tooltip;
697 getglobal(slidername.."High"):SetText();
698 getglobal(slidername.."Low"):SetText();
699 slider:Show();
700 end
701 Enchantrix_BarkerOptions_ActiveTab = index
702 for i, opt in pairs(frame.options) do
703 local slidername = 'EnchantrixBarker_OptionsSlider_'..i
704 local slider = getglobal(slidername);
705 slider:SetValue(opt.getvalue(i));
706 getglobal(slidername.."Text"):SetText(opt.name..' - '..EnchantrixBarker_OptionsSlider_GetTextFromValue(slider:GetValue(),opt.units));
707 end
708 end
709 end
710 end
711  
712 function Enchantrix_BarkerOptions_OnClick()
713 --Enchantrix.Util.ChatPrint("You pressed the options button." );
714 Enchantrix_BarkerOptions_Frame:Show();
715 --ShowUIPanel(Enchantrix_BarkerOptions_Frame);
716 end
717  
718  
719 function Enchantrix_CheckButton_OnShow()
720 end
721 function Enchantrix_CheckButton_OnClick()
722 end
723 function Enchantrix_CheckButton_OnEnter()
724 end
725 function Enchantrix_CheckButton_OnLeave()
726 end
727  
728  
729 -- end UI code
730  
731  
732 function Enchantrix_CreateBarker()
733 local availableEnchants = {};
734 local numAvailable = 0;
735 local temp = GetCraftSkillLine(1);
736 if Enchantrix_BarkerGetZoneText() then
737 Enchantrix_ResetBarkerString();
738 Enchantrix_ResetPriorityList();
739 if (temp) then
740 EnhTooltip.DebugPrint("Starting creation of EnxBarker")
741 for index=1, GetNumCrafts() do
742 local craftName, craftSubSpellName, craftType, numEnchantsAvailable, isExpanded = GetCraftInfo(index);
743 --EnhTooltip.DebugPrint(GetCraftInfo(index))
744 if((numEnchantsAvailable > 0) and (string.find(craftName, "Enchant"))) then --have reagents and it is an enchant
745 --Enchantrix.Util.ChatPrint(""..craftName, 0.8, 0.8, 0.2);
746 local cost = 0;
747 for j=1,GetCraftNumReagents(index),1 do
748 local a,b,c = GetCraftReagentInfo(index,j);
749 reagent = GetCraftReagentItemLink(index,j);
750  
751 --EnhTooltip.DebugPrint("Adding: "..reagent.." - "..Enchantrix_GetReagentHSP(reagent).." x "..c.." = " ..(Enchantrix_GetReagentHSP(reagent)*c/10000));
752 cost = cost + (Enchantrix_GetReagentHSP(reagent)*c);
753 end
754  
755 local profit = cost * Enchantrix_BarkerGetConfig("profit_margin")*0.01;
756 if( profit > Enchantrix_BarkerGetConfig("highest_profit") ) then
757 profit = Enchantrix_BarkerGetConfig("highest_profit");
758 end
759 local price = Enchantrix_RoundPrice(cost + profit);
760  
761 local enchant = {
762 index = index,
763 name = craftName,
764 type = craftType,
765 available = numEnchantsAvailable,
766 isExpanded = isExpanded,
767 cost = cost,
768 price = price,
769 profit = price - cost
770 };
771 availableEnchants[ numAvailable] = enchant;
772  
773 EnhTooltip.DebugPrint(GetCraftDescription(index));
774 local p_gold,p_silver,p_copper = EnhTooltip.GetGSC(enchant.price);
775 local pr_gold,pr_silver,pr_copper = EnhTooltip.GetGSC(enchant.profit);
776 --EnhTooltip.DebugPrint("Price: "..p_gold.."."..p_silver.."g, profit: "..pr_gold.."."..pr_silver.."g");
777  
778 Enchantrix_AddEnchantToPriorityList( enchant )
779 --EnhTooltip.DebugPrint( "numReagents: "..GetCraftNumReagents(index) );
780 numAvailable = numAvailable + 1;
781 end
782 end
783  
784 if numAvailable == 0 then
785 Enchantrix.Util.ChatPrint("Enchantrix: You either don't have any enchants or don't have the reagents to make them."); --TODO: Localize
786 return nil
787 end
788  
789 for i,element in ipairs(priorityList) do
790 EnhTooltip.DebugPrint(element.enchant.name);
791 Enchantrix_AddEnchantToBarker( element.enchant );
792 end
793  
794 return Enchantrix_GetBarkerString();
795  
796 else
797 Enchantrix.Util.ChatPrint("Enchantrix: Enchant Window not open."); --TODO: Localize
798 end
799 end
800  
801 return nil
802 end
803  
804  
805  
806 function Enchantrix_ScoreEnchantPriority( enchant )
807  
808 local score_item = 0;
809  
810 if Enchantrix_BarkerGetConfig( Enchantrix_GetItemCategoryKey(enchant.index) ) then
811 score_item = Enchantrix_BarkerGetConfig( Enchantrix_GetItemCategoryKey(enchant.index) );
812 score_item = score_item * Enchantrix_BarkerGetConfig( 'factor_item' )*0.01;
813 end
814  
815 local score_stat = 0;
816  
817 if Enchantrix_BarkerGetConfig( Enchantrix_GetEnchantStat(enchant) ) then
818 score_stat = Enchantrix_BarkerGetConfig( Enchantrix_GetEnchantStat(enchant));
819 else
820 score_stat = Enchantrix_BarkerGetConfig( 'other' );
821 end
822  
823 score_stat = score_stat * Enchantrix_BarkerGetConfig( 'factor_stat' )*0.01;
824  
825 local score_price = 0;
826 local price_score_floor = Enchantrix_BarkerGetConfig("sweet_price");
827 local price_score_ceiling = Enchantrix_BarkerGetConfig("high_price");
828  
829 if enchant.price < price_score_floor then
830 score_price = (price_score_floor - (price_score_floor - enchant.price))/price_score_floor * 100;
831 elseif enchant.price < price_score_ceiling then
832 range = (price_score_ceiling - price_score_floor);
833 score_price = (range - (enchant.price - price_score_floor))/range * 100;
834 end
835  
836 score_price = score_price * Enchantrix_BarkerGetConfig( 'factor_price' )*0.01;
837 score_total = (score_item + score_stat + score_price);
838  
839 return score_total * (1 - Enchantrix_BarkerGetConfig("randomise")*0.01) + math.random(300) * Enchantrix_BarkerGetConfig("randomise")*0.01;
840 end
841  
842 function Enchantrix_ResetPriorityList()
843 priorityList = {};
844 end
845  
846 function Enchantrix_AddEnchantToPriorityList(enchant)
847  
848 local enchant_score = Enchantrix_ScoreEnchantPriority( enchant );
849  
850 for i,priorityentry in ipairs(priorityList) do
851 if( priorityentry.score < enchant_score ) then
852 table.insert( priorityList, i, {score = enchant_score, enchant = enchant} );
853 return;
854 end
855 end
856  
857 table.insert( priorityList, {score = enchant_score, enchant = enchant} );
858 end
859  
860  
861 function Enchantrix_RoundPrice( price )
862  
863 local round
864  
865 if( price < 5000 ) then
866 round = 1000;
867 elseif ( price < 20000 ) then
868 round = 2500;
869 else
870 round = 5000;
871 end
872  
873 odd = math.mod(price,round);
874  
875 price = price + (round - odd);
876  
877 if( price < Enchantrix_BarkerGetConfig("lowest_price") ) then
878 price = Enchantrix_BarkerGetConfig("lowest_price");
879 end
880  
881 return price
882 end
883  
884 function Enchantrix_GetReagentHSP( itemLink )
885  
886 local itemID = Enchantrix.Util.GetItemIdFromLink(itemLink);
887 local itemKey = string.format("%s:0:0", itemID);
888  
889  
890 -- Work out what version if any of auctioneer is installed
891 local auctVerStr;
892 if (not Auctioneer) then
893 auctVerStr = AUCTIONEER_VERSION or "0.0.0";
894 else
895 auctVerStr = AUCTIONEER_VERSION or Auctioneer.Version or "0.0.0";
896 end
897 local auctVer = Enchantrix.Util.Split(auctVerStr, ".");
898 local major = tonumber(auctVer[1]) or 0;
899 local minor = tonumber(auctVer[2]) or 0;
900 local rev = tonumber(auctVer[3]) or 0;
901 if (auctVer[3] == "DEV") then rev = 0; minor = minor + 1; end
902 local hsp = nil;
903  
904 if (major == 3 and minor == 0 and rev <= 11) then
905 --Enchantrix.Util.ChatPrint("Calling Auctioneer_GetHighestSellablePriceForOne");
906  
907 if (rev == 11) then
908 hsp = Auctioneer_GetHighestSellablePriceForOne(itemKey, false, Auctioneer_GetAuctionKey());
909 else
910 if (Auctioneer_GetHighestSellablePriceForOne) then
911 hsp = Auctioneer_GetHighestSellablePriceForOne(itemKey, false);
912 elseif (getHighestSellablePriceForOne) then
913 hsp = getHighestSellablePriceForOne(itemKey, false);
914 end
915 end
916 elseif (major == 3 and (minor > 0 and minor <= 3) and (rev > 11 and rev < 675)) then
917 --Enchantrix.Util.ChatPrint("Calling GetHSP");
918 hsp = Auctioneer_GetHSP(itemKey, Auctioneer_GetAuctionKey());
919 elseif (major >= 3 and minor >= 3 and (rev >= 675 or rev == 0)) then
920 --Enchantrix.Util.ChatPrint("Calling Statistic.GetHSP");
921 hsp = Auctioneer.Statistic.GetHSP(itemKey, Auctioneer.Util.GetAuctionKey());
922 else
923 Enchantrix.Util.ChatPrint("Calling Nothing: "..major..", "..minor..", "..rev);
924 end
925 if hsp == nil then
926 hsp = 0;
927 end
928  
929 return hsp;
930 end
931  
932 local barkerString = '';
933 local barkerCategories = {};
934  
935 function Enchantrix_ResetBarkerString()
936 barkerString = "("..Enchantrix_BarkerGetZoneText()..") Selling Enchants:"; --TODO: Localize
937 barkerCategories = {};
938 end
939  
940 local short_location = {
941 Orgrimmar = 'Org',
942 ['Thunder Bluff'] = 'TB',
943 Undercity = 'UC',
944 ['Stormwind City'] = 'SW',
945 Darnassus = 'Dar',
946 ['City of Ironforge'] = 'IF'
947 };
948  
949 function Enchantrix_BarkerGetZoneText()
950 --Enchantrix.Util.ChatPrint(GetZoneText());
951 return short_location[GetZoneText()];
952 end
953  
954 function Enchantrix_AddEnchantToBarker( enchant )
955  
956 local currBarker = Enchantrix_GetBarkerString();
957  
958 local category_key = Enchantrix_GetItemCategoryKey( enchant.index )
959 local category_string = "";
960 local test_category = {};
961 if barkerCategories[ category_key ] then
962 for i,element in ipairs(barkerCategories[category_key]) do
963 --Enchantrix.Util.ChatPrint("Inserting: "..i..", elem: "..element.index );
964 table.insert(test_category, element);
965 end
966 end
967  
968 table.insert(test_category, enchant);
969  
970 category_string = Enchantrix_GetBarkerCategoryString( test_category );
971  
972  
973 if string.len(currBarker) + string.len(category_string) > 255 then
974 return false;
975 end
976  
977 if not barkerCategories[ category_key ] then
978 barkerCategories[ category_key ] = {};
979 end
980  
981 table.insert( barkerCategories[ category_key ],enchant );
982  
983 return true;
984 end
985  
986  
987 function Enchantrix_GetBarkerString()
988 local barker = ""..barkerString;
989  
990 for index, key in ipairs(print_order) do
991 if( barkerCategories[key] ) then
992 barker = barker..Enchantrix_GetBarkerCategoryString( barkerCategories[key] )
993 end
994 end
995  
996 return barker;
997 end
998  
999 function Enchantrix_GetBarkerCategoryString( barkerCategory )
1000 local barkercat = ""
1001 barkercat = barkercat.." ["..Enchantrix_GetItemCategoryString(barkerCategory[1].index)..": ";
1002 for j,enchant in ipairs(barkerCategory) do
1003 if( j > 1) then
1004 barkercat = barkercat..", "
1005 end
1006 barkercat = barkercat..Enchantrix_GetBarkerEnchantString(enchant);
1007 end
1008 barkercat = barkercat.."]"
1009  
1010 return barkercat
1011 end
1012  
1013 function Enchantrix_GetBarkerEnchantString( enchant )
1014 local p_gold,p_silver,p_copper = EnhTooltip.GetGSC(enchant.price);
1015  
1016 enchant_barker = Enchantrix_GetShortDescriptor(enchant.index).." - ";
1017 if( p_gold > 0 ) then
1018 enchant_barker = enchant_barker..p_gold.."g";
1019 end
1020 if( p_silver > 0 ) then
1021 enchant_barker = enchant_barker..p_silver.."s";
1022 end
1023 --enchant_barker = enchant_barker..", ";
1024 return enchant_barker
1025 end
1026  
1027  
1028  
1029  
1030 function Enchantrix_GetItemCategoryString( index )
1031  
1032 local enchant = GetCraftInfo( index );
1033  
1034 for key,category in pairs(categories) do
1035 --Enchantrix.Util.ChatPrint( "cat key: "..key);
1036 if( string.find( enchant, category.search ) ~= nil ) then
1037 --Enchantrix.Util.ChatPrint( "cat key: "..key..", name: "..category.print..", enchant: "..enchant );
1038 return category.print;
1039 end
1040 end
1041  
1042 return 'Unknown';
1043 end
1044  
1045 function Enchantrix_GetItemCategoryKey( index )
1046  
1047 local enchant = GetCraftInfo( index );
1048  
1049 for key,category in pairs(categories) do
1050 --Enchantrix.Util.ChatPrint( "cat key: "..key..", name: "..category );
1051 if( string.find( enchant, category.search ) ~= nil ) then
1052 return key;
1053 end
1054 end
1055  
1056 return 'Unknown';
1057  
1058 end
1059  
1060 function EnchantrixBarker_GetCraftDescription( index )
1061 return GetCraftDescription(index) or "";
1062 end
1063  
1064 function Enchantrix_GetShortDescriptor( index )
1065 local long_str = string.lower(EnchantrixBarker_GetCraftDescription(index));
1066  
1067 for index,attribute in ipairs(attributes) do
1068 if( string.find( long_str, attribute ) ~= nil ) then
1069 statvalue = string.sub(long_str ,string.find(long_str,'[0-9]+[^%%]'));
1070 statvalue = string.sub(statvalue ,string.find(statvalue,'[0-9]+'));
1071 return "+"..statvalue..' '..short_attributes[index];
1072 end
1073 end
1074 local enchant = Enchantrix.Util.Split(GetCraftInfo(index), "-");
1075  
1076 return enchant[table.getn(enchant)];
1077 end
1078  
1079 function Enchantrix_GetEnchantStat( enchant )
1080 local index = enchant.index;
1081 local long_str = string.lower(EnchantrixBarker_GetCraftDescription(index));
1082  
1083 for index,attribute in ipairs(attributes) do
1084 if( string.find( long_str, attribute ) ~= nil ) then
1085 return short_attributes[index];
1086 end
1087 end
1088 local enchant = Enchantrix.Util.Split(GetCraftInfo(index), "-");
1089  
1090 return enchant[table.getn(enchant)];
1091 end