tank:SetShadowOffset(1, -1) |
end |
|
-- Initialize show/hide handler coroutine |
local displayHandler = coroutine.create(function() |
local show = false |
-- Group-based handlers |
if (showSolo and not (UnitExists("pet") or GetRealNumPartyMembers() or GetRealNumRaidMembers())) then show = true end |
if (showWithPet and UnitExists("pet")) then show = true end |
if (showInParty and GetRealNumPartyMembers()) then show = true end |
if (showInRaid and GetRealNumRaidMembers()) then show = true end |
-- Aggro handler |
if (hideIfTanking and playerInfo.tanking) then show = false end |
-- Locked handler |
if (not locked) then show = true end |
|
if (show) then frame:Show else frame:Hide end |
if (showPercent) then |
if (showTank) then tank:Show() else tank:Hide() end |
end) |
|
-- Update handler |
frame:SetScript("OnUpdate", function(self, elapsed) |
local isTanking, playerThreat, threatPercent, tankThreat, threatDiff |
|
-- Don't update too quickly. New handler using OnUpdate's built-in elapsed time variable to eliminate a GetTime call |
local player, tank, ToT = {}, {}, {} |
|
-- Only run if we have an NPC target with a target (or 'locked' is false), otherwise don't waste the cycles |
if (not UnitExists("target") or not UnitExists("targettarget") or UnitIsPlayer("target") or locked) then return end |
|
-- Don't update too quickly |
if (timeSinceLastUpdate == nil) then timeSinceLastUpdate = 0 end |
timeSinceLastUpdate = timeSinceLastUpdate + elapsed |
if (timeSinceLastUpdate < updateTime) then |
return |
else |
timeSinceLastUpdate = 0 |
if (timeSinceLastUpdate >= updateTime) then timeSinceLastUpdate = 0 |
else return |
end |
|
-- For configuring the anchor |
if (not locked) then |
threat:SetText("50%") |
if (showTank) then |
tank:SetText("SomeTank") |
else |
tank:SetText("") |
coroutine.resume(displayHandler) -- Runs the displayHandler coroutine in parallel, since it doesn't affect the following code |
|
-- Get threat values and determine tank status |
player.tanking, player.status, _, _, player.threat = UnitDetailedThreatSituation("player", "target") |
ToT.name = UnitName("targettarget") |
if (tank.name and ToT.name == tank.name) then -- Check to see if ToT is actually our tank so we can display the correct data |
_, _, _, _, tank.threat = UnitDetailedThreatSituation("targettarget", "target") |
elseif (tank.name) then |
_, _, _, _, ToT.threat = UnitDetailedThreatSituation(ToT.name, "target") |
_, _, _, _, tank.threat = UnitDetailedThreatSituation(tank.name, "target") |
if (ToT.threat > tank.threat) then -- We aren't using 'ToT.tanking' because it's faster to just assume ToT is tanking until the target actually starts attacking its tank |
tank.name = ToT.name |
tank.threat = ToT.threat |
end |
return |
end |
|
-- Clear display if no target |
if (not UnitExists("target") or not UnitExists("targettarget")) then |
threat:SetText("") |
tank:SetText("") |
return |
end |
|
-- Don't update if we don't have a pet, are not in a party or raid |
if (not UnitExists("pet")) and (not UnitExists("Party1")) and (not UnitExists("Raid1")) then |
threat:SetText("") |
tank:SetText("") |
return |
end |
|
-- Get threat values |
_, _, _, threatPercent, playerThreat = UnitDetailedThreatSituation("player", "target") |
_, _, _, _, tankThreat = UnitDetailedThreatSituation("targettarget", "target") |
if (playerThreat and playerThreat > 0 and tankThreat and tankThreat > 0) then |
threatPercent = (playerThreat / tankThreat) * 100 -- 'threatPercent' gets reset, even after being set to a value, because it isn't handled correctly in the script, yet |
threatDiff = playerThreat - tankThreat -- Pre-seed for "threat until aggro" display |
else |
return -- Drop out if any tests are false. Players don't get threat against players, so the script will throw an error if we don't drop out here |
tank.name = ToT.name |
_, _, _, _, tank.threat = UnitDetailedThreatSituation(tank.name, "target") |
end |
threatPercent = (playerThreat / tankThreat) * 100 -- 'threatPercent' gets reset, even after being set to a value, because it isn't handled correctly in the script, yet |
threatDiff = playerThreat - tankThreat -- Pre-seed for "threat until aggro" display |
|
-- Color threat font |
if (showColor) then |
if (threatPercent >= 100) then |
-- Set 'threat' display |
-- Color 'threat' font |
if (colorThreat) then |
if (threatPercent >= threatRedThreshold) then |
threat:SetTextColor(1, 0, 0) |
elseif (threatPercent >= 80) then |
elseif (threatPercent >= threatYellowThreshold) then |
threat:SetTextColor(1, 1, 0) |
else |
threat:SetTextColor(0, 1, 0) |
end |
end |
threat:SetText(threatPercent:floor() .. "%") |
|
-- Display values |
if (threatPercent > 130 and hideIfAggro) then |
-- We got aggro for sure, don't display anything unless 'hideIfAggro' is false |
threat:SetText("") |
elseif (threatPercent >= 100) then |
threat:SetText(tostring(threatPercent):sub(1,3) .. "%") |
elseif (threatPercent >= 10) then |
threat:SetText(tostring(threatPercent):sub(1,2) .. "%") |
else |
threat:SetText(tostring(threatPercent):sub(1,1) .. "%") |
-- Set 'info' display |
-- Color 'info' font |
if (colorInfo) then |
if (threatPercent >= threatRedThreshold) then |
threat:SetTextColor(1, 0, 0) |
elseif (threatPercent >= threatYellowThreshold) then |
threat:SetTextColor(1, 1, 0) |
else |
threat:SetTextColor(0, 1, 0) |
end |
end |
tank:SetText(UnitName("targettarget")) |
if (infoIsTank) then |
info:SetText(UnitName("targettarget")) |
elseif (player.status == 3) then |
info:SetText("Strongly Tanking") |
elseif (player.status == 2) then |
info:SetText("Weakly Tanking") |
elseif (player.status == 1) then |
info:SetText("Threat High") |
elseif (player.status == 0) then |
info:SetText("Threat Low") |
end |
end) |