Загрузить файлы в «/»

This commit is contained in:
Ade
2026-10-26 19:13:05 +00:00
parent c3b59dcd54
commit 0c6db42be8
4 changed files with 103 additions and 8 deletions
+46 -5
View File
@@ -94,6 +94,18 @@ local function ResizeToText()
frame:SetHeight(height)
end
-- While the player is flagged AFK, the addon makes no pet queries at all.
-- On some servers (seen on OctoWoW) pet API calls count as player activity,
-- which clears the AFK flag and makes it flicker on/off while standing still.
-- Checks simply resume on the first tick after the AFK flag is gone.
local chatAFK = false -- fallback if the client has no UnitIsAFK
local function IsPlayerAFK()
if UnitIsAFK then
return UnitIsAFK("player") and true or false
end
return chatAFK
end
-- Reads the pet's happiness. 1 = unhappy, 2 = content, 3 = happy.
-- Anything below "happy" is treated as hungry.
local function UpdateHunger()
@@ -241,13 +253,23 @@ driver:SetScript("OnUpdate", function()
loyaltyElapsed = loyaltyElapsed + arg1
hungerElapsed = hungerElapsed + arg1
-- Work at most once per second.
if loyaltyElapsed < LOYALTY_INTERVAL then
return
end
loyaltyElapsed = 0
-- AFK: touch nothing. hungerElapsed keeps growing, so the first tick after
-- the AFK flag is gone runs a full hunger check right away.
if IsPlayerAFK() then
return
end
if hungerElapsed >= GetHungryInterval() then
hungerElapsed = 0
loyaltyElapsed = 0
CheckFeeding()
CheckHunger()
elseif loyaltyElapsed >= LOYALTY_INTERVAL then
loyaltyElapsed = 0
else
CheckFeeding()
UpdateDisplay()
end
@@ -257,10 +279,22 @@ driver:RegisterEvent("PLAYER_ENTERING_WORLD")
driver:RegisterEvent("UNIT_PET")
driver:RegisterEvent("UNIT_AURA")
driver:RegisterEvent("PLAYER_REGEN_ENABLED") -- left combat
driver:RegisterEvent("CHAT_MSG_SYSTEM") -- only used for the AFK fallback
driver:SetScript("OnEvent", function()
if event == "CHAT_MSG_SYSTEM" then
if arg1 then
if string.find(arg1, "now AFK", 1, true) then
chatAFK = true
elseif string.find(arg1, "no longer AFK", 1, true) then
chatAFK = false
end
end
return
end
if event == "UNIT_AURA" then
if isHunter and arg1 == "pet" then
if isHunter and arg1 == "pet" and not IsPlayerAFK() then
CheckFeeding()
end
return
@@ -289,6 +323,13 @@ driver:SetScript("OnEvent", function()
return
end
-- While AFK, don't query the pet: just make sure the next non-AFK tick
-- runs a hunger check.
if IsPlayerAFK() then
hungerElapsed = GetHungryInterval()
return
end
-- Entering world, pet change, or leaving combat: check hunger right away.
hungerElapsed = 0
CheckHunger()
@@ -335,7 +376,7 @@ SlashCmdList["ADEPET"] = function(msg)
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()))
DEFAULT_CHAT_FRAME:AddMessage("AdePet debug: hungry = " .. tostring(isHungry) .. ", feeding = " .. tostring(PetIsFeeding()) .. ", interval = " .. GetHungryInterval() .. "s, window shown = " .. tostring(frame:IsShown()) .. ", AFK = " .. tostring(IsPlayerAFK()) .. " (UnitIsAFK " .. (UnitIsAFK and "available" or "missing") .. ")")
else
DEFAULT_CHAT_FRAME:AddMessage("AdePet commands: /adepet lock, unlock, reset, debug | /hungry X")
end