vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2  
3 HealBot Contined
4  
5 ]]
6  
7 local _scale=0;
8 local CalcEquipBonus=false;
9 local InitCalcEquipBonus=false;
10 local FlagEquipUpdate1=1;
11 local FlagEquipUpdate2=1;
12 local NeedEquipUpdate=0;
13 local HealValue=0;
14 local InitSpells=1;
15 local DebugDebuff=false;
16 local Delay_RecalcParty=0;
17  
18  
19 function HealBot_AddChat(msg)
20 local chanid=HealBot_Get_DebugChan();
21 if chanid and HealBot_SpamCnt < 3 then
22 HealBot_SpamCnt=HealBot_SpamCnt+1;
23 local hour,minute = GetGameTime();
24 if minute==0 then
25 msg="["..hour..":00] "..msg;
26 elseif minute<10 then
27 msg="["..hour..":0"..minute.."] "..msg;
28 else
29 msg="["..hour..":"..minute.."] "..msg;
30 end
31 SendChatMessage(msg , "CHANNEL", nil, chanid);
32 elseif ( DEFAULT_CHAT_FRAME ) then
33 DEFAULT_CHAT_FRAME:AddMessage(msg);
34 end
35 end
36  
37  
38 function HealBot_AddDebug(msg)
39 local chanid=HealBot_Get_DebugChan();
40 if chanid and HealBot_SpamCnt < 3 then
41 HealBot_SpamCnt=HealBot_SpamCnt+1;
42 local hour,minute = GetGameTime();
43 if minute==0 then
44 msg="["..hour..":00] DEBUG: "..msg;
45 elseif minute<10 then
46 msg="["..hour..":0"..minute.."] DEBUG: "..msg;
47 else
48 msg="["..hour..":"..minute.."] DEBUG: "..msg;
49 end
50 SendChatMessage(msg , "CHANNEL", nil, chanid);
51 end
52 end
53  
54 function HealBot_Report_Error(msg)
55 if HealBot_ErrorCnt<28 then
56 HealBot_ErrorCnt=HealBot_ErrorCnt+1;
57 ShowUIPanel(HealBot_Error);
58 HealBot_ErrorsIn(msg,HealBot_ErrorCnt);
59 end
60 end
61  
62 function HealBot_AddError(msg)
63 UIErrorsFrame:AddMessage(msg, 1.0, 1.0, 1.0, 1.0, UIERRORS_HOLD_TIME);
64 HealBot_AddDebug(msg);
65 end
66  
67 function HealBot_TogglePanel(panel)
68 if (not panel) then return end
69 if ( panel:IsVisible() ) then
70 HideUIPanel(panel);
71 else
72 ShowUIPanel(panel);
73 end
74 end
75  
76 function HealBot_StartMoving(frame)
77 if ( not frame.isMoving ) and ( frame.isLocked ~= 1 ) then
78 frame:StartMoving();
79 frame.isMoving = true;
80 end
81 end
82  
83 function HealBot_StopMoving(frame)
84 if ( frame.isMoving ) then
85 frame:StopMovingOrSizing();
86 frame.isMoving = false;
87 end
88 if HealBot_Config.GrowUpwards==1 then
89 local left,bottom = HealBot_Action:GetLeft(),HealBot_Action:GetBottom();
90 if left and bottom then
91 HealBot_Config.PanelAnchorX=left;
92 HealBot_Config.PanelAnchorY=bottom;
93 end
94 -- HealBot_AddDebug("Pos X="..HealBot_Config.PanelAnchorX.." Pos Y="..HealBot_Config.PanelAnchorY)
95 end
96  
97 end
98  
99 function HealBot_SlashCmd(cmd)
100 if (cmd=="") then
101 HealBot_TogglePanel(HealBot_Action);
102 return
103 end
104 if (cmd=="options" or cmd=="opt" or cmd=="config" or cmd=="cfg") then
105 HealBot_TogglePanel(HealBot_Options);
106 return
107 end
108  
109 if (cmd=="reset" or cmd=="recalc" or cmd=="defaults") then
110 initSpells=2;
111 HealBot_Options_Defaults_OnClick(HealBot_Options_Defaults);
112 return
113 end
114 if (cmd=="ui") then
115 ReloadUI();
116 return;
117 end
118 if (cmd=="init") then
119 HealBot_RegisterThis(this);
120 end
121 if (cmd=="x") then
122 initSpells=2;
123 NeedEquipUpdate=1
124 HealBot_RecalcSpells();
125 return;
126 end
127 if (cmd=="ver") then
128 local text=UnitName("player");
129 SendAddonMessage( "HealBot", ">> RequestVersion <<=>> "..text.." <<=>> nil <<", "RAID" );
130 return;
131 end
132 if (cmd=="chan") then
133 HealBot_AddDebug( "Channel active" );
134 return;
135 end
136 end
137  
138 function HealBot_TargetName()
139 if UnitIsEnemy("target","player") then return nil end
140 -- if not UnitPlayerControlled("target") then return nil end
141 if (UnitIsPlayer("target")) then
142 if UnitIsUnit("target","player") then return "player" end
143 if (UnitInParty("target")) then
144 for i=1,4 do
145 if UnitIsUnit("target","party"..i) then return "party"..i end
146 end
147 end
148 if (UnitInRaid("target")) then
149 for i=1,40 do
150 if UnitIsUnit("target","raid"..i) then return "raid"..i end
151 end
152 end
153 else
154 if UnitIsUnit("target","pet") then return "pet" end
155 if (UnitInParty("player")) then
156 for i=1,4 do
157 if UnitIsUnit("target","partypet"..i) then return "partypet"..i end
158 end
159 end
160 if (UnitInRaid("player")) then
161 for i=1,40 do
162 if UnitIsUnit("target","raidpet"..i) then return "raidpet"..i end
163 end
164 end
165 end
166 return nil
167 end
168  
169  
170  
171 function HealBot_PackBagSlot(bag,slot)
172 return bag*100+slot;
173 end
174  
175 function HealBot_UnpackBagSlot(bagslot)
176 return math.floor(bagslot/100),math.mod(bagslot,100);
177 end
178  
179 function HealBot_GetItemName(bag,slot)
180 local link = GetContainerItemLink(bag,slot);
181 if not link then return nil end;
182 local _,_,item = string.find(link,"%[(.*)%]");
183 local _,count = GetContainerItemInfo(bag,slot);
184 return item,count;
185 end
186  
187 function HealBot_GetBagSlot(item)
188 local BagSlot,BestCount;
189 for bag=0,NUM_BAG_FRAMES do
190 for slot=1,GetContainerNumSlots(bag) do
191 local bagitem,count = HealBot_GetItemName(bag,slot);
192 if (item==bagitem) then
193 if not BestCount or BestCount>count then
194 BagSlot = HealBot_PackBagSlot(bag,slot);
195 BestCount = count;
196 end
197 end
198 end
199 end
200 return BagSlot;
201 end
202  
203 function HealBot_UseItem(item)
204 local bagslot = HealBot_GetBagSlot(item);
205 if not bagslot then return end;
206 local bag,slot = HealBot_UnpackBagSlot(bagslot);
207 local Link = GetContainerItemLink(bag,slot);
208 UseContainerItem(bag,slot);
209 end
210  
211 function HealBot_GetSpellName(id)
212 if (not id) then
213 return nil;
214 end
215 local spellName, subSpellName = GetSpellName(id,BOOKTYPE_SPELL);
216 if (not spellName) then
217 return nil;
218 end
219 if (not subSpellName or subSpellName=="") then
220 return spellName;
221 end
222 return spellName .. "(" .. subSpellName .. ")";
223 end
224  
225 function HealBot_GetSpellId(spell)
226 local id,idd = 1,0;
227 while true do
228 local spellName, subSpellName = GetSpellName(id,BOOKTYPE_SPELL);
229 if (spellName) then
230 if (spell == spellName .. " (" .. subSpellName .. ")") or (spell == spellName .. "(" .. subSpellName .. ")") then
231 return id;
232 end
233 if (spell == spellName) then
234 idd=id;
235 end
236 else
237 do break end
238 end
239 id = id + 1;
240 end
241 if idd>0 then
242 return idd
243 else
244 return nil;
245 end
246 end
247  
248 function HealBot_CastSpellByName(spell)
249 if (HealBot_Spells[spell] and HealBot_Spells[spell].BagSlot) then
250 HealBot_UseItem(spell);
251 return;
252 end
253 local id;
254 if not HealBot_Spells[spell] then
255 id = HealBot_GetSpellId(spell);
256 elseif HealBot_Spells[spell].id then
257 id = HealBot_Spells[spell].id
258 else
259 id = HealBot_GetSpellId(spell);
260 end
261 if (not id) then
262 return;
263 end
264 CastSpell(id,BOOKTYPE_SPELL);
265 end
266  
267 HealBot_CastingSpell = nil;
268 HealBot_CastingTarget = nil;
269  
270 function HealBot_StartCasting(spell,target,ttype)
271 HealBot_CastSpellByName(spell);
272 HealBot_CastingSpell = spell;
273 HealBot_CastingTarget = target;
274 if ( SpellCanTargetUnit(target) ) then
275 SpellTargetUnit(target);
276 ttype="fired";
277 elseif SpellIsTargeting() then
278 SpellTargetUnit(target);
279 SpellStopTargeting()
280 elseif ttype=="direct" then
281 if ( CheckInteractDistance(target, 4) ) then
282 ttype="fired";
283 end
284 end
285  
286 if HealBot_Config.CastNotify>1 then
287 if target=="target" then target = HealBot_TargetName() or "target" end
288 local Notify = HealBot_Config.CastNotify;
289 if Notify==5 and GetNumRaidMembers()==0 then Notify = 4 end
290 if Notify==4 and GetNumPartyMembers()==0 then Notify = 3 end
291 if Notify==3 and not (UnitPlayerControlled(target) and target~='player' and target~='pet') then Notify = 2 end
292 if Notify==3 then
293 SendChatMessage(string.format(HEALBOT_CASTINGSPELLONYOU,spell),"WHISPER",nil,UnitName(target));
294 elseif Notify==4 then
295 SendChatMessage(string.format(HEALBOT_CASTINGSPELLONUNIT,spell,UnitName(target)),"PARTY",nil,nil);
296 elseif Notify==5 then
297 SendChatMessage(string.format(HEALBOT_CASTINGSPELLONUNIT,spell,UnitName(target)),"RAID",nil,nil);
298 else
299 HealBot_AddChat(string.format(HEALBOT_CASTINGSPELLONUNIT,spell,UnitName(target)));
300 end
301 end
302 if ttype=="fired" and HealBot_Spells[spell] then
303 -- if not HealBot_Spells[spell].CastTime then
304 -- if HealBot_Spells[spell].id then
305 -- HealBot_InitGetSpellData(spell, HealBot_Spells[spell].id, HealBot_UnitClass("player"))
306 -- HealBot_AddDebug("Requested init spell data for "..spell)
307 -- end
308 -- if not HealBot_Spells[spell].CastTime then
309 -- HealBot_Spells[spell].CastTime=0
310 -- HealBot_AddDebug("Unable to init spell data for "..spell)
311 -- InitSpells=2;
312 -- return
313 -- end
314 -- end
315 if HealBot_Spells[spell].CastTime > 1 then
316 HealValue=HealBot_Spells[spell].HealsDur;
317 SendAddonMessage( HEALBOT_ADDON_ID, ">> "..UnitName(target).." <<=>> "..HealValue.." << ", "RAID" );
318 end
319 end
320 end
321  
322 function HealBot_StopCasting()
323 if HealBot_CastingTarget then
324 if HealBot_HealsIn[UnitName(HealBot_CastingTarget)] then
325 if HealValue > 0 then
326 SendAddonMessage( HEALBOT_ADDON_ID, ">> "..UnitName(HealBot_CastingTarget).." <<=>> "..0-HealValue.." << ", "RAID" );
327 HealValue=0;
328 end
329 end
330 end
331 HealBot_CastingSpell = nil;
332 HealBot_CastingTarget = nil;
333 local bar = HealBot_Action_HealthBar(HealBot_Action_AbortButton);
334 local ar=HealBot_Config.babortcolr[HealBot_Config.Current_Skin] or 0.1;
335 local ag=HealBot_Config.babortcolg[HealBot_Config.Current_Skin] or 0.1;
336 local ab=HealBot_Config.babortcolb[HealBot_Config.Current_Skin] or 0.5;
337 local aa=HealBot_Config.babortcola[HealBot_Config.Current_Skin] or 1;
338 bar.txt = getglobal(bar:GetName().."_text"); bar:SetStatusBarColor(ar,ag,ab,0);
339 local sr=HealBot_Config.btextdisbledcolr[HealBot_Config.Current_Skin];
340 local sg=HealBot_Config.btextdisbledcolg[HealBot_Config.Current_Skin];
341 local sb=HealBot_Config.btextdisbledcolb[HealBot_Config.Current_Skin];
342 local sa=HealBot_Config.btextdisbledcola[HealBot_Config.Current_Skin];
343 bar.txt:SetTextColor(sr,sg,sb,sa);
344 end
345  
346  
347 local HealBot_Health60 = {
348 ["DRUID"] = 3500,
349 ["MAGE"] = 2500,
350 ["HUNTER"] = 3500,
351 ["PALADIN"] = 4000,
352 ["PRIEST"] = 2500,
353 ["ROGUE"] = 3500,
354 ["SHAMAN"] = 3800,
355 ["WARLOCK"] = 3500,
356 ["WARRIOR"] = 5000,
357 }
358 function HealBot_UnitHealth(unit)
359 local Current,Desired = UnitHealth(unit),UnitHealthMax(unit);
360 if unit=='target' and Desired==100 then
361 local class,level = HealBot_UnitClass(unit),UnitLevel(unit);
362 if HealBot_Health60[class] and level>0 then
363 Desired = math.floor(HealBot_Health60[class]/60*level+0.5)
364 else
365 Desired = UnitHealthMax('player');
366 end
367 Current = Desired/100*Current;
368 end
369 return Current,Desired;
370 end
371  
372 function HealBot_CheckCasting(unit)
373 if not HealBot_CastingSpell or HealBot_AlwaysHeal() then return nil end
374 if not HealBot_Spells[HealBot_CastingSpell] then return nil end
375 if not unit then unit = HealBot_CastingTarget end
376 if unit~=HealBot_CastingTarget then return nil end
377  
378 local bar = HealBot_Action_HealthBar(HealBot_Action_AbortButton);
379 local ar=HealBot_Config.babortcolr[HealBot_Config.Current_Skin] or 0.1;
380 local ag=HealBot_Config.babortcolg[HealBot_Config.Current_Skin] or 0.1;
381 local ab=HealBot_Config.babortcolb[HealBot_Config.Current_Skin] or 0.5;
382 local aa=HealBot_Config.babortcola[HealBot_Config.Current_Skin] or 1;
383 bar.txt = getglobal(bar:GetName().."_text");
384  
385 if HealBot_IsCasting==false and HealBot_AbortButton==0 then
386 bar:SetStatusBarColor(ar,ag,ab,0);
387 local sr=HealBot_Config.btextdisbledcolr[HealBot_Config.Current_Skin];
388 local sg=HealBot_Config.btextdisbledcolg[HealBot_Config.Current_Skin];
389 local sb=HealBot_Config.btextdisbledcolb[HealBot_Config.Current_Skin];
390 local sa=HealBot_Config.btextdisbledcola[HealBot_Config.Current_Skin];
391 bar.txt:SetTextColor(sr,sg,sb,sa);
392 return nil
393 end
394  
395 local Current,Desired = HealBot_UnitHealth(unit)
396 local Needed = Desired-Current;
397 Needed = Needed * (1 + (HealBot_Config.OverHeal*4));
398 if Needed<0 then Needed = 0 end
399 if (Needed>HealBot_Spells[HealBot_CastingSpell].HealsDur) then
400 local sr=HealBot_Config.btextdisbledcolr[HealBot_Config.Current_Skin];
401 local sg=HealBot_Config.btextdisbledcolg[HealBot_Config.Current_Skin];
402 local sb=HealBot_Config.btextdisbledcolb[HealBot_Config.Current_Skin];
403 local sa=HealBot_Config.btextdisbledcola[HealBot_Config.Current_Skin];
404 bar.txt:SetTextColor(sr,sg,sb,sa);
405 bar:SetStatusBarColor(ar,ag,ab,0);
406 return nil
407 elseif HealBot_AbortButton==1 and HealBot_IsCasting==true then
408  
409 bar:SetStatusBarColor(ar,ag,ab,aa);
410 local sr=HealBot_Config.btextenabledcolr[HealBot_Config.Current_Skin];
411 local sg=HealBot_Config.btextenabledcolg[HealBot_Config.Current_Skin];
412 local sb=HealBot_Config.btextenabledcolb[HealBot_Config.Current_Skin];
413 local sa=HealBot_Config.btextenabledcola[HealBot_Config.Current_Skin];
414 bar.txt = getglobal(bar:GetName().."_text");
415 bar.txt:SetTextColor(sr,sg,sb,sa);
416 end
417 end
418  
419 function HealBot_CastSpellOnFriend(spell,target)
420 local old;
421 local ttype="other";
422 if (not spell or not target or not UnitName(target)) then
423 return;
424 end
425 if (UnitCanAttack("player","target")) then
426 old = "enemy";
427 else
428 old = UnitName("target");
429 if UnitName("target")~=UnitName(target) then
430 ClearTarget();
431 else
432 ttype="direct";
433 end
434 end
435 HealBot_StartCasting(spell,target,ttype);
436 if (old=="enemy") then
437 TargetLastEnemy();
438 elseif (old) then
439 TargetByName(old);
440 else
441 ClearTarget();
442 end
443 end
444  
445 function HealBot_UnitClass(unit)
446 local playerClass, englishClass = UnitClass(unit);
447 return englishClass;
448 end
449  
450 -- TBD: use the event UNIT_AURA to keep track instead of querying each time
451  
452 function HealBot_UnitAffected(unit,effect)
453 if not effect then return nil; end
454 local i = 1
455 while true do
456 local buff = UnitBuff(unit,i)
457 if not buff then
458 do break end
459 end
460 if buff==effect then
461 return buff
462 end
463 i = i + 1
464 end
465 i = 1
466 while true do
467 local debuff = UnitDebuff(unit,i)
468 if not debuff then
469 do break end
470 end
471 if debuff==effect then
472 return debuff
473 end
474 i = i + 1
475 end
476 return nil;
477 end
478 -- safer to use GameTooltip:SetUnitBuff and read the lines in the tooltip ...
479 -- maybe make an additional GameTooltip frame if possible ?
480  
481 function HealBot_SetItemDefaults(spell)
482 if not HealBot_Spells[spell].Target then
483 HealBot_Spells[spell].Target = {"player","party","pet"};
484 end
485 if not HealBot_Spells[spell].Price then
486 HealBot_Spells[spell].Price = 0;
487 end
488 if not HealBot_Spells[spell].CastTime then
489 HealBot_Spells[spell].CastTime = 0;
490 end
491 if not HealBot_Spells[spell].Mana then
492 HealBot_Spells[spell].Mana = 0;
493 end
494 if not HealBot_Spells[spell].Channel then
495 HealBot_Spells[spell].Channel = HealBot_Spells[spell].CastTime;
496 end
497 if not HealBot_Spells[spell].Duration then
498 HealBot_Spells[spell].Duration = HealBot_Spells[spell].Channel;
499 end
500 if not HealBot_Spells[spell].HealsMin then
501 HealBot_Spells[spell].HealsMin = 0;
502 end
503 if not HealBot_Spells[spell].HealsMax then
504 HealBot_Spells[spell].HealsMax = 0;
505 end
506 HealBot_Spells[spell].RealHealing=0;
507 HealBot_Spells[spell].HealsCast = (HealBot_Spells[spell].HealsMin+HealBot_Spells[spell].HealsMax)/2;
508 if not HealBot_Spells[spell].HealsExt then
509 HealBot_Spells[spell].HealsExt = 0;
510 end
511 end
512  
513 function HealBot_SetSpellDefaults(spell)
514 HealBot_Spells[spell].HealsDur = floor((HealBot_Spells[spell].HealsCast+HealBot_Spells[spell].HealsExt) + HealBot_Spells[spell].RealHealing);
515 end
516  
517 function HealBot_AddHeal(spell)
518 HealBot_SetSpellDefaults(spell);
519 table.foreachi(HealBot_Spells[spell].Target,function (i,val)
520 table.insert(HealBot_Heals[val],spell);
521 end);
522 HealBot_Spells[spell].BagSlot = HealBot_GetBagSlot(spell);
523 end
524  
525  
526 function HealBot_FindHealSpells()
527 local id = 1;
528 if InitSpells>0 then NeedEquipUpdate=1; return; end
529  
530 HealBot_Heals = { player = {}, pet = {}, party = {} };
531  
532 table.foreach(HealBot_CurrentSpells, function (index,spell)
533 if (HealBot_Spells[spell]) then
534 if CalcEquipBonus then
535 local healingbonus_penalty=1;
536 if HealBot_Spells[spell].Level < 20 then
537 healingbonus_penalty=(1-((20-HealBot_Spells[spell].Level)*0.0375));
538 end
539 local temp_Spell_cast=3.5;
540 if HealBot_Spells[spell].CastTime == 0 then
541 temp_Spell_cast=3.5;
542 end
543 if not HealBot_Spells[spell].CastTime then
544 -- HealBot_SetOldDefaults(spell);
545 -- HealBot_Report_Error( "================================" );
546 -- HealBot_Report_Error( "ERROR: HealBot_Spells[spell].CastTime == nil" );
547 -- HealBot_Report_Error( "ERROR: spell = "..spell );
548 HealBot_Spells[spell].CastTime = 1.5;
549 end
550 if HealBot_Spells[spell].CastTime >= 1.5 and HealBot_Spells[spell].CastTime < 3.5 then
551 temp_Spell_cast=HealBot_Spells[spell].CastTime;
552 end
553 RealHealing = ((HealBot_GetBonus() * healingbonus_penalty) * (temp_Spell_cast/3.5));
554 local playerClass, englishClass = UnitClass("player");
555 local SpiBonus = 0;
556 if (englishClass=="PRIEST") then
557 SpiBonus = ((HealBot_SpiBonus(spell) * healingbonus_penalty) * (temp_Spell_cast/3.5))
558 RealHealing = RealHealing + SpiBonus;
559 end
560 RealHealing = floor(RealHealing);
561 HealBot_Spells[spell].RealHealing = RealHealing;
562 end
563 HealBot_AddHeal(spell);
564 end
565 end);
566  
567 local items = {};
568 for bag=0,NUM_BAG_FRAMES do
569 for slot=1,GetContainerNumSlots(bag) do
570 local item = HealBot_GetItemName(bag,slot);
571 if HealBot_Spells[item] and not items[item] then
572 HealBot_SetItemDefaults(item);
573 HealBot_AddHeal(item);
574 items[item] = 1;
575 end
576 end
577 end
578 table.foreach(HealBot_Heals, function (key,val)
579 if (table.getn(val)==0) then
580 HealBot_Heals[key] = nil;
581 end
582 end);
583 HealBot_Heals.target = HealBot_Heals.party;
584 for i=1,4 do
585 HealBot_Heals["party"..i] = HealBot_Heals.party;
586 HealBot_Heals["partypet"..i] = HealBot_Heals.party;
587 end
588 for i=1,40 do
589 HealBot_Heals["raid"..i] = HealBot_Heals.party;
590 HealBot_Heals["raidpet"..i] = HealBot_Heals.party;
591 end
592  
593 table.foreach(HealBot_Heals, function (key,val)
594 table.foreachi(val, function (i,val)
595 end);
596 end);
597 if CalcEquipBonus then
598 HealBot_AddDebug("...Done Equip Bonus:"..RealHealing);
599 end
600 CalcEquipBonus=false;
601 end
602  
603  
604 function HealBot_GetShapeshiftForm()
605 local forms = GetNumShapeshiftForms();
606 if forms then
607 local i;
608 for i=1,forms do
609 local icon,name,active = GetShapeshiftFormInfo(i);
610 if active and not string.find(icon,"HumanoidForm") then return i; end
611 end
612 end
613 return nil;
614 end
615  
616 function HealBot_CanCastSpell(spell,unit)
617 local this = HealBot_Spells[spell];
618 if this.Mana>UnitMana("player") then return false end;
619 if this.BagSlot then
620 local bag,slot = HealBot_UnpackBagSlot(this.BagSlot);
621 local start, duration, enable = GetContainerItemCooldown(bag,slot);
622 if (start > 0 and duration > 0 and enable > 0) then
623 return false;
624 end
625 end
626 return true;
627 end
628  
629  
630 function HealBot_GetHealSpell(unit,pattern)
631 if (not UnitName(unit)) then return nil end;
632 if UnitOnTaxi("player") then return nil end;
633 if HealBot_Config.ProtectPvP==1 and UnitIsPVP(unit) and not UnitIsPVP("player") then return nil end
634 if HealBot_UnitClass("player")=="DRUID" then
635 if HealBot_GetShapeshiftForm() then return nil end;
636 end
637 local spell = HealBot_GetSpellName(HealBot_GetSpellId(pattern))
638 local range=40;
639 if HealBot_Spells[spell] then
640 if not HealBot_CanCastSpell(spell,unit) then return nil end;
641 range=HealBot_Spells[spell].range;
642 end
643 if HealBot_Range_Check(unit, range)==0 then return nil end;
644 return spell;
645 end
646  
647 function HealBot_HealUnit(unit,pattern)
648 HealBot_CastSpellOnFriend(HealBot_GetHealSpell(unit,pattern),unit);
649 end
650  
651 function HealBot_RecalcHeals(unit)
652 HealBot_Action_Refresh(unit);
653 end
654  
655 function HealBot_RecalcParty()
656 HealBot_Action_PartyChanged();
657 HealBot_Action_RefreshButtons();
658 end
659  
660 function HealBot_RecalcSpells()
661 HealBot_FindHealSpells();
662 HealBot_RecalcParty();
663 end
664  
665 --------------------------------------------------------------------------------------------------
666 -- OnFoo functions
667 --------------------------------------------------------------------------------------------------
668  
669 function HealBot_OnLoad(this)
670 this:RegisterEvent("VARIABLES_LOADED");
671  
672 SLASH_HEALBOT1 = "/healbot";
673 SLASH_HEALBOT2 = "/hb";
674 SlashCmdList["HEALBOT"] = function(msg)
675 HealBot_SlashCmd(msg);
676 end
677 HealBot_AddError(HEALBOT_ADDON .. HEALBOT_LOADED);
678 end
679  
680 function HealBot_RegisterThis(this)
681  
682 end
683  
684 local HealBot_Timer1,HealsIn_Timer = 0,0;
685 function HealBot_OnUpdate(this,arg1)
686 HealBot_Timer1 = HealBot_Timer1+arg1;
687 if HealBot_Timer1>=2.5 then
688 if not HealBot_IsFighting then
689 HealsIn_Timer=HealsIn_Timer+1;
690 if HealsIn_Timer>=10 then
691 HealBot_HealsIn={};
692 HealBot_Healers={};
693 HealsIn_Timer=0;
694 InitCalcEquipBonus=true
695 end
696 if FlagEquipUpdate1>0 and FlagEquipUpdate2>0 then
697 FlagEquipUpdate1=0;
698 FlagEquipUpdate2=0;
699 NeedEquipUpdate=1;
700 elseif FlagEquipUpdate1>0 then
701 FlagEquipUpdate1=FlagEquipUpdate1+1;
702 if FlagEquipUpdate1>1 then
703 FlagEquipUpdate1=0;
704 end
705 elseif FlagEquipUpdate2>0 then
706 FlagEquipUpdate2=FlagEquipUpdate2+1;
707 if FlagEquipUpdate2>1 then
708 FlagEquipUpdate2=0;
709 end
710 end
711 if NeedEquipUpdate>0 and InitCalcEquipBonus then
712 NeedEquipUpdate=NeedEquipUpdate+1;
713 if NeedEquipUpdate>1 then
714 HealBot_BonusScanner:ScanEquipment()
715 CalcEquipBonus=true;
716 InitCalcEquipBonus=false;
717 NeedEquipUpdate=0;
718 HealBot_RecalcSpells();
719 end
720 end
721 if InitSpells>1 then
722 InitSpells=InitSpells+1;
723 if InitSpells>2 then
724 local cnt=HealBot_InitSpells();
725 InitSpells=0;
726 InitCalcEquipBonus=true;
727 end
728 end
729 if Delay_RecalcParty>0 then
730 Delay_RecalcParty=Delay_RecalcParty+1
731 if Delay_RecalcParty>1 then
732 Delay_RecalcParty=0;
733 HealBot_RecalcParty();
734 end
735 end
736 else
737 HealsIn_Timer=0;
738 end
739 HealBot_Timer1 = 0;
740 HealBot_SpamCnt = 0;
741 end
742 end
743  
744 function HealBot_OnEvent(this, event, arg1,arg2,arg3,arg4)
745 if (event=="CHAT_MSG_ADDON") then
746 HealBot_OnEvent_AddonMsg(this,arg1,arg2,arg3,arg4);
747 elseif (event=="UNIT_HEALTH") then
748 HealBot_OnEvent_UnitHealth(this,arg1);
749 elseif (event=="UNIT_MANA") then
750 HealBot_OnEvent_UnitMana(this,arg1);
751 elseif (event=="UNIT_AURA") then
752 HealBot_OnEvent_UnitAura(this,arg1);
753 elseif (event=="SPELLCAST_START") then
754 HealBot_OnEvent_SpellcastStart(this,arg1,arg2);
755 elseif (event=="SPELLCAST_STOP") then
756 HealBot_OnEvent_SpellcastStop(this);
757 elseif (event=="SPELLCAST_INTERRUPTED") then
758 HealBot_OnEvent_SpellcastStop(this);
759 elseif (event=="SPELLCAST_FAILED") then
760 HealBot_OnEvent_SpellcastStop(this);
761 elseif (event=="PLAYER_REGEN_DISABLED") then
762 HealBot_OnEvent_PlayerRegenDisabled(this);
763 elseif (event=="PLAYER_REGEN_ENABLED") then
764 HealBot_OnEvent_PlayerRegenEnabled(this);
765 elseif (event=="BAG_UPDATE_COOLDOWN") then
766 HealBot_OnEvent_BagUpdateCooldown(this,arg1);
767 elseif (event=="BAG_UPDATE") then
768 HealBot_OnEvent_BagUpdate(this,arg1);
769 elseif (event=="PARTY_MEMBER_DISABLE") then
770 HealBot_OnEvent_PartyMemberDisable(this,arg1);
771 elseif (event=="PARTY_MEMBER_ENABLE") then
772 HealBot_OnEvent_PartyMemberEnable(this,arg1);
773 elseif (event=="CHAT_MSG_SYSTEM") then
774 HealBot_OnEvent_SystemMsg(this,arg1);
775 elseif (event=="PARTY_MEMBERS_CHANGED") then
776 HealBot_OnEvent_PartyMembersChanged(this);
777 elseif (event=="PLAYER_TARGET_CHANGED") then
778 HealBot_OnEvent_PlayerTargetChanged(this);
779 elseif (event=="ZONE_CHANGED_NEW_AREA") then
780 HealBot_OnEvent_ZoneChanged(this);
781 elseif (event=="UPDATE_INVENTORY_ALERTS") then
782 HealBot_OnEvent_PlayerEquipmentChanged(this);
783 elseif (event=="UNIT_INVENTORY_CHANGED") then
784 HealBot_OnEvent_PlayerEquipmentChanged2(this,arg1);
785 elseif (event=="PET_BAR_SHOWGRID") then
786 HealBot_OnEvent_PartyMembersChanged(this);
787 elseif (event=="PET_BAR_HIDEGRID") then
788 HealBot_OnEvent_PartyMembersChanged(this);
789 elseif (event=="SPELLS_CHANGED") then
790 HealBot_OnEvent_SpellsChanged(this,arg1);
791 elseif (event=="PLAYER_ENTERING_WORLD") then
792 HealBot_OnEvent_PlayerEnteringWorld(this);
793 -- elseif (event=="CHARACTER_POINTS_CHANGED") then
794 -- HealBot_OnEvent_TalentsChanged(this, arg1);
795 elseif (event=="VARIABLES_LOADED") then
796 HealBot_OnEvent_VariablesLoaded(this);
797 else
798 HealBot_AddDebug("OnEvent (" .. event .. ")");
799 end
800 end
801  
802 function HealBot_OnEvent_VariablesLoaded(this)
803  
804 local class=HealBot_UnitClass("player")
805  
806 table.foreach(HealBot_ConfigDefaults, function (key,val)
807 if not HealBot_Config[key] then
808 HealBot_Config[key] = val;
809 end
810 end);
811  
812 HealBot_InitData();
813  
814 if class=="PRIEST" or class=="DRUID" or class=="PALADIN" or class=="SHAMAN" then
815  
816 HealBot_BonusScanner:ScanEquipment();
817  
818 if HealBot_Config.ActionVisible==1 then HealBot_Action:Show() end
819  
820 this:RegisterEvent("ZONE_CHANGED_NEW_AREA");
821 this:RegisterEvent("PLAYER_REGEN_DISABLED");
822 this:RegisterEvent("PLAYER_REGEN_ENABLED");
823 this:RegisterEvent("PLAYER_TARGET_CHANGED");
824 this:RegisterEvent("PARTY_MEMBERS_CHANGED");
825 this:RegisterEvent("PARTY_MEMBER_DISABLE");
826 this:RegisterEvent("PARTY_MEMBER_ENABLE");
827 this:RegisterEvent("PET_BAR_SHOWGRID");
828 this:RegisterEvent("PET_BAR_HIDEGRID");
829 this:RegisterEvent("UNIT_HEALTH");
830 this:RegisterEvent("UNIT_MANA");
831 this:RegisterEvent("SPELLS_CHANGED");
832 this:RegisterEvent("SPELLCAST_START");
833 this:RegisterEvent("SPELLCAST_STOP");
834 this:RegisterEvent("SPELLCAST_INTERRUPTED");
835 this:RegisterEvent("SPELLCAST_FAILED");
836 this:RegisterEvent("BAG_UPDATE");
837 this:RegisterEvent("BAG_UPDATE_COOLDOWN");
838 this:RegisterEvent("UNIT_AURA");
839 -- this:RegisterEvent("CHARACTER_POINTS_CHANGED");
840 this:RegisterEvent("UPDATE_INVENTORY_ALERTS");
841 this:RegisterEvent("UNIT_INVENTORY_CHANGED");
842 this:RegisterEvent("CHAT_MSG_ADDON");
843 this:RegisterEvent("CHAT_MSG_SYSTEM");
844 this:RegisterEvent("PLAYER_ENTERING_WORLD");
845 InitSpells=2;
846 end
847 end
848  
849 function HealBot_OnEvent_AddonMsg(this,addon_id,inc_msg,dist_target,sender_id)
850 if addon_id==HEALBOT_ADDON_ID then
851 local tmpTest, unitname, heal_val
852 tmpTest,tmpTest,unitname,heal_val = string.find(inc_msg, ">> (%a+) <<=>> (.%d+) <<" );
853 if heal_val then
854 if not HealBot_HealsIn[unitname] then
855 HealBot_HealsIn[unitname]=0;
856 end
857 HealBot_Healers[sender_id] = ">> "..unitname.." <<=>> "..heal_val.." <<";
858 HealBot_HealsIn[unitname] = HealBot_HealsIn[unitname] + tonumber(heal_val);
859 if tonumber(heal_val) > 0 then
860 HealBot_RecalcHeals(HealBot_FindUnitID(unitname))
861 elseif HealBot_HealsIn[unitname] < 0 then
862 HealBot_HealsIn[unitname]=0;
863 end
864 end
865 elseif addon_id=="HealBot" then
866 local tmpTest, datatype, datamsg, sender
867 local PName=UnitName("player");
868 tmpTest, tmpTest, datatype, sender, datamsg = string.find(inc_msg, ">> (%a+) <<=>> (%a+) <<=>> (.+)");
869 if datatype=="RequestVersion" then
870 SendAddonMessage( "HealBot", ">> SendVersion <<=>> "..sender.." <<=>> Version="..HEALBOT_VERSION, "RAID" );
871 elseif datatype=="SendVersion" and PName==sender then
872 HealBot_AddChat(sender_id..": "..datamsg);
873 end
874 elseif addon_id=="CTRA" then
875 if ( strsub(inc_msg, 1, 3) == "RES" ) then
876 if ( inc_msg == "RESNO" ) then
877 HealBot_AddDebug(sender_id.." Stopped ressing");
878 if HealBot_Ressing[unitname] then HealBot_Ressing[unitname] = nil; end
879 else
880 local unitname, tmpTest
881 tmpTest, tmpTest, unitname = string.find(inc_msg, "^RES (.+)$");
882 if ( unitname ) then
883 HealBot_AddDebug(sender_id.." is ressing "..unitname);
884 HealBot_Ressing[unitname] = sender_id;
885 end
886 end
887 HealBot_RecalcHeals(HealBot_FindUnitID(unitname));
888 end
889 end
890 end
891  
892  
893 function HealBot_OnEvent_UnitHealth(this,unit)
894 if (not HealBot_Heals[unit]) then return end
895 HealBot_CheckCasting(unit);
896 HealBot_RecalcHeals(unit);
897 if unit==HealBot_Action_TooltipUnit then
898 HealBot_Action_RefreshTooltip(HealBot_Action_TooltipUnit);
899 end
900 end
901  
902 function HealBot_OnEvent_UnitMana(this,unit)
903 if (unit~="player") then return end
904 HealBot_RecalcHeals();
905 end
906  
907 function HealBot_OnEvent_ZoneChanged(this)
908 -- HealBot_AddDebug("HB: ZoneChange");
909 _scale = 0;
910 Delay_RecalcParty=1;
911 end
912  
913 function HealBot_OnEvent_UnitAura(this,unit)
914 local DebuffType;
915  
916 if HealBot_Heals[unit] and unit~="target" then
917 local i = 1;
918 while true do
919 local debuff, tmp, debuff_type = UnitDebuff(unit,i, 1)
920 if debuff then
921 if HealBot_CDCInc[UnitClass(unit)]==1 and HealBot_DebuffWatch[debuff_type]=="YES" then
922 HealBot_UnitDebuff[unit]=debuff_type
923 -- HealBot_UnitDebuff[unit.."_debuff_texture"]=debuff
924 DebuffType=debuff_type;
925 if HealBot_DebuffPriority[debuff_type] then
926 do break end
927 end
928 end
929 i = i + 1;
930 else
931 if i==1 then HealBot_UnitDebuff[unit] = nil; end
932 do break end
933 end
934 end
935 if HealBot_UnitDebuff[unit] then
936 if DebuffType and HealBot_Range_Check(unit, 27)==1 then
937 if HealBot_Config.ShowDebuffWarning==1 then
938 UIErrorsFrame:AddMessage(UnitName(unit).." suffers from "..DebuffType,
939 HealBot_Config.CDCBarColour[DebuffType].R,
940 HealBot_Config.CDCBarColour[DebuffType].G,
941 HealBot_Config.CDCBarColour[DebuffType].B,
942 1, UIERRORS_HOLD_TIME);
943 end
944 if HealBot_Config.SoundDebuffWarning==1 then HealBot_PlaySound(HealBot_Config.SoundDebuffPlay); end
945 end
946 end
947 HealBot_RecalcHeals(unit);
948 end
949 end
950  
951 function HealBot_OnEvent_PlayerRegenDisabled(this)
952 HealBot_RecalcParty();
953 if (UnitIsDeadOrGhost("player")) or (UnitOnTaxi("player")) then
954 if HealBot_Config.AutoClose==1 and HealBot_Config.ActionVisible~=0 then HideUIPanel(HealBot_Action); end;
955 else
956 ShowUIPanel(HealBot_Action);
957 HealBot_IsFighting = true;
958 end
959 -- HealBot_RecalcHeals();
960 end
961  
962 function HealBot_OnEvent_PlayerRegenEnabled(this)
963 HealBot_IsFighting = false;
964 Delay_RecalcParty=1;
965 end
966  
967 function HealBot_OnEvent_PlayerTargetChanged(this)
968 HealBot_RecalcParty();
969 end
970  
971 function HealBot_OnEvent_PartyMembersChanged(this)
972 Delay_RecalcParty=1;
973 end
974  
975 function HealBot_OnEvent_PartyMemberDisable(this,unit)
976 HealBot_RecalcHeals();
977 end
978  
979 function HealBot_OnEvent_SystemMsg(this,msg)
980 if type(msg)=="string" then
981 local tmpTest, tmpTest, deserter = string.find(msg, HB_HASLEFTRAID);
982 if not deserter then
983 local tmpTest, tmpTest, deserter = string.find(msg, HB_HASLEFTPARTY);
984 end
985 if deserter then
986 if (HealBot_Healers[deserter]) then
987 local tmpTest, unitname, heal_val, heal_valn
988 tmpTest,tmpTest,unitname,heal_val = string.find(HealBot_Healers[deserter], ">> (%a+) <<=>> (.%d+) <<" );
989 heal_valn=tonumber(heal_val)
990 HealBot_Healers[deserter]=nil;
991 HealBot_AddDebug("Healer "..deserter.." left the group - Last known activity was heal "..unitname.." for "..heal_val.." << trapped in event SystemMsg");
992 if heal_valn>0 and HealBot_HealsIn[unitname] then
993 HealBot_HealsIn[unitname] = HealBot_HealsIn[unitname] - heal_valn;
994 if HealBot_HealsIn[unitname] < 0 then
995 HealBot_HealsIn[unitname]=0;
996 end
997 end
998 end
999 elseif msg==HB_YOULEAVETHEGROUP or msg==HB_YOULEAVETHERAID then
1000 Delay_RecalcParty=1;
1001 else
1002 -- find other messges
1003 end
1004 end
1005 end
1006  
1007 function HealBot_OnEvent_PartyMemberEnable(this,unit)
1008 HealBot_RecalcHeals();
1009 end
1010  
1011 function HealBot_OnEvent_PlayerEquipmentChanged(this)
1012 FlagEquipUpdate1=1;
1013 end
1014  
1015 function HealBot_OnEvent_PlayerEquipmentChanged2(this,unit)
1016 if unit=="player" then
1017 FlagEquipUpdate2=1;
1018 end
1019 end
1020  
1021 function HealBot_OnEvent_SpellsChanged(this, arg1)
1022 if arg1 then return; end
1023 HealBot_AddDebug("HB: SpellsChanged");
1024 InitSpells=2;
1025 end
1026  
1027 function HealBot_OnEvent_TalentsChanged(this, arg1)
1028 HealBot_AddDebug("HB: TalentsChanged");
1029 end
1030  
1031 function HealBot_OnEvent_BagUpdate(this,bag)
1032 if FlagEquipUpdate1==0 and FlagEquipUpdate2==0 then
1033 HealBot_RecalcSpells();
1034 end
1035 end
1036  
1037 function HealBot_OnEvent_BagUpdateCooldown(this,bag)
1038 if not bag then
1039 bag = "undef"
1040 elseif FlagEquipUpdate1==0 and FlagEquipUpdate2==0 then
1041 HealBot_RecalcSpells();
1042 end
1043 end
1044  
1045 function HealBot_OnEvent_PlayerEnteringWorld(this)
1046 HealBot_IsFighting = false;
1047 end
1048  
1049 function HealBot_OnEvent_SpellcastStart(this,spell,duration)
1050 HealBot_IsCasting = true;
1051 HealBot_RecalcHeals();
1052 HealBot_CheckCasting();
1053 if spell==HEALBOT_RESURRECTION or spell==HEALBOT_ANCESTRALSPIRIT or spell==HEALBOT_REBIRTH or spell==HEALBOT_REDEMPTION then
1054 if UnitName("Target") then
1055 SendAddonMessage( "CTRA", "RES "..UnitName("Target"),"RAID");
1056 --HealBot_AddDebug("I am ressing "..UnitName("Target"))
1057 HealBot_IamRessing=true;
1058 end
1059 end
1060 end
1061  
1062 function HealBot_OnEvent_SpellcastStop(this)
1063 HealBot_IsCasting = false;
1064 HealBot_StopCasting();
1065 HealBot_RecalcHeals();
1066 if HealBot_IamRessing then
1067 SendAddonMessage( "CTRA", "RESNO","RAID");
1068 --HealBot_AddDebug("I finished ressing")
1069 HealBot_IamRessing=false;
1070 end
1071 end
1072  
1073 function HealBot_SpiBonus(spell)
1074 local heals_modifer = 0;
1075 local base, stat, posBuff, negBuff = UnitStat("player",5);
1076 nameTalent, icon, tier, column, currRank, maxRank = GetTalentInfo(2,14); -- Spiritual guidence
1077 spiGuideBonus = stat * 0.05;
1078 heals_modifer = heals_modifer + (currRank * spiGuideBonus);
1079 return heals_modifer;
1080 end
1081  
1082 function HealBot_GetBonus()
1083 local HealBonus=HealBot_BonusScanner:GetBonus();
1084 return HealBonus;
1085 end
1086  
1087 function HealBot_FindUnitID(unitname)
1088 local text;
1089 for _,unit in ipairs(HealBot_Action_HealGroup) do
1090 text = UnitName(unit);
1091 if text then
1092 if text==unitname then
1093 return unit;
1094 end
1095 end
1096 end
1097 for i=1,40 do
1098 local unit = "raid"..i;
1099 text = UnitName(unit);
1100 if text then
1101 if text==unitname then
1102 return unit;
1103 end
1104 end
1105 end
1106 return nil;
1107 end
1108  
1109 function HealBot_PlaySound(id)
1110 if id==1 then
1111 PlaySoundFile("Sound\\Doodad\\BellTollTribal.wav");
1112 elseif id==2 then
1113 PlaySoundFile("Sound\\Spells\\Thorns.wav");
1114 elseif id==3 then
1115 PlaySoundFile("Sound\\Doodad\\BellTollNightElf.wav");
1116 end
1117 end
1118  
1119 function HealBot_InitSpells()
1120 local id = 1
1121 local cnt = 0;
1122 local class=HealBot_UnitClass("player")
1123 HealBot_CurrentSpells = {};
1124 while true do
1125 local spell = HealBot_GetSpellName(id);
1126 if not spell then
1127 do break end
1128 end
1129 if (HealBot_Spells[spell]) then
1130 HealBot_Spells[spell].id = id;
1131 HealBot_InitGetSpellData(spell, id, class);
1132 table.insert(HealBot_CurrentSpells,spell);
1133 cnt = cnt + 1;
1134 end
1135 id = id + 1;
1136 end
1137 if class=="PRIEST" or class=="DRUID" or class=="PALADIN" or class=="SHAMAN" then
1138 HealBot_AddChat("Initiated HealBot_CurrentSpells with ".. cnt .." Spells");
1139 end
1140 return cnt;
1141 end
1142  
1143 function HealBot_InitData()
1144 HealBot_Skins = HealBot_Config.Skins;
1145 if(CT_RegisterMod) then
1146 CT_RegisterMod(HEALBOT_ADDON,"HealBot Options",5,"Interface\\AddOns\\HealBot\\Images\\HealBot","Opens HealBot Options","off",nil,HealBot_ToggleOptions);
1147 end
1148  
1149 -- remove after 1.126
1150 local tmp=HealBot_Config.ShowHeader[HealBot_Config.Current_Skin] or 0
1151 HealBot_Config.ShowHeader[HealBot_Config.Current_Skin]=tmp
1152  
1153 HealBot_Options_CDCMonitor_Reset()
1154 HealBot_Options_EmergencyFilter_Reset()
1155 HealBot_Options_Debuff_Reset()
1156 end
1157  
1158 function HealBot_ToggleOptions()
1159 HealBot_TogglePanel(HealBot_Options)
1160 end
1161  
1162 function HealBot_InitGetSpellData(spell, id, class)
1163  
1164 local i, _mana, _cast, _HealsMin, _HealsMax, _HealsExt, _duration, _range, _shield, _channel;
1165 local tooltip = getglobal( "HealBot_ScanTooltip" );
1166 local tmpText, line, tmpTest
1167  
1168 if ( not spell ) then
1169 return;
1170 end
1171  
1172 HealBot_ScanTooltip:SetOwner(HealBot_ScanTooltip, "ANCHOR_NONE")
1173 HealBot_ScanTooltip:SetSpell( id, BOOKTYPE_SPELL );
1174 tmpText = getglobal("HealBot_ScanTooltipTextLeft2");
1175 if (tmpText:GetText()) then
1176 line = tmpText:GetText();
1177 tmpTest,tmpTest,_mana = string.find(line, HB_TOOLTIP_MANA );
1178 else
1179 HealBot_Report_Error( "================================" );
1180 HealBot_Report_Error( "ERROR: HealBot_ScanTooltip is lost" );
1181 HealBot_Report_Error( "ERROR: If BonusScanner is used, try disabling BonusScanner" );
1182 end
1183  
1184 tmpText = getglobal("HealBot_ScanTooltipTextRight2");
1185 if (tmpText:GetText()) then
1186 line = tmpText:GetText();
1187 tmpTest,tmpTest,_range = string.find(line, HB_TOOLTIP_RANGE );
1188 else
1189 HealBot_Report_Error( "================================" );
1190 HealBot_Report_Error( "ERROR: HealBot_ScanTooltip is lost" );
1191 HealBot_Report_Error( "ERROR: If BonusScanner is used, try disabling BonusScanner" );
1192 end
1193  
1194 tmpText = getglobal("HealBot_ScanTooltipTextLeft3");
1195 _cast = nil;
1196 if (tmpText:GetText()) then
1197 line = tmpText:GetText();
1198 if ( line == HB_TOOLTIP_INSTANT_CAST ) then
1199 _cast = 0;
1200 elseif line == HB_TOOLTIP_CHANNELED then
1201 _cast = 0;
1202 elseif ( tmpText ) then
1203 tmpTest,tmpTest,_cast = string.find(line, HB_TOOLTIP_CAST_TIME );
1204 end
1205 else
1206 HealBot_Report_Error( "================================" );
1207 HealBot_Report_Error( "ERROR: HealBot_ScanTooltip is lost" );
1208 HealBot_Report_Error( "ERROR: If BonusScanner is used, try disabling BonusScanner" );
1209 end
1210  
1211 tmpText = getglobal("HealBot_ScanTooltipTextLeft4");
1212 tmpTest = nil;
1213 if (tmpText:GetText()) then
1214 line = tmpText:GetText();
1215 if class == "PRIEST" then
1216 if strsub(spell, 0, 14) == strsub(HEALBOT_POWER_WORD_SHIELD, 0, 14) then
1217 tmpTest,tmpTest,_HealsMin,_shield = string.find(line, HB_SPELL_PATTERN_SHIELD );
1218 _HealsExt=0;
1219 _HealsMax=_HealsMin;
1220 elseif strsub(spell, 0, 4) == strsub(HEALBOT_RENEW, 0, 4) then
1221 tmpTest,tmpTest,_HealsExt,tmpTest,_duration = string.find(line, HB_SPELL_PATTERN_RENEW );
1222 _HealsMin=0;
1223 _HealsMax=0;
1224 if ( _HealsExt == nil ) then
1225 tmpTest,tmpTest,_HealsExt,_duration = string.find(line, HB_SPELL_PATTERN_RENEW1 );
1226 end
1227 if ( _HealsExt == nil ) then
1228 tmpTest,tmpTest,_duration,_HealsExt = string.find(line, HB_SPELL_PATTERN_RENEW2 );
1229 end
1230 if ( _HealsExt == nil ) then
1231 tmpTest,tmpTest,_duration,_HealsExt = string.find(line, HB_SPELL_PATTERN_RENEW3 );
1232 end
1233 elseif strsub(spell, 0, 9) == strsub(HEALBOT_LESSER_HEAL, 0, 9) then
1234 tmpTest,_HealsMin,_HealsMax = HealBot_Generic_Patten(line,HB_SPELL_PATTERN_LESSER_HEAL);
1235 elseif strsub(spell, 0, 9) == strsub(HEALBOT_GREATER_HEAL, 0, 9) then
1236 tmpTest,_HealsMin,_HealsMax = HealBot_Generic_Patten(line, HB_SPELL_PATTERN_GREATER_HEAL );
1237 elseif strsub(spell, 0, 9) == strsub(HEALBOT_FLASH_HEAL, 0, 9) then
1238 tmpTest,_HealsMin,_HealsMax = HealBot_Generic_Patten(line, HB_SPELL_PATTERN_FLASH_HEAL );
1239 elseif strsub(spell, 0, 4) == strsub(HEALBOT_HEAL, 0, 4) then
1240 tmpTest,_HealsMin,_HealsMax = HealBot_Generic_Patten(line, HB_SPELL_PATTERN_HEAL );
1241 end
1242 elseif class=="DRUID" then
1243 if strsub(spell, 0, 6) == strsub(HEALBOT_REGROWTH, 0, 6) then
1244 tmpTest,tmpTest,_HealsMin,_HealsMax,_HealsExt = string.find(line, HB_SPELL_PATTERN_REGROWTH );
1245 if ( tmpTest == nil ) then
1246 tmpTest,tmpTest,_HealsMin,_HealsMax,tmpTest,_HealsExt = string.find(line, HB_SPELL_PATTERN_REGROWTH1 );
1247 end
1248 elseif strsub(spell, 0, 9) == strsub(HEALBOT_REJUVENATION, 0, 9) then
1249 tmpTest,tmpTest,_HealsExt,_duration = string.find(line, HB_SPELL_PATTERN_REJUVENATION );
1250 _HealsMin=0;
1251 _HealsMax=0;
1252 if ( _HealsExt == nil ) then
1253 tmpTest,tmpTest,_HealsExt,tmpTest,_duration = string.find(line, HB_SPELL_PATTERN_REJUVENATION1 );
1254 end
1255 elseif strsub(spell, 0, 7) == strsub(HEALBOT_HEALING_TOUCH, 0, 7) then
1256 tmpTest,_HealsMin,_HealsMax = HealBot_Generic_Patten(line, HB_SPELL_PATTERN_HEALING_TOUCH );
1257 end
1258 elseif class=="PALADIN" then
1259 if strsub(spell, 0, 9) == strsub(HEALBOT_HOLY_LIGHT, 0, 9) then
1260 tmpTest,_HealsMin,_HealsMax = HealBot_Generic_Patten(line, HB_SPELL_PATTERN_HOLY_LIGHT );
1261 elseif strsub(spell, 0, 9) == strsub(HEALBOT_FLASH_OF_LIGHT, 0, 9) then
1262 tmpTest,_HealsMin,_HealsMax = HealBot_Generic_Patten(line, HB_SPELL_PATTERN_FLASH_OF_LIGHT );
1263 end
1264 elseif class=="SHAMAN" then
1265 if strsub(spell, 0, 9) == strsub(HEALBOT_HEALING_WAVE, 0, 9) then
1266 tmpTest,_HealsMin,_HealsMax = HealBot_Generic_Patten(line, HB_SPELL_PATTERN_HEALING_WAVE );
1267 elseif strsub(spell, 0, 9) == strsub(HEALBOT_LESSER_HEALING_WAVE, 0, 9) then
1268 tmpTest,_HealsMin,_HealsMax = HealBot_Generic_Patten(line, HB_SPELL_PATTERN_LESSER_HEALING_WAVE );
1269 end
1270 end
1271 else
1272 HealBot_Report_Error( "================================" );
1273 HealBot_Report_Error( "ERROR: HealBot_ScanTooltip is lost" );
1274 HealBot_Report_Error( "ERROR: If BonusScanner is used, try disabling BonusScanner" );
1275 end
1276  
1277 if ( _mana == nil ) then
1278 HealBot_Report_Error( "================================" );
1279 HealBot_Report_Error( "ERROR: _mana is NIL" );
1280 HealBot_Report_Error( "ERROR: Spell: "..spell );
1281 if HealBot_ScanTooltipTextLeft2:GetText() then
1282 HealBot_Report_Error( "ERROR: Tooltip = >> "..HealBot_ScanTooltipTextLeft2:GetText().." <<" );
1283 end
1284 HealBot_Report_Error( "ERROR: Patten = >> "..HB_TOOLTIP_MANA.." <<" );
1285 end
1286 if ( _range == nil ) then
1287 HealBot_Report_Error( "================================" );
1288 HealBot_Report_Error( "ERROR: _range is NIL" );
1289 HealBot_Report_Error( "ERROR: Spell: "..spell );
1290 if HealBot_ScanTooltipTextRight2:GetText() then
1291 HealBot_Report_Error( "ERROR: Tooltip = >> "..HealBot_ScanTooltipTextRight2:GetText().." <<" );
1292 end
1293 HealBot_Report_Error( "ERROR: Patten = >> "..HB_TOOLTIP_RANGE.." <<" );
1294 end
1295 if ( _cast == nil ) then
1296 HealBot_Report_Error( "================================" );
1297 HealBot_Report_Error( "ERROR: _cast is NIL" );
1298 HealBot_Report_Error( "ERROR: Spell: "..spell );
1299 if HealBot_ScanTooltipTextLeft3:GetText() then
1300 HealBot_Report_Error( "ERROR: Tooltip = >> "..HealBot_ScanTooltipTextLeft3:GetText().." <<" );
1301 end
1302 HealBot_Report_Error( "ERROR: Patten = >> "..HB_TOOLTIP_CAST_TIME.." <<" );
1303 end
1304 if ( tmpTest == nil ) then
1305 HealBot_Report_Error( "================================" );
1306 HealBot_Report_Error( "ERROR: tmpTest == nil" );
1307 HealBot_Report_Error( "ERROR: spell = "..spell );
1308 if line then
1309 HealBot_Report_Error( "ERROR: Tooltip = >> "..line.." <<" );
1310 end
1311 end
1312  
1313 HealBot_Spells[spell].CastTime=tonumber(_cast);
1314 HealBot_Spells[spell].Mana=tonumber(_mana);
1315 HealBot_Spells[spell].Range=tonumber(_range);
1316 HealBot_Spells[spell].HealsMin=tonumber(_HealsMin);
1317 HealBot_Spells[spell].HealsMax=tonumber(_HealsMax);
1318 if _HealsExt then
1319 HealBot_Spells[spell].HealsExt=tonumber(_HealsExt);
1320 end
1321 if _duration then
1322 HealBot_Spells[spell].Duration=tonumber(_duration);
1323 end
1324 if _shield then
1325 HealBot_Spells[spell].Shield=tonumber(_shield);
1326 end
1327 if _channel then
1328 HealBot_Spells[spell].Channel=tonumber(_channel);
1329 end
1330  
1331 if not HealBot_Spells[spell].Target then
1332 HealBot_Spells[spell].Target = {"player","party","pet"};
1333 end
1334 if not HealBot_Spells[spell].Price then
1335 HealBot_Spells[spell].Price = 0;
1336 end
1337 if not HealBot_Spells[spell].Channel then
1338 HealBot_Spells[spell].Channel = HealBot_Spells[spell].CastTime;
1339 end
1340 if not HealBot_Spells[spell].Duration then
1341 HealBot_Spells[spell].Duration = HealBot_Spells[spell].Channel;
1342 end
1343 if not HealBot_Spells[spell].RealHealing then
1344 HealBot_Spells[spell].RealHealing=0;
1345 end
1346 HealBot_Spells[spell].HealsCast = (HealBot_Spells[spell].HealsMin+HealBot_Spells[spell].HealsMax)/2;
1347 if not HealBot_Spells[spell].HealsExt then
1348 HealBot_Spells[spell].HealsExt = 0;
1349 end
1350  
1351 end
1352  
1353 function HealBot_Generic_Patten(matchStr,matchPattern)
1354 local tmpTest,_HealsMin,_HealsMax,_HealsExt,_duration
1355 tmpTest,tmpTest,_HealsMin,_HealsMax = string.find(matchStr, matchPattern );
1356 if ( tmpTest == nil ) then
1357 HealBot_Report_Error( "================================" );
1358 HealBot_Report_Error( "ERROR: tmpTest == nil" );
1359 HealBot_Report_Error( "ERROR: pattern = "..matchPattern );
1360 HealBot_Report_Error( "ERROR: Tooltip = >> "..matchStr.." <<" );
1361 end
1362 return tmpTest,_HealsMin,_HealsMax;
1363 end
1364  
1365 function HealBot_Get_DebugChan()
1366 local index = GetChannelName("HBmsg");
1367 if (index>0) then
1368 return index;
1369 else
1370 return nil;
1371 end
1372 end
1373  
1374 function HealBot_Range_Check(unit, range)
1375  
1376 local return_val = 0;
1377 if not range then
1378 range=40;
1379 end
1380 if ( unit=="player" ) then
1381 return_val = 1;
1382 elseif ( UnitIsVisible(unit) == 1) then
1383 local tx, ty = GetPlayerMapPosition(unit)
1384 local dist
1385 if tx > 0 or ty > 0 then
1386 local px, py = GetPlayerMapPosition("player")
1387 dist = sqrt((px - tx)^2 + (py - ty)^2)
1388 if dist > _scale and (px > 0 or py > 0) then
1389 if (CheckInteractDistance(unit, 4)) then
1390 _scale = dist
1391 end
1392 end
1393 if dist <=(_scale*range/27) then
1394 return_val=1
1395 end
1396 else
1397 if (HealBot_Config.QualityRange == 1) or range <= 27 then
1398 if ( CheckInteractDistance(unit, 4) ) then
1399 return_val = 1;
1400 end
1401 else
1402 return_val = 1;
1403 end
1404 end
1405 end
1406 return return_val;
1407 end