Fix pet loyalty notifications and trim level-up copy

- Loyalty now read from MTH_GetCurrentPetInfo().loyaltyLevel; GetPetLoyalty()
  returns a localized name (not a number), so the loyalty branch never fired
- Listen for UNIT_HAPPINESS so a loyalty gain actually triggers the check
- Drop redundant 'has leveled up' / 'is now <rank>' openers from pet and
  loyalty lines, keeping the sarcasm
This commit is contained in:
DuvelCorp
2026-09-13 09:54:04 +02:00
parent d1d2660c2c
commit dec41628ad
+22 -15
View File
@@ -87,20 +87,20 @@ local MTH_LT_Priority = {
} }
local MTH_LT_PetLines = { local MTH_LT_PetLines = {
"has leveled up. It is now statistically better than your last pull.", "It is now statistically better than your last pull.",
"has leveled up. The food budget has noticed.", "The food budget has noticed.",
"has leveled up. Please do not celebrate by pulling three extra mobs.", "Please do not celebrate by pulling three extra mobs.",
"has leveled up. It remains committed to solving problems with teeth.", "It remains committed to solving problems with teeth.",
"has leveled up. The wilderness has filed no objection.", "The wilderness has filed no objection.",
"has leveled up. Your dependable colleague is carrying this team again.", "Your dependable colleague is carrying this team again.",
} }
local MTH_LT_LoyaltyLines = { local MTH_LT_LoyaltyLines = {
[2] = "is now Unruly. It tolerates your leadership as long as the food arrives on time.", [2] = "It tolerates your leadership as long as the food arrives on time.",
[3] = "is now Submissive. Your authority has been acknowledged, reluctantly.", [3] = "Your authority has been acknowledged, reluctantly.",
[4] = "is now Dependable. It has decided your plans are survivable often enough.", [4] = "It has decided your plans are survivable often enough.",
[5] = "is now Faithful. Please do not reward this trust with an elite pull.", [5] = "Please do not reward this trust with an elite pull.",
[6] = "is your Best Friend. Against all evidence, it trusts you completely.", [6] = "Against all evidence, it trusts you completely.",
} }
local function MTH_LT_Store() local function MTH_LT_Store()
@@ -273,9 +273,13 @@ local function MTH_LT_GetPetState()
local level = type(UnitLevel) == "function" and tonumber(UnitLevel("pet")) or nil local level = type(UnitLevel) == "function" and tonumber(UnitLevel("pet")) or nil
local name = type(UnitName) == "function" and UnitName("pet") or "Your pet" local name = type(UnitName) == "function" and UnitName("pet") or "Your pet"
if not level or level <= 0 then return nil end if not level or level <= 0 then return nil end
-- Loyalty is a localized name via GetPetLoyalty(); reuse the pet service which
-- parses it (plus UI fallbacks) into a numeric 1-6 level.
local loyalty = nil local loyalty = nil
local getPetLoyalty = (type(getglobal) == "function" and getglobal("GetPetLoyalty")) or (_G and _G["GetPetLoyalty"]) if type(MTH_GetCurrentPetInfo) == "function" then
if type(getPetLoyalty) == "function" then loyalty = tonumber(getPetLoyalty()) end local info = MTH_GetCurrentPetInfo()
if type(info) == "table" then loyalty = tonumber(info.loyaltyLevel) or nil end
end
return { key = tostring(name or "pet"), name = tostring(name or "Your pet"), level = level, loyalty = loyalty } return { key = tostring(name or "pet"), name = tostring(name or "Your pet"), level = level, loyalty = loyalty }
end end
@@ -296,7 +300,7 @@ local function MTH_LT_HandlePetState()
MTH_LT_HandlePetGrowlLevel(state.name, state.level) MTH_LT_HandlePetGrowlLevel(state.name, state.level)
end end
if state.loyalty and state.loyalty > 1 and state.loyalty > (tonumber(pet.loyalty) or 0) then if state.loyalty and state.loyalty > 1 and state.loyalty > (tonumber(pet.loyalty) or 0) then
local line = MTH_LT_LoyaltyLines[state.loyalty] or "has gained a loyalty level. The food arrangement appears to be working." local line = MTH_LT_LoyaltyLines[state.loyalty] or "The food arrangement appears to be working."
if MTH_LT_MessageEnabled("petLoyaltyUp", true) then MTH:Print(state.name .. " reached Loyalty Level " .. state.loyalty .. ". " .. line) end if MTH_LT_MessageEnabled("petLoyaltyUp", true) then MTH:Print(state.name .. " reached Loyalty Level " .. state.loyalty .. ". " .. line) end
if type(MTH_FX_IsEnabled) == "function" and MTH_FX_IsEnabled("level.loyalty") and type(MTH_Celebrate) == "function" then if type(MTH_FX_IsEnabled) == "function" and MTH_FX_IsEnabled("level.loyalty") and type(MTH_Celebrate) == "function" then
MTH_Celebrate(state.name .. " - Loyalty " .. state.loyalty, line, state.loyalty == 6 and "victory" or "fanfare") MTH_Celebrate(state.name .. " - Loyalty " .. state.loyalty, line, state.loyalty == 6 and "victory" or "fanfare")
@@ -333,7 +337,7 @@ function MTH_LevelTracker_Test(kind, level)
return false return false
end end
local petName = state and state.name or "Your pet" local petName = state and state.name or "Your pet"
local line = MTH_LT_LoyaltyLines[loyalty] or "has gained a loyalty level. The food arrangement appears to be working." local line = MTH_LT_LoyaltyLines[loyalty] or "The food arrangement appears to be working."
MTH:Print(petName .. " reached Loyalty Level " .. tostring(loyalty) .. ". " .. line) MTH:Print(petName .. " reached Loyalty Level " .. tostring(loyalty) .. ". " .. line)
if type(MTH_Celebrate) == "function" then if type(MTH_Celebrate) == "function" then
MTH_Celebrate(petName .. " - Loyalty " .. tostring(loyalty), line, loyalty == 6 and "victory" or "fanfare") MTH_Celebrate(petName .. " - Loyalty " .. tostring(loyalty), line, loyalty == 6 and "victory" or "fanfare")
@@ -351,6 +355,7 @@ function MTH_LevelTracker_Initialize()
MTH_LT_Frame:RegisterEvent("UNIT_LEVEL") MTH_LT_Frame:RegisterEvent("UNIT_LEVEL")
MTH_LT_Frame:RegisterEvent("UNIT_PET") MTH_LT_Frame:RegisterEvent("UNIT_PET")
MTH_LT_Frame:RegisterEvent("PET_BAR_UPDATE") MTH_LT_Frame:RegisterEvent("PET_BAR_UPDATE")
MTH_LT_Frame:RegisterEvent("UNIT_HAPPINESS")
MTH_LT_Frame:SetScript("OnEvent", function() MTH_LT_Frame:SetScript("OnEvent", function()
if event == "PLAYER_ENTERING_WORLD" then if event == "PLAYER_ENTERING_WORLD" then
local level = type(UnitLevel) == "function" and tonumber(UnitLevel("player")) or nil local level = type(UnitLevel) == "function" and tonumber(UnitLevel("player")) or nil
@@ -364,6 +369,8 @@ function MTH_LevelTracker_Initialize()
MTH_LT_RequestPetCheck() MTH_LT_RequestPetCheck()
elseif event == "PET_BAR_UPDATE" then elseif event == "PET_BAR_UPDATE" then
MTH_LT_RequestPetCheck() MTH_LT_RequestPetCheck()
elseif event == "UNIT_HAPPINESS" then
MTH_LT_RequestPetCheck()
end end
end) end)
end end