Обновить AdePet.lua
This commit is contained in:
+73
-8
@@ -151,7 +151,8 @@ local function UpdateDisplay()
|
|||||||
local petName = UnitName("pet") or "Pet"
|
local petName = UnitName("pet") or "Pet"
|
||||||
local loyaltyLevel = ParseLoyalty(GetPetLoyalty())
|
local loyaltyLevel = ParseLoyalty(GetPetLoyalty())
|
||||||
|
|
||||||
if loyaltyLevel and loyaltyLevel >= MAX_LOYALTY then
|
-- At max loyalty the window is only shown while the pet is hungry.
|
||||||
|
if loyaltyLevel and loyaltyLevel >= MAX_LOYALTY and not isHungry then
|
||||||
frame:Hide()
|
frame:Hide()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -184,9 +185,56 @@ local function CheckHunger()
|
|||||||
UpdateDisplay()
|
UpdateDisplay()
|
||||||
end
|
end
|
||||||
|
|
||||||
local loyaltyElapsed = 0
|
-- Feeding detection: while eating, the pet carries the "Feed Pet Effect" buff
|
||||||
|
-- (about 20 sec). We detect it by buff name in a hidden tooltip, with the
|
||||||
|
-- feeding icon as a secondary check. When the buff disappears, re-check hunger
|
||||||
|
-- immediately.
|
||||||
|
local scanTooltip = CreateFrame("GameTooltip", "AdePetScanTooltip", nil, "GameTooltipTemplate")
|
||||||
|
scanTooltip:SetOwner(WorldFrame, "ANCHOR_NONE")
|
||||||
|
|
||||||
|
local wasFeeding = false
|
||||||
local hungerElapsed = 0
|
local hungerElapsed = 0
|
||||||
frame:SetScript("OnUpdate", function()
|
|
||||||
|
local function PetIsFeeding()
|
||||||
|
if not UnitExists("pet") then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
for i = 1, 16 do
|
||||||
|
local texture = UnitBuff("pet", i)
|
||||||
|
if not texture then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
if string.find(texture, "BeastTraining", 1, true) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
scanTooltip:ClearLines()
|
||||||
|
scanTooltip:SetUnitBuff("pet", i)
|
||||||
|
local line = getglobal("AdePetScanTooltipTextLeft1")
|
||||||
|
local name = line and line:GetText()
|
||||||
|
if name and string.find(string.lower(name), "feed pet", 1, true) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local function CheckFeeding()
|
||||||
|
local feeding = PetIsFeeding()
|
||||||
|
if wasFeeding and not feeding then
|
||||||
|
-- Feeding just ended: check hunger now, regardless of the timer.
|
||||||
|
hungerElapsed = 0
|
||||||
|
CheckHunger()
|
||||||
|
end
|
||||||
|
wasFeeding = feeding
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Timer and event handling live on a separate, always-active frame. A hidden
|
||||||
|
-- frame never receives OnUpdate, so running the timer on the (hideable) window
|
||||||
|
-- would stop all hunger checks at max loyalty, exactly when the window is hidden.
|
||||||
|
local driver = CreateFrame("Frame", "AdePetDriver")
|
||||||
|
|
||||||
|
local loyaltyElapsed = 0
|
||||||
|
driver:SetScript("OnUpdate", function()
|
||||||
if not isHunter then
|
if not isHunter then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -196,18 +244,28 @@ frame:SetScript("OnUpdate", function()
|
|||||||
if hungerElapsed >= GetHungryInterval() then
|
if hungerElapsed >= GetHungryInterval() then
|
||||||
hungerElapsed = 0
|
hungerElapsed = 0
|
||||||
loyaltyElapsed = 0
|
loyaltyElapsed = 0
|
||||||
|
CheckFeeding()
|
||||||
CheckHunger()
|
CheckHunger()
|
||||||
elseif loyaltyElapsed >= LOYALTY_INTERVAL then
|
elseif loyaltyElapsed >= LOYALTY_INTERVAL then
|
||||||
loyaltyElapsed = 0
|
loyaltyElapsed = 0
|
||||||
|
CheckFeeding()
|
||||||
UpdateDisplay()
|
UpdateDisplay()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
|
driver:RegisterEvent("PLAYER_ENTERING_WORLD")
|
||||||
frame:RegisterEvent("UNIT_PET")
|
driver:RegisterEvent("UNIT_PET")
|
||||||
frame:RegisterEvent("PLAYER_REGEN_ENABLED") -- left combat
|
driver:RegisterEvent("UNIT_AURA")
|
||||||
|
driver:RegisterEvent("PLAYER_REGEN_ENABLED") -- left combat
|
||||||
|
|
||||||
|
driver:SetScript("OnEvent", function()
|
||||||
|
if event == "UNIT_AURA" then
|
||||||
|
if isHunter and arg1 == "pet" then
|
||||||
|
CheckFeeding()
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
frame:SetScript("OnEvent", function()
|
|
||||||
if event == "PLAYER_ENTERING_WORLD" then
|
if event == "PLAYER_ENTERING_WORLD" then
|
||||||
local _, englishClass = UnitClass("player")
|
local _, englishClass = UnitClass("player")
|
||||||
isHunter = (englishClass == "HUNTER")
|
isHunter = (englishClass == "HUNTER")
|
||||||
@@ -271,7 +329,14 @@ SlashCmdList["ADEPET"] = function(msg)
|
|||||||
frame:ClearAllPoints()
|
frame:ClearAllPoints()
|
||||||
frame:SetPoint("CENTER", UIParent, "CENTER", 0, 200)
|
frame:SetPoint("CENTER", UIParent, "CENTER", 0, 200)
|
||||||
DEFAULT_CHAT_FRAME:AddMessage("AdePet: position reset.")
|
DEFAULT_CHAT_FRAME:AddMessage("AdePet: position reset.")
|
||||||
|
elseif msg == "debug" then
|
||||||
|
-- Prints the raw values the client returns, for troubleshooting.
|
||||||
|
local happiness, damage, rate = GetPetHappiness()
|
||||||
|
DEFAULT_CHAT_FRAME:AddMessage("AdePet debug: GetPetHappiness = " .. tostring(happiness) .. " (" .. type(happiness) .. "), " .. tostring(damage) .. ", " .. tostring(rate))
|
||||||
|
local loyalty = GetPetLoyalty()
|
||||||
|
DEFAULT_CHAT_FRAME:AddMessage("AdePet debug: GetPetLoyalty = " .. tostring(loyalty) .. " (" .. type(loyalty) .. "), parsed level = " .. tostring(ParseLoyalty(loyalty)))
|
||||||
|
DEFAULT_CHAT_FRAME:AddMessage("AdePet debug: hungry = " .. tostring(isHungry) .. ", feeding = " .. tostring(PetIsFeeding()) .. ", interval = " .. GetHungryInterval() .. "s, window shown = " .. tostring(frame:IsShown()))
|
||||||
else
|
else
|
||||||
DEFAULT_CHAT_FRAME:AddMessage("AdePet commands: /adepet lock, unlock, reset | /hungry X")
|
DEFAULT_CHAT_FRAME:AddMessage("AdePet commands: /adepet lock, unlock, reset, debug | /hungry X")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user