Beast Lore: colour abilities by known status and add known/unknown filter

This commit is contained in:
DuvelCorp
2026-10-02 21:08:45 +02:00
parent c35258e615
commit 60171b559e
3 changed files with 112 additions and 3 deletions
+46
View File
@@ -24,6 +24,33 @@ function MTH_BOOK_GetBeastAbilitiesSummary(beast)
return tostring(beast.abilities)
end
-- Like the summary, but colours each ability green when the hunter already knows
-- that exact rank and red when it is still unlearned, to spot tameable upgrades.
function MTH_BOOK_GetBeastAbilitiesColored(beast)
if not beast or not beast.abilities or beast.abilities == "" or beast.abilities == "None" then
return "-"
end
local tokens = MTH_BOOK_SplitAbilities(beast.abilities)
if table.getn(tokens) == 0 then
return "-"
end
local canCheck = type(MTH_IsPetAbilityKnownByHunter) == "function"
local parts = {}
for i = 1, table.getn(tokens) do
local text = tostring(tokens[i])
if canCheck then
local _, label, rank = MTH_BOOK_ParseAbilityToken(tokens[i])
if MTH_IsPetAbilityKnownByHunter(label, rank) then
text = "|cff40ff40" .. text .. "|r"
else
text = "|cffff4040" .. text .. "|r"
end
end
table.insert(parts, text)
end
return table.concat(parts, ", ")
end
function MTH_BOOK_GetBeastZoneSummary(beast)
if not beast or not beast.coords or table.getn(beast.coords) == 0 then
return "-"
@@ -282,6 +309,22 @@ function MTH_BOOK_ParseBeastTraits(beast)
return traits
end
-- "known" keeps beasts with at least one ability the hunter already knows;
-- "unknown" keeps beasts that can still teach something not yet learned.
function MTH_BOOK_BeastMatchesAbilityKnowledge(beast, mode)
if type(MTH_IsPetAbilityKnownByHunter) ~= "function" then return true end
local tokens = MTH_BOOK_SplitAbilities(beast and beast.abilities)
local n = table.getn(tokens)
if n == 0 then return false end
for i = 1, n do
local _, label, rank = MTH_BOOK_ParseAbilityToken(tokens[i])
local known = MTH_IsPetAbilityKnownByHunter(label, rank)
if mode == "known" and known then return true end
if mode == "unknown" and not known then return true end
end
return false
end
function MTH_BOOK_BeastMatches(beastId, beast)
if not beast then return false end
local forcedBeastId = MTH_BOOK_STATE and tonumber(MTH_BOOK_STATE.forcedBeastId) or nil
@@ -305,6 +348,9 @@ function MTH_BOOK_BeastMatches(beastId, beast)
if not MTH_BOOK_HasKnownLevel(beast) then return false end
if not MTH_BOOK_HasKnownZone(beast) then return false end
end
if MTH_BOOK_STATE.petKnownFilter and MTH_BOOK_STATE.petKnownFilter ~= "all" then
if not MTH_BOOK_BeastMatchesAbilityKnowledge(beast, MTH_BOOK_STATE.petKnownFilter) then return false end
end
if MTH_BOOK_STATE.quick ~= "all" then
if familyLower ~= MTH_BOOK_STATE.quick then