Refactor: Tracking spell detection

Improved tracking spell detection to use SpellID + icon path matching (case-insensitive) for more accurate and locale-independent results
This commit is contained in:
Meow
2026-04-02 19:32:00 +02:00
parent 1b04754a30
commit fbb1b9df46
+63 -61
View File
@@ -14,34 +14,46 @@ pfUI:RegisterModule("tracking", "vanilla", function ()
local size = tonumber(C.appearance.minimap.tracking_size) local size = tonumber(C.appearance.minimap.tracking_size)
local pulse = C.appearance.minimap.tracking_pulse == "1" local pulse = C.appearance.minimap.tracking_pulse == "1"
local knownTrackingSpellTextures = { -- Tracking spells identified by SpellID + expected icon path.
-- SpellID is the primary identifier (stable, locale-independent).
-- Icon path is used as secondary confirmation when scanning the spellbook.
local knownTrackingSpells = {
any = { any = {
"Racial_Dwarf_FindTreasure", -- Find Treasure { id = 2481, icon = "Racial_Dwarf_FindTreasure" }, -- Find Treasure
"Spell_Nature_Earthquake", -- Find Minerals { id = 2580, icon = "Spell_Nature_Earthquake" }, -- Find Minerals
"INV_Misc_Flower_02", -- Find Herbs { id = 2383, icon = "INV_Misc_Flower_02" }, -- Find Herbs (Rank 1)
"inv_tradeskillitem_03" -- Find Trees (TurtleWow Survival) { id = 8387, icon = "INV_Misc_Flower_02" }, -- Find Herbs (Rank 2)
{ id = 52917, icon = "INV_TradeSkillItem_03" }, -- Find Trees (TurtleWow)
}, },
HUNTER = { HUNTER = {
"Ability_Tracking", -- Track Beasts, 4+ { id = 1494, icon = "Ability_Tracking" }, -- Track Beasts
"Spell_Holy_PrayerOfHealing", -- Track Humanoids, 10+ { id = 19883, icon = "Spell_Holy_PrayerOfHealing" }, -- Track Humanoids
"Spell_Shadow_DarkSummoning", -- Track Undead, 18+ { id = 19884, icon = "Spell_Shadow_DarkSummoning" }, -- Track Undead
"Ability_Stealth", -- Track Hidden, 24+ { id = 19885, icon = "Ability_Stealth" }, -- Track Hidden
"Spell_Frost_SummonWaterElemental", -- Track Elementals, 26+ { id = 19880, icon = "Spell_Frost_SummonWaterElemental" }, -- Track Elementals
"Spell_Shadow_SummonFelHunter", -- Track Deamons, 32+ { id = 19878, icon = "Spell_Shadow_SummonFelHunter" }, -- Track Demons
"Ability_Racial_Avatar", -- Track Giants, 40+ { id = 19882, icon = "Ability_Racial_Avatar" }, -- Track Giants
"INV_Misc_Head_Dragon_01" -- Track Dragonkin, 50+ { id = 19879, icon = "INV_Misc_Head_Dragon_01" }, -- Track Dragonkin
}, },
PALADIN = { PALADIN = {
"Spell_Holy_SenseUndead" -- Sense Undead, 20+ { id = 5502, icon = "Spell_Holy_SenseUndead" }, -- Sense Undead
}, },
WARLOCK = { WARLOCK = {
"Spell_Shadow_Metamorphosis" -- Sense Demons, 24+ { id = 5500, icon = "Spell_Shadow_Metamorphosis" }, -- Sense Demons
}, },
DRUID = { DRUID = {
"Ability_Tracking" -- Track Humanoids, 32+, Cat Form only! { id = 5225, icon = "Ability_Tracking" }, -- Track Humanoids (Cat Form only)
} },
} }
-- Build a flat lookup: spellId -> entry, for fast spellbook matching
local spellIdLookup = {}
for _, entries in pairs(knownTrackingSpells) do
for _, entry in ipairs(entries) do
spellIdLookup[entry.id] = entry
end
end
local state = { local state = {
texture = nil, texture = nil,
spells = {} spells = {}
@@ -73,7 +85,6 @@ pfUI:RegisterModule("tracking", "vanilla", function ()
if event == "SPELLS_CHANGED" then if event == "SPELLS_CHANGED" then
state.spells = {} state.spells = {}
end end
this:RefreshSpells() this:RefreshSpells()
this:RefreshMenu() this:RefreshMenu()
end) end)
@@ -87,7 +98,6 @@ pfUI:RegisterModule("tracking", "vanilla", function ()
elseif alpha <= .5 then elseif alpha <= .5 then
this.modifier = 0.03 / fpsmod this.modifier = 0.03 / fpsmod
end end
this.icon:SetVertexColor(1,1,1,alpha + this.modifier) this.icon:SetVertexColor(1,1,1,alpha + this.modifier)
end end
end) end)
@@ -121,55 +131,49 @@ pfUI:RegisterModule("tracking", "vanilla", function ()
local _, playerClass = UnitClass("player") local _, playerClass = UnitClass("player")
local isCatForm = pfUI.tracking:PlayerIsDruidInCatForm(playerClass) local isCatForm = pfUI.tracking:PlayerIsDruidInCatForm(playerClass)
-- Build set of valid SpellIDs for this class
local validIds = {}
for _, entry in ipairs(knownTrackingSpells.any) do
validIds[entry.id] = true
end
if knownTrackingSpells[playerClass] then
for _, entry in ipairs(knownTrackingSpells[playerClass]) do
validIds[entry.id] = true
end
end
-- Druids only get Track Humanoids in Cat Form
if playerClass == "DRUID" and not isCatForm then
validIds[5225] = nil
end
-- Scan spellbook: match by icon path, confirm SpellID is valid for this class
for tabIndex = 1, GetNumSpellTabs() do for tabIndex = 1, GetNumSpellTabs() do
local _, _, offset, numSpells = GetSpellTabInfo(tabIndex) local _, _, offset, numSpells = GetSpellTabInfo(tabIndex)
for spellIndex = offset + 1, offset + numSpells do for spellIndex = offset + 1, offset + numSpells do
local spellTexture = GetSpellTexture(spellIndex, BOOKTYPE_SPELL) local spellTexture = GetSpellTexture(spellIndex, BOOKTYPE_SPELL)
local spellName = GetSpellName(spellIndex, BOOKTYPE_SPELL) local spellName = GetSpellName(spellIndex, BOOKTYPE_SPELL)
-- disable and remove invalid spells
if pfUI.tracking.invalidSpells[spellName] then if pfUI.tracking.invalidSpells[spellName] then
-- delete all previously set bad spell icons
for _, texture in pairs(knownTrackingSpellTextures["any"]) do
if spellTexture and strfind(spellTexture, texture) then
state.spells[texture] = nil
end
end
-- unset current variable to stop here
spellTexture = nil spellTexture = nil
end end
-- scan for generic tracking icons if spellTexture then
for _, texture in pairs(knownTrackingSpellTextures["any"]) do local lowerTexture = string.lower(spellTexture)
if spellTexture and strfind(spellTexture, texture) and not state.spells[texture] then for spellId, entry in pairs(spellIdLookup) do
state.spells[texture] = { if validIds[spellId] and not state.spells[spellId]
index = spellIndex, and strfind(lowerTexture, string.lower(entry.icon)) then
name = GetSpellName(spellIndex, BOOKTYPE_SPELL), state.spells[spellId] = {
texture = spellTexture index = spellIndex,
} name = spellName,
end texture = spellTexture,
end spellId = spellId,
}
-- scan class specific tracking icons
if knownTrackingSpellTextures[playerClass] then
for _, texture in pairs(knownTrackingSpellTextures[playerClass]) do
if spellTexture and strfind(spellTexture, texture) and not state.spells[texture] then
state.spells[texture] = {
index = spellIndex,
name = GetSpellName(spellIndex, BOOKTYPE_SPELL),
texture = spellTexture
}
end end
end end
end end
end end
end end
-- remove humanoid tracking for non-cat druids
if playerClass == "DRUID" and not isCatForm then
state.spells["Ability_Tracking"] = nil
end
end end
function pfUI.tracking:RefreshMenu() function pfUI.tracking:RefreshMenu()
@@ -197,12 +201,10 @@ pfUI:RegisterModule("tracking", "vanilla", function ()
function pfUI.tracking:PlayerIsDruidInCatForm(playerClass) function pfUI.tracking:PlayerIsDruidInCatForm(playerClass)
if playerClass == "DRUID" then if playerClass == "DRUID" then
for i = 0, 31 do local b = GetUnitField("player", "bytes1")
local texture = GetPlayerBuffTexture(i) if b then
if not texture then break end local form = math.floor(b / 65536) - math.floor(b / 16777216) * 256
if strfind(texture, "Ability_Druid_CatForm") then return form == 1 -- 1 = Cat Form
return true
end
end end
end end
return false return false
@@ -229,4 +231,4 @@ pfUI:RegisterModule("tracking", "vanilla", function ()
end end
end, "MENU") end, "MENU")
end end
end) end)