Expand announcer to items and buffs

This commit is contained in:
2024-03-08 15:22:47 +01:00
parent 93b7c7ac65
commit 17dd6e8c6a
4 changed files with 187 additions and 79 deletions

View File

@@ -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<BaseCooldown>|nil
ActiveSet = nil
---@type table<string, table<BaseCooldown>>
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"),
}
}