public
Description: WoW Addon - Hunter pet macro thing
Homepage: http://www.tekkub.net/
Clone URL: git://github.com/tekkub/fuzzylogic.git
Click here to lend your support to: fuzzylogic and make a donation at www.pledgie.com !
fuzzylogic / FuzzyLogic.lua
100644 129 lines (97 sloc) 3.463 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
-- Only load for hunters
if select(2, UnitClass("player")) ~= "HUNTER" then
DisableAddOn("FuzzyLogic")
return
end
 
 
----------------------------
-- Localization --
----------------------------
 
local L = GetLocale() == "deDE" and {
petdead = "Euer Begleiter ist tot.",
petmend = "Tier heilen",
petcall = "Tier rufen",
petdis = "Tier freigeben",
petrevive = "Tier wiederbeleben",
macro = "/cast [target=pet,dead] Tier wiederbeleben; [nopet] Tier rufen; Tier heilen",
macrodead = "/cast [target=pet,dead] Tier wiederbeleben; [nopet] Tier wiederbeleben; Tier heilen",
} or {
petdead = "Your pet is dead.",
petmend = "Mend Pet",
petcall = "Call Pet",
petdis = "Dismiss Pet",
petrevive = "Revive Pet",
macro = "/cast [target=pet,dead] Revive Pet; [nopet] Call Pet; Mend Pet",
macrodead = "/cast [target=pet,dead] Revive Pet; [nopet] Revive Pet; Mend Pet",
}
 
 
------------------------------
-- Are you local? --
------------------------------
 
local healthresh = 0.90 -- Change this to the threshold you want to cast Mend Pet instead of Dismiss
local binding -- Set this to the key you wish to be bound
local petIsDead, frame, hasImpMendPet
 
 
local function SetManyAttributes(self, ...)
for i=1,select("#", ...),2 do
local att,val = select(i, ...)
if not att then return end
self:SetAttribute(att,val)
end
end
 
 
-------------------------------------
-- Namespace Declaration --
-------------------------------------
 
FuzzyLogic = DongleStub("Dongle-1.0"):New("FuzzyLogic")
 
 
------------------------------
-- Initialization --
------------------------------
 
function FuzzyLogic:Initialize()
frame = CreateFrame("Button", "FuzzyLogicFrame", UIParent, "SecureActionButtonTemplate")
if binding then SetBindingClick(binding, "FuzzyLogicFrame") end
frame.SetManyAttributes = SetManyAttributes
frame:Hide()
 
frame:SetScript("PreClick", self.PreClick)
end
 
 
function FuzzyLogic:Enable()
self:RegisterEvent("UI_ERROR_MESSAGE")
self:RegisterEvent("PLAYER_REGEN_DISABLED")
self:RegisterEvent("UNIT_HEALTH")
 
hasImpMendPet = select(5, GetTalentInfo(1, 10)) > 0
end
 
 
------------------------------
-- Event Handlers --
------------------------------
 
function FuzzyLogic:UI_ERROR_MESSAGE(event, msg)
if msg == L.petdead then petIsDead = true end
end
 
 
function FuzzyLogic:PLAYER_REGEN_DISABLED()
self:Debug(1, "Entering Combat")
frame:SetManyAttributes("type1", "macro", "macrotext", petIsDead and L.macrodead or L.macro)
end
 
 
function FuzzyLogic:UNIT_HEALTH(event, unit)
if unit ~= "pet" then return end
 
local hp = UnitHealth("pet")
if petIsDead and hp > 0 then
self:Debug(1, "Pet alive again")
petIsDead = false
elseif not petIsDead and hp == 0 then
self:Debug(1, "Pet died")
petIsDead = true
end
end
 
 
------------------------------
-- Frame Handlers --
------------------------------
 
function FuzzyLogic.PreClick()
if InCombatLockdown() then return end
 
local exists = UnitExists("pet")
if UnitIsDead("pet") or (not exists and petIsDead) then
frame:SetManyAttributes("type1", "spell", "spell", L.petrevive)
elseif exists then
if (UnitHealth("pet")/UnitHealthMax("pet") < healthresh) or (hasImpMendPet and UnitDebuff("pet", 1)) then
frame:SetManyAttributes("type1", "spell", "spell", L.petmend)
else
frame:SetManyAttributes("type1", "spell", "spell", L.petdis)
end
else
frame:SetManyAttributes("type1", "spell", "spell", L.petcall)
end
end