From 52e878f89d4972dba0e9664e2686a7952a0ff170 Mon Sep 17 00:00:00 2001 From: Adirelle Date: Sat, 13 Dec 2014 12:49:18 +0100 Subject: [PATCH 1/3] Add a module to summon/revive/dismiss hunters' pet. --- Cork.toc | 1 + modules/HunterPet.lua | 150 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 151 insertions(+) create mode 100644 modules/HunterPet.lua diff --git a/Cork.toc b/Cork.toc index e1ba37b..614f978 100644 --- a/Cork.toc +++ b/Cork.toc @@ -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 diff --git a/modules/HunterPet.lua b/modules/HunterPet.lua new file mode 100644 index 0000000..2457662 --- /dev/null +++ b/modules/HunterPet.lua @@ -0,0 +1,150 @@ + +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 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 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() self.player = self:Test() end + +function dataobj:CorkIt(frame) + RefreshKnownPets() + if self.player then return frame:SetManyAttributes("type1", "spell", "spell", DoTest()) end +end + +ae.RegisterEvent("Cork Hunter Pet", "UNIT_PET", function(event, unit) + if unit == "player" then dataobj.player = dataobj:Test() end +end) +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) From 4bb19c89628c1b1e897860a573c78f1c925bac12 Mon Sep 17 00:00:00 2001 From: Adirelle Date: Mon, 29 Dec 2014 11:13:50 +0100 Subject: [PATCH 2/3] Hunter pets: do not call a pet with the Lone Wolf buff. --- modules/HunterPet.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/HunterPet.lua b/modules/HunterPet.lua index 2457662..fc47cfa 100644 --- a/modules/HunterPet.lua +++ b/modules/HunterPet.lua @@ -8,6 +8,7 @@ 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 = {}, {} @@ -45,7 +46,7 @@ local function DoTest() return end - if not UnitExists("pet") then + if not UnitExists("pet") and not UnitBuff("player", loneWolfSpell) then return spell end end From 4edbc48652f7a28dadeefdd4a1842f7051f81b41 Mon Sep 17 00:00:00 2001 From: Adirelle Date: Tue, 30 Dec 2014 14:56:05 +0100 Subject: [PATCH 3/3] Hunter pets: do not mess with the pet at all if the player has the Lone Wolf buff. --- modules/HunterPet.lua | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/modules/HunterPet.lua b/modules/HunterPet.lua index fc47cfa..20fe10a 100644 --- a/modules/HunterPet.lua +++ b/modules/HunterPet.lua @@ -33,6 +33,10 @@ function dataobj:Init() end local function DoTest() + if UnitBuff("player", loneWolfSpell) then + return + end + if UnitExists("pet") and UnitIsDead("pet") then return reviveSpell end @@ -46,7 +50,7 @@ local function DoTest() return end - if not UnitExists("pet") and not UnitBuff("player", loneWolfSpell) then + if not UnitExists("pet") then return spell end end @@ -60,16 +64,17 @@ function dataobj:Test() end end -function dataobj:Scan() self.player = self:Test() 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("Cork Hunter Pet", "UNIT_PET", function(event, unit) - if unit == "player" then dataobj.player = dataobj:Test() 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