public
Description: WoW Addon - Swap a random minipet every time you visit the bank
Homepage: http://www.tekkub.net
Clone URL: git://github.com/tekkub/kennel.git
Click here to lend your support to: kennel and make a donation at www.pledgie.com !
tekkub (author)
Mon Aug 10 01:47:01 -0700 2009
commit  36129463967eb84ccb862c1482dc605151459be7
tree    62d26509392c7e1597e44d2e7a8713f46913f6c8
parent  97e354559c0572837c6e4941729da740018e6ff8 parent  9647ca4c65af7c85449f082cb5804bd0f8829df5
kennel / Kennel.lua
100644 159 lines (120 sloc) 4.775 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159

local debugf = tekDebug and tekDebug:GetFrame("Kennel")
local function Debug(...) if debugf then debugf:AddMessage(string.join(", ", ...)) end end
 
 
local SOR, FOOD, DRINK = GetSpellInfo(20711), GetSpellInfo(7737), GetSpellInfo(430)
 
local DELAY = 2
local blistzones, db = {
["Throne of Kil'jaeden"] = true,
["\208\162\209\128\208\190\208\189 \208\154\208\184\208\187'\208\180\208\182\208\181\208\180\208\181\208\189\208\176"] = true, -- ruRU
["Tr\195\180ne de Kil'jaeden"] = true, -- frFR
}
 
local f = CreateFrame("Frame")
f:SetScript("OnEvent", function(self, event, ...) if self[event] then return self[event](self, event, ...) end end)
f:Hide()
 
 
local function GetZonePet()
local z, sz = GetZoneText(), GetSubZoneText()
local name = sz and sz ~= "" and KennelDBPC.zone[z .." - "..sz] or KennelDBPC.zone[z]
if not name then return end
for i=1,GetNumCompanions("CRITTER") do
local _, pname, id = GetCompanionInfo("CRITTER", i)
if pname == name then return i, pname end
end
end
 
 
local function GetRandomPet()
local numpets = GetNumCompanions("CRITTER")
if not f.nlow then
f.nlow = 0
for i=1,numpets do
local _, name, id = GetCompanionInfo("CRITTER", i)
if db[id] == 1 then f.nlow = f.nlow + 1 end
end
end
if numpets > 0 then
local i = math.random(numpets)
local _, name, id = GetCompanionInfo("CRITTER", i)
if db[id] == 2 or db[id] == 1 and math.random(f.nlow) == 1 then return i, name end
end
end
 
 
local function SummonedPet()
for i=1,GetNumCompanions("CRITTER") do
local _, name, _, _, summoned = GetCompanionInfo("CRITTER", i)
if summoned then return name end
end
end
 
 
local numpets = 0
local function PutTheCatOut(self, event)
Debug(event or "nil", HasFullControl() and "In control" or "Not in control", InCombatLockdown() and "In combat" or "Not in combat")
 
if InCombatLockdown() then return self:RegisterEvent("PLAYER_REGEN_ENABLED") end
if not HasFullControl() then return self:RegisterEvent("PLAYER_CONTROL_GAINED") end
self:UnregisterEvent("PLAYER_REGEN_ENABLED")
 
local summ, _, zonepet = SummonedPet(), GetZonePet()
if (not zonepet and summ) or (zonepet and zonepet == summ) then return end
 
Debug("Queueing pet to be put out")
self:Show()
end
 
 
local elapsed
f:SetScript("OnShow", function() elapsed = 0 end)
f:SetScript("OnUpdate", function(self, elap)
if KennelDBPC.disabled then return end
 
elapsed = elapsed + elap
if elapsed < DELAY then return end
 
local _, instanceType = IsInInstance()
local pvpink = instanceType == "pvp" or instanceType == "arena"
 
if pvpink or InCombatLockdown() or IsStealthed() or IsMounted() or IsFlying() or IsFalling() or UnitCastingInfo("player") or UnitChannelInfo("player") or blistzones[GetSubZoneText()]
or UnitBuff("player", SOR) or UnitBuff("player", FOOD) or UnitBuff("player", DRINK) then
elapsed = 0
return
end
 
local peti, name = GetZonePet()
if not peti then peti, name = GetRandomPet() end
if peti then
local numpets = GetNumCompanions("CRITTER")
Debug("Putting out pet", name)
CallCompanion("CRITTER", peti)
self:Hide()
end
end)
 
 
f:RegisterEvent("ADDON_LOADED")
 
 
function f:ADDON_LOADED(event, addon)
if addon:lower() ~= "kennel" then return end
 
KennelDBPC = KennelDBPC or {random = {}, zone = {}}
if not KennelDBPC.random then
for i,v in pairs(KennelDBPC) do KennelDBPC[i] = 0 end
KennelDBPC = {random = KennelDBPC}
KennelDBPC.disabled, KennelDBPC.random.disabled = KennelDBPC.random.disabled
end
if not KennelDBPC.zone then KennelDBPC.zone = {} end
 
db = setmetatable(KennelDBPC.random, {__index = function() return 2 end})
self.randomdb = db
 
self:UnregisterEvent("ADDON_LOADED")
self.ADDON_LOADED = nil
 
if IsLoggedIn() then PutTheCatOut(f, "PLAYER_LOGIN") else f:RegisterEvent("PLAYER_LOGIN") end
self:RegisterEvent("PLAYER_LOGOUT")
end
 
 
function f:PLAYER_LOGOUT()
for i,v in pairs(db) do if v == 2 then db[i] = nil end end
end
 
 
f.PLAYER_REGEN_ENABLED = PutTheCatOut
f.PLAYER_CONTROL_GAINED = PutTheCatOut
f.PLAYER_LOGIN = PutTheCatOut
f.PLAYER_UNGHOST = PutTheCatOut
f.ZONE_CHANGED = PutTheCatOut
f.ZONE_CHANGED_INDOORS = PutTheCatOut
f.ZONE_CHANGED_NEW_AREA = PutTheCatOut
 
 
function f:COMPANION_UPDATE(event, comptype)
local wasmounted
if comptype == "CRITTER" then return PutTheCatOut(self, "COMPANION_UPDATE") end
if comptype == "MOUNT" then
local found
for i=1,GetNumCompanions("CRITTER") do found = found or select(5, GetCompanionInfo("MOUNT", i)) end
if KennelDBPC.dismissonmount and found and not wasmounted then DismissCompanion("CRITTER") end
wasmounted = found
return
end
end
 
f:RegisterEvent("COMPANION_UPDATE")
f:RegisterEvent("PLAYER_UNGHOST")
f:RegisterEvent("ZONE_CHANGED")
f:RegisterEvent("ZONE_CHANGED_INDOORS")
f:RegisterEvent("ZONE_CHANGED_NEW_AREA")
 
 
KENNELFRAME = f