/trunk
--[[ |
BabySeal |
by Ailae of Emeriss-EU |
]] |
local addon, BabySeal = ... |
BabySeal.prefix = string.format("|cff00aaff%s|r", addon) |
BabySeal.wp = "|cffff0000Warning!|r" |
function BabySeal:PLAYER_LOGIN() |
BabySealDB = BabySealDB or { |
prewarning = true, |
raidwarning = false, |
sound = false, |
} |
db = BabySealDB |
local class = select(2, UnitClass("player")) |
self.spells, self.messages = self:GetData(class) |
if self.spells then |
self:RegisterEvent("PLAYER_REGEN_DISABLED") |
self:RegisterEvent("PLAYER_REGEN_ENABLED") |
local timer = self.frame:CreateAnimationGroup() |
timer:SetLooping("REPEAT") |
local animation = timer:CreateAnimation() |
animation:SetDuration(1) |
animation:SetMaxFramerate(1) |
self.complained = 0 |
local buff, expires |
timer:SetScript("OnLoop", function(t, requested) |
buff, expires = self:Inspect() |
if not buff and self.playerBuff then |
self.playerBuff = false |
self:Complain(self.messages.expired) |
end |
if db.prewarning then |
if expires and expires - GetTime() <= 5 and GetTime() - self.complained > 10 and self.playerBuff then |
self.complained = GetTime() |
self:Complain(self.messages.notify) |
end |
end |
end) |
self.timer = timer |
SLASH_BabySeal1 = "/babyseal" |
SLASH_BabySeal2 = "/bs" |
SlashCmdList.BabySeal = function() |
InterfaceOptionsFrame_OpenToCategory(self.panel) |
end |
end |
end |
function BabySeal:Complain(s) |
if db.raidwarning then |
RaidNotice_AddMessage(RaidWarningFrame, s, ChatTypeInfo["RAID_WARNING"]) |
else |
print(self.wp, s) |
end |
if db.sound then |
PlaySound("RaidWarning") |
end |
end |
function BabySeal:Inspect() |
for k,v in pairs(self.spells) do |
local name, rank, icon, count, dispelType, duration, expires, caster, isStealable = UnitBuff("player", v) |
if name then |
if caster == "player" then |
self.playerBuff = true |
return true, expires |
else |
-- equivalent buff is active, but is not mine |
self.playerBuff = false |
return true, expires |
end |
end |
end |
return false |
end |
-- Warn if entering combat without buff |
function BabySeal:PLAYER_REGEN_DISABLED() |
if not self:Inspect() then |
self.playerBuff = false |
self:Complain(self.messages.combat) |
end |
self.timer:Play() |
end |
function BabySeal:PLAYER_REGEN_ENABLED() |
self.timer:Stop() |
end |
BabySeal.frame = CreateFrame("Frame", nil, UIParent) |
BabySeal.frame:SetScript("OnEvent", function(self, event, ...) return BabySeal[event] and BabySeal[event](BabySeal, ...) end) |
function BabySeal:RegisterEvent(event) return self.frame:RegisterEvent(event) end |
function BabySeal:UnregisterEvent(event) return self.frame:UnregisterEvent(event) end |
BabySeal:RegisterEvent("PLAYER_LOGIN") |
## Interface: 40000 |
## Title: BabySeal |
## Notes: Complains when you lose a class-buff or enter combat without one. |
## Author: Ailae |
## Version: 40000.wowi:revision |
## SavedVariables: BabySealDB |
BabySeal.lua |
Data.lua |
Options.lua |
local _, BabySeal = ... |
local spells = {} |
local spellIDs = { |
PALADIN = { |
31801, -- Seal of Truth |
20164, -- Seal of Justice |
20165, -- Seal of Insight |
20154, -- Seal of Righteousness |
}, |
WARRIOR = { |
6673, -- Battle Shout |
8076, -- Strength of Earth (exclusive with BS) |
57330, -- Horn of Winter (exclusive with BS) |
93435, -- Roar of Courage (exclusive with BS) |
469, -- Commanding Shout |
21562, -- Power Word: Fortitude (exclusive with CS) |
90364, -- Qiraji Fortitude (exclusive with CS) |
}, |
WARLOCK = { |
687, -- Demon Armor |
28176, -- Fel Armor |
}, |
DEATHKNIGHT = { |
57330, -- Horn of Winter |
6673, -- Battle Shout (exclusive with HoW) |
8076, -- Strength of Earth (exclusive with HoW) |
93435, -- Roar of Courage (exclusive with HoW) |
}, |
PRIEST = { |
588, -- Inner Fire |
15286, -- Vampiric Embrace |
}, |
SHAMAN = { |
324, -- Lightning Shield |
52127, -- Water Shield |
}, |
} |
local messages = { |
PALADIN = { |
["combat"] = "No active seal.", |
["expired"] = "Seal expired.", |
["notify"] = "Seal expires soon.", |
}, |
WARRIOR = { |
["combat"] = "No active shout.", |
["expired"] = "Shout expired.", |
["notify"] = "Shout expires soon.", |
}, |
WARLOCK = { |
["combat"] = "No active armor buff.", |
["expired"] = "Armor buff expired.", |
["notify"] = "Armor buff expires soon.", |
}, |
DEATHKNIGHT = { |
["combat"] = "No active horn.", |
["expired"] = "Horn expired.", |
["notify"] = "Horn expires soon.", |
}, |
PRIEST = { |
["combat"] = "Missing armor buff.", |
["expired"] = "Armor buff expired.", |
["notify"] = "Armor buff expires soon.", |
}, |
SHAMAN = { |
["combat"] = "Missing shield.", |
["expired"] = "Shield expired.", |
["notify"] = "Shield expires soon.", |
}, |
} |
-- Only get relevant data |
function BabySeal:GetData(s) |
if not spellIDs[s] then print(self.prefix, "No data available for your class.") end |
for k,v in pairs(spellIDs[s]) do |
local name = GetSpellInfo(v) |
table.insert(spells, name) |
end |
return spells, messages[s] |
end |
--[[ |
BabySealOptions |
by Ailae of Emeriss-EU |
]] |
local addon, BabySeal = ... |
local db |
local title, desc = select(2, GetAddOnInfo(addon)) |
local f = CreateFrame("Frame", nil, InterfaceOptionsFramePanelContainer) |
BabySeal.panel = f |
f.name = title |
f:Hide() |
f:SetScript("OnShow", function(self) |
db = BabySealDB |
-- Header |
local header = self:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge") |
header:SetPoint("TOPLEFT", 16, -16) |
header:SetText(title) |
-- Tagline |
local tag = self:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall") |
tag:SetPoint("TOPLEFT", header, "BOTTOMLEFT", 0, -5) |
tag:SetText(desc) |
-- RaidWarning |
local rw = CreateFrame("CheckButton", "BabySealRaidWarningCheck", f, "InterfaceOptionsCheckButtonTemplate") |
rw:SetChecked(db.raidwarning) |
rw:SetScript("OnClick", function(self) |
db.raidwarning = not db.raidwarning |
end) |
rw:SetPoint("TOPLEFT", tag, "BOTTOMLEFT", 0, -20) |
rw.text = _G[rw:GetName() .. "Text"] |
rw.text:SetText("Print warnings as RaidWarnings") |
rw.tooltipText = "Raidwarning" |
rw.tooltipRequirement = "Toggle to print as RaidWarnings, otherwise it will print to chat (default)." |
-- PreWarning |
local pw = CreateFrame("CheckButton", "BabySealPreWarningCheck", f, "InterfaceOptionsCheckButtonTemplate") |
pw:SetChecked(db.prewarning) |
pw:SetScript("OnClick", function(self) |
db.prewarning = not db.prewarning |
end) |
pw:SetPoint("TOPLEFT", rw, "BOTTOMLEFT", 0, -2) |
pw.text = _G[pw:GetName() .. "Text"] |
pw.text:SetText("Warn in advance (5 seconds)") |
pw.tooltipText = "Warning" |
pw.tooltipRequirement = "Toggle to print a warning in advance." |
-- Sound |
local sound = CreateFrame("CheckButton", "BabySealSoundCheck", f, "InterfaceOptionsCheckButtonTemplate") |
sound:SetChecked(db.sound) |
sound:SetScript("OnClick", function(self) |
db.sound = not db.sound |
end) |
sound:SetPoint("TOPLEFT", pw, "BOTTOMLEFT", 0, -2) |
sound.text = _G[sound:GetName() .. "Text"] |
sound.text:SetText("Play sound on warning") |
sound.tooltipText = "Sound" |
sound.tooltipRequirement = "Toggle to play the RaidWarning sound on warning." |
self:SetScript("OnShow", nil) |
end) |
InterfaceOptions_AddCategory(f) |