Files
wow-weakauras/FreshShit/StinkyDetector/event3.lua

115 lines
3.2 KiB
Lua

-- CHAT_MSG_ADDON TICKER_1000
---@param allstates allstates
---@param e string
---@param prefix string
---@param msg string
function(allstates, e, prefix, msg, ...)
if e == "TICKER_1000" then
local ttl = aura_env.config.ttl or 120
for _, state in pairs(allstates) do
if state.progress then
local elapsedTime = GetTime() - state.index
if elapsedTime > ttl then
state.show = false
state.changed = true
else
local prettyTime = ""
local minutes = 0
while elapsedTime > 60 do
elapsedTime = elapsedTime - 60
minutes = minutes + 1
end
if minutes > 0 then
prettyTime = string.format("%s%dm", prettyTime, minutes)
end
if elapsedTime > 0 then
prettyTime = string.format("%s %ds", prettyTime, elapsedTime)
end
state.progress = string.format("%20s", prettyTime)
state.changed = true
end
end
end
for i = 1, 40 do
if UnitIsPlayer("nameplate" .. i) then
local name = UnitName("nameplate" .. i)
local faction = UnitFactionGroup("nameplate" .. i)
local _, race = UnitRace("nameplate" .. i)
local raceFaction = aura_env.raceFactions[race]
if not raceFaction and aura_env.config.debug then
print("Unknown race faction", race)
else
faction = raceFaction
end
WeakAurasSaved.Cyka.PlayerFactionCache[name] = faction
end
end
return true
end
if not prefix or prefix ~= aura_env.addonprefix then return end
local parts = {}
for part in string.gmatch(msg, "([^" .. aura_env.separator .. "]+)") do
table.insert(parts, part)
end
local name = parts[1]
local threat = tonumber(parts[2])
local note = parts[3]
if not name then
if aura_env.config.debug then
print(string.format("Could not get name for %s (%s) with deliminer '%s'", msg, name or "nil", aura_env.separator))
end
return
end
if not threat then
if aura_env.config.debug then
print(string.format("Could not get threat for %s (%s) with deliminer '%s'", msg, threat or "nil", aura_env.separator))
end
return
end
if not note then
if aura_env.config.debug then
print(string.format("Could not get note for %s (%s) with deliminer '%s'", msg, note or "nil", aura_env.separator))
end
end
if threat < aura_env.config.threatThreshold then
if aura_env.config.debug then
print(string.format("Skipping notify due to low threat (%d < %d)", threat, aura_env.config.threatThreshold))
end
return
end
local stinky = aura_env.stinkies[name]
if not stinky then
if aura_env.config.debug then
print(string.format("Could not find stinky for %s", name))
end
return false
end
if not aura_env.soundNotifyTimer[name] or aura_env.soundNotifyTimer[name] < GetTime() then
PlaySoundFile("Interface\\Sounds\\Domination.ogg", "Master")
aura_env.soundNotifyTimer[name] = GetTime() + aura_env.config.alertThrottle
end
allstates[name] = {
show = true,
changed = true,
name = string.format("%-20s%2d%35s", name, stinky.threat, note),
progressType = "timed",
duration = 60,
expirationTime = GetTime() + aura_env.config.alertThrottle,
autohide = true,
index = GetTime(),
progress = string.format("%20s", "0s"),
}
return true
end