diff --git a/FreshShit/PersonalAnnouncer/event.lua b/FreshShit/PersonalAnnouncer/event.lua new file mode 100644 index 0000000..53087a7 --- /dev/null +++ b/FreshShit/PersonalAnnouncer/event.lua @@ -0,0 +1,10 @@ +-- TICKER_500 +function(e) + if ActiveSet == nil then + ActiveSet = Spells[UnitClass("player")] + end + for _, cooldown in ipairs(ActiveSet) do + if aura_env.debug then print(string.format("Calling update on %s", cooldown.name)) end + cooldown:Update() + end +end \ No newline at end of file diff --git a/FreshShit/PersonalAnnouncer/init.lua b/FreshShit/PersonalAnnouncer/init.lua new file mode 100644 index 0000000..ca321c0 --- /dev/null +++ b/FreshShit/PersonalAnnouncer/init.lua @@ -0,0 +1,177 @@ +aura_env.debug = false + +---@class BaseCooldown +---@field name string +---@field filename string +---@field id number +---@field isOnCooldown boolean +---@field announced boolean +---@field remaining number +BaseCooldown = { + ---@param id number + ---@param name string + ---@return BaseCooldown + new = function(id, name) + local self = setmetatable({}, { + __index = BaseCooldown + }) + self.id = id + self.name = name + name = string.gsub(name, " ", "_") + name = string.gsub(name, "'", "") + self.filename = name + self.isOnCooldown = false + self.announced = false + self.remaining = 0 + return self + end, + + ---@param self BaseCooldown + ---@param cooldownFunc fun(spellId: number): number, number + Update = function(self, cooldownFunc) + local start, duration = cooldownFunc(self.id) + local isOnCooldown = start > 0 and duration > 3 + local remaining = start + duration - GetTime() + + if not isOnCooldown and self.isOnCooldown then + self:playComplete() + self.announced = false + end + if not self.announced and isOnCooldown and remaining < 10 then + self:playSoon() + self.announced = true + end + + self.isOnCooldown = isOnCooldown + self.remaining = remaining + end, + + ---@param self BaseCooldown + playComplete = function(self) + local soundFile = string.format("Interface\\Sounds\\alerts\\%s.ogg", self.filename) + if aura_env.debug then + print(string.format("%s is off cooldown, playing sound file at %s", self.filename, + soundFile)) + end + WeakAuras.ScanEvents("PLAY_SOUND", soundFile) + end, + + ---@param self BaseCooldown + playSoon = function(self) + local soundFile = string.format("Interface\\Sounds\\alerts\\%s_soon.ogg", self.filename) + if aura_env.debug then + print(string.format("%s is almost off cooldown, playing sound file at %s", self.filename, + soundFile)) + end + WeakAuras.ScanEvents("PLAY_SOUND", soundFile) + end +} + +---@class Spell:BaseCooldown +Spell = { + ---@param id number + ---@param name string + ---@return Spell + new = function(id, name) + local obj = BaseCooldown.new(id, name) + ---@cast obj Spell + setmetatable(obj, { + __index = Spell + }) + return obj + end, + Update = function(self) + BaseCooldown.Update(self, GetSpellCooldown) + end, + playComplete = BaseCooldown.playComplete, + playSoon = BaseCooldown.playSoon +} +---@class Item:BaseCooldown +Item = { + ---@param id number + ---@param name string + ---@return Item + new = function(id, name) + local obj = BaseCooldown.new(id, name) + ---@cast obj Item + setmetatable(obj, { + __index = Item + }) + return obj + end, + Update = function(self) + BaseCooldown.Update(self, GetItemCooldown) + end, + playComplete = BaseCooldown.playComplete, + playSoon = BaseCooldown.playSoon +} +---@class Buff:BaseCooldown +---@field isActive boolean +Buff = { + ---@param id number + ---@param name string + ---@return Buff + new = function(id, name) + local obj = BaseCooldown.new(id, name) + ---@cast obj Buff + setmetatable(obj, { + __index = Buff + }) + obj.isActive = false + return obj + end, + Update = function(self) + local duration, expiry = select(6, UnitBuff("player", self.name)) + + local isActive = true + if duration == nil or expiry == nil then + isActive = false + end + local remaining = expiry - GetTime() + + if not isActive and self.isActive then + self:playComplete() -- More like "PlayExpired" + self.announced = false + end + if not self.announced and isActive and remaining < 5 then + self:playSoon() -- More like "PlayExpiring" + self.announced = true + end + + self.isActive = isActive + self.remaining = remaining + end, + ---@param self Buff + playComplete = function(self) + local soundFile = string.format("Interface\\Sounds\\alerts\\%s_expired.ogg", self.name) + if aura_env.debug then print(string.format("%s expired, playing sound file at %s", self.name, soundFile)) end + WeakAuras.ScanEvents("PLAY_SOUND", soundFile) + end, + ---@param self Buff + playSoon = function(self) + local soundFile = string.format("Interface\\Sounds\\alerts\\%s_expiring.ogg", self.name) + if aura_env.debug then print(string.format("%s expiring, playing sound file at %s", self.name, soundFile)) end + WeakAuras.ScanEvents("PLAY_SOUND", soundFile) + end +} + +---@type table|nil +ActiveSet = nil + +---@type table> +Spells = { + ["Warrior"] = { + Spell.new(107574, "Avatar"), + Spell.new(1719, "BattleCry"), + Spell.new(205545, "OdynsFury"), + Spell.new(26297, "Berserking"), + Spell.new(12292, "Bloodbath"), + }, + ["Warlock"] = { + Spell.new(108416, "Dark Pact"), + Spell.new(104773, "Unending Resolve"), + Spell.new(196098, "Soul Harvest"), + Item.new(5512, "Healthstone"), + Buff.new(207472, "Xavaric's Magnum Opus"), + } +} diff --git a/FreshShit/PersonalCooldownAnnouncer/event.lua b/FreshShit/PersonalCooldownAnnouncer/event.lua deleted file mode 100644 index 91a0f26..0000000 --- a/FreshShit/PersonalCooldownAnnouncer/event.lua +++ /dev/null @@ -1,7 +0,0 @@ --- TICKER_500 -function(e) - for _, spell in ipairs(aura_env.spells) do - ---@cast spell Spell - spell:Update() - end -end \ No newline at end of file diff --git a/FreshShit/PersonalCooldownAnnouncer/init.lua b/FreshShit/PersonalCooldownAnnouncer/init.lua deleted file mode 100644 index 5b52246..0000000 --- a/FreshShit/PersonalCooldownAnnouncer/init.lua +++ /dev/null @@ -1,72 +0,0 @@ -aura_env.debug = false -aura_env.ticker = nil - ----@class Spell ----@field name string ----@field id number ----@field isOnCooldown boolean ----@field announced boolean ----@field remaining number -Spell = { - ---@param id number - ---@param name string - ---@return Spell - new = function(id, name) - local self = setmetatable({}, { - __index = Spell - }) - self.id = id - self.name = name - self.isOnCooldown = false - self.announced = false - self.remaining = 0 - return self - end, - - ---@param self Spell - Update = function(self) - local start, duration = GetSpellCooldown(self.id) - local isOnCooldown = start > 0 and duration > 3 - local remaining = start + duration - GetTime() - - if not isOnCooldown and self.isOnCooldown then - self:playComplete() - self.announced = false - end - if not self.announced and isOnCooldown and remaining < 10 then - self:playSoon() - self.announced = true - end - - self.isOnCooldown = isOnCooldown - self.remaining = remaining - end, - - ---@param self Spell - playComplete = function(self) - local soundFile = string.format("Interface\\Sounds\\cooldown\\%s.ogg", self.name) - if aura_env.debug then print(string.format("%s is off cooldown, playing sound file at %s", self.name, soundFile)) end - local success = PlaySoundFile(soundFile, "Master") - if not success then - print(string.format("Failed to play sound for %s", self.name)) - end - end, - - ---@param self Spell - playSoon = function(self) - local soundFile = string.format("Interface\\Sounds\\cooldown\\%sSoon.ogg", self.name) - if aura_env.debug then print(string.format("%s is almost off cooldown, playing sound file at %s", self.name, soundFile)) end - local success = PlaySoundFile(soundFile, "Master") - if not success then - print(string.format("Failed to play sound for %s", self.name)) - end - end -} - -aura_env.spells = { - Spell.new(107574, "Avatar"), - Spell.new(1719, "BattleCry"), - Spell.new(205545, "OdynsFury"), - Spell.new(26297, "Berserking"), - Spell.new(12292, "Bloodbath"), -}