Refactor nameplate cast tracking to be fully GUID-based

Problem:
Since a recent Turtle-WoW update, nameplates would show the same castbar on all mobs sharing a name (e.g. multiple "Defias Rogue Wizard"). Additionally, a targeted mob that was not casting would incorrectly display the castbar of a nearby mob with the same name.

Changes:
**`modules/nameplates.lua`**
- Removed `hasNampower` version-sniffing entirely. Nampower is a hard requirement for pfUI; all related guards have been removed and the code runs unconditionally.
- Castbar lookup now always uses `nameplate.cachedGuid` directly — never `GetUnitGUID("target")` or a unit name string.
- Removed dead fallback block using `UnitCastingInfo("target")`.
- Restored fallback via `pfGetCastInfo(cachedGuid)` / `pfGetChannelInfo(cachedGuid)` (see libcast changes below) for casts not tracked by libdebuff (e.g. already-in-progress casts on login).

**`libs/libcast.lua`**
- Renamed `UnitCastingInfo` → `pfGetCastInfo` and `UnitChannelInfo` → `pfGetChannelInfo` to avoid confusion with the Blizzard API of the same name, which does not exist in Vanilla.
- Name-based fallback lookup (`libcast.db[unitName]`) is now skipped when a GUID is available. This prevents cast bleed between mobs that share a name.

**`libs/libpredict.lua`, `modules/castbar.lua`, `modules/afkcam.lua`**
- Updated all call sites to use the renamed `pfGetCastInfo` / `pfGetChannelInfo`.
This commit is contained in:
Meow
2026-03-23 10:47:42 +01:00
parent cd4a3343cb
commit 2ef9c5ee1e
5 changed files with 84 additions and 135 deletions
+10 -8
View File
@@ -4,10 +4,10 @@ setfenv(1, pfUI:GetEnvironment())
--[[ libcast ]]--
-- A pfUI library that detects and saves all ongoing castbars of players, NPCs and enemies.
-- The library also includes spells that usually don't have a castbar like Multi-Shot and Aimed Shot.
-- This is exclusivly used for vanilla in order to provide UnitChannelInfo and UnitCastingInfo functions.
-- This is exclusivly used for vanilla in order to provide pfGetChannelInfo and pfGetCastInfo functions.
--
-- External functions:
-- UnitChannelInfo(unit)
-- pfGetChannelInfo(unit)
-- Returns information on the spell currently cast by the specified unit.
-- Returns nil if no spell is being cast.
--
@@ -19,7 +19,7 @@ setfenv(1, pfUI:GetEnvironment())
-- endTime[Number] - Specifies when casting will end, in milliseconds.
-- isTradeSkill[Boolean] - (DUMMY) Specifies if the cast is a tradeskill
--
-- UnitCastingInfo(unit)
-- pfGetCastInfo(unit)
-- Returns information on the spell currently channeled by the specified unit.
-- Returns nil if no spell is being channeled.
--
@@ -53,7 +53,7 @@ local scanner = libtipscan:GetScanner("libcast")
local libcast = CreateFrame("Frame", "pfEnemyCast")
local player = UnitName("player")
UnitChannelInfo = function(unit)
pfGetChannelInfo = function(unit)
-- convert to name if unitstring was given
local unitName = pfValidUnits[unit] and UnitName(unit) or unit
@@ -117,7 +117,8 @@ UnitChannelInfo = function(unit)
end
-- Fallback to name-based lookup (CHAT_MSG castbars)
if not db and libcast.db[unitName] then
-- Skip when GUID is available to avoid same-name mob bleed
if not db and not guid and libcast.db[unitName] then
db = libcast.db[unitName]
end
@@ -145,7 +146,7 @@ UnitChannelInfo = function(unit)
return cast, nameSubtext, text, texture, startTime, endTime, isTradeSkill
end
UnitCastingInfo = function(unit)
pfGetCastInfo = function(unit)
-- convert to name if unitstring was given
local unitName = pfValidUnits[unit] and UnitName(unit) or unit
@@ -209,7 +210,8 @@ UnitCastingInfo = function(unit)
end
-- Fallback to name-based lookup (CHAT_MSG castbars)
if not db and libcast.db[unitName] then
-- Skip when GUID is available to avoid same-name mob bleed
if not db and not guid and libcast.db[unitName] then
db = libcast.db[unitName]
end
@@ -533,7 +535,7 @@ local function CastCustom(id, bookType, rawSpellName, rank, texture, castingTime
local func = libcast.customcast[strlower(rawSpellName)]
if not func then return end
if GetSpellCooldown(id, bookType) == 0 or UnitCastingInfo(player) then return end -- detect casting
if GetSpellCooldown(id, bookType) == 0 or pfGetCastInfo(player) then return end -- detect casting
func(true)
end
+5 -5
View File
@@ -446,7 +446,7 @@ function libpredict:ParseComm(sender, msg)
rank = tonumber(rankStr)
end
end
elseif select and UnitCastingInfo then
elseif select and pfGetCastInfo then
-- latest healcomm
msgtype = tonumber(string.sub(msg, 1, 3))
if not msgtype then return end
@@ -456,8 +456,8 @@ function libpredict:ParseComm(sender, msg)
heal = tonumber(string.sub(msg, 4, 8))
target = string.sub(msg,9, -1)
local starttime = select(5, UnitCastingInfo(sender))
local endtime = select(6, UnitCastingInfo(sender))
local starttime = select(5, pfGetCastInfo(sender))
local endtime = select(6, pfGetCastInfo(sender))
if not starttime or not endtime then return end
time = endtime - starttime
elseif msgtype == 1 then
@@ -466,8 +466,8 @@ function libpredict:ParseComm(sender, msg)
msgtype = "Heal"
heal = tonumber(string.sub(msg,4, 8))
target = {strsplit(":", string.sub(msg,9, -1))}
local starttime = select(5, UnitCastingInfo(sender))
local endtime = select(6, UnitCastingInfo(sender))
local starttime = select(5, pfGetCastInfo(sender))
local endtime = select(6, pfGetCastInfo(sender))
if not starttime or not endtime then return end
time = endtime - starttime
end