vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 SMARTPET_VERSION = "2.3";
2  
3 -- KeyBinding Info
4 BINDING_HEADER_SMARTPET = "SmartPet";
5 BINDING_NAME_TOGGLETAUNT = SMARTPET_BINDING_NAME_TOGGLETAUNT;
6 BINDING_NAME_CHASETOGGLE = SMARTPET_BINDING_NAME_CHASETOGGLE;
7  
8 -- Config Options
9 SmartPet_Config = {};
10  
11 -- General Variables
12 SmartPet_Vars = {};
13 SmartPet_Vars.Class = nil; --What is the player's class
14 SmartPet_Vars.MainAction = ""; --Main Action for pet to use (Growl/Cower)
15 SmartPet_Vars.InCombat = false; --Is pet in combat
16 SmartPet_Vars.InPVP = false; --Is combat PVP
17 SmartPet_Vars.UseTaunt = false; --Useing Growl
18 SmartPet_Vars.Detaunt = false; --Useing Cower
19 SmartPet_Vars.AutoCower = false; --Useing Autocower
20 SmartPet_Vars.LastHealthWarning = 0;
21 SmartPet_Vars.LastHealthPercent = 0;
22 SmartPet_Vars.CombatStartTime = 0;
23 SmartPet_Vars.Party = {}; --Storage for party info
24 SmartPet_Vars.PetSkills = {}; --Storage for pet skill info
25 SmartPet_Vars.PickedUp_Spell = ""; --Index of spell picked up from spell book
26 SmartPet_Vars.PickedUp_SpellBook = ""; --Name of spell book that spell was picked up from
27 SmartPet_Vars.TheButton = ""; --What should "The Button" do when pressed
28  
29 -- Debug Variables
30 SmartPet_Vars.FirstAttackTime = 0;
31 SmartPet_Vars.LastAttackTime = 0;
32 SmartPet_Vars.SpellDamage = 0;
33 SmartPet_Vars.SimSpellDamage = 0;
34  
35 -- Local Variables
36 local Pre_SmartPet_PetAttack;
37 local Pre_SmartPet_CastPetAction;
38 local Pre_SmartPet_ShowUIPanel;
39 local Pre_SmartPet_PickupSpell;
40  
41  
42 -- Pet Abilities
43 SmartPet_Actions = {};
44 SmartPet_Actions["Attack"] = { name = "PET_ACTION_ATTACK", id = 0};
45 SmartPet_Actions["Taunt"] = { name = SMARTPET_ACTIONS_GROWL, id = 0, index = 0, cost = 15, lastTime = 0} ;
46 SmartPet_Actions["Detaunt"] = { name = SMARTPET_ACTIONS_COWER, id = 0, index = 0, cost = 15, lastTime = 0 };
47 SmartPet_Actions["Burst"] = { name = SMARTPET_ACTIONS_CLAW, id = 0, index = 0, cost = 25, lastTime = 0 };
48 SmartPet_Actions["Sustain"] = { name = SMARTPET_ACTIONS_BITE, id = 0, index = 0, cost = 35, lastTime = 0 };
49 SmartPet_Actions["Nochase"] = { name = SMARTPET_ACTION_NOCHASE, id = 0, index = 0, cost = 0, lastTime = 0 };
50 SmartPet_Actions["Dash"] = { name = SMARTPET_ACTION_DASH, id = 0, index = 0, cost = 20, lastTime = 15 };
51 SmartPet_Actions["Dive"] = { name = SMARTPET_ACTION_DIVE, id = 0, index = 0, cost = 20, lastTime = 15 };
52 SmartPet_Abilities ={};
53  
54 -- Slash Commands are in Localization file
55 -- Misc
56 SMARTPET_FOCUSREGEN = 5;
57  
58 COLOR_RED = "|cffff0000";
59 COLOR_YELLOW = "|cffffff00";
60 COLOR_GREEN = "|cff00ff00";
61 COLOR_GREY = "|caaaaaaaa";
62 COLOR_WHITE = "|cffffffff";
63 COLOR_BLUE = "|cff3366ff";
64 COLOR_CLOSE = "|r";
65  
66  
67 -- ==[Function Hooks]==
68  
69 --Modified to catch casting attack from the PetAction Bar and use modifed pet attack
70 function SmartPet_CastPetAction(id)
71 SmartPet_AddDebugMessage(id, "spew");
72 if (id == SmartPet_Actions["Attack"].id ) then
73 PetAttack();
74 else
75 Pre_SmartPet_CastPetAction(id);
76 end
77 end
78  
79 --Modified to record Spell id and Spell book Type when picking up a spell from the spell book
80 function SP_PickupSpell(id, bookType)
81 Pre_SmartPet_PickupSpell(id, bookType);
82 SmartPet_Vars.PickedUp_Spell = id;
83 SmartPet_Vars.PickedUp_SpellBook = bookType;
84 end
85  
86  
87  
88 -- Modifies UI To display checkboxes on pet spell book
89 function SmartPet_ShowUIPanel(frame, force)
90 Pre_SmartPet_ShowUIPanel(frame, force);
91 SmartPet_PetSkillsLoad();
92 end
93  
94  
95 --Pet Attack Hook. Modifies the default PetAttack() function for added functionality
96 --function SmartPet_PetAttack()
97 --SmartPet_Attack();
98 --Pre_SmartPet_PetAttack();
99 --end
100  
101 function UUIToggleSmartPet()
102 if( SmartPetOptionsFrame:IsVisible() ) then
103 SmartPetOptionsFrame:Hide();
104 else
105 SmartPetOptionsFrame:Show();
106 end
107 end
108  
109 --==[Handlers]==
110  
111 -- Load Handler
112 function SmartPet_OnLoad()
113 this:RegisterEvent("UNIT_FOCUS");
114 this:RegisterEvent("UNIT_HEALTH");
115 this:RegisterEvent("CHAT_MSG_SPELL_PET_DAMAGE");
116 this:RegisterEvent("CHAT_MSG_MONSTER_EMOTE");
117 this:RegisterEvent("PET_ATTACK_START");
118 this:RegisterEvent("PET_ATTACK_STOP");
119 this:RegisterEvent("VARIABLES_LOADED");
120 this:RegisterEvent("PET_BAR_UPDATE");
121 this:RegisterEvent("UNIT_NAME_UPDATE");
122 this:RegisterEvent("PET_UI_UPDATE");
123 this:RegisterEvent("CHAT_MSG_SPELL_SELF_DAMAGE");
124 this:RegisterEvent("CHAT_MSG_SPELL_PERIODIC_SELF_DAMAGE");
125 this:RegisterEvent("CHAT_MSG_COMBAT_CREATURE_VS_SELF_HITS");
126 this:RegisterEvent("PLAYER_DEAD");
127 this:RegisterEvent("UNIT_COMBAT");
128  
129 SmartPet_ResetConfig();
130  
131 Pre_SmartPet_PetAttack = PetAttack;
132 PetAttack = SmartPet_Attack;
133  
134 Pre_SmartPet_CastPetAction = CastPetAction;
135 CastPetAction = SmartPet_CastPetAction;
136  
137 Pre_SmartPet_PickupSpell = PickupSpell;
138 PickupSpell = SP_PickupSpell;
139  
140 Pre_SmartPet_ShowUIPanel = ShowUIPanel;
141 ShowUIPanel = SmartPet_ShowUIPanel;
142  
143 SLASH_SMARTPET1 = "/smartpet";
144 SLASH_SMARTPET2 = "/sp";
145 SlashCmdList["SMARTPET"] = function(msg)
146 SmartPet_OnSlashCommand(msg);
147 end
148  
149 -- SmartPet_AddInfoMessage(string.gsub(SMARTPET_VERSION_RUNNING, '%%v', SMARTPET_VERSION));
150  
151  
152  
153  
154 -- DEFAULT_CHAT_FRAME:AddMessage(SmartPet_Vars.Class);
155  
156 if(UltimateUI_RegisterButton) then
157 UltimateUI_RegisterButton (
158 "SmartPet",
159 "Options",
160 "|cFF00CC00SmartPet|r\nVarious options for pet users to make life a lot easier",
161 "Interface\\Icons\\Spell_Magic_PolymorphChicken",
162 UUIToggleSmartPet
163 );
164 end
165  
166 end
167  
168 -- Slash Command Handler
169 function SmartPet_OnSlashCommand(msg)
170  
171 if (not msg) then
172 return;
173 end
174  
175 if ( SmartPet_Config.AcceptedClass == false ) then
176 SmartPet_AddInfoMessage(SMARTPET_ONLY_FOR_HUNTER);
177 return;
178 end
179  
180 local command = string.lower(msg);
181  
182 if ((SmartPet_Vars.Class == "HUNTER") or (SmartPet_Vars.Class == "WARLOCK")) then
183 -- Enable/Disable the SmartPet AddOn
184 if (command == SMARTPET_ENABLE or command == SMARTPET_ON) then
185 SmartPet_Config.Enabled = true;
186 SmartPet_AddInfoMessage(SMARTPET_COMMANDS_SMARTPET_ENABLED);
187 elseif (command == SMARTPET_DISABLE or command == SMARTPET_OFF ) then
188 SmartPet_Config.Enabled = false;
189 SmartPet_AddInfoMessage(SMARTPET_COMMANDS_SMARTPET_DISABLED);
190  
191 -- Enable/Disable Mouse Over Tooltips
192 elseif (strsub(command, 1, strlen(SMARTPET_TOOLTIPS)) == SMARTPET_TOOLTIPS) then
193 if (SmartPet_Config.ToolTips) then
194 SmartPet_Config.ToolTips = false;
195 SmartPet_AddInfoMessage(SMARTPET_COMMANDS_TOOLTIPS_DISABLED);
196 else
197 SmartPet_Config.ToolTips = true;
198 SmartPet_AddInfoMessage(SMARTPET_COMMANDS_TOOLTIPS_ENABLED);
199 end
200  
201 -- Health Warning
202 elseif (strsub(command, 1, strlen(SMARTPET_AUTOWARN )) == SMARTPET_AUTOWARN ) then
203 if (SmartPet_ToggleOption(command, SmartPet_Config.AutoWarn)) then
204 SmartPet_Config.AutoWarn = true;
205 SmartPet_AddInfoMessage(SMARTPET_COMMANDS_AUTOWARN_ENABLED);
206 else
207 SmartPet_Config.AutoWarn = false;
208 SmartPet_AddInfoMessage(SMARTPET_COMMANDS_AUTOWARN_DISABLED);
209 end
210  
211 -- Health Warning Channel
212 elseif (strsub(command, 1, strlen(SMARTPET_CHANNEL)) == SMARTPET_CHANNEL ) then
213 if (strfind(command, "party")) then
214 SmartPet_Config.Channel = "party";
215 elseif (strfind(command, "say")) then
216 SmartPet_Config.Channel = "say";
217 elseif (strfind(command, "guild")) then
218 SmartPet_Config.Channel = "guild";
219 else
220 firsti, lasti, value = strfind(command, "(%d+)");
221 if (value) then
222 SmartPet_Config.ChannelNumber = tonumber(value);
223 SmartPet_Config.Channel = "channel";
224 else
225 SmartPet_Config.Channel = "say";
226 end
227 end
228 SmartPet_AddInfoMessage(string.gsub(SMARTPET_COMMANDS_CHANNEL, '%%c', SmartPet_Config.Channel));
229  
230 -- Health Warning Threshold
231 elseif (strsub(command, 1, strlen(SMARTPET_WARNHEALTH)) == SMARTPET_WARNHEALTH ) then
232 firsti, lasti, value = strfind(command, "(%d+)");
233 if (value) then
234 SmartPet_Config.WarnHealth = tonumber(value);
235 else
236 SmartPet_Config.WarnHealth = 30;
237 end
238 SmartPet_AddInfoMessage(string.gsub(SMARTPET_COMMANDS_WARNHEALTH, '%%h', SmartPet_Config.WarnHealth));
239  
240 -- No Chase
241 elseif (strsub(command, 1, strlen(SMARTPET_NOCHASE)) == SMARTPET_NOCHASE ) then
242 if (SmartPet_Config.NoChase) then
243 SmartPet_Config.NoChase = false;
244 SmartPet_AddInfoMessage(SMARTPET_COMMANDS_NOCHASE_DISABLED);
245 else
246 PetFollow();
247 SmartPet_Config.NoChase = true;
248 SmartPet_AddInfoMessage(SMARTPET_COMMANDS_NOCHASE_ENABLED);
249 end
250  
251 elseif ((SmartPet_Vars.Class == "HUNTER") and (SmartPet_Vars.Class ~= "WARLOCK")) then
252  
253 -- Focus Management
254 if (strsub(command, 1, strlen(SMARTPET_TAUNTMAN )) == SMARTPET_TAUNTMAN ) then
255 --SmartPet_AddInfoMessage("SmartPet: Use the check buttons above Growl and Cower on your pet action bar to enable Taunt Management");
256 -- if (SmartPet_ToggleOption(command, SmartPet_Config.TauntMan)) then
257 -- SmartPet_Config.TauntMan = true;
258 -- SmartPet_AddInfoMessage("SmartPet: Taunt management enabled");
259 -- else
260 -- SmartPet_Config.TauntMan = false;
261 -- SmartPet_AddInfoMessage("SmartPet: Taunt management disabled");
262 -- end
263  
264 -- Focus Management
265 elseif (strsub(command, 1, strlen(SMARTPET_SMARTFOCUS )) == SMARTPET_SMARTFOCUS ) then
266 if (SmartPet_ToggleOption(command, SmartPet_Config.SmartFocus)) then
267 SmartPet_Config.SmartFocus = true;
268 SmartPet_AddInfoMessage(SMARTPET_COMMANDS_SMARTFOCUS_ENABLED);
269 else
270 SmartPet_Config.SmartFocus = false;
271 SmartPet_AddInfoMessage(SMARTPET_COMMANDS_SMARTFOCUS_DISABLED);
272 end
273  
274  
275 -- Cower Mode
276 elseif (strsub(command, 1, strlen(SMARTPET_AUTOCOWER)) == SMARTPET_AUTOCOWER ) then
277 if (SmartPet_Config.AutoCower) then
278 SmartPet_Config.AutoCower = false;
279 SmartPet_AddInfoMessage(SMARTPET_COMMANDS_AUTOCOWER_DISABLED);
280 else
281 SmartPet_Config.AutoCower = true;
282 SmartPet_AddInfoMessage(SMARTPET_COMMANDS_AUTOCOWER_ENABLED);
283 end
284  
285 --Auto Cower Threshold
286 elseif (strsub(command, 1, strlen(SMARTPET_COWERHEALTH)) == SMARTPET_COWERHEALTH ) then
287 firsti, lasti, value = strfind(command, "(%d+)");
288 if (value) then
289 SmartPet_Config.CowerHealth = tonumber(value);
290 else
291 SmartPet_Config.CowerHealth = 30;
292 end
293 SmartPet_AddInfoMessage(string.gsub(SMARTPET_COMMANDS_COWERHEALTH, '%%h', SmartPet_Config.CowerHealth));
294  
295  
296 --Options gui
297 elseif (command == "options") then
298 SmartPetOptions_Toggle();
299  
300 --Options gui
301 elseif (command == "show") then
302 SmartPetDefendOptionsFrame:Show();
303  
304 --resets config to deal with not huntter error
305 elseif (command == "reset") then
306 SmartPet_ResetConfig();
307  
308 -- Debug Text
309 elseif (strsub(command, 1, 9) == SMARTPET_SHOWDEBUG) then
310 if (command == SMARTPET_SHOWDEBUG) then
311 SmartPet_Config.ShowDebug = false;
312 SmartPet_AddInfoMessage(SMARTPET_COMMANDS_SHOWDEBUG_DISABLED);
313 else
314 SmartPet_Config.ShowDebug = true;
315 SmartPet_Config.ShowDebugString = command;
316 SmartPet_AddInfoMessage(SMARTPET_COMMANDS_SHOWDEBUG_ENABLED);
317 end
318  
319 -- Help Text
320 elseif (command == SMARTPET_HELP) then
321 SmartPet_AddInfoMessage(SMARTPET_HELP_TITLE);
322 SmartPet_AddHelpMessage(SMARTPET_HELP_TAUNTMAN1,SMARTPET_HELP_TAUNTMAN2);
323 SmartPet_AddHelpMessage(SMARTPET_HELP_SMARTFOCUS1,SMARTPET_HELP_SMARTFOCUS2);
324 SmartPet_AddHelpMessage(SMARTPET_HELP_AUTOHEALTH1,SMARTPET_HELP_AUTOHEALTH2);
325 SmartPet_AddHelpMessage(SMARTPET_HELP_AUTOCOWER1,SMARTPET_HELP_AUTOCOWER2);
326  
327  
328 -- Typos and Default
329  
330 elseif (command == "show") then
331 DEFAULT_CHAT_FRAME:AddMessage(" ");
332 SmartPet_AddInfoMessage("SmartPet Status:");
333 DEFAULT_CHAT_FRAME:AddMessage(COLOR_GREEN.."Use "..COLOR_CLOSE..COLOR_WHITE.."/smartpet <command> "..COLOR_CLOSE..COLOR_GREEN.."or "..COLOR_CLOSE..COLOR_WHITE.."/sp <command> "..COLOR_CLOSE..COLOR_GREEN.."to perform the following commands:"..COLOR_CLOSE);
334 SmartPet_AddHelpMessage(SMARTPET_ENABLE.."|"..SMARTPET_DISABLE, SMARTPET_USAGE_SMARTPET, nil, SmartPet_Config.Enabled);
335 --SmartPet_AddHelpMessage(SMARTPET_TAUNTMAN, SMARTPET_USAGE_TAUNTMAN, nil, SmartPet_Config.TauntMan);
336 SmartPet_AddHelpMessage(SMARTPET_SMARTFOCUS, SMARTPET_USAGE_SMARTFOCUS, nil, SmartPet_Config.SmartFocus);
337 SmartPet_AddHelpMessage(SMARTPET_AUTOWARN, SMARTPET_USAGE_AUTOWARN, nil, SmartPet_Config.AutoWarn);
338 SmartPet_AddHelpMessage(SMARTPET_WARNHEALTH .. " " .. SMARTPET_USAGE_PERCENT, SMARTPET_USAGE_WARNHEALTH, "("..SmartPet_Config.WarnHealth.."%)", SmartPet_Config.AutoWarn);
339 SmartPet_AddHelpMessage(SMARTPET_CHANNEL.." <say|party|guild|#>", SMARTPET_USAGE_CHANNEL, "("..SmartPet_Config.Channel..")", SmartPet_Config.AutoWarn);
340 SmartPet_AddHelpMessage(SMARTPET_AUTOCOWER, SMARTPET_USAGE_AUTOCOWER, nil, SmartPet_Config.AutoCower);
341 SmartPet_AddHelpMessage(SMARTPET_COWERHEALTH .. " " .. SMARTPET_USAGE_PERCENT, SMARTPET_USAGE_COWERHEALTH, "("..SmartPet_Config.CowerHealth.."%)", SmartPet_Config.AutoCower);
342 SmartPet_AddHelpMessage(SMARTPET_NOCHASE, SMARTPET_USAGE_NOCHASE, nil, SmartPet_Config.NoChase);
343 SmartPet_AddHelpMessage(SMARTPET_HELP, SMARTPET_USEAGE_HELP, nil, nil);
344 SmartPet_AddHelpMessage(SMARTPET_TOOLTIPS, SMARTPET_USAGE_TOOLTIPS, nil, SmartPet_Config.Tooltips);
345 DEFAULT_CHAT_FRAME:AddMessage(" ");
346 DEFAULT_CHAT_FRAME:AddMessage(COLOR_GREEN.."For example: "..COLOR_CLOSE..COLOR_WHITE.."/smartpet warnhealth 40 "..COLOR_CLOSE..COLOR_GREEN.."will make your pet warn the party when it's health is below 40%."..COLOR_CLOSE);
347  
348 else
349 SmartPetOptionsFrame:Show();
350  
351 end
352  
353 else
354  
355 --[[
356 DEFAULT_CHAT_FRAME:AddMessage(" ");
357 SmartPet_AddInfoMessage(SMARTPET_WARLOCK_MEMO);
358 SmartPet_AddInfoMessage("SmartPet Status:");
359 DEFAULT_CHAT_FRAME:AddMessage(COLOR_GREEN.."Use "..COLOR_CLOSE..COLOR_WHITE.."/smartpet <command> "..COLOR_CLOSE..COLOR_GREEN.."or "..COLOR_CLOSE..COLOR_WHITE.."/sp <command> "..COLOR_CLOSE..COLOR_GREEN.."to perform the following commands:"..COLOR_CLOSE);
360 SmartPet_AddHelpMessage(SMARTPET_ENABLE.."|"..SMARTPET_DISABLE, SMARTPET_USAGE_SMARTPET, nil, SmartPet_Config.Enabled);
361 SmartPet_AddHelpMessage(SMARTPET_AUTOWARN, SMARTPET_USAGE_AUTOWARN, nil, SmartPet_Config.AutoWarn);
362 SmartPet_AddHelpMessage(SMARTPET_WARNHEALTH .. " " .. SMARTPET_USAGE_PERCENT, SMARTPET_USAGE_WARNHEALTH, "("..SmartPet_Config.WarnHealth.."%)", SmartPet_Config.AutoWarn);
363 SmartPet_AddHelpMessage(SMARTPET_CHANNEL.." <say|party|guild|#>", SMARTPET_USAGE_CHANNEL, "("..SmartPet_Config.Channel..")", SmartPet_Config.AutoWarn);
364 SmartPet_AddHelpMessage(SMARTPET_NOCHASE, SMARTPET_USAGE_NOCHASE, nil, SmartPet_Config.NoChase);
365 SmartPet_AddHelpMessage(SMARTPET_TOOLTIPS, SMARTPET_USAGE_TOOLTIPS, nil, SmartPet_Config.Tooltips);
366 DEFAULT_CHAT_FRAME:AddMessage(" ");
367 DEFAULT_CHAT_FRAME:AddMessage(COLOR_GREEN.."For example: "..COLOR_CLOSE..COLOR_WHITE.."/smartpet warnhealth 40 "..COLOR_CLOSE..COLOR_GREEN.."will make your pet warn the party when it's health is below 40%."..COLOR_CLOSE);
368 ]]
369  
370 end
371  
372 end
373  
374 SmartPet_UpdateActionIcons(true);
375 end
376  
377  
378 -- Main Event Handler
379 function SmartPet_OnEvent()
380 if (event == "VARIABLES_LOADED") then
381  
382 -- Add SmartPet to myAddOns addons list
383 if(myAddOnsFrame) then
384 myAddOnsList.SmartPet = {
385 name = "SmartPet",
386 description = "Addon to make you pet more useful",
387 version = SMARTPET_VERSION,
388 category = MYADDONS_CATEGORY_CLASS,
389 frame = "SmartPetFrame",
390 optionsframe = "SmartPetOptionsFrame"
391 };
392 myAddOnsList.SmartPetDefend = {
393 name = "SmartPet Defend",
394 description = "Have your pet defend party members",
395 version = SMARTPET_VERSION,
396 category = MYADDONS_CATEGORY_CLASS,
397 frame = "SmartPetFrame",
398 optionsframe = "SmartPetDefendOptionsFrame"
399 };
400 end
401  
402 --Version Check
403 if (not SmartPet_Config.Version or SmartPet_Config.Version ~= SMARTPET_VERSION) then
404 SmartPet_AddInfoMessage(SMARTPET_VERSION_CHANGED);
405 SmartPet_ResetConfig();
406 end
407  
408 --RegisterForSave("SmartPet_Config");
409 SmartPet_UpdateActionIcons(false);
410  
411 if (not SmartPet_Config.Enabled) then
412 return;
413 end
414  
415 if (SmartPet_Config.Icon == true) then
416 SmartPetOptionButton:Show();
417 else
418 SmartPetOptionButton:Hide();
419 end
420  
421  
422 if (not SmartPet_Vars.Class) then
423 if ((UnitName("player")) and (UnitName("player") ~= "") and (UnitName("player") ~= UNKNOWNOBJECT) and (UnitName("player") ~= UKNOWNBEING)) then
424 local localizedClass, englishClass = UnitClass("player");
425 if ((localizedClass) and (englishClass)) then
426 if (englishClass ~= "") then
427 SmartPet_Vars.Class = englishClass;
428 end
429 end
430 end
431 end
432  
433 if (not SmartPet_Vars.Class) then
434 return;
435 end
436  
437 -- Below we can be sure our unit is loaded and we have a class set!
438 --Checks to see if player is a class that can use SmartPet.
439 SmartPet_AddDebugMessage("Class is " .. SmartPet_Vars.Class, "spew");
440 if (SmartPet_Vars.Class == "HUNTER") then
441 SmartPet_Config.AcceptedClass = true;
442 elseif (SmartPet_Vars.Class == "WARLOCK") then
443 SmartPet_Config.AcceptedClass = true;
444 else
445 SmartPet_Config.AcceptedClass = false;
446 end
447  
448 if (SmartPet_Vars.Class == "WARLOCK") then
449 SmartPet_Config.ToolTips = false;
450 SmartPet_Config.TauntMan = false;
451 SmartPet_Config.SmartFocus = false;
452 SmartPet_Config.AutoWarn = false;
453 SmartPet_Config.AutoCower = false;
454 SmartPet_Config.ShowDebug = false;
455 SmartPet_Config.NoChase = false;
456 SmartPet_Config.UseTaunt = false;
457 SmartPet_Config.UseDetaunt = false;
458 SmartPet_Config.UseBurst = false;
459 SmartPet_Config.UseSustain = false;
460 SmartPet_AddInfoMessage(SMARTPET_WARLOCK_MEMO);
461 end
462  
463  
464 --Unregister events if our class is not a hunter so we don't generate any overhead.
465 if (SmartPet_Config.AcceptedClass == false) then
466 this:UnregisterEvent("UNIT_FOCUS");
467 this:UnregisterEvent("UNIT_HEALTH");
468 this:UnregisterEvent("CHAT_MSG_SPELL_PET_DAMAGE");
469 this:UnregisterEvent("CHAT_MSG_MONSTER_EMOTE");
470 this:UnregisterEvent("PET_ATTACK_START");
471 this:UnregisterEvent("PET_ATTACK_STOP");
472 this:UnregisterEvent("VARIABLES_LOADED");
473 this:UnregisterEvent("PET_BAR_UPDATE");
474 this:UnregisterEvent("UNIT_NAME_UPDATE");
475 this:UnregisterEvent("PET_UI_UPDATE");
476 this:UnregisterEvent("CHAT_MSG_SPELL_SELF_DAMAGE");
477 this:UnregisterEvent("CHAT_MSG_SPELL_PERIODIC_SELF_DAMAGE");
478 this:UnregisterEvent("CHAT_MSG_COMBAT_CREATURE_VS_SELF_HITS");
479 this:UnregisterEvent("PLAYER_DEAD");
480 return;
481 end
482 end
483  
484 if (event == "PET_UI_UPDATE") then
485 SmartPet_PetSkillsLoad();
486 end
487  
488 if (event == "PET_BAR_UPDATE") then
489 SmartPet_UpdateActionIcons(false);
490 SmartPet_PetSkillsLoad();
491 end
492  
493 if (event == "PET_ATTACK_START") then
494 SmartPet_InitActions();
495 SmartPet_Vars.inCombat = true;
496 SmartPet_Vars.CombatStartTime = GetTime();
497 SmartPet_Vars.LastHealthPercent = (100 * UnitHealth("pet") / UnitHealthMax("pet"));
498 SmartPet_Vars.TheButton = "";
499 -- Debug Variables
500 SmartPet_Vars.FirstAttackTime = 0;
501 SmartPet_Vars.LastAttackTime = 0;
502 SmartPet_Vars.SpellDamage = 0;
503 SmartPet_Vars.SimSpellDamage = 0;
504 end
505  
506 if ((event == "PET_ATTACK_STOP") or (event == "PLAYER_DEAD"))then
507 SmartPet_Vars.inCombat = false;
508 if (SmartPet_Vars.InPVP) then
509 SmartPet_EndPVP();
510  
511 end
512 SmartPet_Vars.TheButton = "";
513 SmartPet_SetActionByUse("Taunt", SmartPet_Config.UseTaunt);
514 SmartPet_SetActionByUse("Detaunt", SmartPet_Config.UseDetaunt);
515 SmartPet_SetActionByUse("Burst", SmartPet_Config.UseBurst);
516 SmartPet_SetActionByUse("Sustain", SmartPet_Config.UseSustain);
517 SmartPet_AddDebugMessage("Combat Time: "..(SmartPet_Vars.LastAttackTime - SmartPet_Vars.FirstAttackTime), "dps");
518 SmartPet_AddDebugMessage("Spell DPS: "..SmartPet_Vars.SpellDamage / (SmartPet_Vars.LastAttackTime - SmartPet_Vars.FirstAttackTime), "dps");
519 SmartPet_AddDebugMessage("Sim Spell DPS: "..SmartPet_Vars.SimSpellDamage / (SmartPet_Vars.LastAttackTime - SmartPet_Vars.FirstAttackTime), "dps");
520 end
521  
522 if (event == "CHAT_MSG_SPELL_PET_DAMAGE") then
523 SmartPet_OnPetSpellEvent(arg1);
524 end
525  
526 if (event == "CHAT_MSG_MONSTER_EMOTE") then
527 SmartPet_OnMonsterEmote(arg1, arg2);
528 end
529  
530 if (event == "UNIT_FOCUS" and arg1 == "pet" and (SmartPet_Config.TauntMan or SmartPet_Config.SmartFocus)) then
531 SmartPet_OnFocusEvent(arg1, arg2);
532 end
533  
534 if ((event == "UNIT_HEALTH") and (arg1 == "pet") and (SmartPet_Config.AutoWarn or SmartPet_Config.AutoCower)) then
535 SmartPet_OnHealthEvent(arg1, arg2);
536 end
537  
538 --Causes Pet to Stop Attack when using Scatter Shot
539 if ( event == "CHAT_MSG_SPELL_SELF_DAMAGE") then
540 if (strfind (arg1, "Your Scatter Shot")) then
541 if (keym) then
542 keym.whack.add(TRUE, SmartPetScatterShot);
543 end
544  
545 end
546 end
547  
548 if ( event == "UNIT_COMBAT" ) then
549 --SmartPetDefendTest(arg1, arg2);
550 end
551  
552 end
553  
554 --Checks monster's emote to see if it is fleeing
555 function SmartPet_OnMonsterEmote(arg1, arg2)
556 local target = "target";
557 local petTarget = "pettarget";
558  
559 if (not SmartPet_Config.NoChase) then
560 return
561 end
562  
563 if (arg2 == UnitName("pettarget") and strfind (arg1, SMARTPET_SEARCH_RUNAWAY)) then
564 --SmartPet_AddInfoMessage(string.gsub(SMARTPET_PET_BREAKS_COMBAT, '%%n', UnitName("pet")));
565 --SmartPet_AddInfoMessage(UnitAffectingCombat("target"));
566 --SmartPet_AddInfoMessage(UnitAffectingCombat("pettarget"));
567 --if (UnitHealth("target") > UnitHealth("pettarget")) or not (UnitExists("target"))then
568 --PetFollow();
569 if (keym) then
570 keym.whack.add(TRUE, PetFollow);
571 end
572 if (SmartPet_Config.RecallWarn) then
573 UIErrorsFrame:AddMessage("Recall Pet", 0, 0, 1, 1.0, UIERRORS_HOLD_TIME);
574 end
575 SmartPet_Vars.TheButton = "recall";
576  
577 end
578 end
579  
580 -- Spell Damage Event Handler
581 function SmartPet_OnPetSpellEvent(arg1)
582 if (strfind (arg1, SmartPet_Actions["Taunt"].name)) then
583 SmartPet_ProcessSpellEvent("Taunt");
584 end
585 if (strfind (arg1, SmartPet_Actions["Sustain"].name)) then
586 SmartPet_ProcessSpellEvent("Sustain");
587 end
588 if (strfind (arg1, SmartPet_Actions["Burst"].name)) then
589 SmartPet_ProcessSpellEvent("Burst");
590 end
591 if (strfind (arg1, SmartPet_Actions["Detaunt"].name)) then
592 SmartPet_ProcessSpellEvent("Detaunt");
593 end
594 end
595  
596 --??
597 function SmartPet_ProcessSpellEvent(action)
598 SmartPet_AddDebugMessage(SmartPet_Actions[action].name..": Time Since Last: "..GetTime() - SmartPet_Actions[action].lastTime, "usage");
599 if (SmartPet_Vars.FirstAttackTime == 0) then
600 SmartPet_Vars.FirstAttackTime = GetTime();
601 end
602 SmartPet_Actions[action].lastTime = GetTime();
603 SmartPet_Vars.LastAttackTime = SmartPet_Actions[action].lastTime;
604  
605 firsti, lasti, value = strfind(arg1, "(%d+)");
606 if (value) then
607 SmartPet_Vars.SpellDamage = SmartPet_Vars.SpellDamage + tonumber(value);
608 if (action == "Burst") then
609 SmartPet_Vars.SimSpellDamage = SmartPet_Vars.SimSpellDamage + 31;
610 elseif (action == "Sustain") then
611 SmartPet_Vars.SimSpellDamage = SmartPet_Vars.SimSpellDamage + 54;
612 end
613 end
614 end
615  
616 -- Focus Event Handler
617 function SmartPet_OnFocusEvent(arg1, arg2)
618 if (not SmartPet_Vars.inCombat) then
619 return;
620 end
621  
622 if (SmartPet_Vars.InPVP) then
623 SmartPet_SetActionByFocus("Burst");
624 SmartPet_AddDebugMessage("pvp fous ", "spew");
625 return
626 end
627  
628 if (SmartPet_Config.SmartFocus and SmartPet_Config.UseSustain and SmartPet_Config.UseBurst) then
629 if (GetTime() - SmartPet_Vars.CombatStartTime > 12.0) then
630 SmartPet_DisableAction("Burst");
631 SmartPet_SetActionByFocus("Sustain");
632 else
633 SmartPet_DisableAction("Sustain");
634 SmartPet_SetActionByFocus("Burst");
635 end
636 elseif (SmartPet_Config.TauntMan) then
637 if (SmartPet_Config.UseSustain) then
638 SmartPet_SetActionByFocus("Sustain");
639 end
640  
641 if (SmartPet_Config.UseBurst) then
642 SmartPet_SetActionByFocus("Burst");
643 end
644 end
645 end
646  
647  
648  
649  
650 -- Health Event Handler
651 function SmartPet_OnHealthEvent(arg1, arg2)
652 if (not SmartPet_Vars.inCombat) then
653 SmartPet_AddDebugMessage("Not checking health because we're not in combat", "spew");
654 return;
655 end
656  
657 healthPercent = (100 * UnitHealth("pet") / UnitHealthMax("pet"));
658 if (SmartPet_Config.AutoCower and SmartPet_Actions["Detaunt"].index > 0) then
659 if (healthPercent < SmartPet_Config.CowerHealth) then
660 SmartPet_AddDebugMessage("AutoCower Health Check Failed, switching to cower", "spew");
661 SmartPet_DisableAction("Taunt");
662 SmartPet_EnableAction("Detaunt");
663 SmartPet_Vars.MainAction = "Detaunt";
664 else
665 SmartPet_SetActionByUse("Taunt", SmartPet_Config.UseTaunt);
666 SmartPet_SetActionByUse("Detaunt", SmartPet_Config.UseDetaunt);
667 end
668 end
669  
670  
671 if (SmartPet_Config.AutoWarn) then
672 if (healthPercent >= 60) then
673 warnTime = 10;
674 elseif (healthPercent >= 50) then
675 warnTime = 8;
676 elseif (healthPercent >= 30) then
677 warnTime = 6;
678 else
679 warnTime = 4;
680 end
681 if (healthPercent < SmartPet_Config.WarnHealth and ((GetTime() - SmartPet_Vars.LastHealthWarning) > warnTime) and SmartPet_Vars.LastHealthPercent > healthPercent ) then
682 local m = SMARTPET_PET_NEEDS_HEALING;
683 m = string.gsub(m, '%%n', UnitName("pet"));
684 m = string.gsub(m, '%%h', string.format("%d", healthPercent));
685 SmartPet_SendChatMessage(m);
686  
687 SmartPet_Vars.LastHealthWarning = GetTime();
688 end
689 end
690 SmartPet_Vars.LastHealthPercent = healthPercent;
691 end
692  
693  
694 -- PVP Start Handler. Checks to see if combat is PVP and optimises settings for it
695 function SmartPet_StartPVP()
696 if ((UnitExists("target")) and (UnitIsPlayer("target")) and (UnitCanAttack("player", "target"))) then
697 if not (SmartPet_Vars.InPVP) then
698 SmartPet_AddDebugMessage("Storing prePVP Settings", "spew");
699 SmartPet_Vars.InPVP = true;
700 SmartPet_Vars.UseTaunt = SmartPet_Config.UseTaunt;
701 SmartPet_Vars.UseDetaunt = SmartPet_Config.UseDetaunt;
702 SmartPet_Vars.AutoCower = SmartPet_Config.AutoCower;
703 if (SmartPet_Config.UseTaunt) then
704 SmartPet_ToggleUse(SmartPet_Actions["Taunt"].index);
705 end
706 if (SmartPet_Config.UseDetaunt) then
707 SmartPet_ToggleUse(SmartPet_Actions["Detaunt"].index);
708 end
709 SmartPet_Config.AutoCower = false;
710 SmartPet_EnableAction("Burst");
711 SmartPet_EnableAction("Sustain");
712 end
713 end
714 end
715  
716 -- PVP End Handler. Resets taunt variables to orginal config that was changed on entering PVP
717 function SmartPet_EndPVP()
718 SmartPet_AddDebugMessage("Restoring to PrePVP conditions", "spew");
719 SmartPet_Vars.InPVP = false;
720 if (SmartPet_Vars.UseTaunt) then
721 SmartPet_ToggleUse(SmartPet_Actions["Taunt"].index);
722 end
723 if (SmartPet_Vars.UseDetaunt) then
724 SmartPet_ToggleUse(SmartPet_Actions["Detaunt"].index);
725 end
726 if (SmartPet_Vars.AutoCower) then
727 SmartPet_Config.AutoCower = true;
728 end
729 end
730  
731  
732 --Note To Self Go Over Closely and see if SmartPet_Vars.PetSkills[index] is needed
733 -- Stores pet skills from spell book and puts checkboxes next to them on the spellbook pet tab
734 function SmartPet_PetSkillsLoad()
735 if (SpellBookFrame.bookType == BOOKTYPE_PET) then
736 SmartPetFrame2:Show();
737 else
738 SmartPetFrame2:Hide();
739 end
740 SmartPet_Actions["Taunt"].id = -1;
741 SmartPet_Actions["Detaunt"].id = -1;
742 SmartPet_Actions["Burst"].id = -1;
743 SmartPet_Actions["Sustain"].id = -1;
744 SmartPet_Actions["Nochase"].id = -1;
745 SmartPet_Actions["Dash"].id = -1;
746 SmartPet_Actions["Dive"].id = -1;
747  
748 for index=1, 10, 1 do
749  
750 local spellName, spellRank = GetSpellName(index, BOOKTYPE_PET)
751 local l_petActionButton = getglobal("PetSkillButton"..index);
752 local texture = GetSpellTexture(index, BOOKTYPE_PET);
753  
754 if (spellName == SMARTPET_ACTIONS_GROWL) then
755 l_petActionButton:Show();
756 SmartPet_Actions["Taunt"].id = index;
757 SmartPet_Vars.PetSkills[index] = SmartPet_Actions["Taunt"].index;
758 l_petActionButton:SetChecked(SmartPet_Config.UseTaunt);
759  
760 elseif (SMARTPET_ACTIONS_COWER == spellName) then
761 l_petActionButton:Show();
762 SmartPet_Actions["Detaunt"].id = index;
763 SmartPet_Vars.PetSkills[index] = SmartPet_Actions["Detaunt"].index;
764 l_petActionButton:SetChecked(SmartPet_Config.UseDetaunt);
765  
766 elseif (SMARTPET_ACTIONS_CLAW == spellName) then
767 SmartPet_Actions["Burst"].id = index;
768 if (SmartPet_Config.TauntMan or SmartPet_Config.SmartFocus) then
769 l_petActionButton:Show();
770 else
771 l_petActionButton:Hide();
772 end
773 SmartPet_Vars.PetSkills[index] = SmartPet_Actions["Burst"].index;
774 l_petActionButton:SetChecked(SmartPet_Config.UseBurst);
775  
776 elseif (SMARTPET_ACTIONS_BITE == spellName) then
777 SmartPet_Actions["Sustain"].id = index;
778 if (SmartPet_Config.TauntMan or SmartPet_Config.SmartFocus) then
779 l_petActionButton:Show();
780 else
781 l_petActionButton:Hide();
782 end
783 SmartPet_Vars.PetSkills[index] = SmartPet_Actions["Sustain"].index;
784 l_petActionButton:SetChecked(SmartPet_Config.UseSustain);
785  
786 elseif (SMARTPET_ACTIONS_DASH == spellName) then
787 SmartPet_Actions["Dash"].id = index;
788 l_petActionButton:Hide();
789  
790 elseif (SMARTPET_ACTIONS_DIVE == spellName) then
791 SmartPet_Actions["Dive"].id = index;
792 l_petActionButton:Hide();
793 else
794 l_petActionButton:Hide();
795 end
796 end
797 end
798  
799  
800  
801  
802 --
803 -- General Functions
804 --
805 --
806  
807 --Note To Self Clean up and verify Attack Command
808 --Attack Command
809 function SmartPet_Attack()
810 local pet = UnitName("pet");
811 local target = UnitName("target");
812  
813 -- Check if Enabled
814 if not (SmartPet_Config.Enabled) then
815 SmartPet_AddDebugMessage("SmartPet Disabled, using default petAttack", "spew");
816 Pre_SmartPet_PetAttack();
817 return;
818 end
819  
820 --Casts Spell if Spell Attack is active
821 SmartPetSpellAttack();
822  
823 if (not (pet == nil) and not ( UnitIsDead("pet") ) )then
824  
825 -- check for PVP Ability toggle
826 SmartPet_StartPVP();
827  
828 --Assist Other. If target is assistable player then we will have pet assist them
829 if ( UnitIsPlayer("target") ) and ( UnitCanCooperate("player", "target")) and (UnitIsEnemy("player", "targettarget")) and not (UnitIsDead("targettarget") ) then
830 player = target;
831 AssistUnit("target");
832 target = UnitName("target");
833  
834 if (target == nil) then
835 return;
836 end
837  
838 if not (UnitCanAttack("player", "target")) then
839 return;
840 end
841 message = SetMessage(pet, target, player, "assist_other");
842  
843 elseif (UnitCanAttack("player", "target")) then
844  
845 -- Assist Player
846 if UnitIsTappedByPlayer("target") then
847 message = SetMessage(pet, target, "me", "assist_me");
848  
849 -- Attack Mob
850 else
851 message = SetMessage(pet, target, "none", "attack");
852 end
853  
854 end
855  
856 if (UnitExists("target") and UnitCanAttack("player", "target") ) then
857  
858 if not ( UnitIsDead("target") ) then
859 SmartPet_AddDebugMessage("Attack", "spew");
860 -- Check Alert
861  
862 if (SmartPet_Config.Alert) then
863 SendChatMessage(message, "SAY");
864 end
865  
866 Pre_SmartPet_PetAttack();
867  
868 --Check to see if we want to use Dash/Dive on attack start
869 SmartPetChargeCheck();
870 end
871 else
872 --Turns Pet Attack command into Pet Follow if no target is selected
873 PetFollow();
874 end
875 end
876 end
877  
878  
879 --Casts a Selected Spell on attack command
880 function SmartPetChargeCheck()
881 if ((SmartPet_Config.RushAttack) and (not SmartPet_Vars.InCombat))then
882 local SkillToUse = "";
883 SmartPet_AddDebugMessage("Trying to cast Dash/Dive", "spew");
884 if (SmartPet_Actions["Dash"].id > 0) then
885 SkillToUse = "Dash";
886 elseif (SmartPet_Actions["Dive"].id > 0) then
887 SkillToUse = "Dive";
888 else
889 SmartPet_AddDebugMessage("Dash/Dive Not Found", "spew");
890 SkillToUse = "";
891 end
892  
893 local start, duration = GetSpellCooldown((SmartPet_Actions[SkillToUse].id), "Pet");
894 if ( start == 0 and duration == 0 and SkillToUse ~="") then
895 CastSpell((SmartPet_Actions[SkillToUse].id), "Pet");
896 end
897 end
898  
899 end
900  
901 function SmartPetScatterShot()
902 --Causes Pet to Stop Attack when using Scatter Shot
903 if (SmartPet_Config.Scatter) then
904 SmartPet_AddDebugMessage("Scatter Shot Cast, new variables being set","spew");
905 if (SmartPet_Config.ScatterOrder ~= "") then
906 SmartPet_Config.ScatterOrder();
907 end
908 if (SmartPet_Config.ScatterMood ~= "") then
909 SmartPet_Config.ScatterMood();
910 end
911 end
912 CastSpellByName(SMARTPET_SCATTERSHOT);
913 end
914  
915  
916 --Casts a Selected Spell on attack command
917 function SmartPetSpellAttack()
918 if (SmartPet_Config.SpellAttack == false) or (SmartPet_Config.Spell == "") then
919 return;
920 end
921 CastSpell(SmartPet_Config.Spell, SmartPet_Config.SpellBook);
922 end
923  
924 -- Toggles Taunt Management between Growl & Cower
925 function SmartPet_TauntToggle()
926 if (SmartPet_Config.UseTaunt and not (SmartPet_Actions["Detaunt"].index < 1)) then
927 SmartPet_ToggleUse(SmartPet_Actions["Detaunt"].index);
928 return;
929 end
930  
931 if (SmartPet_Config.UseDetaunt and not (SmartPet_Actions["Taunt"].index < 1)) then
932 SmartPet_ToggleUse(SmartPet_Actions["Taunt"].index);
933 end
934 end
935  
936  
937 -- Enables the specified pet ability based on available focus
938 function SmartPet_SetActionByFocus(action)
939  
940  
941 if (SmartPet_Vars.MainAction == "") then
942 if (SmartPet_Vars.InPVP) then
943 if (action == "Burst") then
944 if ((UnitMana("pet") + SmartPet_FocusRegen("Sustain")) - SmartPet_Actions[action].cost < SmartPet_Actions["Sustain"].cost) then
945 SmartPet_DisableAction(action);
946 else
947 SmartPet_EnableAction(action);
948 end
949 end
950  
951 else
952 SmartPet_EnableAction(action);
953 end
954 return;
955 end
956  
957  
958  
959 if ((UnitMana("pet") + SmartPet_FocusRegen(SmartPet_Vars.MainAction)) - SmartPet_Actions[action].cost < SmartPet_Actions[SmartPet_Vars.MainAction].cost) then
960 SmartPet_DisableAction(action);
961 else
962 SmartPet_EnableAction(action);
963 end
964 end
965  
966 -- Enables the specified pet ability
967 function SmartPet_EnableAction(action)
968 if (SmartPet_Actions[action].index < 1) then
969 return;
970 end
971 name, subtext, texture, isToken, isActive, autoCastAllowed, autoCastEnabled = GetPetActionInfo(SmartPet_Actions[action].index);
972 if (not autoCastEnabled) then
973 SmartPet_AddDebugMessage("Enabling Action: "..SmartPet_Actions[action].name, "spew");
974 TogglePetAutocast(SmartPet_Actions[action].index);
975 end
976 end
977  
978 -- Disables the specified pet ability
979 function SmartPet_DisableAction(action)
980 name, subtext, texture, isToken, isActive, autoCastAllowed, autoCastEnabled = GetPetActionInfo(SmartPet_Actions[action].index);
981 if (autoCastEnabled) then
982 SmartPet_AddDebugMessage("Disabling Action: "..SmartPet_Actions[action].name, "spew");
983 TogglePetAutocast(SmartPet_Actions[action].index);
984 end
985 end
986  
987  
988 -- Returns the estimated amount of focus that will be regen'd during this actions cooldown
989 function SmartPet_FocusRegen(action)
990 startTime, duration, enable = GetActionCooldown(SmartPet_Actions[action].index);
991 if (startTime == 0) then
992 return 0;
993 else
994 return SMARTPET_FOCUSREGEN * (duration);
995 end
996 end
997  
998 -- Initialize the pet actions for combat
999 function SmartPet_InitActions()
1000 SmartPet_UpdateActionIcons(true);
1001  
1002 SmartPet_SetActionByUse("Taunt", SmartPet_Config.UseTaunt);
1003 SmartPet_SetActionByUse("Detaunt", SmartPet_Config.UseDetaunt);
1004  
1005 if (SmartPet_Config.UseTaunt) then
1006 SmartPet_Vars.MainAction = "Taunt";
1007 elseif (SmartPet_Config.UseDetaunt) then
1008 SmartPet_Vars.MainAction = "Detaunt";
1009 else
1010 SmartPet_Vars.MainAction = "";
1011 end
1012  
1013 if (SmartPet_Config.SmartFocus and SmartPet_Config.UseBurst and SmartPet_Config.UseSustain) then
1014 SmartPet_DisableAction("Sustain");
1015 SmartPet_EnableAction("Burst");
1016 end
1017 end
1018  
1019 -- Determine if an action is to be used during this combat session
1020  
1021 -- Enables/Disables the specified pet ability based on it's .use setting
1022 function SmartPet_SetActionByUse(action, enabled)
1023 if (enabled) then
1024 SmartPet_EnableAction(action);
1025 else
1026 SmartPet_DisableAction(action);
1027 end
1028 end
1029  
1030 -- Decide to toggle a variable based on its current state, or the command string
1031 function SmartPet_ToggleOption(command, enabled)
1032 if (strfind(command, SMARTPET_ON) or strfind(command, SMARTPET_ENABLE)) then
1033 return true;
1034 elseif (strfind(command, SMARTPET_OFF) or strfind(command, SMARTPET_DISABLE)) then
1035 return false;
1036 else
1037 if (enabled) then
1038 return false;
1039 else
1040 return true;
1041 end
1042 end
1043 end
1044  
1045 -- Sends a message to the specified channel
1046 function SmartPet_SendChatMessage(message, channel)
1047 channelNumber = SmartPet_Config.ChannelNumber;
1048 channel = string.upper(SmartPet_Config.Channel);
1049  
1050 -- add additional invalid channel error checking
1051 if ((channelNumber > 0) and (channel == "CHANNEL")) then
1052 SendChatMessage(message, channel, nil, channelNumber);
1053 else
1054 if (channel == 'PARTY') then
1055 if ((UnitInParty('player')) and (UnitInParty('party1'))) then
1056 SendChatMessage(message, channel);
1057 else
1058 SmartPet_AddDebugMessage("Not In A Party", "spew");
1059 SendChatMessage(message, "SAY");
1060 end
1061 elseif (channel == 'RAID') then
1062 if ((UnitInRaid('player'))) then
1063 SendChatMessage(message, channel);
1064 else
1065 SmartPet_AddDebugMessage("Not In A RAID", "spew");
1066 SendChatMessage(message, "SAY");
1067 end
1068 elseif (channel == 'GUILD') then
1069 if (IsInGuild()) then
1070 SendChatMessage(message, channel);
1071 else
1072 SendChatMessage(message, "SAY");
1073 end
1074 else
1075 SendChatMessage(message, "SAY");
1076 end
1077 end
1078 end
1079  
1080 -- Toggles Settings
1081 function SmartPet_ToggleUse(id)
1082 if (id == SmartPet_Actions["Taunt"].index) then
1083 if (SmartPet_Config.UseTaunt or SmartPet_Config.UseDetaunt) then
1084 if (SmartPet_Config.UseTaunt) then
1085 SmartPet_Config.TauntMan = false; -- disable tauntman
1086 SmartPet_Config.UseTaunt = false; -- disable taunt
1087 else
1088 SmartPet_Config.TauntMan = true; -- enable tauntman
1089 SmartPet_Config.UseTaunt = true; -- enable taunt
1090 SmartPet_Config.UseDetaunt = false;-- disable detaunt
1091 end
1092 else
1093 SmartPet_Config.TauntMan = true; -- enable tauntman
1094 SmartPet_Config.UseTaunt = true;-- set tauntman to taunt
1095 SmartPet_Config.UseDetaunt = false;
1096 end
1097  
1098 SmartPet_SetActionByUse("Taunt", SmartPet_Config.UseTaunt);
1099 SmartPet_SetActionByUse("Detaunt", SmartPet_Config.UseDetaunt);
1100  
1101 elseif (id == SmartPet_Actions["Detaunt"].index) then
1102 if (SmartPet_Config.UseTaunt or SmartPet_Config.UseDetaunt) then
1103 if (SmartPet_Config.UseDetaunt) then
1104 SmartPet_Config.TauntMan = false; -- disable tauntman
1105 SmartPet_Config.UseDetaunt = false; -- disable taunt
1106 else
1107 SmartPet_Config.TauntMan = true; -- enable tauntman
1108 SmartPet_Config.UseDetaunt = true; -- enable taunt
1109 SmartPet_Config.UseTaunt = false;-- disable detaunt
1110 end
1111 else
1112 SmartPet_Config.TauntMan = true; -- enable tauntman
1113 SmartPet_Config.UseDetaunt = true;-- set tauntman to taunt
1114 SmartPet_Config.UseTaunt = false;
1115 end
1116  
1117 SmartPet_SetActionByUse("Taunt", SmartPet_Config.UseTaunt);
1118 SmartPet_SetActionByUse("Detaunt", SmartPet_Config.UseDetaunt);
1119  
1120 elseif (id == SmartPet_Actions["Burst"].index) then
1121 if (SmartPet_Config.UseBurst) then
1122 SmartPet_Config.UseBurst = false;
1123 else
1124 SmartPet_Config.UseBurst = true;
1125 end
1126  
1127 SmartPet_SetActionByUse("Burst", SmartPet_Config.UseBurst);
1128  
1129 elseif (id == SmartPet_Actions["Sustain"].index) then
1130 if (SmartPet_Config.UseSustain) then
1131 SmartPet_Config.UseSustain = false;
1132 else
1133 SmartPet_Config.UseSustain = true;
1134 end
1135 SmartPet_SetActionByUse("Sustain", SmartPet_Config.UseSustain);
1136  
1137 elseif (id == SmartPet_Actions["Nochase"].index) then
1138 if (SmartPet_Config.NoChase) then
1139 SmartPet_Config.NoChase = false;
1140 else
1141 SmartPet_Config.NoChase = true;
1142 PetFollow();
1143 end
1144 end
1145 SmartPet_UpdateActionIcons(true);
1146 end
1147  
1148  
1149 function SmartPet_SetupAction(name, index, enabled)
1150 local l_smartPetActionButton = getglobal("SmartPetActionButton"..index);
1151 if (enabled) then
1152 l_smartPetActionButton:SetChecked(1);
1153 else
1154 l_smartPetActionButton:SetChecked(nil);
1155 end
1156 SmartPet_Actions[name].index = index;
1157 end
1158  
1159 --Looks at icons on the pet action bar and places the check boxes above appropriate skills
1160 function SmartPet_UpdateActionIcons(resetIDs)
1161 if (resetIDs) then
1162 SmartPet_Actions["Attack"].id = 0;
1163 SmartPet_Actions["Taunt"].index = -1;
1164 SmartPet_Actions["Detaunt"].index = -1;
1165 SmartPet_Actions["Burst"].index = -1;
1166 SmartPet_Actions["Sustain"].index = -1;
1167 SmartPet_Actions["Nochase"].index = -1;
1168 SmartPet_Actions["Dash"].index = -1;
1169 SmartPet_Actions["Dive"].index = -1;
1170 end
1171  
1172 for index=1, NUM_PET_ACTION_SLOTS, 1 do
1173 local name, subtext, texture, isToken, isActive, autoCastAllowed, autoCastEnabled = GetPetActionInfo(index);
1174 local l_petActionButton = getglobal("SmartPetActionButton"..index);
1175  
1176 if (not SmartPet_Config.Enabled) then
1177 l_petActionButton:Hide();
1178 elseif (name == SmartPet_Actions["Taunt"].name) then
1179 l_petActionButton:Show();
1180 SmartPet_SetupAction("Taunt", index, SmartPet_Config.UseTaunt);
1181 elseif (name == SmartPet_Actions["Detaunt"].name) then
1182 l_petActionButton:Show();
1183 SmartPet_SetupAction("Detaunt", index, SmartPet_Config.UseDetaunt);
1184 elseif (name == SmartPet_Actions["Burst"].name) then
1185 if (SmartPet_Config.TauntMan or SmartPet_Config.SmartFocus) then
1186 l_petActionButton:Show();
1187 else
1188 l_petActionButton:Hide();
1189 end
1190 SmartPet_SetupAction("Burst", index, SmartPet_Config.UseBurst);
1191 elseif (name == SmartPet_Actions["Sustain"].name) then
1192 if (SmartPet_Config.TauntMan or SmartPet_Config.SmartFocus) then
1193 l_petActionButton:Show();
1194 else
1195 l_petActionButton:Hide();
1196 end
1197 SmartPet_SetupAction("Sustain", index, SmartPet_Config.UseSustain);
1198  
1199 elseif (name == SmartPet_Actions["Nochase"].name) then
1200 l_petActionButton:Show();
1201 SmartPet_SetupAction("Nochase", index, SmartPet_Config.NoChase);
1202  
1203 elseif (name == SmartPet_Actions["Attack"].name) then
1204 --DEFAULT_CHAT_FRAME:AddMessage("attack Found");
1205  
1206 SmartPet_Actions["Attack"].id = index;
1207  
1208  
1209 else
1210 l_petActionButton:Hide();
1211 end
1212 end
1213  
1214 if (resetIDs) then
1215 if (SmartPet_Actions["Taunt"].index < 1) then
1216 SmartPet_Config.UseTaunt = false;
1217 end
1218 if (SmartPet_Actions["Detaunt"].index < 1) then
1219 SmartPet_Config.UseDetaunt = false;
1220 end
1221 if (SmartPet_Actions["Burst"].index < 1) then
1222 SmartPet_Config.UseBurst = false;
1223 end
1224 if (SmartPet_Actions["Sustain"].index < 1) then
1225 SmartPet_Config.UseSustain = false;
1226 end
1227 if (not SmartPet_Config.UseTaunt and not SmartPet_Config.UseDetaunt) then
1228 SmartPet_Config.TauntMan = false;
1229 end
1230 end
1231 end
1232  
1233  
1234 --Resets values to factory defaults
1235 function SmartPet_ResetConfig()
1236 SmartPet_Config.Enabled = true; --SmartPet On/Off
1237 SmartPet_Config.Version = SMARTPET_VERSION; --Version of SmartPet Running
1238 SmartPet_Config.AcceptedClass = false; --Is Player a class that can use SmartPet
1239 SmartPet_Config.ToolTips = true; --ToolTip On/Off
1240 SmartPet_Config.Icon = true; --Icon on pet bar On/Off
1241  
1242 SmartPet_Config.TauntMan = true; --Use Taunt Management ON/Off
1243 SmartPet_Config.SmartFocus = true; --Use SmartFocus
1244 SmartPet_Config.WarnHealth = 30; --% of pets health to start warning
1245 SmartPet_Config.AutoWarn = false; --Give Warning if pet is hurt
1246 SmartPet_Config.CowerHealth = 30; --% of pets health to start cowering at
1247 SmartPet_Config.AutoCower = false; --Autocower On/Off
1248 SmartPet_Config.ShowDebug = false; --Display Debug Info
1249 SmartPet_Config.Channel = "say"; --Type of channel to give warning on
1250 SmartPet_Config.ChannelNumber = 0; --Specific numeric channel to use
1251 SmartPet_Config.NoChase = true; --NoChase On/Off
1252 SmartPet_Config.RecallWarn = true; --Displays Recall Warnings
1253  
1254 SmartPet_Config.UseTaunt = false; --Always use Pets Taunt Skill
1255 SmartPet_Config.UseDetaunt = false; --Always use Pets Detaunt Skill
1256 SmartPet_Config.UseBurst = false; --Ulse Pets Burst Damge Skill
1257 SmartPet_Config.UseSustain = false; --Use Pets Sustained Damage Skill
1258  
1259 SmartPet_Config.ShowDebugString = ""; --Type of Debug message being shown
1260 SmartPet_Config.RushAttack = true; --Use Dash/Dive on attacking
1261 SmartPet_Config.Alert = false; --Say an allert on attacking
1262  
1263 SmartPet_Config.Scatter = true; --Have pet break off combat on use of Scatter Shot\
1264 SmartPet_Config.ScatterMood = PetPassiveMode; --Mood to set on Scatter Shot [Passive/Defensive]
1265 SmartPet_Config.ScatterOrder = PetFollow; --Command to set on Scatter Shot [Stay/Follow]
1266  
1267 SmartPet_Config.SpellAttack = false; --Cast a spell when atcking
1268 SmartPet_Config.Spell = ""; --Id of Spell to cast
1269 SmartPet_Config.SpellBook = ""; --Id of Spellbook to be cast
1270  
1271 end
1272  
1273  
1274 function SmartPetTheButton()
1275 if (SmartPet_Vars.TheButton == "recall" ) then
1276 PetFollow();
1277 SmartPet_Vars.TheButton = "";
1278 else
1279 PetAttack();
1280 end
1281 end
1282  
1283 --function SmartPetHeal();
1284  
1285  
1286 Mend={};
1287 Mend[7]={mana=480; health = 245};
1288 Mend[6]={mana=385; health = 189};
1289 Mend[5]={mana=300; health = 142};
1290 Mend[4]={mana=225; health = 245};
1291 Mend[3]={mana=155; health = 68};
1292 Mend[2]={mana=90; health = 38};
1293 Mend[1]={mana=50; health = 20};