Anouncements + Gladdy RegisterMessages

This commit is contained in:
Sumsebrum 2022-01-27 14:00:59 +01:00
parent ce3812d234
commit d8391b0f66
4 changed files with 45 additions and 23 deletions

View File

@ -15,7 +15,7 @@ local L = Gladdy.L
local Cooldowns = Gladdy.modules["Cooldowns"]
local Diminishings = Gladdy.modules["Diminishings"]
local EventListener = Gladdy:NewModule("EventListener", 100, {
local EventListener = Gladdy:NewModule("EventListener", 10, {
test = true,
})
@ -214,6 +214,7 @@ Gladdy.exceptionNames = { -- TODO MOVE ME TO CLASSBUFFS LIB
Gladdy.cooldownBuffs = {
[GetSpellInfo(6346)] = { cd = 180, spellId = 6346 }, -- Fear Ward
-- TODO sprint, shadowstep
racials = {
[GetSpellInfo(20600)] = { cd = 180, spellId = 20600 }, -- Perception
}
@ -257,7 +258,6 @@ function EventListener:UNIT_AURA(unit)
spellName = Gladdy.exceptionNames[spellID]
end
Gladdy:SendMessage("AURA_GAIN", unit, auraType, spellID, spellName, texture, duration, expirationTime, count, debuffType, i)
Gladdy:Call("Announcements", "CheckDrink", unit, spellName)
end
end
end

View File

@ -187,6 +187,12 @@ function Gladdy:NewModule(name, priority, defaults)
module.defaults = defaults or {}
module.messages = {}
module.RegisterMessages = function(self, ...)
for _,message in pairs({...}) do
self.messages[message] = message
end
end
module.RegisterMessage = function(self, message, func)
self.messages[message] = func or message
end
@ -195,6 +201,12 @@ function Gladdy:NewModule(name, priority, defaults)
self.messages[message] = nil
end
module.UnregisterMessages = function(self, ...)
for _,message in pairs({...}) do
self.messages[message] = nil
end
end
module.UnregisterAllMessages = function(self)
for msg,_ in pairs(self.messages) do
self.messages[msg] = nil

View File

@ -16,7 +16,7 @@ local UnitName = UnitName
local Gladdy = LibStub("Gladdy")
local L = Gladdy.L
local Announcements = Gladdy:NewModule("Announcements", nil, {
local Announcements = Gladdy:NewModule("Announcements", 101, {
announcements = {
drinks = true,
resurrections = true,
@ -42,18 +42,20 @@ function Announcements:Initialize()
[GetSpellInfo(20777)] = true,
}
self:RegisterMessage("CAST_START")
self:RegisterMessage("ENEMY_SPOTTED")
self:RegisterMessage("UNIT_SPEC")
self:RegisterMessage("UNIT_HEALTH")
self:RegisterMessage("TRINKET_USED")
self:RegisterMessage("TRINKET_READY")
self:RegisterMessage("SHADOWSIGHT")
self:RegisterMessage("SPELL_INTERRUPT")
self:RegisterMessage("JOINED_ARENA")
end
function Announcements:Reset()
self:UnregisterAllMessages()
self:UnregisterMessages(
"CAST_START",
"ENEMY_SPOTTED",
"UNIT_SPEC",
"AURA_GAIN",
"UNIT_HEALTH",
"TRINKET_USED",
"TRINKET_READY",
"SHADOWSIGHT",
"SPELL_INTERRUPT")
self.enemy = {}
self.throttled = {}
end
@ -63,17 +65,25 @@ function Announcements:Test(unit)
if (not button) then
return
end
if (unit == "arena1") then
self:UNIT_SPEC(unit, button.testSpec)
elseif (unit == "arena2") then
self:CheckDrink(unit, self.DRINK_AURA)
elseif (unit == "arena3") then
self:UNIT_HEALTH(unit, button.health, button.healthMax)
self:ENEMY_SPOTTED(unit)
self:JOINED_ARENA()
if unit == "arena1" then
self:AURA_GAIN(unit, nil, nil, self.DRINK_AURA)
end
end
function Announcements:JOINED_ARENA()
self:RegisterMessages(
"CAST_START",
"ENEMY_SPOTTED",
"UNIT_SPEC",
"AURA_GAIN",
"UNIT_HEALTH",
"TRINKET_USED",
"TRINKET_READY",
"SHADOWSIGHT",
"SPELL_INTERRUPT")
end
function Announcements:CAST_START(unit, spell)
local button = Gladdy.buttons[unit]
if (not button or not Gladdy.db.announcements.resurrections) then
@ -149,13 +159,13 @@ function Announcements:SPELL_INTERRUPT(destUnit,spellID,spellName,spellSchool,ex
self:Send(L["INTERRUPTED: %s (%s)"]:format(extraSpellName, button.name or ""), nil, RAID_CLASS_COLORS[button.class])
end
function Announcements:CheckDrink(unit, aura)
function Announcements:AURA_GAIN(unit, auraType, spellID, spellName)
local button = Gladdy.buttons[unit]
if (not button or not Gladdy.db.announcements.drinks) then
return
end
if (aura == self.DRINK_AURA) then
if (spellName == self.DRINK_AURA) then
self:Send(L["DRINKING: %s (%s)"]:format(button.name, button.classLoc), 3, RAID_CLASS_COLORS[button.class])
end
end

View File

@ -472,7 +472,7 @@ function Auras:Test(unit)
local extraSpellSchool = spellSchools[rand(1, #spellSchools)]
spellid = tonumber(enabledInterrupts[rand(1, #enabledInterrupts)])
spellName = select(1, GetSpellInfo(spellid))
self:SPELL_INTERRUPT(unit,spellid, spellName, "physical", spellid, spellName, extraSpellSchool)
Gladdy:SendMessage("SPELL_INTERRUPT", unit,spellid, spellName, "physical", spellid, spellName, extraSpellSchool)
end
end
end