Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a module to summon/revive/dismiss hunters' pet. #104

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cork.toc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ templates\TempEnchant.lua
modules\DeathKnight.lua
modules\Druid.lua
modules\Hunter.lua
modules\HunterPet.lua
modules\Mage.lua
modules\Monk.lua
modules\Paladin.lua
Expand Down
156 changes: 156 additions & 0 deletions modules/HunterPet.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@

local myname, Cork = ...
if Cork.MYCLASS ~= "HUNTER" then return end
local ldb, ae = LibStub:GetLibrary("LibDataBroker-1.1"), LibStub("AceEvent-3.0")
local GetSpellInfo = GetSpellInfo
local IconLine = Cork.IconLine

local spellidlist = {883,83242,83243,83244,83245,2641}
local dismissSpell, _, dismissIcon = GetSpellInfo(2641)
local reviveSpell, _, reviveIcon = GetSpellInfo(982)
local loneWolfSpell = GetSpellInfo(164273)

local known, names = {}, {}

for _, id in ipairs(spellidlist) do
names[id] = GetSpellInfo(id)
end

local dataobj = ldb:NewDataObject("Cork Hunter Pet", {
type = "cork"
})

local function RefreshKnownPets()
for id, spell in pairs(names) do
known[spell] = GetSpellInfo(spell)
end
end

function dataobj:Init()
RefreshKnownPets()
Cork.defaultspc["Hunter Pet-spell"] = names[spellidlist[1]]
Cork.defaultspc["Hunter Pet-enabled"] = next(known) ~= nil
end

local function DoTest()
if UnitBuff("player", loneWolfSpell) then
return
end

if UnitExists("pet") and UnitIsDead("pet") then
return reviveSpell
end

local spell = Cork.dbpc["Hunter Pet-spell"]

if spell == dismissSpell then
if UnitExists("pet") then
return dismissSpell
end
return
end

if not UnitExists("pet") then
return spell
end
end

function dataobj:Test()
if Cork.dbpc["Hunter Pet-enabled"] and not (IsResting() and not Cork.db.debug) and not UnitIsUnit('pet', 'vehicle') then
local spell = DoTest()
if spell then
return IconLine(select(3, GetSpellInfo(spell)), spell)
end
end
end

function dataobj:Scan(event, unit)
if not unit or unit == "player" then self.player = self:Test() end
end

function dataobj:CorkIt(frame)
RefreshKnownPets()
if self.player then return frame:SetManyAttributes("type1", "spell", "spell", DoTest()) end
end

ae.RegisterEvent(dataobj, "UNIT_PET", "Scan")
ae.RegisterEvent(dataobj, "UNIT_AURA", "Scan")
ae.RegisterEvent(dataobj, "PLAYER_UPDATE_RESTING", "Scan")

-- PET_ATTACK_STOP happens when the pet dies
ae.RegisterEvent(dataobj, "PET_ATTACK_STOP", "Scan")

----------------------
-- Config --
----------------------

local frame = CreateFrame("Frame", nil, Cork.config)
frame:SetWidth(1) frame:SetHeight(1)
dataobj.configframe = frame
frame:Hide()

frame:SetScript("OnShow", function()
local EDGEGAP, ROWHEIGHT, ROWGAP, GAP = 16, 18, 2, 4
local spellbuttons = {}

local function OnClick(self)
Cork.dbpc["Hunter Pet-spell"] = self.spell
for spell,butt in pairs(spellbuttons) do butt:SetChecked(butt == self) end
dataobj:Scan()
end

local function OnEnter(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetHyperlink(GetSpellLink(self.spellid))
end
local function OnLeave() GameTooltip:Hide() end


local lasticon
for _,id in ipairs(spellidlist) do
local spell = names[id]

local butt = CreateFrame("CheckButton", nil, frame)
butt:SetWidth(ROWHEIGHT) butt:SetHeight(ROWHEIGHT)

local tex = butt:CreateTexture(nil, "BACKGROUND")
tex:SetAllPoints()
tex:SetTexture((select(3, GetSpellInfo(spell))))
tex:SetTexCoord(4/48, 44/48, 4/48, 44/48)
butt.icon = tex

butt:SetPushedTexture("Interface\\Buttons\\UI-Quickslot-Depress")
butt:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square")
butt:SetCheckedTexture("Interface\\Buttons\\CheckButtonHilight")

if lasticon then lasticon:SetPoint("RIGHT", butt, "LEFT", -ROWGAP, 0) end

butt.spell = spell
butt.spellid = id
butt:SetScript("OnClick", OnClick)
butt:SetScript("OnEnter", OnEnter)
butt:SetScript("OnLeave", OnLeave)
butt:SetMotionScriptsWhileDisabled(true)

spellbuttons[spell], lasticon = butt, butt
end
lasticon:SetPoint("RIGHT", 0, 0)

local function Update(self)
RefreshKnownPets()

for spell,butt in pairs(spellbuttons) do
butt:SetChecked(Cork.dbpc["Hunter Pet-spell"] == spell)
if known[spell] then
butt:Enable()
butt.icon:SetVertexColor(1.0, 1.0, 1.0)
else
butt:Disable()
butt.icon:SetVertexColor(0.4, 0.4, 0.4)
end
end
end

frame:SetScript("OnShow", Update)
Update(frame)
end)