Files
Nanami-DPS/Modules/ThreatEstimate.lua
rucky 5c3f2243c4 更新发送到功能
更新仇恨计算方式 还在开发
更新其他细节
2026-03-23 10:26:31 +08:00

111 lines
3.4 KiB
Lua

local NanamiDPS = NanamiDPS
local DataStore = NanamiDPS.DataStore
local L = NanamiDPS.L
local ThreatEstimate = {}
function ThreatEstimate:GetName()
return L["Threat (Est.)"]
end
local function ResolvePetOwner(name)
local stored = DataStore:GetClass(name)
if stored and not NanamiDPS.validClasses[stored] and stored ~= "__other__" then
local ownerClass = DataStore:GetClass(stored)
if ownerClass and NanamiDPS.validClasses[ownerClass] then
return stored, ownerClass
end
end
return nil, nil
end
function ThreatEstimate:GetBars(segment)
if not segment or not segment.data or not segment.data.threat then return {} end
local bars = {}
for name, entry in pairs(segment.data.threat) do
local class = DataStore:GetClass(name)
local r, g, b = NanamiDPS.GetClassColor(class)
local displayName = name
local ownerName, ownerClass = ResolvePetOwner(name)
if NanamiDPS.validClasses[class] then
-- player: use class color as-is
elseif ownerName and ownerClass then
r, g, b = NanamiDPS.GetClassColor(ownerClass)
r, g, b = r * 0.7, g * 0.7, b * 0.7
displayName = name .. " <" .. ownerName .. ">"
else
r, g, b = NanamiDPS.str2rgb(name)
r = r * 0.6 + 0.4
g = g * 0.6 + 0.4
b = b * 0.6 + 0.4
end
table.insert(bars, {
id = name,
name = displayName,
value = entry._sum or 0,
class = ownerClass or class,
r = r, g = g, b = b,
})
end
table.sort(bars, function(a, b) return a.value > b.value end)
local best = bars[1] and bars[1].value or 0
for _, bar in ipairs(bars) do
bar.percent = best > 0 and (bar.value / best * 100) or 0
end
return bars
end
function ThreatEstimate:GetTooltip(playerName, segment, tooltip)
if not segment or not segment.data.threat[playerName] then return end
local entry = segment.data.threat[playerName]
local ownerName, ownerClass = ResolvePetOwner(playerName)
tooltip:AddLine("|cffffd100" .. playerName)
if ownerName then
tooltip:AddDoubleLine("|cffffffff" .. L["Owner"], "|cffffffff" .. ownerName)
end
tooltip:AddDoubleLine("|cffffffff" .. L["Threat (Est.)"], "|cffffffff" .. NanamiDPS.formatNumber(entry._sum))
tooltip:AddLine(" ")
if ownerName then
tooltip:AddLine("|cffaaaaaa" .. L["Threat Note"])
else
local dmgEntry = segment.data.damage[playerName]
local healEntry = segment.data.healing[playerName]
if dmgEntry then
tooltip:AddDoubleLine("|cffffffff" .. L["Damage Done"],
"|cffffffff" .. NanamiDPS.formatNumber(dmgEntry._sum))
end
if healEntry then
tooltip:AddDoubleLine("|cffffffff" .. L["Healing Done"],
"|cffffffff" .. NanamiDPS.formatNumber(healEntry._sum) .. " (x0.5)")
end
tooltip:AddLine("|cffaaaaaa" .. L["Threat Note"])
end
end
function ThreatEstimate:GetReportLines(segment, count)
local bars = self:GetBars(segment)
local lines = {}
count = count or 5
for i = 1, math.min(count, table.getn(bars)) do
local d = bars[i]
table.insert(lines, string.format("%d. %s - %s (%.1f%%)",
i, d.name, NanamiDPS.formatNumber(d.value), d.percent))
end
return lines
end
NanamiDPS:RegisterModule("ThreatEstimate", ThreatEstimate)