Gladdy-TBC/Modules/Announcements.lua

320 lines
10 KiB
Lua
Raw Permalink Normal View History

2021-05-17 16:49:54 +02:00
local pairs = pairs
local floor = math.floor
local GetSpellInfo = GetSpellInfo
local RAID_CLASS_COLORS = RAID_CLASS_COLORS
local GetTime = GetTime
local SendChatMessage = SendChatMessage
local RaidNotice_AddMessage = RaidNotice_AddMessage
local RaidBossEmoteFrame = RaidBossEmoteFrame
local IsAddOnLoaded = IsAddOnLoaded
local IsInGroup = IsInGroup
local LE_PARTY_CATEGORY_HOME = LE_PARTY_CATEGORY_HOME
local LE_PARTY_CATEGORY_INSTANCE = LE_PARTY_CATEGORY_INSTANCE
local CombatText_AddMessage = CombatText_AddMessage
local UnitName = UnitName
local Gladdy = LibStub("Gladdy")
local L = Gladdy.L
2022-01-27 14:00:59 +01:00
local Announcements = Gladdy:NewModule("Announcements", 101, {
2021-05-17 16:49:54 +02:00
announcements = {
drinks = true,
resurrections = true,
enemy = false,
2021-05-22 13:28:46 +02:00
spec = true,
2021-05-17 16:49:54 +02:00
health = false,
healthThreshold = 20,
trinketUsed = true,
trinketReady = false,
2022-01-10 23:59:20 +01:00
spellInterrupt = true,
2021-05-22 13:28:46 +02:00
dest = "party",
2021-05-17 16:49:54 +02:00
},
})
function Announcements:Initialize()
self.enemy = {}
self.throttled = {}
self.DRINK_AURA = GetSpellInfo(46755)
self.RES_SPELLS = {
[GetSpellInfo(20770)] = true,
[GetSpellInfo(20773)] = true,
[GetSpellInfo(20777)] = true,
}
2022-01-27 14:00:59 +01:00
self:RegisterMessage("JOINED_ARENA")
2021-05-17 16:49:54 +02:00
end
function Announcements:Reset()
2022-01-27 14:00:59 +01:00
self:UnregisterMessages(
"CAST_START",
"ENEMY_SPOTTED",
"UNIT_SPEC",
"AURA_GAIN",
"UNIT_HEALTH",
"TRINKET_USED",
"TRINKET_READY",
"SHADOWSIGHT",
"SPELL_INTERRUPT")
2021-05-17 16:49:54 +02:00
self.enemy = {}
self.throttled = {}
end
function Announcements:Test(unit)
local button = Gladdy.buttons[unit]
if (not button) then
return
end
2022-01-27 14:00:59 +01:00
self:JOINED_ARENA()
if unit == "arena1" then
self:AURA_GAIN(unit, nil, nil, self.DRINK_AURA)
2021-05-17 16:49:54 +02:00
end
end
2022-01-27 14:00:59 +01:00
function Announcements:JOINED_ARENA()
self:RegisterMessages(
"CAST_START",
"ENEMY_SPOTTED",
"UNIT_SPEC",
"AURA_GAIN",
"UNIT_HEALTH",
"TRINKET_USED",
"TRINKET_READY",
"SHADOWSIGHT",
"SPELL_INTERRUPT")
end
2021-05-17 16:49:54 +02:00
function Announcements:CAST_START(unit, spell)
local button = Gladdy.buttons[unit]
if (not button or not Gladdy.db.announcements.resurrections) then
return
end
if (self.RES_SPELLS[spell]) then
self:Send(L["RESURRECTING: %s (%s)"]:format(button.name, button.classLoc), 3, RAID_CLASS_COLORS[button.class])
end
end
function Announcements:ENEMY_SPOTTED(unit)
local button = Gladdy.buttons[unit]
if (not button or not Gladdy.db.announcements.enemy) then
return
end
if (not self.enemy[unit]) then
if button.name == "Unknown" then
button.name = UnitName(unit)
end
self:Send("ENEMY SPOTTED:" .. ("%s (%s)"):format(button.name, button.classLoc), 0, RAID_CLASS_COLORS[button.class])
self.enemy[unit] = true
end
end
function Announcements:UNIT_SPEC(unit, spec)
local button = Gladdy.buttons[unit]
if (not button or not Gladdy.db.announcements.spec) then
return
end
if button.name == "Unknown" then
button.name = UnitName(unit)
end
self:Send(L["SPEC DETECTED: %s - %s (%s)"]:format(button.name, spec, button.classLoc), 0, RAID_CLASS_COLORS[button.class])
end
function Announcements:UNIT_HEALTH(unit, health, healthMax)
local button = Gladdy.buttons[unit]
if (not button or not Gladdy.db.announcements.health) then
return
end
local healthPercent = floor(health * 100 / healthMax)
if (healthPercent < Gladdy.db.announcements.healthThreshold) then
self:Send(L["LOW HEALTH: %s (%s)"]:format(button.name, button.classLoc), 10, RAID_CLASS_COLORS[button.class])
end
end
function Announcements:TRINKET_USED(unit)
local button = Gladdy.buttons[unit]
if (not button or not Gladdy.db.announcements.trinketUsed) then
return
end
self:Send(L["TRINKET USED: %s (%s)"]:format(button.name, button.classLoc), 0, RAID_CLASS_COLORS[button.class])
end
function Announcements:TRINKET_READY(unit)
local button = Gladdy.buttons[unit]
if (not button or not Gladdy.db.announcements.trinketReady) then
return
end
self:Send(L["TRINKET READY: %s (%s)"]:format(button.name, button.classLoc), 3, RAID_CLASS_COLORS[button.class])
end
2022-01-10 23:59:20 +01:00
function Announcements:SPELL_INTERRUPT(destUnit,spellID,spellName,spellSchool,extraSpellId,extraSpellName,extraSpellSchool)
local button = Gladdy.buttons[destUnit]
if (not button or not Gladdy.db.announcements.spellInterrupt) then
return
end
2022-01-11 03:01:32 +01:00
self:Send(L["INTERRUPTED: %s (%s)"]:format(extraSpellName, button.name or ""), nil, RAID_CLASS_COLORS[button.class])
2022-01-10 23:59:20 +01:00
end
2022-01-27 14:00:59 +01:00
function Announcements:AURA_GAIN(unit, auraType, spellID, spellName)
2021-05-17 16:49:54 +02:00
local button = Gladdy.buttons[unit]
if (not button or not Gladdy.db.announcements.drinks) then
return
end
2022-01-27 14:00:59 +01:00
if (spellName == self.DRINK_AURA) then
2021-05-17 16:49:54 +02:00
self:Send(L["DRINKING: %s (%s)"]:format(button.name, button.classLoc), 3, RAID_CLASS_COLORS[button.class])
end
end
2021-06-15 09:05:32 +02:00
function Announcements:SHADOWSIGHT(msg)
self:Send(msg, 2)
end
2021-05-17 16:49:54 +02:00
function Announcements:Send(msg, throttle, color)
if (throttle and throttle > 0) then
if (not self.throttled[msg]) then
self.throttled[msg] = GetTime() + throttle
2022-01-11 03:01:32 +01:00
Gladdy:Debug("INFO", msg, "- NOT THROTTLED -", self.throttled[msg])
2021-05-17 16:49:54 +02:00
elseif (self.throttled[msg] < GetTime()) then
2022-01-11 03:01:32 +01:00
Gladdy:Debug("INFO", msg, "- THROTTLED OVER -", self.throttled[msg])
self.throttled[msg] = GetTime() + throttle
2021-05-17 16:49:54 +02:00
else
2022-01-11 03:01:32 +01:00
Gladdy:Debug("INFO", msg, "- THROTTLED -", self.throttled[msg])
2021-05-17 16:49:54 +02:00
return
end
end
local dest = Gladdy.db.announcements.dest
color = color or { r = 0, g = 1, b = 0 }
if (dest == "self") then
Gladdy:Print(msg)
elseif (dest == "party" and IsInGroup(LE_PARTY_CATEGORY_HOME)) then --(GetNumSubgroupMembers() > 0 or GetNumGroupMembers() > 0)) then
SendChatMessage(msg, "PARTY")
elseif dest == "party" and IsInGroup(LE_PARTY_CATEGORY_INSTANCE) then
SendChatMessage(msg, "INSTANCE_CHAT")
elseif (dest == "rw") then
RaidNotice_AddMessage(RaidBossEmoteFrame, msg, color)
elseif (dest == "fct" and IsAddOnLoaded("Blizzard_CombatText")) then
CombatText_AddMessage(msg, nil, color.r, color.g, color.b, "crit", 1)
2021-07-26 11:28:04 +02:00
elseif (dest == "msbt" and IsAddOnLoaded("MikScrollingBattleText")) then
MikSBT.Animations.DisplayMessage(msg, MikSBT.DISPLAYTYPE_NOTIFICATION, true, color.r * 255, color.g * 255, color.b * 255)
--[[elseif (dest == "sct" and IsAddOnLoaded("sct")) then
2021-05-17 16:49:54 +02:00
SCT:DisplayText(msg, color, true, "event", 1)
elseif (dest == "parrot" and IsAddOnLoaded("parrot")) then
Parrot:ShowMessage(msg, "Notification", true, color.r, color.g, color.b)--]]
end
end
local function option(params)
local defaults = {
get = function(info)
local key = info.arg or info[#info]
return Gladdy.dbi.profile.announcements[key]
end,
set = function(info, value)
local key = info.arg or info[#info]
Gladdy.dbi.profile.announcements[key] = value
end,
}
for k, v in pairs(params) do
defaults[k] = v
end
return defaults
end
function Announcements:GetOptions()
local destValues = {
["self"] = L["Self"],
["party"] = L["Party"],
["rw"] = L["Raid Warning"],
}
if IsAddOnLoaded("Blizzard_CombatText") then
destValues["fct"] = L["Blizzard's Floating Combat Text"]
end
if IsAddOnLoaded("MikScrollingBattleText") then
destValues["msbt"] = L["MikScrollingBattleText"]
end
2021-05-17 16:49:54 +02:00
return {
headerAnnouncements = {
type = "header",
name = L["Announcements"],
order = 2,
},
trinketUsed = option({
type = "toggle",
name = L["Trinket used"],
desc = L["Announce when an enemy's trinket is used"],
order = 3,
}),
trinketReady = option({
type = "toggle",
name = L["Trinket ready"],
desc = L["Announce when an enemy's trinket is ready again"],
order = 4,
}),
2022-01-10 23:59:20 +01:00
spellInterrupt = option({
type = "toggle",
name = L["Interrupts"],
desc = L["Announces when enemies' spells are interrupted"],
order = 5,
}),
2021-05-17 16:49:54 +02:00
drinks = option({
type = "toggle",
name = L["Drinking"],
desc = L["Announces when enemies sit down to drink"],
2022-01-10 23:59:20 +01:00
order = 6,
2021-05-17 16:49:54 +02:00
}),
resurrections = option({
type = "toggle",
name = L["Resurrection"],
desc = L["Announces when an enemy tries to resurrect a teammate"],
2022-01-10 23:59:20 +01:00
order = 7,
2021-05-17 16:49:54 +02:00
}),
enemy = option({
type = "toggle",
name = L["New enemies"],
desc = L["Announces when new enemies are discovered"],
2022-01-10 23:59:20 +01:00
order = 8,
2021-05-17 16:49:54 +02:00
}),
spec = option({
type = "toggle",
name = L["Spec Detection"],
desc = L["Announces when the spec of an enemy was detected"],
2022-01-10 23:59:20 +01:00
order = 9,
2021-05-17 16:49:54 +02:00
}),
health = option({
type = "toggle",
name = L["Low health"],
desc = L["Announces when an enemy drops below a certain health threshold"],
2022-01-10 23:59:20 +01:00
order = 10,
2021-05-17 16:49:54 +02:00
}),
healthThreshold = option({
type = "range",
name = L["Low health threshold"],
desc = L["Choose how low an enemy must be before low health is announced"],
2022-01-10 23:59:20 +01:00
order = 11,
2021-05-17 16:49:54 +02:00
min = 1,
max = 100,
step = 1,
disabled = function()
return not Gladdy.dbi.profile.announcements.health
end,
}),
dest = option({
type = "select",
name = L["Destination"],
desc = L["Choose how your announcements are displayed"],
2022-01-10 23:59:20 +01:00
order = 12,
2021-05-17 16:49:54 +02:00
values = destValues,
}),
}
end