Add files via upload

This commit is contained in:
Relationship
2026-07-08 18:24:21 +01:00
committed by GitHub
parent d0a77fe622
commit 16705f72ac
6 changed files with 196 additions and 18 deletions
+117 -1
View File
@@ -57,7 +57,11 @@ local partyNames = {}
local partyUnits = {}
-- Update throttle (seconds)
local THROTTLE = 0.2
local THROTTLE = 0.1
-- Cache of per-mob tank-mode details, keyed by mob UID (name in vanilla).
-- Populated by UpdateUnitThreat via ThreatEngine, and read by the Nameplates
-- module when rendering the tank-mode text (raw threat lead).
local tankDetailsCache = {}
-- ==================================================================
-- Safe API call helpers
@@ -647,12 +651,54 @@ function addon.Threat:UpdateUnitThreat(unit)
mobTargetName = mt
end
-- ------------------------------------------------------------
-- TARGET-SNAP override: if the mob is currently targeting the
-- player, force display to 100% (aggro). Some mobs pick focused
-- / random targets regardless of threat, so the plate should
-- immediately snap to 100% while targeted, and fall back to the
-- real threat % when the mob switches targets.
-- ------------------------------------------------------------
local targetSnapped = false
if RelationshipsThreatPlatesDB and RelationshipsThreatPlatesDB.targetSnap100
and mobTargetName and playerName and mobTargetName == playerName then
local ok_pc, pc = pcall(UnitAffectingCombat, "player")
if ok_pc and pc then
pct = 100
situation = 3
targetSnapped = true
end
end
-- ------------------------------------------------------------
-- Compute raw tank-mode details (player threat vs 2nd highest).
-- Uses ThreatEngine's combat-log-parsed absolute values when
-- available. This is what the nameplate renders in Tank Mode.
-- ------------------------------------------------------------
local ok_mn, mobName = pcall(UnitName, unit)
if ok_mn and mobName then
local ePct, eSit, ePlayerThreat, eTopThreat, eHasGroup, eTopPlayer, eSecondThreat =
addon.ThreatEngine:GetThreatOnTarget(mobName)
tankDetailsCache[uid] = {
playerThreat = ePlayerThreat or 0,
topThreat = eTopThreat or 0,
secondThreat = eSecondThreat or 0,
topPlayer = eTopPlayer,
hasAggro = (eTopPlayer == playerName) or targetSnapped,
hasGroupData = eHasGroup or false,
targetSnapped = targetSnapped,
mobTargetName = mobTargetName,
lastUpdate = GetTime(),
}
end
threatCache[uid] = {
pct = pct,
situation = situation,
unit = unit,
lastUpdate = GetTime(),
mobTargetName = mobTargetName,
targetSnapped = targetSnapped,
}
-- Also store in group threat cache for cross-reference
@@ -681,6 +727,76 @@ function addon.Threat:GetCachedThreat(uid)
return 0, 0
end
-- ==================================================================
-- Tank-mode details for a mob (by UID / name in vanilla).
-- Returns a table (or nil) with:
-- playerThreat, topThreat, secondThreat, topPlayer,
-- hasAggro, hasGroupData, targetSnapped, mobTargetName
-- ==================================================================
function addon.Threat:GetTankDetails(uid)
if not uid then return nil end
local d = tankDetailsCache[uid]
if not d then return nil end
if GetTime() - d.lastUpdate > 5 then return nil end
return d
end
-- ==================================================================
-- Format a raw threat value as a compact signed string.
-- Examples: 12345 -> "+12.3K", -845 -> "-845", 0 -> "0"
-- ==================================================================
function addon.Threat:FormatThreatLead(v)
if not v then return "--" end
local a = math.abs(v)
local sign = ""
if v > 0 then sign = "+" elseif v < 0 then sign = "-" end
if a >= 100000 then
return sign .. string.format("%.0fK", a / 1000)
elseif a >= 10000 then
return sign .. string.format("%.1fK", a / 1000)
elseif a >= 1000 then
return sign .. string.format("%.2fK", a / 1000)
else
return sign .. string.format("%d", a)
end
end
-- ==================================================================
-- Return the display string for tank mode given a plate's mob name.
-- Uses the ThreatEngine directly (works even without a unit token,
-- e.g. for unique-name plates).
-- Returns: string like "+1.20K" or "-450", or "--" if unknown.
-- ==================================================================
function addon.Threat:GetTankDisplayForMob(mobName)
if not mobName then return "--" end
local d = tankDetailsCache[mobName]
if not d or (GetTime() - d.lastUpdate > 5) then
-- Query ThreatEngine on demand (no cache hit).
local _, _, playerThreat, topThreat, _, topPlayer, secondThreat =
addon.ThreatEngine:GetThreatOnTarget(mobName)
if not playerThreat or playerThreat <= 0 then
return "--"
end
local lead
if topPlayer == playerName then
lead = playerThreat - (secondThreat or 0)
else
lead = playerThreat - (topThreat or 0)
end
return self:FormatThreatLead(lead)
end
if d.playerThreat <= 0 then return "--" end
local lead
if d.hasAggro then
lead = d.playerThreat - (d.secondThreat or 0)
else
lead = d.playerThreat - (d.topThreat or 0)
end
return self:FormatThreatLead(lead)
end
-- ==================================================================
-- Get threat percentage by mob NAME (no unit token required)
-- This is the fallback for when FindUnitByName couldn't resolve