/trunk/MyThreat
local MYTHREAT_VERSION = '1.3.4'; |
local MYTHREAT_VERSION = '1.4'; |
local MYTHREAT_ADJUST_VALUE = -410065408; |
local options = { |
type='group', |
MyThreat:Print('Current version: ' .. MYTHREAT_VERSION); |
end, |
}, |
autoAdjust = { |
type = 'toggle', |
name = 'Auto-adjust threat', |
desc = 'Auto-adjusts threat when abilities such as Fade and Mirror Image are active.', |
get = function() |
return MyThreat.db.profile.autoAdjust; |
end, |
set = function() |
MyThreat.db.profile.autoAdjust = not MyThreat.db.profile.autoAdjust; |
MyThreat:Process(); |
end; |
} |
} |
}; |
}, |
fontSize = 16, |
tankMode = false, |
autoAdjust = true, |
} |
}); |
function MyThreat:GetThreat(pUnit, pTarget) |
local isTanking, _, _, _, threatValue = UnitDetailedThreatSituation(pUnit, pTarget); |
local adjusted = false; |
-- adjust threat for Mirror Image and Fade abilities |
if (threatValue and threatValue < 0 and pUnit == "player" and MyThreat.db.profile.autoAdjust) then |
threatValue = threatValue - MYTHREAT_ADJUST_VALUE; |
adjusted = true; |
end |
return threatValue, isTanking; |
return threatValue, isTanking, adjusted; |
end |
function MyThreat:Process() |
-- use current handler to get threat information |
local threatDiff, threatDiffPercent, tankName = MyThreat.threatSourceHandler(); |
local threatDiff, threatDiffPercent, tankName, adjusted = MyThreat.threatSourceHandler(); |
-- if there is a current tank |
if (tankName ~= nil and threatDiff ~= nil and threatDiffPercent ~= nil) then |
MyThreat_ThreatFrameThreatPlayerName:Show(); |
end |
local threatText, relativeThreatText; |
local r = 0; |
local g = 1; |
local b = 0; |
-- set the label for absolute threat diff |
-- set the text for absolute threat diff |
if (threatDiff >= 1000 or threatDiff <= -1000) then |
MyThreat_ThreatFrameThreatDiff:SetText(format("%.2f", threatDiff / 1000) .. "k"); |
threatText = format("%.2f", threatDiff / 1000) .. "k"; |
else |
MyThreat_ThreatFrameThreatDiff:SetText(format("%.0f", threatDiff)); |
threatText = format("%.0f", threatDiff); |
end |
-- set relative text |
relativeThreatText = format("%.0f", threatDiffPercent * 100) .. "%"; |
if (adjusted) then |
r = 0.4; |
g = 0.8; |
b = 0.95; |
threatText = "(" .. threatText .. ")"; |
relativeThreatText = "(" .. relativeThreatText .. ")"; |
else |
-- set the label for relative threat diff |
MyThreat_ThreatFrameThreatPercDiff:SetText(format("%.0f", threatDiffPercent * 100) .. "%"); |
local r = 0; |
local g = 1; |
-- set the right bar colors |
if (threatDiff <= MyThreat.db.profile.red.absolute or threatDiffPercent >= MyThreat.db.profile.red.relative) then |
r = 1; |
g = 0; |
elseif (threatDiff <= MyThreat.db.profile.orange.absolute or threatDiffPercent >= MyThreat.db.profile.orange.relative) then |
r = 1; |
g = 0.5; |
elseif (threatDiff <= MyThreat.db.profile.yellow.absolute or threatDiffPercent >= MyThreat.db.profile.yellow.relative) then |
r = 1; |
g = 1; |
-- set the right bar colors |
if (threatDiff <= MyThreat.db.profile.red.absolute or threatDiffPercent >= MyThreat.db.profile.red.relative) then |
r = 1; |
g = 0; |
elseif (threatDiff <= MyThreat.db.profile.orange.absolute or threatDiffPercent >= MyThreat.db.profile.orange.relative) then |
r = 1; |
g = 0.5; |
elseif (threatDiff <= MyThreat.db.profile.yellow.absolute or threatDiffPercent >= MyThreat.db.profile.yellow.relative) then |
r = 1; |
g = 1; |
end |
end |
-- adjust labels |
MyThreat_ThreatFrameThreatDiff:SetText(threatText); |
MyThreat_ThreatFrameThreatPercDiff:SetText(relativeThreatText); |
MyThreat_ThreatFrameThreatDiff:SetTextColor(r,g,0); |
MyThreat_ThreatFrameThreatPercDiff:SetTextColor(r,g,0); |
MyThreat_ThreatFrameThreatPlayerName:SetTextColor(r,g,0); |
MyThreat_ThreatFrameThreatDiff:SetTextColor(r,g,b); |
MyThreat_ThreatFrameThreatPercDiff:SetTextColor(r,g,b); |
MyThreat_ThreatFrameThreatPlayerName:SetTextColor(r,g,b); |
MyThreat_ThreatFrameThreatPlayerName:SetText(tankName); |
return nil, nil, nil; |
end |
local currentTankName, currentTankThreat, playerThreat, threatDiff, threatDiffPercent; |
local currentTankName, currentTankThreat, playerThreat, threatDiff, threatDiffPercent, adjusted; |
adjusted = false; |
-- first try for targettarget mode before using full scanning |
if (UnitExists("targettarget")) then |
if (currentTankName ~= nil) then |
playerThreat = MyThreat:GetThreat("player", "target"); |
playerThreat, _, adjusted = MyThreat:GetThreat("player", "target"); |
if (playerThreat ~= nil) then |
end |
return threatDiff, threatDiffPercent, currentTankName; |
return threatDiff, threatDiffPercent, currentTankName, adjusted; |
end |
return nil, nil, nil; |
end |
local currentTrailing, currentTrailingThreat, playerThreat, threatDiff, threatDiffPercent; |
local currentTrailing, currentTrailingThreat, playerThreat, threatDiff, threatDiffPercent, adjusted; |
currentTrailingThreat = 0; |
adjusted = false; |
for pName, uid in MyThreat:GetPartyUnitIds() do |
if (currentTrailing ~= nil) then |
playerThreat = MyThreat:GetThreat("player", "target"); |
playerThreat, _, adjusted = MyThreat:GetThreat("player", "target"); |
if (playerThreat ~= nil) then |
end |
return threatDiff, threatDiffPercent, currentTrailing; |
return threatDiff, threatDiffPercent, currentTrailing, adjusted; |
end |
return nil, nil, nil; |
end |
local currentLowestFocus, currentLowestFocusThreat, playerThreat, threatDiff, threatDiffPercent; |
local currentLowestFocus, currentLowestFocusThreat, playerThreat, threatDiff, threatDiffPercent, adjusted; |
currentLowestFocusThreat = nil; |
for i = 1, MyThreat.focusUnitsNum, 1 do |
if (currentLowestFocus ~= nil) then |
playerThreat = MyThreat:GetThreat("player", "target"); |
playerThreat, _, adjusted = MyThreat:GetThreat("player", "target"); |
if (playerThreat ~= nil) then |
end |
return threatDiff, threatDiffPercent, currentLowestFocus; |
return threatDiff, threatDiffPercent, currentLowestFocus, adjusted; |
end |
## Author: Brimm |
## SavedVariables: MyThreatDB |
## SavedVariablesPerCharacter: MyThreatDBPC |
## Version: 1.3.4 |
## Version: 1.4 |
## X-Category: Interface Enhancements |
## OptionalDeps: Ace3 |