Allright, this is a module i've made for my layout a while ago and always had the same issue with it, it works for the most part exept for warriors.
I use it to detect who's tank and who's not, it's fine for every tanking classes exept warriors since their defensive stance isn't an aura, it isn't even listed in the buffs list. So i'm simply checking if they have a shield equipped, unfortunately, it only works for myself.
For testing purposes, i play a dps warrior and run a dungeon with another warrior tanking. What is happening is, whenever i equip a shield, the tanking warrior is considered as a tank, but if i equip 2x 2h weapons, he's also being considered as a dps.
Could anyone shed some light on this please ?
Code:
local _, caelThreat = ...
local abs = math.abs
local playerClass = caelLib.playerClass
local unitClass, lastWarning, itemLink, itemType
caelThreat.eventFrame = CreateFrame("Frame", nil, self)
local warningSounds = true
local isTankClassSpec = {
["PALADIN"] = {
GetSpellInfo(25780), -- Righteous Fury
(GetSpellInfo(465)), -- Devotion Aura
},
["WARRIOR"] = function(unit) -- We check for this since Defensive Stance isn't an aura
if unit == "player" then
return IsEquippedItemType("Shields")
else
if CheckInteractDistance("unit", 1) then
NotifyInspect("unit")
itemLink = GetInventoryItemLink(unit, 17)
if itemLink then
itemType = select(7, GetItemInfo(itemLink))
end
return itemLink and (itemType == "Shields")
end
end
end,
["DEATHKNIGHT"] = GetSpellInfo(48263), -- Blood Presence
["DRUID"] = GetSpellInfo(5487), -- Bear Form
}
local function IsTankCheck(unit, check)
local status = false
_, unitClass = UnitClass(unit)
if type(check) == "table" then
status = true
for i = 1, #check do
if not UnitAura(unit, check[i]) then
status = false
end
end
elseif type(check) == "function" then
if isTankClassSpec[unitClass](unit) then
status = true
end
elseif check then
if UnitAura(unit, check) then
status = true
end
end
return status
end
local aggroColors = {
[true] = {
[1] = {1, 0.6, 0, 1},
[2] = {1, 1, 0.47, 1},
[3] = {0.33, 0.59, 0.33, 1},
},
[false] = {
[1] = {1, 1, 0.47, 1},
[2] = {1, 0.6, 0, 1},
[3] = {0.69, 0.31, 0.31, 1},
}
}
caelThreat.eventFrame:RegisterEvent("UNIT_AURA")
caelThreat.eventFrame:RegisterEvent("PARTY_MEMBERS_CHANGED")
caelThreat.eventFrame:RegisterEvent("UNIT_INVENTORY_CHANGED")
caelThreat.eventFrame:RegisterEvent("UNIT_THREAT_LIST_UPDATE")
caelThreat.eventFrame:RegisterEvent("UNIT_THREAT_SITUATION_UPDATE")
caelThreat.eventFrame:HookScript("OnEvent", function(self, event, unit)
if tostring(GetZoneText()) == "Wintergrasp" or MiniMapBattlefieldFrame.status == "active" then return end
if not unit then return end
_, unitClass = UnitClass(unit)
local unitIsTank = IsTankCheck(unit, isTankClassSpec[unitClass])
local playerIsTank = IsTankCheck("player", isTankClassSpec[playerClass])
if GetNumPartyMembers() > 0 then
if IsAddOnLoaded("oUF_Caellian") then
if not oUF.units[unit] then return end
local status = UnitThreatSituation(unit)
if (status and status > 0) then
local r, g, b = unpack(aggroColors[unitIsTank][status])
oUF.units[unit].FrameBackdrop:SetBackdropColor(r, g, b, a)
if oUF.units[unit].Overlay then
oUF.units[unit].Overlay:SetStatusBarColor(r, g, b, a)
end
else
oUF.units[unit].FrameBackdrop:SetBackdropColor(0, 0, 0, 0)
if oUF.units[unit].Overlay then
oUF.units[unit].Overlay:SetStatusBarColor(0.1, 0.1, 0.1, 0.75)
end
end
end
end
end)