diff --git a/ClassicAPI.lua b/ClassicAPI.lua index 67c03ab..20eec3a 100644 --- a/ClassicAPI.lua +++ b/ClassicAPI.lua @@ -95,6 +95,19 @@ function API.GetUnitAuraBySpellID(unit, spellID, filter) return C_UnitAuras.GetUnitAuraBySpellID(unit, spellID, filter) end +-- First matching aura on `unit` by spell NAME, or nil. Same whole-array search as +-- GetUnitAuraBySpellID; the name is case-sensitive and locale-resolved, so pass it +-- in the client's locale (what C_Spell.GetSpellName returns). filter +-- ("HELPFUL"/"HARMFUL") restricts the search. Prefer the by-ID variant for +-- portability where a spellID is known. +function API.GetAuraDataBySpellName(unit, spellName, filter) + if not unit or not spellName or spellName == "" then return nil end + if type(C_UnitAuras) ~= "table" or type(C_UnitAuras.GetAuraDataBySpellName) ~= "function" then + return nil + end + return C_UnitAuras.GetAuraDataBySpellName(unit, spellName, filter) +end + -------------------------------------------------------------------------------- -- GetUnitSpeed -------------------------------------------------------------------------------- diff --git a/Utility.lua b/Utility.lua index 35a9fd5..fadcb36 100644 --- a/Utility.lua +++ b/Utility.lua @@ -8800,23 +8800,12 @@ function CleveRoids.CheckImmunity(unitId, spellOrSchool) end end - -- Check buff-based immunity (if NPC has the required buff) + -- Check buff-based immunity (if NPC has the required buff). One by-name + -- lookup across the unit's buffs via C_UnitAuras -- no 32-slot scan. if immunityData.buff then - local requiredBuff = immunityData.buff - - -- Check target's buffs - for i = 1, 32 do - local texture, stacks, spellID = UnitBuff(unitId, i) - if not texture then break end - - if spellID then - local buffName = C_Spell.GetSpellName(spellID) - if buffName and buffName == requiredBuff then - return true - end - end + if CleveRoids.ClassicAPI.GetAuraDataBySpellName(unitId, immunityData.buff, "HELPFUL") then + return true end - -- Buff not found, not currently immune return false end