--{{{ Libraries local Aura = AceLibrary("SpecialEvents-Aura-2.0") local Dewdrop = AceLibrary("Dewdrop-2.0") --}}} GridStatusDebuff = GridStatus:NewModule("GridStatusDebuff") GridStatusDebuff.menuName = "Debuff" GridStatusDebuff.defaultDB = { debug = true } local defaultStatus = { ["Debuff type: Poison"] = "debuff_poison", ["Debuff type: Disease"] = "debuff_disease", ["Debuff type: Magic"] = "debuff_magic", ["Debuff type: Curse"] = "debuff_curse", ["Debuff: Weakened Soul"] = "debuff_WeakenedSoul", ["Debuff: Mortal Strike"] = "debuff_MortalStrike", ["Buff: Renew"] = "buff_Renew", ["Buff: Rejuvenation"] = "buff_Rejuventation", ["Buff: Power Word: Shield"] = "buff_PowerWordShield" } function GridStatusDebuff:OnInitialize() self:InitDefaultDB() self.super.OnInitialize(self) local status, statusTbl, desc for status, statusTbl in pairs(self.db.profile) do if type(statusTbl) == "table" and statusTbl.text then desc = statusTbl.desc or statusTbl.text self:Debug("registering", status, desc) self:RegisterStatus(status, desc) end end end function GridStatusDebuff:InitDefaultDB() for name, status in pairs(defaultStatus) do self:CreateDefaults(status, name) end self:CreateDefaultColors() end function GridStatusDebuff:CreateDefaults(status, name) self.defaultDB[status] = { ["text"] = string.gsub(name, "[BD]e?b?uff: ", ""), ["enable"] = true, ["priority"] = 90, ["range"] = true, ["color"] = { r = .5, g = .5, b = .5, a = 1 }, } end function GridStatusDebuff:CreateDefaultColors() self.defaultDB["debuff_poison"]["color"] = { r = 0, g = .6, b = 0, a = 1 } self.defaultDB["debuff_disease"]["color"] = { r = .6, g = .4, b = 0, a = 1 } self.defaultDB["debuff_magic"]["color"] = { r = .2, g = .6, b = 1, a = 1 } self.defaultDB["debuff_curse"]["color"] = { r = .6, g = 0, b = 1, a = 1 } self.defaultDB["debuff_WeakenedSoul"]["color"] = { r = .5, g = .5, b = .5, a = 1 } self.defaultDB["debuff_MortalStrike"]["color"] = { r = .8, g = .2, b = .2, a = 1 } self.defaultDB["buff_Renew"]["color"] = { r = 0, g = .7, b = .3, a = 1 } self.defaultDB["buff_Rejuventation"]["color"] = { r = 0, g = .3, b = .7, a = 1 } self.defaultDB["buff_PowerWordShield"]["color"] = { r = .8, g = .8, b = 0, a = 1 } end function GridStatusDebuff:OnEnable() self:RegisterEvent("SpecialEvents_UnitDebuffGained") self:RegisterEvent("SpecialEvents_UnitDebuffLost") self:RegisterEvent("SpecialEvents_UnitBuffGained") self:RegisterEvent("SpecialEvents_UnitBuffLost") self:RegisterEvent("Grid_UnitDeath") self:CreateAddRemoveOptions() end function GridStatusDebuff:CreateAddRemoveOptions() self.options.args["add_buff"] = { type = "text", name = "Add new Buff", desc = "Adds a new buff to the status module", get = false, usage = "", set = function(v) self:AddBuff("buff_",v) end, order = 201 } self.options.args["add_debuff"] = { type = "text", name = "Add new Debuff", desc = "Adds a new debuff to the status module", get = false, usage = "", set = function(v) self:AddBuff("debuff_",v) end, order = 202 } self.options.args["delete_debuff"] = { type = "group", name = "Delete (De)buff", desc = "Deletes an existing debuff from the status module", args = {}, order = 203 } for status, statusTbl in pairs(self.db.profile) do local status = status if type(statusTbl) == "table" and statusTbl.text and not self.defaultDB[status] then local debuffName = (statusTbl.desc or statusTbl.text) self.options.args["delete_debuff"].args[status] = { type = "execute", name = debuffName, desc = string.format("Remove %s from the menu", debuffName), func = function() return self:DeleteBuff(status) end } end end end function GridStatusDebuff:AddBuff(prefix, name) local status = prefix .. string.gsub(name, "[^%a]", "") local desc if prefix == "debuff_" then desc = "Debuff: "..name else desc = "Buff: "..name end self.db.profile[status] = { ["text"] = name, ["desc"] = desc, ["enable"] = true, ["priority"] = 90, ["range"] = true, ["color"] = { r = .5, g = .5, b = .5, a = 1 }, } self:RegisterStatus(status, desc) self:CreateAddRemoveOptions() end function GridStatusDebuff:DeleteBuff(status) GridStatus:UnregisterStatus(status, name) self.options.args[status] = nil self.options.args["delete_debuff"].args[status] = nil self.db.profile[status] = nil end function GridStatusDebuff:SpecialEvents_UnitDebuffGained(unit, debuff, apps, type, tex) -- check if this is a specific debuff or a debuff type local debuffNameStatus = "debuff_" .. string.gsub(debuff, "[^%a]", "") local debuffTypeStatus = "debuff_" .. strlower(type) self:Debug("gained",debuffNameStatus) local settings = ( self.db.profile[debuffNameStatus] and self.db.profile[debuffNameStatus] ) or self.db.profile[debuffTypeStatus] local status = ( self.db.profile[debuffNameStatus] and debuffNameStatus) or debuffTypeStatus if not (settings and settings.enable) then return end GridStatus:SendStatusGained(UnitName(unit), status, settings.priority, (settings.range and 40), settings.color, settings.text, nil, nil, tex) end function GridStatusDebuff:SpecialEvents_UnitDebuffLost(unit, debuff, apps, type, tex) local debuffNameStatus = "debuff_" .. string.gsub(debuff, "[^%a]", "") local debuffTypeStatus = "debuff_" .. strlower(type) if self.db.profile[debuffNameStatus] then if not Aura:UnitHasDebuff(unit, debuff) then self:Debug("lost", debuffNameStatus) GridStatus:SendStatusLost(UnitName(unit), debuffNameStatus) end else if not Aura:UnitHasDebuffType(unit, type) then self:Debug("lost", debuffTypeStatus) GridStatus:SendStatusLost(UnitName(unit), debuffTypeStatus) end end end function GridStatusDebuff:SpecialEvents_UnitBuffGained(unit, buff, apps, type, tex) local buffNameStatus = "buff_" .. string.gsub(buff, "[^%a]", "") self:Debug("gained",buffNameStatus) local settings = self.db.profile[buffNameStatus] if not (settings and settings.enable) then return end GridStatus:SendStatusGained(UnitName(unit), buffNameStatus, settings.priority, (settings.range and 40), settings.color, settings.text, nil, nil, tex) end function GridStatusDebuff:SpecialEvents_UnitBuffLost(unit, buff, apps, type, tex) local buffNameStatus = "buff_" .. string.gsub(buff, "[^%a]", "") if self.db.profile[buffNameStatus] then if not Aura:UnitHasBuff(unit, buff) then GridStatus:SendStatusLost(UnitName(unit), buffNameStatus) end end end function GridStatusDebuff:Grid_UnitDeath(unitname) local status, statusTbl, desc -- some day we'll be able to ask GridStatus for all the statuses this module -- has registered. until then, here's a dirty hack. for status, statusTbl in pairs(self.db.profile) do if type(statusTbl) == "table" and statusTbl.text then GridStatus:SendStatusLost(unitname, status) end end end