From d8391b0f66badbe323a0a2d340c29ff80ccc0d72 Mon Sep 17 00:00:00 2001 From: Sumsebrum Date: Thu, 27 Jan 2022 14:00:59 +0100 Subject: [PATCH] Anouncements + Gladdy RegisterMessages --- EventListener.lua | 4 ++-- Gladdy.lua | 12 ++++++++++ Modules/Announcements.lua | 50 +++++++++++++++++++++++---------------- Modules/Auras.lua | 2 +- 4 files changed, 45 insertions(+), 23 deletions(-) diff --git a/EventListener.lua b/EventListener.lua index c7f2172..0086627 100644 --- a/EventListener.lua +++ b/EventListener.lua @@ -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 diff --git a/Gladdy.lua b/Gladdy.lua index 32fb1e3..63c5d17 100644 --- a/Gladdy.lua +++ b/Gladdy.lua @@ -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 diff --git a/Modules/Announcements.lua b/Modules/Announcements.lua index 27de5f1..5cb0066 100644 --- a/Modules/Announcements.lua +++ b/Modules/Announcements.lua @@ -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 diff --git a/Modules/Auras.lua b/Modules/Auras.lua index 7d903e4..5d33667 100644 --- a/Modules/Auras.lua +++ b/Modules/Auras.lua @@ -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