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 !
kennel / Kennel.lua
100644 76 lines (54 sloc) 2.361 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

local debugf = tekDebug and tekDebug:GetFrame("Kennel")
local function Debug(...) if debugf then debugf:AddMessage(string.join(", ", ...)) end end
 
 
local DELAY = 2
local blistzones = {
  ["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 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")
 
  for i=1,GetNumCompanions("CRITTER") do if select(5, GetCompanionInfo("CRITTER", i)) then return end 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)
  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 UnitCastingInfo("player") or blistzones[GetSubZoneText()] then
    elapsed = 0
    return
  end
 
  local numpets = GetNumCompanions("CRITTER")
  Debug("Putting out pet", tostring(numpets))
  if numpets > 0 then CallCompanion("CRITTER", math.random(numpets)) end
  self:Hide()
end)
 
 
f.PLAYER_REGEN_ENABLED = PutTheCatOut
f.PLAYER_CONTROL_GAINED = PutTheCatOut
f.PLAYER_LOGIN = PutTheCatOut
f.PLAYER_UNGHOST = PutTheCatOut
 
 
function f:ZONE_CHANGED_NEW_AREA()
  SetMapToCurrentZone()
  PutTheCatOut(self, "ZONE_CHANGED_NEW_AREA")
end
 
 
function f:COMPANION_UPDATE(event, comptype)
  if comptype ~= "CRITTER" then return end
  PutTheCatOut(self, "COMPANION_UPDATE")
end
 
f:RegisterEvent("COMPANION_UPDATE")
f:RegisterEvent("PLAYER_UNGHOST")
f:RegisterEvent("ZONE_CHANGED_NEW_AREA")
 
if IsLoggedIn() then PutTheCatOut(f, "PLAYER_LOGIN") else f:RegisterEvent("PLAYER_LOGIN") end