|
class_color = {
['HUNTER'] = 'aad372',
['WARRIOR'] = 'c69b6d',
['MAGE'] = '3fc6ea',
['WARLOCK'] = '8787ed',
['ROGUE'] = 'fff468',
['PALADIN'] = 'f48cba',
['SHAMAN'] = '0070dd',
['DRUID'] = 'ff7c0a',
['PRIEST'] = 'ffffff',
['DEATHKNIGHT'] = 'C41E3A',
}
raidOrder = {'D','T','I'} --'D'ULD/'T'TOC/'I'ICC
-- 从 WeakAura 配置中获取团队名称
local function getRaidName()
-- 假设 WeakAura 配置中有一个名为 "raidName" 的选项
return aura_env.config['raidName'] or "D" -- 默认值为 "D"
end
reportRaidName = raidOrder[getRaidName()]
result = ''
loadData = function(playerName)
if type(WP_Database) ~= 'table' then return end
return (
WP_Database[playerName]
)
end
getSpecScore = function(data)
local textTable = {strsplit('%', data)}
for _, text in pairs(textTable) do
if text and string.len(text) > 10 then
local raid, info = strsplit(':', text)
local point, score = strsplit('/', info)
local raidName = strsub(raid, 2, 2)
if raidName == reportRaidName then
local stringScore = strsplit('%', score)
local num = tonumber(stringScore) -- 获取数字部分
local _,title = strsplit("()", text)
local spec = strsub(title,-6)
return spec,num
end
end
end
return '',0
end
-- 获取玩家颜色
local function getPlayerColor(className)
return class_color[className] or 'ffffff' -- 默认白色
end
-- 获取玩家专精和评分
local function getPlayerScore(playerName)
local data = loadData(playerName)
if data then
local spec, score = getSpecScore(data)
return spec,score
end
return '',0
end
-- 格式化评分文本
-- 0-24 - #666666
-- 25-49 - #1eff00
-- 50-74 - #0070ff
-- 75-94 - #a335ee
-- 95-98 - #ff8000
-- 99 - #e268a8
-- 100 - #e5cc80
local function formatScoreText(score)
local color = '666666'
if score >= 25 then
color = '1eff00'
end
if score >= 50 then
color = '0070ff'
end
if score >= 75 then
color = 'a335ee'
end
if score >= 95 then
color = 'ff8000'
end
if score >= 99 then
color = 'e268a8'
end
if score == 100 then
color = 'e5cc80'
end
return string.format('|c00%s(%s)|r', color, score)
end
-- 格式化聊天信息
local function formatChatMessage(msg, author, guid)
-- 如果author里包含了服务器名,去掉
local authorName = strsplit("-", author)
local spec, score = getPlayerScore(authorName)
if score > 0 then
local localizedClass, englishClass, localizedRace, englishRace, sex, name, realm = GetPlayerInfoByGUID(guid)
local playerColor = getPlayerColor(englishClass)
msg = string.format(
'|c00%s[%s]|r %s %s',
playerColor,
spec,
formatScoreText(score),
msg
)
end
return msg
end
local event_list = {
'CHAT_MSG_CHANNEL',
'CHAT_MSG_RAID',
'CHAT_MSG_RAID_LEADER',
'CHAT_MSG_GUILD',
'CHAT_MSG_WHISPER',
}
function chatFilter(self, event, msg, author, languageName, channelName, playerName2, specialFlags, zoneChannelID, channelIndex, channelBaseName, languageID, lineID, guid, ...)
if event == 'CHAT_MSG_CHANNEL' or event == 'CHAT_MSG_RAID' or event == 'CHAT_MSG_RAID_LEADER' or event == 'CHAT_MSG_GUILD' or event == 'CHAT_MSG_WHISPER' then
return false, formatChatMessage(msg, author, guid), author, languageName, channelName, playerName2, specialFlags, zoneChannelID, channelIndex, channelBaseName, languageID, lineID, guid, ...
end
return false, msg, author, languageName, channelName, playerName2, specialFlags, zoneChannelID, channelIndex, channelBaseName, languageID, lineID, guid, ...
end
function filterExists(event, filterFunction)
local filters = { ChatFrame_GetMessageEventFilters(event) }
for _, existingFilter in ipairs(filters) do
if existingFilter == filterFunction then
return true
end
end
return false
end
for _, event in ipairs(event_list) do
if not filterExists(event, chatFilter) then
ChatFrame_AddMessageEventFilter(event, chatFilter)
end
end
-- MeetingHorn
local gameTooltip = _G["GameTooltip"]
local hasAddedScore = false
gameTooltip:SetScript("OnShow", function(self)
hasAddedScore = false
end)
gameTooltip:SetScript("OnUpdate", function(self)
-- 仅在第一次获取玩家分数后添加文字
if not hasAddedScore then
-- 获取玩家昵称
local playerName = GameTooltipTextLeft2:GetText()
if playerName then
local spec, score = getPlayerScore(playerName)
if score > 0 then
-- self:AddLine(formatScoreText(score))
GameTooltipTextLeft2:SetText(playerName .. ' ' .. formatScoreText(score))
hasAddedScore = true
end
end
end
end)
|
|